From fc5b34a35292776fe2d3b20e5ca521056d117ca3 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 28 Mar 2023 16:11:54 +0100 Subject: [PATCH] Debug by removing skills from SkillSlots when the skills gets locked.Done by creating a Listener for ItemLockedEvent. --- .../net/Indyuce/mmocore/MMOCoreBukkit.java | 1 + .../listener/SkillLockingListener.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/SkillLockingListener.java diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/MMOCoreBukkit.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/MMOCoreBukkit.java index 160c0922..4ded3211 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/MMOCoreBukkit.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/MMOCoreBukkit.java @@ -47,6 +47,7 @@ public class MMOCoreBukkit { Bukkit.getPluginManager().registerEvents(new FishingListener(), plugin); Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin); Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin); + Bukkit.getPluginManager().registerEvents(new SkillLockingListener(),plugin); // Bukkit.getPluginManager().registerEvents(new ClassTriggers(), plugin); } } diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/SkillLockingListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/SkillLockingListener.java new file mode 100644 index 00000000..d65c79d9 --- /dev/null +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/SkillLockingListener.java @@ -0,0 +1,25 @@ +package net.Indyuce.mmocore.listener; + +import io.lumine.mythic.lib.api.event.unlocking.ItemLockedEvent; +import net.Indyuce.mmocore.api.player.PlayerData; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class SkillLockingListener implements Listener { + + /** + * Unbind the skill from boundSkills when it becomes locked. + */ + @EventHandler + public void onSkillLock(ItemLockedEvent event) { + if (event.getItemTypeId().equals("skill")) { + PlayerData playerData = PlayerData.get(event.getData().getUniqueId()); + playerData.mapBoundSkills() + .forEach((slot, skillId) -> { + if (skillId.equalsIgnoreCase(event.getItemId())) + playerData.unbindSkill(slot); + }); + } + } +}