diff --git a/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java b/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java index f8e060b..fdc2b73 100644 --- a/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java +++ b/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java @@ -3,9 +3,11 @@ package dev.zxq5.fantasysmp; import dev.zxq5.fantasysmp.events.HereticWarner; import dev.zxq5.fantasysmp.events.StevenKillCheck; import dev.zxq5.fantasysmp.items.*; +import dev.zxq5.fantasysmp.items.gear.LightningSword; +import dev.zxq5.fantasysmp.items.gear.StevensWrath; +import dev.zxq5.fantasysmp.items.gear.WitheriteGear; import dev.zxq5.fantasysmp.warps.Warp; import dev.zxq5.fantasysmp.warps.Warper; -import org.bukkit.entity.Panda; import org.bukkit.plugin.java.JavaPlugin; public final class Fantasysmp extends JavaPlugin { @@ -33,15 +35,6 @@ public final class Fantasysmp extends JavaPlugin { getServer().broadcastMessage("registered commands + \n /home \n /sethome \n /warp \n /setwarp"); - GenericGearSet witherite = new Witherite(); - witherite.registerRecipes(); - - Lightning lightning = new Lightning(); - lightning.registerRecipes(); - - StevensWrath stevensWrath = new StevensWrath(); - stevensWrath.registerRecipes(); - getServer().getPluginManager().registerEvents(new StevenKillCheck(), this); HereticWarner hereticWarner = new HereticWarner(); diff --git a/src/main/java/dev/zxq5/fantasysmp/items/Food.java b/src/main/java/dev/zxq5/fantasysmp/items/Food.java new file mode 100644 index 0000000..b88474e --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/Food.java @@ -0,0 +1,4 @@ +package dev.zxq5.fantasysmp.items; + +public class Food { +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java b/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java index 144dcb7..32baa68 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java @@ -1,22 +1,22 @@ package dev.zxq5.fantasysmp.items; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.entity.Item; -import org.bukkit.inventory.EquipmentSlotGroup; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.RecipeChoice; +import org.bukkit.event.Listener; +import org.bukkit.inventory.*; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.components.EquippableComponent; +import org.bukkit.plugin.Plugin; import java.util.ArrayList; import java.util.List; import java.util.UUID; -public abstract class GenericGearSet implements HasRecipes { +public abstract class GenericGearSet implements HasRecipes, Listener { protected ItemStats sword = new ItemStats(); protected ItemStats helmet = new ItemStats(); @@ -27,6 +27,10 @@ public abstract class GenericGearSet implements HasRecipes { protected static RecipeChoice NETHERITE_UPGRADE = new RecipeChoice.MaterialChoice(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE); protected static RecipeChoice WITHER_SKULL = new RecipeChoice.MaterialChoice(Material.WITHER_SKELETON_SKULL); + public void registerEvents(Plugin plugin) { + Bukkit.getServer().getPluginManager().registerEvents(this, plugin); + } + public void setTier1() { sword.setMaterial(Material.WOODEN_SWORD); helmet.setMaterial(Material.LEATHER_HELMET); @@ -143,13 +147,13 @@ public abstract class GenericGearSet implements HasRecipes { meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); meta.setDisplayName(sword.name); - if (!sword.customModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + sword.customModel)); + if (!sword.customItemModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + sword.customItemModel)); ArrayList lore = new ArrayList<>(List.of(sword.lore)); lore.add("\n"); lore.add(ChatColor.GRAY + "When in Main Hand:" + ChatColor.RESET); - if (sword.attackDamage > 0) lore.add(ChatColor.GREEN + " " + sword.attackDamage + " Attack Damage" + ChatColor.RESET); - if (sword.attackSpeed > 0) lore.add(ChatColor.GREEN + " " + sword.attackSpeed + " Attack Speed" + ChatColor.RESET); + if (sword.attackDamage > 0) lore.add(ChatColor.GREEN + String.format(" %.1f Attack Damage", sword.attackDamage) + ChatColor.RESET); + if (sword.attackSpeed > 0) lore.add(ChatColor.GREEN + String.format(" %.1f Attack Speed", sword.attackSpeed) + ChatColor.RESET); meta.setLore(lore); item.setItemMeta(meta); @@ -163,6 +167,7 @@ public abstract class GenericGearSet implements HasRecipes { meta.setDisplayName(helmet.name); meta.setLore(new ArrayList<>(List.of(helmet.lore))); + meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier( UUID.randomUUID(), "armour", @@ -188,7 +193,11 @@ public abstract class GenericGearSet implements HasRecipes { EquipmentSlotGroup.HEAD )); } - if (!helmet.customModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + helmet.customModel)); + if (!helmet.customItemModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + helmet.customItemModel)); + EquippableComponent equippable = meta.getEquippable(); + equippable.setModel(NamespacedKey.fromString("fantasysmp:" + helmet.customEquipmentModel)); + equippable.setSlot(EquipmentSlot.HEAD); + meta.setEquippable(equippable); item.setItemMeta(meta); return item; @@ -227,7 +236,11 @@ public abstract class GenericGearSet implements HasRecipes { )); } - if (!chestplate.customModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + chestplate.customModel)); + if (!chestplate.customItemModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + chestplate.customItemModel)); + EquippableComponent equippable = meta.getEquippable(); + equippable.setModel(NamespacedKey.fromString("fantasysmp:" + chestplate.customEquipmentModel)); + equippable.setSlot(EquipmentSlot.CHEST); + meta.setEquippable(equippable); item.setItemMeta(meta); return item; @@ -266,7 +279,12 @@ public abstract class GenericGearSet implements HasRecipes { )); } - if (!leggings.customModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + leggings.customModel)); + if (!leggings.customItemModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + leggings.customItemModel)); + EquippableComponent equippable = meta.getEquippable(); + equippable.setModel(NamespacedKey.fromString("fantasysmp:" + leggings.customEquipmentModel)); + equippable.setSlot(EquipmentSlot.LEGS); + meta.setEquippable(equippable); + item.setItemMeta(meta); return item; } @@ -304,42 +322,17 @@ public abstract class GenericGearSet implements HasRecipes { )); } - if (!boots.customModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + boots.customModel)); + if (!boots.customItemModel.isEmpty()) meta.setItemModel(NamespacedKey.fromString("fantasysmp:" + boots.customItemModel)); + EquippableComponent equippable = meta.getEquippable(); + equippable.setModel(NamespacedKey.fromString("fantasysmp:" + boots.customEquipmentModel)); + equippable.setSlot(EquipmentSlot.FEET); + meta.setEquippable(equippable); + item.setItemMeta(meta); return item; } } -class ItemStats { - public double attackDamage; - public double attackSpeed; - public int durability; - public int armour; - public int armourToughness; - public double knockbackResistance ; - public String name; - public String lore; - public String customModel; - public ItemStack material; - - public ItemStats() { - this.attackDamage = 0; - this.attackSpeed = 0; - this.durability = 0; - this.armour = 0; - this.armourToughness = 0; - this.knockbackResistance = 0; - this.name = ""; - this.lore = ""; - this.customModel = ""; - this.material = new ItemStack(Material.AIR); - } - - public void setMaterial(Material material) { - this.material = new ItemStack(material); - } -} - diff --git a/src/main/java/dev/zxq5/fantasysmp/items/ItemStats.java b/src/main/java/dev/zxq5/fantasysmp/items/ItemStats.java new file mode 100644 index 0000000..5acb73a --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/ItemStats.java @@ -0,0 +1,36 @@ +package dev.zxq5.fantasysmp.items; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class ItemStats { + public double attackDamage; + public double attackSpeed; + public int durability; + public int armour; + public int armourToughness; + public double knockbackResistance ; + public String name; + public String lore; + public String customItemModel; + public String customEquipmentModel; + public ItemStack material; + + public ItemStats() { + this.attackDamage = 0; + this.attackSpeed = 0; + this.durability = 0; + this.armour = 0; + this.armourToughness = 0; + this.knockbackResistance = 0; + this.name = ""; + this.lore = ""; + this.customItemModel = ""; + this.customEquipmentModel = ""; + this.material = new ItemStack(Material.AIR); + } + + public void setMaterial(Material material) { + this.material = new ItemStack(material); + } +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/Items.java b/src/main/java/dev/zxq5/fantasysmp/items/Items.java index 0066e7d..9e7badd 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/Items.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/Items.java @@ -1,11 +1,8 @@ package dev.zxq5.fantasysmp.items; -import org.bukkit.Bukkit; -import org.bukkit.block.data.type.Light; +import dev.zxq5.fantasysmp.items.gear.*; import org.bukkit.command.CommandExecutor; import org.bukkit.entity.Player; -import org.bukkit.entity.Wither; -import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import static org.bukkit.Bukkit.getServer; @@ -36,7 +33,12 @@ public class Items implements CommandExecutor { CommandExecutor handler; switch (args[0]) { - case "witherite" -> handler = new Witherite(); + case "witherite" -> handler = new WitheriteGear(); + case "lightning" -> handler = new LightningSword(); + case "steven" -> handler = new StevensWrath(); + case "blazing" -> handler = new BlazingGear(); + case "dragon" -> handler = new DragonGear(); + case "trueneth" -> handler = new TrueNetheriteGear(); default -> { return false; } } @@ -46,10 +48,29 @@ public class Items implements CommandExecutor { } public Items(JavaPlugin plugin) { - Witherite.init(); - Lightning.init(); - getServer().getPluginManager().registerEvents(new Witherite(), plugin); - getServer().getPluginManager().registerEvents(new Lightning(), plugin); - getServer().getPluginManager().registerEvents(new StevensWrath(), plugin); + + WitheriteGear witherite = new WitheriteGear(); + witherite.registerRecipes(); + witherite.registerEvents(plugin); + + LightningSword lightning = new LightningSword(); + lightning.registerRecipes(); + lightning.registerEvents(plugin); + + StevensWrath stevensWrath = new StevensWrath(); + stevensWrath.registerRecipes(); + stevensWrath.registerEvents(plugin); + + BlazingGear blazing = new BlazingGear(); + blazing.registerRecipes(); + blazing.registerEvents(plugin); + + DragonGear dragon = new DragonGear(); + dragon.registerRecipes(); + dragon.registerEvents(plugin); + + TrueNetheriteGear trueNetherite = new TrueNetheriteGear(); + trueNetherite.registerRecipes(); + trueNetherite.registerEvents(plugin); } } diff --git a/src/main/java/dev/zxq5/fantasysmp/items/food/GenericDrink.java b/src/main/java/dev/zxq5/fantasysmp/items/food/GenericDrink.java new file mode 100644 index 0000000..2ca88f1 --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/food/GenericDrink.java @@ -0,0 +1,40 @@ +package dev.zxq5.fantasysmp.items.food; + +import dev.zxq5.fantasysmp.items.HasRecipes; +import org.bukkit.Material; +import org.bukkit.command.CommandExecutor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; + +import java.util.ArrayList; +import java.util.List; + +public abstract class GenericDrink implements Listener, CommandExecutor, HasRecipes { + public String name; + public String lore; + + @EventHandler + public abstract void itemCraftingHandler(org.bukkit.event.inventory.PrepareItemCraftEvent event); + + @Override + public abstract boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args); + + public abstract void registerRecipes(); + + public ItemStack getDrink() { + ItemStack item = new ItemStack(Material.POTION, 1); + + PotionMeta pm = (PotionMeta) item.getItemMeta(); + pm.setBasePotionType(org.bukkit.potion.PotionType.WATER); + + List lore = new ArrayList<>(); + lore.add(this.lore); + pm.setLore(lore); + pm.setDisplayName(this.name); + item.setItemMeta(pm); + return item; + } + +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/gear/BlazingGear.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/BlazingGear.java new file mode 100644 index 0000000..88283a8 --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/BlazingGear.java @@ -0,0 +1,130 @@ +package dev.zxq5.fantasysmp.items.gear; + +import dev.zxq5.fantasysmp.items.GenericGearSet; +import dev.zxq5.fantasysmp.util.LoreChecker; +import org.bukkit.*; +import org.bukkit.command.CommandExecutor; +import org.bukkit.damage.DamageType; +import org.bukkit.entity.Fireball; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.SmallFireball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; +import org.bukkit.inventory.SmithingTransformRecipe; +import org.bukkit.plugin.Plugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.Objects; + +import static org.bukkit.Bukkit.*; + +public class BlazingGear extends GenericGearSet implements Listener, CommandExecutor { + private ArrayList cooldown = new ArrayList<>(); + + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + Player player = (Player) sender; + player.getInventory().addItem(this.getSword()); + player.getInventory().addItem(this.getHelmet()); + player.getInventory().addItem(this.getChestplate()); + player.getInventory().addItem(this.getLeggings()); + player.getInventory().addItem(this.getBoots()); + + return true; + } + + @Override + public void registerRecipes() {} + + @EventHandler + public void onPlayerSetOnFire(org.bukkit.event.entity.EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player player)) return; + + if (!(LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore))) return; + if (!(LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore))) return; + if (!(LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore))) return; + if (!(LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore))) return; + + if (event.getDamageSource().getDamageType() == DamageType.ON_FIRE) event.setCancelled(true); + if (event.getDamageSource().getDamageType() == DamageType.IN_FIRE) event.setCancelled(true); + if (event.getDamageSource().getDamageType() == DamageType.LAVA) event.setCancelled(true); + + player.setFireTicks(0); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { + return; + } + + if (!(LoreChecker.itemLoreContains(item, this.sword.lore))) return; + if (cooldown.contains(player)) return; + + Plugin plugin = getPluginManager().getPlugin("fantasysmp"); + + cooldown.add(player); + Bukkit.getScheduler().runTaskLater(plugin, () -> cooldown.remove(player), 25); + + shootFireball(player); + Bukkit.getScheduler().runTaskLater(plugin, () -> shootFireball(player), 4); + Bukkit.getScheduler().runTaskLater(plugin, () -> shootFireball(player), 8); + } + + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player player)) return; + if (!(LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore))) return; + if (event.getEntity().getFireTicks() < 240) event.getEntity().setFireTicks(240); + } + + public void shootFireball(Player player) { + Location location = player.getLocation(); + World world = player.getWorld(); + player.launchProjectile(SmallFireball.class); + player.playSound(location, Sound.ENTITY_BLAZE_SHOOT, 1.0f, 1.0f); + world.spawnParticle(Particle.FLAME, location, 1); + } + + public static void init() {} + + public BlazingGear() { + this.setTier4(); + this.sword.name = "Blazing Sword"; + this.sword.customItemModel = "blazing_sword"; + + this.helmet.name = "Blazing Helmet"; + this.helmet.customItemModel = "blazing_helmet"; + this.helmet.customEquipmentModel = "blazing"; + + this.chestplate.name = "Blazing Chestplate"; + this.chestplate.customItemModel = "blazing_chestplate"; + this.chestplate.customEquipmentModel = "blazing"; + + this.leggings.name = "Blazing Leggings"; + this.leggings.customItemModel = "blazing_leggings"; + this.leggings.customEquipmentModel = "blazing"; + + this.boots.name = "Blazing Boots"; + this.boots.customItemModel = "blazing_boots"; + this.boots.customEquipmentModel = "blazing"; + + this.sword.lore = "Forged from molten lava and the essence of blazes"; + this.helmet.lore = "Forged from molten lava and the essence of blazes"; + this.chestplate.lore = "Forged from molten lava and the essence of blazes"; + this.leggings.lore = "Forged from molten lava and the essence of blazes"; + this.boots.lore = "Forged from molten lava and the essence of blazes"; + } +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/gear/DragonGear.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/DragonGear.java new file mode 100644 index 0000000..3bf4762 --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/DragonGear.java @@ -0,0 +1,142 @@ +package dev.zxq5.fantasysmp.items.gear; + +import dev.zxq5.fantasysmp.items.GenericGearSet; +import dev.zxq5.fantasysmp.items.ItemStats; +import dev.zxq5.fantasysmp.util.LoreChecker; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; +import org.bukkit.command.CommandExecutor; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.components.EquippableComponent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +import static org.bukkit.Bukkit.getServer; + +public class DragonGear extends GenericGearSet implements Listener, CommandExecutor { + private ArrayList cooldown = new ArrayList<>(); + + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + Player player = (Player) sender; + player.getInventory().addItem(this.getSword()); + player.getInventory().addItem(this.getHelmet()); + player.getInventory().addItem(this.getChestplate()); + player.getInventory().addItem(this.getLeggings()); + player.getInventory().addItem(this.getBoots()); + + return true; + } + + @Override + public void registerRecipes() {} + + @EventHandler + public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) { + if (event.getEntity() instanceof Player player) { + if (event.getNewEffect() == null) return; + + if (event.getNewEffect().getType() != PotionEffectType.LEVITATION) { + return; + } + + try { + if (LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore) + && LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore) + && LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore) + && LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore) + ) { + event.setCancelled(true); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { + return; + } + + if (!(LoreChecker.itemLoreContains(item, this.sword.lore))) return; + if (cooldown.contains(player)) return; + + Location location = player.getLocation(); + Vector direction = location.getDirection(); + player.setVelocity(direction.multiply(2.0)); + player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f); + World world = player.getWorld(); + world.spawnParticle(Particle.PORTAL, location, 1); + + cooldown.add(player); + Bukkit.getScheduler().scheduleSyncDelayedTask( + Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")), + () -> cooldown.remove(player), + 25 + ); + } + + @Override + public ItemStack getHelmet() { +// helmet.setMaterial(Material.DRAGON_HEAD); + return super.getHelmet(); + } + + @Override + public ItemStack getChestplate() { + chestplate.setMaterial(Material.ELYTRA); + ItemStack item = super.getChestplate(); + item.addUnsafeEnchantment(Enchantment.PROTECTION, 4); + return item; + } + + public static void init() {} + + public DragonGear() { + this.setTier5(); + this.sword.name = "Dragon Sword"; + this.sword.customItemModel = "dragon_sword"; + + this.helmet.name = "Dragon Helmet"; + this.helmet.customItemModel = "dragon_helmet"; + this.helmet.customEquipmentModel = "dragon"; + + this.chestplate.name = "Dragon Chestplate"; + this.chestplate.customItemModel = "dragon_chestplate"; + this.chestplate.customEquipmentModel = "dragon"; + + this.leggings.name = "Dragon Leggings"; + this.leggings.customItemModel = "dragon_leggings"; + this.leggings.customEquipmentModel = "dragon"; + + this.boots.name = "Dragon Boots"; + this.boots.customItemModel = "dragon_boots"; + this.boots.customEquipmentModel = "dragon"; + + this.sword.lore = "A blade forged from dragon scales and chorus fruit"; + this.helmet.lore = "Forged from dragon scales and chorus fruit"; + this.chestplate.lore = "Forged from dragon scales and chorus fruit"; + this.leggings.lore = "Forged from dragon scales and chorus fruit"; + this.boots.lore = "Forged from dragon scales and chorus fruit"; + } +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/Lightning.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/LightningSword.java similarity index 74% rename from src/main/java/dev/zxq5/fantasysmp/items/Lightning.java rename to src/main/java/dev/zxq5/fantasysmp/items/gear/LightningSword.java index d797980..194de83 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/Lightning.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/LightningSword.java @@ -1,38 +1,27 @@ -package dev.zxq5.fantasysmp.items; +package dev.zxq5.fantasysmp.items.gear; +import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.util.LoreChecker; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.command.CommandExecutor; -import org.bukkit.entity.LightningStrike; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.List; - -import static org.bukkit.Bukkit.broadcastMessage; import static org.bukkit.Bukkit.getServer; -public class Lightning extends GenericGearSet implements Listener, CommandExecutor { +public class LightningSword extends GenericGearSet implements Listener, CommandExecutor { @Override public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { - if (!(args[0].equals("lightning"))) { - return false; - } - Player player = (Player) sender; - - player.getInventory().addItem(new Lightning().getSword()); + player.getInventory().addItem(this.getSword()); return true; } @@ -77,7 +66,6 @@ public class Lightning extends GenericGearSet implements Listener, CommandExecut @EventHandler public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event) { if (event.getEntity() instanceof Player player) { - if (!(event .getDamageSource() .getDamageType() @@ -88,16 +76,30 @@ public class Lightning extends GenericGearSet implements Listener, CommandExecut if (LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore)) { event.setCancelled(true); + return; + } + } + } + + @EventHandler + public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event) { + if (event.getEntity() instanceof Mob mob) { + if ( + event.getDamageSource().getDamageType().getKey().toString().equals("minecraft:lightning_bolt") + || event.getDamageSource().getDamageType().getKey().toString().equals("minecraft:on_fire") + ) { + Entity e = event.getEntity(); + ((ExperienceOrb) e.getLocation().getWorld().spawn(e.getLocation(), ExperienceOrb.class)).setExperience(10); } } } public static void init() {} - public Lightning() { + public LightningSword() { this.setTier5(); this.sword.name = "Lightning Sword"; - this.sword.customModel = "lightning_sword"; + this.sword.customItemModel = "lightning_sword"; this.sword.lore = "All who oppose shall be smitten."; } } diff --git a/src/main/java/dev/zxq5/fantasysmp/items/StevensWrath.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/StevensWrath.java similarity index 76% rename from src/main/java/dev/zxq5/fantasysmp/items/StevensWrath.java rename to src/main/java/dev/zxq5/fantasysmp/items/gear/StevensWrath.java index b044eed..3369a31 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/StevensWrath.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/StevensWrath.java @@ -1,43 +1,26 @@ -package dev.zxq5.fantasysmp.items; +package dev.zxq5.fantasysmp.items.gear; +import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.util.LoreChecker; import org.bukkit.*; import org.bukkit.command.CommandExecutor; -import org.bukkit.entity.LightningStrike; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ShapedRecipe; -import org.bukkit.inventory.ShapelessRecipe; -import org.bukkit.inventory.SmithingTransformRecipe; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.potion.PotionEffect; - -import java.util.List; - -import static org.bukkit.Bukkit.broadcastMessage; -import static org.bukkit.Bukkit.getServer; public class StevensWrath extends GenericGearSet implements Listener, CommandExecutor { @Override public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { - if (!(args[0].equals("wrath"))) { - return false; - } - Player player = (Player) sender; - - player.getInventory().addItem(new StevensWrath().getSword()); + player.getInventory().addItem(this.getSword()); return true; } @EventHandler public void onCraft(org.bukkit.event.inventory.PrepareItemCraftEvent event) { if (!event.getInventory().contains(Material.NETHERITE_BLOCK)) return; - if (!event.getInventory().contains(new Lightning().getSword())) return; + if (!event.getInventory().contains(new LightningSword().getSword())) return; event.getInventory().setResult(new StevensWrath().getSword()); } @@ -89,7 +72,7 @@ public class StevensWrath extends GenericGearSet implements Listener, CommandExe public StevensWrath() { this.setTier6(); this.sword.name = ChatColor.LIGHT_PURPLE + "Stevens Wrath" + ChatColor.RESET; - this.sword.customModel = "stevens_wrath"; + this.sword.customItemModel = "stevens_wrath"; this.sword.lore = ChatColor.LIGHT_PURPLE + "All who oppose the mighty Steven shall face his wrath of lightning."; } } diff --git a/src/main/java/dev/zxq5/fantasysmp/items/gear/TrueNetheriteGear.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/TrueNetheriteGear.java new file mode 100644 index 0000000..b2f31ea --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/TrueNetheriteGear.java @@ -0,0 +1,22 @@ +package dev.zxq5.fantasysmp.items.gear; + +import dev.zxq5.fantasysmp.items.GenericGearSet; +import org.bukkit.command.CommandExecutor; +import org.bukkit.event.Listener; + +public class TrueNetheriteGear extends GenericGearSet implements CommandExecutor, Listener { + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + return false; + } + + @Override + public void registerRecipes() {} + + public TrueNetheriteGear() { + this.setTier6(); + this.sword.name = "True Netherite Sword"; + this.sword.customItemModel = "true_netherite_sword"; + this.sword.lore = "Destruction awaits."; + } +} diff --git a/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java b/src/main/java/dev/zxq5/fantasysmp/items/gear/WitheriteGear.java similarity index 69% rename from src/main/java/dev/zxq5/fantasysmp/items/Witherite.java rename to src/main/java/dev/zxq5/fantasysmp/items/gear/WitheriteGear.java index 2aa5d67..0e03f95 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/gear/WitheriteGear.java @@ -1,38 +1,38 @@ -package dev.zxq5.fantasysmp.items; +package dev.zxq5.fantasysmp.items.gear; +import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.util.LoreChecker; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; +import org.bukkit.*; import org.bukkit.command.CommandExecutor; +import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.WitherSkull; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.SmithingTransformRecipe; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.components.CustomModelDataComponent; -import org.bukkit.inventory.meta.components.EquippableComponent; import org.bukkit.potion.PotionEffect; +import java.util.ArrayList; +import java.util.Objects; + import static org.bukkit.Bukkit.getServer; -public class Witherite extends GenericGearSet implements Listener, CommandExecutor { +public class WitheriteGear extends GenericGearSet implements Listener, CommandExecutor { + private ArrayList cooldown = new ArrayList<>(); @Override public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { - if (!(args[0].equals("witherite"))) { - return false; - } - Player player = (Player) sender; - - player.getInventory().addItem(new Witherite().getSword()); - player.getInventory().addItem(new Witherite().getHelmet()); - player.getInventory().addItem(new Witherite().getChestplate()); - player.getInventory().addItem(new Witherite().getLeggings()); - player.getInventory().addItem(new Witherite().getBoots()); + player.getInventory().addItem(this.getSword()); + player.getInventory().addItem(this.getHelmet()); + player.getInventory().addItem(this.getChestplate()); + player.getInventory().addItem(this.getLeggings()); + player.getInventory().addItem(this.getBoots()); return true; } @@ -91,6 +91,32 @@ public class Witherite extends GenericGearSet implements Listener, CommandExecut } + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { + return; + } + + if (!(LoreChecker.itemLoreContains(item, this.sword.lore))) return; + if (cooldown.contains(player)) return; + + Location location = player.getLocation(); + player.launchProjectile(WitherSkull.class); + player.playSound(location, Sound.ENTITY_WITHER_SHOOT, 1.0f, 1.0f); + World world = player.getWorld(); + world.spawnParticle(Particle.SOUL_FIRE_FLAME, location, 1); + + cooldown.add(player); + Bukkit.getScheduler().scheduleSyncDelayedTask( + Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")), + () -> cooldown.remove(player), + 25 + ); + } + @EventHandler public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) { if (event.getEntity() instanceof Player player) { @@ -116,18 +142,26 @@ public class Witherite extends GenericGearSet implements Listener, CommandExecut public static void init() {} - public Witherite() { + public WitheriteGear() { this.setTier5(); this.sword.name = "Witherite Sword"; - this.sword.customModel = "witherite_sword"; + this.sword.customItemModel = "witherite_sword"; + this.helmet.name = "Witherite Helmet"; - this.helmet.customModel = "witherite_helmet"; + this.helmet.customItemModel = "witherite_helmet"; + this.helmet.customEquipmentModel = "witherite"; + this.chestplate.name = "Witherite Chestplate"; - this.chestplate.customModel = "witherite_chestplate"; + this.chestplate.customItemModel = "witherite_chestplate"; + this.chestplate.customEquipmentModel = "witherite"; + this.leggings.name = "Witherite Leggings"; - this.leggings.customModel = "witherite_leggings"; + this.leggings.customItemModel = "witherite_leggings"; + this.leggings.customEquipmentModel = "witherite"; + this.boots.name = "Witherite Boots"; - this.boots.customModel = "witherite_boots"; + this.boots.customItemModel = "witherite_boots"; + this.boots.customEquipmentModel = "witherite"; this.sword.lore = "A sword forged with the skulls of wither skeletons."; this.helmet.lore = "A helmet forged with the skulls of wither skeletons."; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2d73bfc..40b96b0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -39,12 +39,6 @@ commands: permissions: - fantasysmp.admin: - description: Manage plugin - default: op - children: - fantasysmp.*: true - fantasysmp.items: description: create custom items from plugin default: false @@ -59,4 +53,14 @@ permissions: fantasysmp.home: description: commands for teleporting home - default: true \ No newline at end of file + default: true + + fantasysmp.admin: + description: Manage plugin + default: op + children: + fantasysmp.items: true + fantasysmp.manage_warps: true + fantasysmp.home: true + fantasysmp.warps: true +