diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticEquipEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticEquipEvent.java new file mode 100644 index 00000000..a214a5cb --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticEquipEvent.java @@ -0,0 +1,53 @@ +package com.hibiscusmc.hmccosmetics.api; + +import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlayerCosmeticEquipEvent extends Event implements Cancellable { + + private CosmeticUser user; + private Cosmetic cosmetic; + private boolean isCancelled; + + public PlayerCosmeticEquipEvent(CosmeticUser user, Cosmetic cosmetic) { + this.user = user; + this.cosmetic = cosmetic; + this.isCancelled = false; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancel) { + isCancelled = cancel; + } + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public CosmeticUser getUser() { + return user; + } + + public Cosmetic getCosmetic() { + return cosmetic; + } + + public void setCosmetic() { + this.cosmetic = cosmetic; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticRemoveEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticRemoveEvent.java new file mode 100644 index 00000000..639e42ee --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerCosmeticRemoveEvent.java @@ -0,0 +1,49 @@ +package com.hibiscusmc.hmccosmetics.api; + +import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlayerCosmeticRemoveEvent extends Event implements Cancellable { + + private CosmeticUser user; + private Cosmetic cosmetic; + private boolean isCancelled; + + public PlayerCosmeticRemoveEvent(CosmeticUser user, Cosmetic cosmetic) { + this.user = user; + this.cosmetic = cosmetic; + this.isCancelled = false; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean cancel) { + isCancelled = cancel; + } + + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public CosmeticUser getUser() { + return user; + } + + public Cosmetic getCosmetic() { + return cosmetic; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index 98828cec..e1b197d5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -1,10 +1,7 @@ package com.hibiscusmc.hmccosmetics.user; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; -import com.hibiscusmc.hmccosmetics.api.PlayerHideCosmeticEvent; -import com.hibiscusmc.hmccosmetics.api.PlayerShowCosmeticEvent; -import com.hibiscusmc.hmccosmetics.api.PlayerWardrobeEnterEvent; -import com.hibiscusmc.hmccosmetics.api.PlayerWardrobeLeaveEvent; +import com.hibiscusmc.hmccosmetics.api.*; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; @@ -81,9 +78,18 @@ public class CosmeticUser { } public void addPlayerCosmetic(Cosmetic cosmetic, Color color) { + // API + PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + cosmetic = event.getCosmetic(); + // Internal if (playerCosmetics.containsKey(cosmetic.getSlot())) { removeCosmeticSlot(cosmetic.getSlot()); } + playerCosmetics.put(cosmetic.getSlot(), cosmetic); if (color != null) colors.put(cosmetic.getSlot(), color); MessagesUtil.sendDebugMessages("addPlayerCosmetic " + cosmetic.getId()); @@ -106,6 +112,13 @@ public class CosmeticUser { } public void removeCosmeticSlot(CosmeticSlot slot) { + // API + PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, getCosmetic(slot)); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + // Internal if (slot == CosmeticSlot.BACKPACK) { despawnBackpack(); }