From 33e2c66b9a4849ba8f97080745d841738c977d95 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 13 Nov 2020 19:47:17 +0000 Subject: [PATCH] Added support for mcmmo fake events --- Plugin/pom.xml | 6 ++++ .../enchantments/util/WatcherTriggers.java | 31 +++++++++++++++++++ .../integrations/mcmmo/McmmoIntegration.java | 8 +++++ .../integrations/mcmmo/McmmoManager.java | 24 ++++++++++++++ .../mcmmo/plugins/McmmoIntegrationImpl.java | 17 ++++++++++ .../com/willfp/ecoenchants/loader/Loader.java | 9 ++++++ pom.xml | 4 +++ 7 files changed, 99 insertions(+) create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoIntegration.java create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoManager.java create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/plugins/McmmoIntegrationImpl.java diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 2294a17a..0943b5de 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -275,5 +275,11 @@ + + com.gmail.nossr50.mcMMO + mcMMO + 2.1.157 + provided + 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 index 1cd1a314..ba9421c2 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -5,6 +5,7 @@ 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.integrations.mcmmo.McmmoManager; import com.willfp.ecoenchants.nms.TridentStack; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -35,6 +36,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onArrowDamage(EntityDamageByEntityEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getDamager() instanceof Arrow)) return; if (!(event.getEntity() instanceof LivingEntity)) @@ -63,6 +66,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onTridentDamage(EntityDamageByEntityEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getDamager() instanceof Trident)) return; @@ -100,6 +105,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onJump(PlayerMoveEvent event) { + if(McmmoManager.isFake(event)) + return; Player player = event.getPlayer(); if (player.getVelocity().getY() > 0) { float jumpVelocity = 0.42f; @@ -126,6 +133,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onMeleeAttack(EntityDamageByEntityEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getDamager() instanceof LivingEntity)) return; @@ -153,6 +162,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onBowShoot(EntityShootBowEvent event) { + if(McmmoManager.isFake(event)) + return; if (event.getProjectile().getType() != EntityType.ARROW) return; @@ -168,6 +179,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onFallDamage(EntityDamageEvent event) { + if(McmmoManager.isFake(event)) + return; if(!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) return; @@ -185,6 +198,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onArrowHit(ProjectileHitEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getEntity().getShooter() instanceof LivingEntity)) return; @@ -201,6 +216,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onTridentHit(ProjectileHitEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getEntity().getShooter() instanceof LivingEntity)) return; @@ -218,6 +235,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { + if(McmmoManager.isFake(event)) + return; Player player = event.getPlayer(); Block block = event.getBlock(); @@ -235,6 +254,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onDamageWearingArmor(EntityDamageEvent event) { + if(McmmoManager.isFake(event)) + return; if (!(event.getEntity() instanceof LivingEntity)) return; @@ -249,6 +270,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onArmorEquip(ArmorEquipEvent event) { + if(McmmoManager.isFake(event)) + return; Player player = event.getPlayer(); Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { @@ -263,6 +286,8 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onDamageBlock(BlockDamageEvent event) { + if(McmmoManager.isFake(event)) + return; Player player = event.getPlayer(); Block block = event.getBlock(); @@ -278,6 +303,9 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onTridentLaunch(ProjectileLaunchEvent event) { + if(McmmoManager.isFake(event)) + return; + if(!(event.getEntity() instanceof Trident)) return; @@ -297,6 +325,9 @@ public class WatcherTriggers implements Listener { @EventHandler(ignoreCancelled = true) public void onDeflect(EntityDamageByEntityEvent event) { + if(McmmoManager.isFake(event)) + return; + if (!(event.getEntity() instanceof Player)) return; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoIntegration.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoIntegration.java new file mode 100644 index 00000000..9a52a8c4 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoIntegration.java @@ -0,0 +1,8 @@ +package com.willfp.ecoenchants.integrations.mcmmo; + +import com.willfp.ecoenchants.integrations.Integration; +import org.bukkit.event.Event; + +public interface McmmoIntegration extends Integration { + boolean isFake(Event event); +} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoManager.java new file mode 100644 index 00000000..adce1903 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/McmmoManager.java @@ -0,0 +1,24 @@ +package com.willfp.ecoenchants.integrations.mcmmo; + +import org.bukkit.event.Event; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +public class McmmoManager { + private static final Set integrations = new HashSet<>(); + + public static void registerIntegration(McmmoIntegration integration) { + integrations.add(integration); + } + + public static boolean isFake(Event event) { + AtomicBoolean isFake = new AtomicBoolean(false); + integrations.forEach(integration -> { + if(integration.isFake(event)) isFake.set(true); + }); + + return isFake.get(); + } +} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/plugins/McmmoIntegrationImpl.java b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/plugins/McmmoIntegrationImpl.java new file mode 100644 index 00000000..16dd8440 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/integrations/mcmmo/plugins/McmmoIntegrationImpl.java @@ -0,0 +1,17 @@ +package com.willfp.ecoenchants.integrations.mcmmo.plugins; + +import com.gmail.nossr50.events.fake.FakeEvent; +import com.willfp.ecoenchants.integrations.mcmmo.McmmoIntegration; +import org.bukkit.event.Event; + +public class McmmoIntegrationImpl implements McmmoIntegration { + @Override + public boolean isFake(Event event) { + return event instanceof FakeEvent; + } + + @Override + public String getPluginName() { + return "mcMMO"; + } +} 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 6acb0d0a..7655fa4b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -42,6 +42,8 @@ import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefTowny; import com.willfp.ecoenchants.integrations.antigrief.plugins.AntigriefWorldGuard; import com.willfp.ecoenchants.integrations.essentials.EssentialsManager; import com.willfp.ecoenchants.integrations.essentials.plugins.IntegrationEssentials; +import com.willfp.ecoenchants.integrations.mcmmo.McmmoManager; +import com.willfp.ecoenchants.integrations.mcmmo.plugins.McmmoIntegrationImpl; import com.willfp.ecoenchants.integrations.placeholder.PlaceholderManager; import com.willfp.ecoenchants.integrations.placeholder.plugins.PlaceholderIntegrationPAPI; import com.willfp.ecoenchants.listeners.ArrowListeners; @@ -428,6 +430,13 @@ public class Loader { Logger.info("PlaceholderAPI: §9DISABLED"); } + if(Bukkit.getPluginManager().isPluginEnabled("mcMMO")) { + McmmoManager.registerIntegration(new McmmoIntegrationImpl()); + Logger.info("mcMMO: §aENABLED"); + } else { + Logger.info("mcMMO: §9DISABLED"); + } + /* Check for paper diff --git a/pom.xml b/pom.xml index a3239ce3..1262c35b 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,10 @@ placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ + + mcmmo-repo + http://repo.mcmmo.org/ +