diff --git a/pom.xml b/pom.xml index d7656d4..f5cce2c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.zxq5 fantasysmp - 1.1-SNAPSHOT + 2.2-SNAPSHOT jar fantasysmp diff --git a/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java b/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java index 268c19a..2f80d8e 100644 --- a/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java +++ b/src/main/java/dev/zxq5/fantasysmp/Fantasysmp.java @@ -1,5 +1,6 @@ package dev.zxq5.fantasysmp; +import dev.zxq5.fantasysmp.events.HereticWarner; import dev.zxq5.fantasysmp.events.StevenKillCheck; import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.Items; @@ -37,6 +38,10 @@ public final class Fantasysmp extends JavaPlugin { witherite.registerRecipes(); getServer().getPluginManager().registerEvents(new StevenKillCheck(), this); + + HereticWarner hereticWarner = new HereticWarner(); + hereticWarner.checkHereticInventory(); + } @Override diff --git a/src/main/java/dev/zxq5/fantasysmp/events/HereticWarner.java b/src/main/java/dev/zxq5/fantasysmp/events/HereticWarner.java new file mode 100644 index 0000000..5b4ac0f --- /dev/null +++ b/src/main/java/dev/zxq5/fantasysmp/events/HereticWarner.java @@ -0,0 +1,40 @@ +package dev.zxq5.fantasysmp.events; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import static org.bukkit.Bukkit.getPluginManager; + +public class HereticWarner { + int task; + + public void checkHereticInventory() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(getPluginManager().getPlugin("fantasysmp"), () -> { + for ( Player heretic : Bukkit.getServer().getOnlinePlayers() ) { + if (heretic.getInventory().contains(Material.CHICKEN) || heretic.getInventory().contains(Material.COOKED_CHICKEN)) { + warnHeretic(heretic); + } + } + }, 0, 20); + } + + public void warnHeretic(Player heretic) { + // apply poison to player + heretic.sendMessage(ChatColor.DARK_RED + "HOLDING CHICKEN IS HERESY!"); + heretic.sendMessage(ChatColor.DARK_RED + "DROP IT IMMEDIATELY!"); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20 * 2, 10)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 20 * 2, 10)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.MINING_FATIGUE, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.DARKNESS, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.NAUSEA, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 2, 3)); + heretic.addPotionEffect(new PotionEffect(PotionEffectType.INSTANT_DAMAGE, 20 * 2, 0)); + } +} \ No newline at end of file diff --git a/src/main/java/dev/zxq5/fantasysmp/events/StevenKillCheck.java b/src/main/java/dev/zxq5/fantasysmp/events/StevenKillCheck.java index e6d5ac2..4f3ec41 100644 --- a/src/main/java/dev/zxq5/fantasysmp/events/StevenKillCheck.java +++ b/src/main/java/dev/zxq5/fantasysmp/events/StevenKillCheck.java @@ -2,6 +2,7 @@ package dev.zxq5.fantasysmp.events; import org.bukkit.*; import org.bukkit.entity.Chicken; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Wither; import org.bukkit.event.EventHandler; @@ -10,6 +11,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.plugin.Plugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; import static org.bukkit.Bukkit.*; @@ -30,12 +34,19 @@ public class StevenKillCheck implements Listener { public void onEntityDamage(EntityDamageEvent event) { if (event.getEntity() instanceof Chicken) { event.setCancelled(true); + + if ( event.getDamageSource().getCausingEntity() instanceof Player player) { + destroyHeretic(player); + } } } @EventHandler public void onProjectileHit(ProjectileHitEvent event) { if (event.getHitEntity() instanceof Chicken && event.getEntity().getShooter() instanceof Player player) { + if (event.getEntity().getType() == EntityType.EGG) return; + if (event.getEntity().getType() == EntityType.SNOWBALL) return; + event.setCancelled(true); destroyHeretic(player); } @@ -67,3 +78,4 @@ public class StevenKillCheck implements Listener { Bukkit.getScheduler().runTaskLater(plugin, () -> heretic.setHealth(0), 10); } } + diff --git a/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java b/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java index c1dfdcb..69dfd38 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/GenericGearSet.java @@ -1,16 +1,19 @@ package dev.zxq5.fantasysmp.items; +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.inventory.EquipmentSlotGroup; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public abstract class GenericGearSet implements HasRecipes { protected int swordAttackDamage = 0; @@ -21,24 +24,28 @@ public abstract class GenericGearSet implements HasRecipes { protected int helmetArmour = 0; protected int helmetArmourToughness = 0; + protected double helmetKnockbackResistance = 0; protected int helmetDurability = 0; protected String helmetName = "leather cap"; protected String helmetLore = ""; protected int chestplateArmour = 0; protected int chestplateArmourToughness = 0; + protected double chestplateKnockbackResistance = 0; protected int chestplateDurability = 0; protected String chestplateName = "leather tunic"; protected String chestplateLore = ""; protected int leggingsArmour = 0; protected int leggingsArmourToughness = 0; + protected double leggingsKnockbackResistance = 0; protected int leggingsDurability = 0; protected String leggingsName = "leather pants"; protected String leggingsLore = ""; protected int bootsArmour = 0; protected int bootsArmourToughness = 0; + protected double bootsKnockbackResistance = 0; protected int bootsDurability = 0; protected String bootsName = "leather boots"; protected String bootsLore = ""; @@ -108,12 +115,16 @@ public abstract class GenericGearSet implements HasRecipes { swordAttackSpeed = 1.6f; helmetArmour = 3; helmetArmourToughness = 3; + helmetKnockbackResistance = 0.1; chestplateArmour = 8; chestplateArmourToughness = 3; + chestplateKnockbackResistance = 0.1; leggingsArmour = 6; leggingsArmourToughness = 3; + leggingsKnockbackResistance = 0.1; bootsArmour = 3; bootsArmourToughness = 3; + bootsKnockbackResistance = 0.1; } public void setTier6() { @@ -127,12 +138,16 @@ public abstract class GenericGearSet implements HasRecipes { swordAttackSpeed = 1.6f; helmetArmour = 3; helmetArmourToughness = 5; + helmetKnockbackResistance = 0.1; chestplateArmour = 8; chestplateArmourToughness = 5; + chestplateKnockbackResistance = 0.1; leggingsArmour = 6; leggingsArmourToughness = 5; + leggingsKnockbackResistance = 0.1; bootsArmour = 3; bootsArmourToughness = 5; + bootsKnockbackResistance = 0.1; } // this must be overridden by the child class. @@ -140,10 +155,7 @@ public abstract class GenericGearSet implements HasRecipes { public ItemStack getSword() { ItemStack item = swordMaterial; - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(this.swordName); - meta.setLore(new ArrayList<>(List.of(this.swordLore))); meta.addAttributeModifier(Attribute.ATTACK_DAMAGE, new AttributeModifier( NamespacedKey.minecraft("generic.attack_damage"), @@ -154,11 +166,21 @@ public abstract class GenericGearSet implements HasRecipes { meta.addAttributeModifier(Attribute.ATTACK_SPEED, new AttributeModifier( NamespacedKey.minecraft("generic.attack_speed"), - swordAttackSpeed, + swordAttackSpeed - 4, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.HAND )); + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + meta.setDisplayName(this.swordName); + + ArrayList lore = new ArrayList<>(List.of(this.swordLore)); + lore.add("\n"); + lore.add(ChatColor.GRAY + "When in Main Hand:" + ChatColor.RESET); + if (swordAttackDamage > 0) lore.add(ChatColor.GREEN + " " + swordAttackDamage + " Attack Damage" + ChatColor.RESET); + if (swordAttackSpeed > 0) lore.add(ChatColor.GREEN + " " + swordAttackSpeed + " Attack Speed" + ChatColor.RESET); + + meta.setLore(lore); item.setItemMeta(meta); return item; } @@ -171,17 +193,31 @@ public abstract class GenericGearSet implements HasRecipes { meta.setLore(new ArrayList<>(List.of(this.helmetLore))); meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier( - NamespacedKey.minecraft("generic.armor"), - helmetArmour, + UUID.randomUUID(), + "armour", + (double) helmetArmour, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.HEAD )); + meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier( - NamespacedKey.minecraft("generic.armor_toughness"), + UUID.randomUUID(), + "armour_toughness", helmetArmourToughness, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.HEAD )); + + if (helmetKnockbackResistance != 0) { + meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, new AttributeModifier( + UUID.randomUUID(), + "knockback_resistance", + helmetKnockbackResistance, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HEAD + )); + } + item.setItemMeta(meta); return item; } @@ -194,17 +230,31 @@ public abstract class GenericGearSet implements HasRecipes { meta.setLore(new ArrayList<>(List.of(this.chestplateLore))); meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier( - NamespacedKey.minecraft("generic.armor"), - chestplateArmour, + UUID.randomUUID(), + "armour", + (double) chestplateArmour, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.CHEST )); + meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier( - NamespacedKey.minecraft("generic.armor_toughness"), + UUID.randomUUID(), + "armour_toughness", chestplateArmourToughness, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.CHEST )); + + if (chestplateKnockbackResistance != 0) { + meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, new AttributeModifier( + UUID.randomUUID(), + "knockback_resistance", + chestplateKnockbackResistance, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.CHEST + )); + } + item.setItemMeta(meta); return item; } @@ -217,17 +267,31 @@ public abstract class GenericGearSet implements HasRecipes { meta.setLore(new ArrayList<>(List.of(this.leggingsLore))); meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier( - NamespacedKey.minecraft("generic.armor"), - leggingsArmour, + UUID.randomUUID(), + "armour", + (double) leggingsArmour, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.LEGS )); + meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier( - NamespacedKey.minecraft("generic.armor_toughness"), + UUID.randomUUID(), + "armour_toughness", leggingsArmourToughness, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.LEGS )); + + if (leggingsKnockbackResistance != 0) { + meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, new AttributeModifier( + UUID.randomUUID(), + "knockback_resistance", + leggingsKnockbackResistance, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.LEGS + )); + } + item.setItemMeta(meta); return item; } @@ -240,17 +304,31 @@ public abstract class GenericGearSet implements HasRecipes { meta.setLore(new ArrayList<>(List.of(this.bootsLore))); meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier( - NamespacedKey.minecraft("generic.armor"), - bootsArmour, + UUID.randomUUID(), + "armour", + (double) bootsArmour, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.FEET )); + meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier( - NamespacedKey.minecraft("generic.armor_toughness"), + UUID.randomUUID(), + "armour_toughness", bootsArmourToughness, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.FEET )); + + if (bootsKnockbackResistance != 0) { + meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, new AttributeModifier( + UUID.randomUUID(), + "knockback_resistance", + bootsKnockbackResistance, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.FEET + )); + } + item.setItemMeta(meta); return item; } diff --git a/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java b/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java index 21fdc86..f9f57a4 100644 --- a/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java +++ b/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java @@ -10,6 +10,9 @@ import org.bukkit.event.Listener; 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 static org.bukkit.Bukkit.getServer; @@ -38,31 +41,31 @@ public class Witherite extends GenericGearSet implements Listener, CommandExecut ItemStack sword = this.getSword(); NamespacedKey swordKey = new NamespacedKey("fantasysmp.items", "witherite_sword"); RecipeChoice swordChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_SWORD); - SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(swordKey, sword, NETHERITE_UPGRADE, WITHER_SKULL, swordChoice); + SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(swordKey, sword, NETHERITE_UPGRADE, swordChoice, WITHER_SKULL); getServer().addRecipe(swordRecipe); ItemStack helmet = this.getHelmet(); NamespacedKey helmetKey = new NamespacedKey("fantasysmp.items", "witherite_helmet"); RecipeChoice helmetChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_HELMET); - SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(helmetKey, helmet, NETHERITE_UPGRADE, WITHER_SKULL, helmetChoice); + SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(helmetKey, helmet, NETHERITE_UPGRADE, helmetChoice, WITHER_SKULL); getServer().addRecipe(helmetRecipe); ItemStack chestplate = this.getChestplate(); NamespacedKey chestplateKey = new NamespacedKey("fantasysmp.items", "witherite_chestplate"); RecipeChoice chestplateChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE); - SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(chestplateKey, chestplate, NETHERITE_UPGRADE, WITHER_SKULL, chestplateChoice); + SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(chestplateKey, chestplate, NETHERITE_UPGRADE, chestplateChoice, WITHER_SKULL); getServer().addRecipe(chestplateRecipe); ItemStack leggings = this.getLeggings(); NamespacedKey leggingsKey = new NamespacedKey("fantasysmp.items", "witherite_leggings"); RecipeChoice leggingsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS); - SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(leggingsKey, leggings, NETHERITE_UPGRADE, WITHER_SKULL, leggingsChoice); + SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(leggingsKey, leggings, NETHERITE_UPGRADE, leggingsChoice, WITHER_SKULL); getServer().addRecipe(leggingsRecipe); ItemStack boots = this.getBoots(); NamespacedKey bootsKey = new NamespacedKey("fantasysmp.items", "witherite_boots"); RecipeChoice bootsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS); - SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(bootsKey, boots, NETHERITE_UPGRADE, WITHER_SKULL, bootsChoice); + SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(bootsKey, boots, NETHERITE_UPGRADE, bootsChoice, WITHER_SKULL); getServer().addRecipe(bootsRecipe); } @@ -112,6 +115,51 @@ public class Witherite extends GenericGearSet implements Listener, CommandExecut } } + @Override + public ItemStack getSword() { + ItemStack item = super.getSword(); + ItemMeta meta = item.getItemMeta(); + meta.setItemModel(NamespacedKey.fromString("fantasysmp:witherite_sword")); + item.setItemMeta(meta); + return item; + } + + @Override + public ItemStack getHelmet() { + ItemStack item = super.getHelmet(); + ItemMeta meta = item.getItemMeta(); + meta.setItemModel(NamespacedKey.fromString("fantasysmp:witherite_helmet")); + item.setItemMeta(meta); + return item; + } + + @Override + public ItemStack getChestplate() { + ItemStack item = super.getChestplate(); + ItemMeta meta = item.getItemMeta(); + meta.setItemModel(NamespacedKey.fromString("fantasysmp:witherite_chestplate")); + item.setItemMeta(meta); + return item; + } + + @Override + public ItemStack getLeggings() { + ItemStack item = super.getLeggings(); + ItemMeta meta = item.getItemMeta(); + meta.setItemModel(NamespacedKey.fromString("fantasysmp:witherite_leggings")); + item.setItemMeta(meta); + return item; + } + + @Override + public ItemStack getBoots() { + ItemStack item = super.getBoots(); + ItemMeta meta = item.getItemMeta(); + meta.setItemModel(NamespacedKey.fromString("fantasysmp:witherite_boots")); + item.setItemMeta(meta); + return item; + } + public static void init() {} public Witherite() {