From e9b78175b0bda729f42bcf6721e53d28fad14035 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 24 Sep 2020 12:36:41 +0100 Subject: [PATCH] Began migration to new listener system --- .../ecoenchants/enchantments/EcoEnchant.java | 3 +- .../ecoenchants/artifact/CloudsArtifact.java | 2 +- .../ecoenchants/artifact/DamageArtifact.java | 2 +- .../ecoenchants/artifact/DragonArtifact.java | 2 +- .../ecoenchants/artifact/DustArtifact.java | 2 +- .../ecoenchants/artifact/EmeraldArtifact.java | 2 +- .../artifact/EnchantmentArtifact.java | 2 +- .../ecoenchants/artifact/EndArtifact.java | 2 +- .../ecoenchants/artifact/FireArtifact.java | 2 +- .../ecoenchants/artifact/HeartArtifact.java | 2 +- .../ecoenchants/artifact/HoneyArtifact.java | 2 +- .../ecoenchants/artifact/InkArtifact.java | 2 +- .../ecoenchants/artifact/LavaArtifact.java | 2 +- .../ecoenchants/artifact/LimeArtifact.java | 2 +- .../ecoenchants/artifact/MagicArtifact.java | 2 +- .../ecoenchants/artifact/MagmaArtifact.java | 2 +- .../ecoenchants/artifact/MusicArtifact.java | 2 +- .../ecoenchants/artifact/NetherArtifact.java | 2 +- .../artifact/RedstoneArtifact.java | 2 +- .../ecoenchants/artifact/SmokeArtifact.java | 2 +- .../ecoenchants/artifact/SnowArtifact.java | 2 +- .../ecoenchants/artifact/SparkleArtifact.java | 2 +- .../ecoenchants/artifact/TotemArtifact.java | 2 +- .../ecoenchants/artifact/WaterArtifact.java | 2 +- .../ecoenchants/artifact/WitchArtifact.java | 2 +- .../ecoenchants/artifact/ZapArtifact.java | 2 +- .../ecoenchants/curse/BreaklessnessCurse.java | 8 +- .../ecoenchants/curse/HarmlessnessCurse.java | 14 +- .../ecoenchants/curse/InaccuracyCurse.java | 14 +- .../ecoenchants/curse/MisfortuneCurse.java | 8 +- .../ecoenchants/normal/Abattoir.java | 18 +- .../ecoenchants/normal/Abrasion.java | 34 +-- .../ecoenchants/normal/Aerial.java | 30 +- .../ecoenchants/normal/Aquatic.java | 27 +- .../ecoenchants/normal/Arachnid.java | 17 +- .../ecoenchants/normal/Arcanic.java | 19 +- .../ecoenchants/normal/Atmospheric.java | 28 +- .../{ => itemtypes}/Artifact.java | 5 +- .../enchantments/util/Watcher.java | 28 ++ .../enchantments/util/WatcherTriggers.java | 280 ++++++++++++++++++ .../com/willfp/ecoenchants/loader/Loader.java | 2 + 41 files changed, 395 insertions(+), 190 deletions(-) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{ => itemtypes}/Artifact.java (96%) create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/Watcher.java create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 377084b9..a7a94f51 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.enchantments; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; +import com.willfp.ecoenchants.enchantments.util.Watcher; import com.willfp.ecoenchants.util.Registerable; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.WordUtils; @@ -17,7 +18,7 @@ import java.lang.reflect.Field; import java.util.*; @SuppressWarnings("unchecked") -public abstract class EcoEnchant extends Enchantment implements Listener, Registerable { +public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher { private String name; private String description; private final String permissionName; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/CloudsArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/CloudsArtifact.java index 7260e309..621760bc 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/CloudsArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/CloudsArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Color; import org.bukkit.Particle; public class CloudsArtifact extends Artifact { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DamageArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DamageArtifact.java index 37f42693..e2a472c5 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DamageArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DamageArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class DamageArtifact extends Artifact { public DamageArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DragonArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DragonArtifact.java index 3ed4f0f5..54517d40 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DragonArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DragonArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class DragonArtifact extends Artifact { public DragonArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DustArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DustArtifact.java index 9750205a..04fd7653 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DustArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/DustArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class DustArtifact extends Artifact { public DustArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EmeraldArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EmeraldArtifact.java index 36242861..dc79b5c3 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EmeraldArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EmeraldArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class EmeraldArtifact extends Artifact { public EmeraldArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EnchantmentArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EnchantmentArtifact.java index 8465195f..f9e5063a 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EnchantmentArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EnchantmentArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class EnchantmentArtifact extends Artifact { public EnchantmentArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EndArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EndArtifact.java index 1007f04f..855f037d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EndArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/EndArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class EndArtifact extends Artifact { public EndArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/FireArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/FireArtifact.java index f1a1982d..e9e1aac4 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/FireArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/FireArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class FireArtifact extends Artifact { public FireArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HeartArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HeartArtifact.java index 29d43f8c..f394ca7b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HeartArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HeartArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class HeartArtifact extends Artifact { public HeartArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HoneyArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HoneyArtifact.java index cb08cdf2..24314b47 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HoneyArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/HoneyArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class HoneyArtifact extends Artifact { public HoneyArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/InkArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/InkArtifact.java index 942f7966..74593d30 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/InkArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/InkArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class InkArtifact extends Artifact { public InkArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LavaArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LavaArtifact.java index 6672dc77..c7ef01ea 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LavaArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LavaArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class LavaArtifact extends Artifact { public LavaArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LimeArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LimeArtifact.java index e14156c3..167ffad0 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LimeArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/LimeArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Color; import org.bukkit.Particle; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagicArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagicArtifact.java index 4d3ff586..4a91dde7 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagicArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagicArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class MagicArtifact extends Artifact { public MagicArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagmaArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagmaArtifact.java index f925451e..4bdd3b9f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagmaArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MagmaArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class MagmaArtifact extends Artifact { public MagmaArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MusicArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MusicArtifact.java index ad5fae63..993656f4 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MusicArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/MusicArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class MusicArtifact extends Artifact { public MusicArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/NetherArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/NetherArtifact.java index 4c095e81..090c7e77 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/NetherArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/NetherArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class NetherArtifact extends Artifact { public NetherArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/RedstoneArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/RedstoneArtifact.java index 4b039619..57733a94 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/RedstoneArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/RedstoneArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Color; import org.bukkit.Particle; public class RedstoneArtifact extends Artifact { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java index c3e6c041..291f0f2c 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class SmokeArtifact extends Artifact { public SmokeArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SnowArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SnowArtifact.java index af1f99d7..d22916cd 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SnowArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SnowArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class SnowArtifact extends Artifact { public SnowArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java index f6b1503e..b4d6d8d0 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class SparkleArtifact extends Artifact { public SparkleArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java index 60da5811..9003976f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class TotemArtifact extends Artifact { public TotemArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java index 37cfca74..84ea9c7f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class WaterArtifact extends Artifact { public WaterArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java index 349da58b..e5ca44de 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Particle; public class WitchArtifact extends Artifact { public WitchArtifact() { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java index 17fe6054..07947447 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.artifact; -import com.willfp.ecoenchants.enchantments.Artifact; +import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import org.bukkit.Color; import org.bukkit.Particle; public class ZapArtifact extends Artifact { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java index 349e7382..52137128 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/BreaklessnessCurse.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.util.NumberUtils; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockDamageEvent; @@ -17,12 +18,9 @@ public class BreaklessnessCurse extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onDamageBlock(BlockDamageEvent event) { - Player player = event.getPlayer(); - - if (!EnchantChecks.mainhand(player, this)) return; + @Override + public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) { if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) return; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java index 61027104..7d00224b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/HarmlessnessCurse.java @@ -19,19 +19,9 @@ public class HarmlessnessCurse extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void harmlessnessHit(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) - return; - if (!(event.getEntity() instanceof LivingEntity)) - return; - if (event.getEntity() instanceof Monster) - return; - - Player player = (Player) event.getDamager(); - - if (!EnchantChecks.mainhand(player, this)) return; + @Override + public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) { if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) return; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/InaccuracyCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/InaccuracyCurse.java index 8712122d..22df131b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/InaccuracyCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/InaccuracyCurse.java @@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityShootBowEvent; @@ -20,18 +21,9 @@ public class InaccuracyCurse extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onShoot(EntityShootBowEvent event) { - if (event.getProjectile().getType() != EntityType.ARROW) - return; - - if (!(event.getEntity() instanceof Player)) - return; - - Player player = (Player) event.getEntity(); - - if (!EnchantChecks.mainhand(player, this)) return; + @Override + public void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) { double spread = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "spread"); Vector velocity = event.getProjectile().getVelocity().clone(); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java index 1868cd99..d9f3287b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/MisfortuneCurse.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.util.NumberUtils; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; @@ -17,12 +18,9 @@ public class MisfortuneCurse extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onBreak(BlockBreakEvent event) { - Player player = event.getPlayer(); - - if (!EnchantChecks.mainhand(player, this)) return; + @Override + public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) { if (NumberUtils.randFloat(0, 1) > 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance")) return; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abattoir.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abattoir.java index ae53c31f..f7472ef6 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abattoir.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abattoir.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.nms.TridentStack; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; @@ -20,20 +21,9 @@ public class Abattoir extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onDamage(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Trident)) - return; - - if(event.getEntity() instanceof Monster) return; - - Trident trident = (Trident) event.getDamager(); - ItemStack item = TridentStack.getTridentStack(trident); - - if(!EnchantChecks.item(item, this)) - return; - - int level = EnchantChecks.getItemLevel(item, this); + @Override + public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { + if(victim instanceof Monster) return; double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java index 39d25989..af5670ab 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java @@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.util.ItemDurability; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -23,28 +24,14 @@ public class Abrasion extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onHit(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) - return; - if (!(event.getEntity() instanceof Player)) - return; - - if (event.isCancelled()) - return; - - Player player = (Player) event.getDamager(); - Player victim = (Player) event.getEntity(); - - if(!AntigriefManager.canInjure(player, victim)) return; - - if (!EnchantChecks.mainhand(player, this)) return; - - int level = EnchantChecks.getMainhandLevel(player, this); + @Override + public void onMeleeAttack(LivingEntity attacker, LivingEntity uncastVictim, int level, EntityDamageByEntityEvent event) { + if(!(uncastVictim instanceof Player)) return; + Player victim = (Player) uncastVictim; boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"); - if (Cooldown.getCooldown(player) != 1.0f && !notcharged) + if (attacker instanceof Player && Cooldown.getCooldown((Player) attacker) != 1.0f && !notcharged) return; ArrayList armor = new ArrayList(Arrays.asList(victim.getInventory().getArmorContents())); @@ -55,18 +42,17 @@ public class Abrasion extends EcoEnchant { if (armorPiece == null) continue; - if(armorPiece.equals(victim.getInventory().getHelmet())) { - ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39); + ItemDurability.damageItem(victim, victim.getInventory().getHelmet(), level, 39); } if(armorPiece.equals(victim.getInventory().getChestplate())) { - ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38); + ItemDurability.damageItem(victim, victim.getInventory().getChestplate(), level, 38); } if(armorPiece.equals(victim.getInventory().getLeggings())) { - ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37); + ItemDurability.damageItem(victim, victim.getInventory().getLeggings(), level, 37); } if(armorPiece.equals(victim.getInventory().getBoots())) { - ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36); + ItemDurability.damageItem(victim, victim.getInventory().getBoots(), level, 36); } } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java index 9ef1cf13..b7532dde 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aerial.java @@ -1,14 +1,17 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal; import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.command.AbstractCommand; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import org.bukkit.entity.Arrow; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.metadata.FixedMetadataValue; @@ -21,33 +24,20 @@ public class Aerial extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onLaunch(ProjectileLaunchEvent event) { - if(!(event.getEntity() instanceof Arrow)) - return; - if(!(event.getEntity().getShooter() instanceof Player)) - return; + @Override + public void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) { + if(!(event.getProjectile() instanceof Arrow)) return; - Arrow arrow = (Arrow) event.getEntity(); - Player player = (Player) arrow.getShooter(); + if(shooter.isOnGround()) return; - if(player.isOnGround()) return; - - arrow.setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true)); + event.getProjectile().setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true)); } - @EventHandler - public void onDamage(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Arrow)) - return; - - Arrow arrow = (Arrow) event.getDamager(); - if(!EnchantChecks.arrow(arrow, this)) return; + @Override + public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) { if(!arrow.hasMetadata("shot-in-air")) return; - int level = EnchantChecks.getArrowLevel(arrow, this); - double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level"); double reduction = 1 + (multiplier * level); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aquatic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aquatic.java index ffb76244..8ab4084c 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aquatic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Aquatic.java @@ -21,31 +21,12 @@ public class Aquatic extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onHit(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Trident)) + + @Override + public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { + if(!attacker.getLocation().getBlock().getType().equals(Material.WATER)) return; - if(!(((Trident) event.getDamager()).getShooter() instanceof Player)) - return; - - if (!(event.getEntity() instanceof LivingEntity)) - return; - - if (event.isCancelled()) - return; - - Player player = (Player) ((Trident) event.getDamager()).getShooter(); - Trident trident = (Trident) event.getDamager(); - ItemStack item = TridentStack.getTridentStack(trident); - - if(!player.getLocation().getBlock().getType().equals(Material.WATER)) - return; - - if (!EnchantChecks.item(item, this)) return; - - int level = EnchantChecks.getItemLevel(item, this); - double perLevelDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "percent-more-per-level"); double totalDamagePercent = (100 + (perLevelDamage * level))/100; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arachnid.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arachnid.java index 21c37423..0b272012 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arachnid.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arachnid.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.nms.TridentStack; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Spider; import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; @@ -20,20 +21,10 @@ public class Arachnid extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onDamage(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Trident)) - return; - if(!(event.getEntity() instanceof Spider)) return; - - Trident trident = (Trident) event.getDamager(); - ItemStack item = TridentStack.getTridentStack(trident); - - if(!EnchantChecks.item(item, this)) - return; - - int level = EnchantChecks.getItemLevel(item, this); + @Override + public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { + if(!(victim instanceof Spider)) return; double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java index 56743c45..6fd04969 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Arcanic.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.util.NumberUtils; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; @@ -16,24 +17,14 @@ public class Arcanic extends EcoEnchant { } // START OF LISTENERS - - @EventHandler - public void onEffect(EntityDamageEvent event) { - if (!(event.getEntity() instanceof Player)) - return; - + + @Override + public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) { if (!(event.getCause().equals(EntityDamageEvent.DamageCause.POISON) || event.getCause().equals(EntityDamageEvent.DamageCause.WITHER))) return; - Player player = (Player) event.getEntity(); - - int totalArcanicPoints = EnchantChecks.getArmorPoints(player, this, 0); - - if (totalArcanicPoints == 0) - return; - double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"); - if (NumberUtils.randFloat(0, 1) > totalArcanicPoints * 0.01 * chance) + if (NumberUtils.randFloat(0, 1) > level * 0.01 * chance) return; event.setCancelled(true); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java index ff831f27..c27ba448 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Atmospheric.java @@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.nms.TridentStack; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; @@ -23,33 +24,16 @@ public class Atmospheric extends EcoEnchant { // START OF LISTENERS - @EventHandler - public void onLaunch(ProjectileLaunchEvent event) { - if(!(event.getEntity() instanceof Trident)) - return; - - if(!(event.getEntity().getShooter() instanceof Player)) - return; - - Trident trident = (Trident) event.getEntity(); - Player player = (Player) trident.getShooter(); - - if(player.isOnGround()) return; + @Override + public void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) { + if(shooter.isOnGround()) return; trident.setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true)); } - @EventHandler - public void onDamage(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Trident)) - return; - - Trident trident = (Trident) event.getDamager(); + @Override + public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) { if(!trident.hasMetadata("shot-in-air")) return; - ItemStack item = TridentStack.getTridentStack(trident); - if(!EnchantChecks.item(item, this)) return; - - int level = EnchantChecks.getItemLevel(item, this); double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier-per-level"); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/Artifact.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java similarity index 96% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/Artifact.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java index b915a86a..cec04666 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/Artifact.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Artifact.java @@ -1,7 +1,10 @@ -package com.willfp.ecoenchants.enchantments; +package com.willfp.ecoenchants.enchantments.itemtypes; import com.google.common.util.concurrent.AtomicDouble; import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; +import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.nms.TridentStack; import com.willfp.ecoenchants.util.NumberUtils; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/Watcher.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/Watcher.java new file mode 100644 index 00000000..752c2821 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/Watcher.java @@ -0,0 +1,28 @@ +package com.willfp.ecoenchants.enchantments.util; + +import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent; +import org.bukkit.block.Block; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Trident; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.player.PlayerMoveEvent; + +public interface Watcher { + default void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {} + default void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {} + default void onJump(Player player, int level, PlayerMoveEvent event) {} + default void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {} + default void onBowShoot(LivingEntity shooter, int level, EntityShootBowEvent event) {} + default void onFallDamage(LivingEntity shooter, int level, EntityDamageEvent event) {} + default void onArrowHit(LivingEntity shooter, int level, ProjectileHitEvent event) {} + default void onTridentHit(LivingEntity shooter, int level, ProjectileHitEvent event) {} + default void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {} + default void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {} + default void onArmorEquip(Player player, int level, ArmorEquipEvent event) {} + default void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) {} + default void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) {} +} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java new file mode 100644 index 00000000..911cdae3 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -0,0 +1,280 @@ +package com.willfp.ecoenchants.enchantments.util; + +import com.google.common.collect.Sets; +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent; +import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager; +import com.willfp.ecoenchants.nms.TridentStack; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.potion.PotionEffectType; + +import java.text.DecimalFormat; +import java.util.Set; +import java.util.UUID; + +public class WatcherTriggers implements Listener { + + @EventHandler(ignoreCancelled = true) + public void onArrowDamage(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Arrow)) + return; + if (!(event.getEntity() instanceof LivingEntity)) + return; + if(!(((Arrow) event.getDamager()).getShooter() instanceof LivingEntity)) + return; + + LivingEntity attacker = (LivingEntity) ((Arrow) event.getDamager()).getShooter(); + Arrow arrow = (Arrow) event.getDamager(); + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(attacker instanceof Player) { + if (!AntigriefManager.canInjure((Player) attacker, victim)) return; + } + + if(event.isCancelled()) return; + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.arrow(arrow, enchant)) return; + int level = EnchantChecks.getArrowLevel(arrow, enchant); + enchant.onArrowDamage(attacker, victim, arrow, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onTridentDamage(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Trident)) + return; + + if(!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity)) + return; + + if (!(event.getEntity() instanceof LivingEntity)) + return; + + if (event.isCancelled()) + return; + + LivingEntity attacker = (LivingEntity) ((Trident) event.getDamager()).getShooter(); + Trident trident = (Trident) event.getDamager(); + ItemStack item = TridentStack.getTridentStack(trident); + + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(attacker instanceof Player) { + if (!AntigriefManager.canInjure((Player) attacker, victim)) return; + } + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.item(item, enchant)) return; + int level = EnchantChecks.getItemLevel(item, enchant); + enchant.onTridentDamage(attacker, victim, trident, level, event); + })); + } + + + private static final Set prevPlayersOnGround = Sets.newHashSet(); + private static final DecimalFormat df = new DecimalFormat("0.00"); + + @EventHandler(ignoreCancelled = true) + public void onJump(PlayerMoveEvent event) { + Player player = event.getPlayer(); + if (player.getVelocity().getY() > 0) { + float jumpVelocity = 0.42f; + if (player.hasPotionEffect(PotionEffectType.JUMP)) { + jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F; + } + jumpVelocity = Float.parseFloat(df.format(jumpVelocity).replace(',', '.')); + if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER && prevPlayersOnGround.contains(player.getUniqueId())) { + if (!player.isOnGround() && Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) { + EcoEnchants.getAll().forEach((enchant -> { + int level = EnchantChecks.getArmorPoints(player, enchant); + if(level == 0) return; + enchant.onJump(player, level, event); + })); + } + } + } + if (player.isOnGround()) { + prevPlayersOnGround.add(player.getUniqueId()); + } else { + prevPlayersOnGround.remove(player.getUniqueId()); + } + } + + @EventHandler(ignoreCancelled = true) + public void onMeleeAttack(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof LivingEntity)) + return; + + if (!(event.getEntity() instanceof LivingEntity)) + return; + + if (event.isCancelled()) + return; + + LivingEntity attacker = (LivingEntity) event.getDamager(); + LivingEntity victim = (LivingEntity) event.getEntity(); + + if(attacker instanceof Player) { + if (!AntigriefManager.canInjure((Player) attacker, victim)) return; + } + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.mainhand(attacker, enchant)) return; + int level = EnchantChecks.getMainhandLevel(attacker, enchant); + enchant.onMeleeAttack(attacker, victim, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onBowShoot(EntityShootBowEvent event) { + if (event.getProjectile().getType() != EntityType.ARROW) + return; + + LivingEntity shooter = event.getEntity(); + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.mainhand(shooter, enchant)) return; + int level = EnchantChecks.getMainhandLevel(shooter, enchant); + enchant.onBowShoot(shooter, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onFallDamage(EntityDamageEvent event) { + if(!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) + return; + + if(!(event.getEntity() instanceof LivingEntity)) + return; + + LivingEntity victim = (LivingEntity) event.getEntity(); + + EcoEnchants.getAll().forEach((enchant -> { + int level = EnchantChecks.getArmorPoints(victim, enchant); + if(level == 0) return; + enchant.onFallDamage(victim, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onArrowHit(ProjectileHitEvent event) { + if (!(event.getEntity().getShooter() instanceof LivingEntity)) + return; + + if (!(event.getEntity() instanceof Arrow)) return; + + Arrow arrow = (Arrow) event.getEntity(); + LivingEntity shooter = (LivingEntity) event.getEntity().getShooter(); + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.arrow(arrow, enchant)) return; + int level = EnchantChecks.getArrowLevel(arrow, enchant); + enchant.onArrowHit(shooter, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onTridentHit(ProjectileHitEvent event) { + if (!(event.getEntity().getShooter() instanceof LivingEntity)) + return; + + if (!(event.getEntity() instanceof Trident)) return; + + Trident trident = (Trident) event.getEntity(); + ItemStack item = TridentStack.getTridentStack(trident); + LivingEntity shooter = (LivingEntity) event.getEntity().getShooter(); + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.item(item, enchant)) return; + int level = EnchantChecks.getItemLevel(item, enchant); + enchant.onTridentHit(shooter, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + + if(!AntigriefManager.canBreakBlock(player, block)) return; + + if (event.isCancelled()) + return; + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.mainhand(player, enchant)) return; + int level = EnchantChecks.getMainhandLevel(player, enchant); + enchant.onBlockBreak(player, block, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onDamageWearingArmor(EntityDamageEvent event) { + if (!(event.getEntity() instanceof LivingEntity)) + return; + + LivingEntity victim = (LivingEntity) event.getEntity(); + + EcoEnchants.getAll().forEach((enchant -> { + int level = EnchantChecks.getArmorPoints(victim, enchant); + if(level == 0) return; + enchant.onDamageWearingArmor(victim, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onArmorEquip(ArmorEquipEvent event) { + Player player = event.getPlayer(); + + Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { + EcoEnchants.getAll().forEach((enchant -> { + int level = EnchantChecks.getArmorPoints(player, enchant); + enchant.onArmorEquip(player, level, event); + })); + }, 1); + } + + @EventHandler(ignoreCancelled = true) + public void onDamageBlock(BlockDamageEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.mainhand(player, enchant)) return; + int level = EnchantChecks.getMainhandLevel(player, enchant); + enchant.onDamageBlock(player, block, level, event); + })); + } + + @EventHandler(ignoreCancelled = true) + public void onTridentLaunch(ProjectileLaunchEvent event) { + if(!(event.getEntity() instanceof Trident)) + return; + + if(!(event.getEntity().getShooter() instanceof LivingEntity)) + return; + + Trident trident = (Trident) event.getEntity(); + LivingEntity shooter = (LivingEntity) trident.getShooter(); + ItemStack item = TridentStack.getTridentStack(trident); + + EcoEnchants.getAll().forEach((enchant -> { + if (!EnchantChecks.item(item, enchant)) return; + int level = EnchantChecks.getItemLevel(item, enchant); + enchant.onTridentLaunch(shooter, trident, level, event); + })); + } +} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java index 4056bb27..3c7d5745 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -16,6 +16,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; +import com.willfp.ecoenchants.enchantments.util.WatcherTriggers; import com.willfp.ecoenchants.events.armorequip.ArmorListener; import com.willfp.ecoenchants.events.armorequip.DispenserArmorListener; import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityListeners; @@ -241,6 +242,7 @@ public class Loader { Bukkit.getPluginManager().registerEvents(new NaturalExpGainListeners(), EcoEnchantsPlugin.getInstance()); Bukkit.getPluginManager().registerEvents(new VillagerListeners(), EcoEnchantsPlugin.getInstance()); Bukkit.getPluginManager().registerEvents(new ArrowListeners(), EcoEnchantsPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(new WatcherTriggers(), EcoEnchantsPlugin.getInstance()); Logger.info(""); /*