Added support for mcmmo fake events

This commit is contained in:
Auxilor 2020-11-13 19:47:17 +00:00
parent 8a6aaa3236
commit 33e2c66b9a
7 changed files with 99 additions and 0 deletions

View File

@ -275,5 +275,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.157</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -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;

View File

@ -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);
}

View File

@ -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<McmmoIntegration> 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();
}
}

View File

@ -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";
}
}

View File

@ -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

View File

@ -73,6 +73,10 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>mcmmo-repo</id>
<url>http://repo.mcmmo.org/</url>
</repository>
</repositories>
<build>