added levetation wand mechanic

This commit is contained in:
kai ohara 2025-02-07 18:34:15 -05:00
parent 3d71110f37
commit 04f731d7cd
33 changed files with 31 additions and 6 deletions

View File

@ -17,3 +17,7 @@ commands:
description: "Gives the player a Gravity Gauntlet"
usage: "/gravitygauntlet"
permission: CoswayUtil.GravityGauntlet
getwand:
description: "Gives player a levitation wand"
usage: "/getwand"
permission: CoswayUtil.wand

View File

@ -70,15 +70,20 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
// Register TotemShield
new TotemShield(this);
// Register the ShadowStep listener
new MobLevitationWand(this);
getServer().getPluginManager().registerEvents(new ShadowStep(this), this);
// Register command
this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand());
//register levitation wand
Bukkit.getPluginManager().registerEvents(new MobLevitationWand(this), this);
// Register the PhantomDodge listener
getServer().getPluginManager().registerEvents(new PhantomDodge(this), this);
// Register the WitherContract listener
getServer().getPluginManager().registerEvents(new WitherContract(this), this);
Bukkit.getPluginManager().registerEvents(new MobLevitationWand(this), this);
// Register commands
this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand());
this.getCommand("getwand").setExecutor(new GiveWandCommand());
}
@Override

View File

@ -4,6 +4,8 @@ import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -15,7 +17,7 @@ import java.util.HashMap;
import java.util.UUID;
public class MobLevitationWand implements Listener {
private final NamespacedKey wandKey = new NamespacedKey("your_plugin", "levitation_wand");
private final NamespacedKey wandKey = new NamespacedKey("coswayutil", "levitation_wand");
private final HashMap<UUID, Entity> levitatedMobs = new HashMap<>();
private final CoswayUtil plugin;
@ -53,6 +55,7 @@ public class MobLevitationWand implements Listener {
}
}
private boolean isLevitationWand(ItemStack item) {
if (item == null || item.getType() != Material.STICK || !item.hasItemMeta()) return false;
ItemMeta meta = item.getItemMeta();
@ -78,6 +81,18 @@ public class MobLevitationWand implements Listener {
Vector direction = player.getLocation().getDirection().normalize().multiply(5);
Location newLocation = player.getLocation().add(direction);
World world = player.getWorld();
// Ensure the mob is not placed inside a solid block
while (newLocation.getBlock().getType().isSolid()) {
newLocation.add(0, 1, 0); // Move up until a free space is found
}
// Ensure the mob is not underground
int highestY = world.getHighestBlockYAt(newLocation);
if (newLocation.getY() < highestY) {
newLocation.setY(highestY + 1); // Adjust to be above ground
}
entity.teleport(newLocation);
@ -92,6 +107,7 @@ public class MobLevitationWand implements Listener {
}.runTaskTimer(plugin, 0L, 2L);
}
private void releaseMob(Player player) {
Entity entity = levitatedMobs.remove(player.getUniqueId());
if (entity != null) {
@ -104,7 +120,7 @@ public class MobLevitationWand implements Listener {
ItemStack wand = new ItemStack(Material.STICK);
ItemMeta meta = wand.getItemMeta();
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Levitation Wand");
meta.getPersistentDataContainer().set(new NamespacedKey("CoswayUtil", "levitation_wand"), PersistentDataType.STRING, "true");
meta.getPersistentDataContainer().set(new NamespacedKey("coswayutil", "levitation_wand"), PersistentDataType.STRING, "true");
wand.setItemMeta(meta);
return wand;
}