added launchStick mechanic

This commit is contained in:
kai ohara 2025-02-10 21:32:12 -05:00
parent 04f731d7cd
commit 1b9efb1987
32 changed files with 102 additions and 1 deletions

View File

@ -3,7 +3,7 @@ plugins {
}
group = 'com.newt-tech'
version = '1.9-RELEASE'
version = '1.10-RELEASE'
repositories {
mavenCentral()

View File

@ -81,6 +81,7 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
// Register commands
this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand());
this.getCommand("getwand").setExecutor(new GiveWandCommand());
getServer().getPluginManager().registerEvents(new LaunchStick(this), this);
@ -98,6 +99,9 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
setScale(player, Float.parseFloat(args[0]));
}
}
if (cmd.getName().equalsIgnoreCase("throw") && sender instanceof Player player) {
player.getInventory().addItem(LaunchStick.createLaunchStick());
}
if (cmd.getName().equalsIgnoreCase("throw") && sender instanceof Player player) {
Player Target = getNearestPlayer(player,10);
if(Target == null) {
@ -414,6 +418,8 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
private void removeMarker(Location loc) {
Location newloc = loc.clone().add(0,1,0);
loc.getBlock().getWorld().playSound(loc,Sound.ITEM_TOTEM_USE,10,0);
loc.getBlock().getWorld().playEffect(loc,Effect.ENDER_DRAGON_DEATH,1);
if (activeAnchors.containsKey(loc)) {
activeAnchors.get(loc).remove();
activeAnchors.remove(loc);

View File

@ -0,0 +1,95 @@
package CoswayUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class LaunchStick implements Listener {
private final CoswayUtil plugin;
private final Set<Player> noFallPlayers = new HashSet<>();
private final double LAUNCH_POWER = 4.0; // Adjust this to change launch strength
public LaunchStick(CoswayUtil plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
// Event handler for right-clicking with the launch stick
@EventHandler
public void onPlayerUseLaunchStick(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack item = player.getInventory().getItemInMainHand();
if (!isLaunchStick(item)) return;
event.setCancelled(true);
// Get the direction the player is looking and apply launch
Vector direction = player.getLocation().getDirection().normalize().multiply(LAUNCH_POWER);
direction.setY(direction.getY() + 0.5); // Add slight upward boost
player.setVelocity(direction);
// Add player to no-fall damage list
noFallPlayers.add(player);
player.sendMessage(ChatColor.GREEN + "You launched yourself forward!");
}
// Prevent fall damage for launched players
@EventHandler
public void onPlayerFallDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player player) {
if (noFallPlayers.contains(player) && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
event.setCancelled(true);
noFallPlayers.remove(player); // Remove player once they hit the ground
}
}
}
// Detect when a player lands on the ground and reset no-fall
@EventHandler
public void onPlayerLand(PlayerMoveEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
if (noFallPlayers.contains(player)) {
if (player.isOnGround()) {
noFallPlayers.remove(player);
}
}
}
// Check if an item is the launch stick
private boolean isLaunchStick(ItemStack item) {
if (item == null || item.getType() != Material.CARROT_ON_A_STICK || !item.hasItemMeta()) return false;
ItemMeta meta = item.getItemMeta();
return meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.LIGHT_PURPLE + "Launch Stick");
}
// Method to create the Launch Stick
public static ItemStack createLaunchStick() {
ItemStack item = new ItemStack(Material.CARROT_ON_A_STICK);
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Launch Stick");
meta.setLore(Collections.singletonList(ChatColor.GOLD + "Click to launch forward"));
meta.addEnchant(Enchantment.UNBREAKING, 1, true);
item.setItemMeta(meta);
}
return item;
}
}