Skip to content

Commit

Permalink
Update skills on pickup/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Travja committed Feb 27, 2024
1 parent d0ecab8 commit 921e4c8
Showing 1 changed file with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
Expand All @@ -33,8 +35,8 @@

public class ItemAbilityHandler extends IListener<QuantumRPG> implements Loadable {

private final ItemGeneratorManager itemGen;
private final List<UUID> noSpam = new ArrayList<>();
private final ItemGeneratorManager itemGen;
private final List<UUID> noSpam = new ArrayList<>();

ItemAbilityHandler(@NotNull ItemGeneratorManager itemGen) {
super(itemGen.plugin);
Expand Down Expand Up @@ -64,44 +66,80 @@ private boolean registerSentMessage(Player player) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) {
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {skillAPIHK.updateSkills(event.getPlayer());}
if (skillAPIHK != null) {
skillAPIHK.updateSkills(event.getPlayer());
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemHeldEvent(PlayerItemHeldEvent event) {
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {skillAPIHK.updateSkills(event.getPlayer());}
if (skillAPIHK != null) {
skillAPIHK.updateSkills(event.getPlayer());
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDrop(PlayerDropItemEvent event) {
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {
skillAPIHK.updateSkills(event.getPlayer());
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDrop(EntityPickupItemEvent event) {
if (!(event.getEntity() instanceof Player)) return;
Player player = (Player) event.getEntity();
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {
skillAPIHK.updateSkills(player);
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onArmorEquip(ArmorEquipEvent event) {
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {skillAPIHK.updateSkills(event.getPlayer());}
if (skillAPIHK != null) {
skillAPIHK.updateSkills(event.getPlayer());
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
InventoryView view = event.getView();
for (Inventory inventory : new Inventory[]{view.getTopInventory(), view.getBottomInventory()}) {
if (!(inventory instanceof PlayerInventory)) { continue; }
if (!(inventory instanceof PlayerInventory)) {
continue;
}
PlayerInventory playerInventory = (PlayerInventory) inventory;
HumanEntity humanEntity = playerInventory.getHolder();
if (!(humanEntity instanceof Player)) { return; }
HumanEntity humanEntity = playerInventory.getHolder();
if (!(humanEntity instanceof Player)) {
return;
}
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {skillAPIHK.updateSkills((Player) humanEntity);}
if (skillAPIHK != null) {
skillAPIHK.updateSkills((Player) humanEntity);
}
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
InventoryView view = event.getView();
for (Inventory inventory : new Inventory[]{view.getTopInventory(), view.getBottomInventory()}) {
if (!(inventory instanceof PlayerInventory)) { continue; }
if (!(inventory instanceof PlayerInventory)) {
continue;
}
PlayerInventory playerInventory = (PlayerInventory) inventory;
HumanEntity humanEntity = playerInventory.getHolder();
if (!(humanEntity instanceof Player)) { return; }
HumanEntity humanEntity = playerInventory.getHolder();
if (!(humanEntity instanceof Player)) {
return;
}
SkillAPIHK skillAPIHK = (SkillAPIHK) this.plugin.getHook(EHook.SKILL_API);
if (skillAPIHK != null) {skillAPIHK.updateSkills((Player) humanEntity);}
if (skillAPIHK != null) {
skillAPIHK.updateSkills((Player) humanEntity);
}
}
}

Expand Down Expand Up @@ -151,7 +189,7 @@ public void onItemConsumeNatural(PlayerItemConsumeEvent e) {
GeneratorItem aItem = this.itemGen.getModuleItem(item);
if (aItem == null) return;

Player player = e.getPlayer();
Player player = e.getPlayer();

e.setCancelled(true);

Expand Down

0 comments on commit 921e4c8

Please sign in to comment.