Fixes DISABLE_LOYALTY_PORTALS doesn't work

This commit is contained in:
Cazcez 2023-02-25 18:43:24 +03:00
parent 2606f39e81
commit e62949e132
3 changed files with 5 additions and 4 deletions

View File

@ -44,6 +44,7 @@ public class Main extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new ImpalingListener(), this); Bukkit.getPluginManager().registerEvents(new ImpalingListener(), this);
Bukkit.getPluginManager().registerEvents(new OffhandListener(), this); Bukkit.getPluginManager().registerEvents(new OffhandListener(), this);
Bukkit.getPluginManager().registerEvents(new TridentThrowListener(), this); Bukkit.getPluginManager().registerEvents(new TridentThrowListener(), this);
Bukkit.getPluginManager().registerEvents(new PortalListener(), this);
getCommand("bettertridents").setExecutor(new ReloadCommand()); getCommand("bettertridents").setExecutor(new ReloadCommand());
@SuppressWarnings("unused") Metrics metrics = new Metrics(this, 11460); @SuppressWarnings("unused") Metrics metrics = new Metrics(this, 11460);
} }

View File

@ -19,8 +19,8 @@ public class PortalListener implements Listener {
if(!main.getConfig().getBoolean(Config.DISABLE_LOYALTY_PORTALS)) return; if(!main.getConfig().getBoolean(Config.DISABLE_LOYALTY_PORTALS)) return;
if(event.getEntityType() != EntityType.TRIDENT) return; if(event.getEntityType() != EntityType.TRIDENT) return;
Trident trident = (Trident) event.getEntity(); Trident trident = (Trident) event.getEntity();
if(EnchantmentUtils.getLoyalty(trident)>0) { if(EnchantmentUtils.getLoyalty(trident)) {
main.debug("Prevented loyalty trident from travelling through portqal"); main.debug("Prevented loyalty trident from travelling through portal");
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -34,8 +34,8 @@ public class EnchantmentUtils {
trident.getPersistentDataContainer().set(Main.IMPALING_TAG, PersistentDataType.INTEGER, level); trident.getPersistentDataContainer().set(Main.IMPALING_TAG, PersistentDataType.INTEGER, level);
} }
public static int getLoyalty(Trident trident) { public static boolean getLoyalty(Trident trident) {
return trident.getPersistentDataContainer().getOrDefault(Main.LOYALTY_TAG, PersistentDataType.INTEGER, 0); return trident.getItem().getEnchantments().containsKey(Enchantment.LOYALTY);
} }
public static void registerLoyalty(Trident trident, int level) { public static void registerLoyalty(Trident trident, int level) {