mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Add CosmeticEquip & Remove Events
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user