From 98d876a1e71d6ae52a3917efed6c901c42173bb7 Mon Sep 17 00:00:00 2001 From: bluefalconhd Date: Tue, 7 Nov 2023 00:11:07 -0600 Subject: [PATCH] fix: plugin instancing --- .../bluefalconhd/sharpglow/PlayerKillDeathListener.java | 9 ++++++++- src/main/java/com/bluefalconhd/sharpglow/Sharpglow.java | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bluefalconhd/sharpglow/PlayerKillDeathListener.java b/src/main/java/com/bluefalconhd/sharpglow/PlayerKillDeathListener.java index f8dc136..25f52e2 100644 --- a/src/main/java/com/bluefalconhd/sharpglow/PlayerKillDeathListener.java +++ b/src/main/java/com/bluefalconhd/sharpglow/PlayerKillDeathListener.java @@ -7,11 +7,18 @@ import org.bukkit.entity.Player; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; public class PlayerKillDeathListener implements Listener { + private Sharpglow plugin; + + public PlayerKillDeathListener(Sharpglow sharpglow) { + plugin = sharpglow; + } + private boolean canEnchantWithSharpness(Material material) { // Define a list of materials that can be enchanted with Sharpness. Material[] enchantable = { @@ -40,7 +47,7 @@ private void killEffects(Player player) { ItemStack item = player.getInventory().getItemInMainHand(); // Get the item in the player's main hand. if (canEnchantWithSharpness(item.getType())) { // Check if the item can be enchanted with Sharpness. // Apply the temporary enchantment to the item for 30 mins - Sharpglow.getTemporaryEnchantmentManager().applyTemporaryEnchantment(item, Enchantment.DAMAGE_ALL, 2, 20 * 60 * 30, player); + plugin.getTemporaryEnchantmentManager().applyTemporaryEnchantment(item, Enchantment.DAMAGE_ALL, 2, 20 * 60 * 30, player); } // give player glowing effect for 30 mins diff --git a/src/main/java/com/bluefalconhd/sharpglow/Sharpglow.java b/src/main/java/com/bluefalconhd/sharpglow/Sharpglow.java index f686576..532cb63 100644 --- a/src/main/java/com/bluefalconhd/sharpglow/Sharpglow.java +++ b/src/main/java/com/bluefalconhd/sharpglow/Sharpglow.java @@ -16,7 +16,7 @@ public void onEnable() { // Register the MilkCancelListener class as a listener getServer().getPluginManager().registerEvents(new MilkCancelListener(), this); // Register the PlayerKillDeathListener class as a listener - getServer().getPluginManager().registerEvents(new PlayerKillDeathListener(), this); + getServer().getPluginManager().registerEvents(new PlayerKillDeathListener(this), this); // } @@ -26,7 +26,7 @@ public void onDisable() { getLogger().info("Sharpglow has been disabled!"); } - public static TemporaryEnchantmentManager getTemporaryEnchantmentManager() { + public TemporaryEnchantmentManager getTemporaryEnchantmentManager() { return tempEnchantManager; } }