mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
expose constructor
This commit is contained in:
@@ -2,33 +2,59 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
|
|||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public abstract class Cosmetic {
|
public abstract class Cosmetic {
|
||||||
|
protected static ItemStack UNDEFINED_DISPLAY_ITEM_STACK;
|
||||||
|
|
||||||
@Getter @Setter
|
static {
|
||||||
|
UNDEFINED_DISPLAY_ITEM_STACK = new ItemStack(Material.BARRIER);
|
||||||
|
UNDEFINED_DISPLAY_ITEM_STACK.editMeta(meta -> {
|
||||||
|
meta.displayName(Component.text("Undefined Item Display", NamedTextColor.RED));
|
||||||
|
meta.lore(List.of(
|
||||||
|
Component.text("Please check your configurations & console to", NamedTextColor.RED),
|
||||||
|
Component.text("ensure there are no errors.", NamedTextColor.RED)
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Identifier of the cosmetic. */
|
||||||
private String id;
|
private String id;
|
||||||
@Getter @Setter
|
|
||||||
|
/** Permission to use the cosmetic. */
|
||||||
private String permission;
|
private String permission;
|
||||||
|
|
||||||
|
/** The display {@link ItemStack} of the cosmetic. */
|
||||||
|
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
|
||||||
private ItemStack item;
|
private ItemStack item;
|
||||||
@Getter @Setter
|
|
||||||
|
/** The material string of the cosmetic. */
|
||||||
private String material;
|
private String material;
|
||||||
@Getter @Setter
|
|
||||||
|
/** The {@link CosmeticSlot} this cosmetic occupies. */
|
||||||
private CosmeticSlot slot;
|
private CosmeticSlot slot;
|
||||||
@Getter @Setter
|
|
||||||
|
/** Whether the cosmetic is dyeable or not. */
|
||||||
private boolean dyeable;
|
private boolean dyeable;
|
||||||
|
|
||||||
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
|
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (!config.node("permission").virtual()) {
|
if (!config.node("permission").virtual()) {
|
||||||
@@ -39,23 +65,49 @@ public abstract class Cosmetic {
|
|||||||
|
|
||||||
if (!config.node("item").virtual()) {
|
if (!config.node("item").virtual()) {
|
||||||
this.material = config.node("item", "material").getString();
|
this.material = config.node("item", "material").getString();
|
||||||
this.item = generateItemStack(config.node("item"));
|
try {
|
||||||
|
this.item = generateItemStack(config.node("item"));
|
||||||
|
} catch(Exception ex) {
|
||||||
|
MessagesUtil.sendDebugMessages("Forcing %s to use undefined display".formatted(getId()));
|
||||||
|
this.item = UNDEFINED_DISPLAY_ITEM_STACK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
||||||
|
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
|
||||||
|
|
||||||
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
this.dyeable = config.node("dyeable").getBoolean(false);
|
||||||
setDyeable(config.node("dyeable").getBoolean(false));
|
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
|
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
|
||||||
Cosmetics.addCosmetic(this);
|
}
|
||||||
|
|
||||||
|
protected Cosmetic(String id, String permission, ItemStack item, String material, CosmeticSlot slot, boolean dyeable) {
|
||||||
|
this.id = id;
|
||||||
|
this.permission = permission;
|
||||||
|
this.item = item;
|
||||||
|
this.material = material;
|
||||||
|
this.slot = slot;
|
||||||
|
this.dyeable = dyeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresPermission() {
|
public boolean requiresPermission() {
|
||||||
return permission != null;
|
return permission != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void update(CosmeticUser user);
|
/**
|
||||||
|
* Dispatched when an update is requested upon the cosmetic.
|
||||||
|
* @param user the user to preform the update against
|
||||||
|
*/
|
||||||
|
public final void update(CosmeticUser user) {
|
||||||
|
this.doUpdate(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action preformed on the update.
|
||||||
|
* @param user the user to preform the update against
|
||||||
|
*/
|
||||||
|
protected void doUpdate(final CosmeticUser user) {
|
||||||
|
// NO-OP.
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
@@ -63,6 +115,11 @@ public abstract class Cosmetic {
|
|||||||
return item.clone();
|
return item.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an {@link ItemStack} from a {@link ConfigurationNode}.
|
||||||
|
* @param config the configuration node
|
||||||
|
* @return the {@link ItemStack}
|
||||||
|
*/
|
||||||
protected ItemStack generateItemStack(ConfigurationNode config) {
|
protected ItemStack generateItemStack(ConfigurationNode config) {
|
||||||
try {
|
try {
|
||||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class CosmeticArmorType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||||
if (user.isInWardrobe()) return;
|
if (user.isInWardrobe()) return;
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||||
Entity entity = user.getEntity();
|
Entity entity = user.getEntity();
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class CosmeticMainhandType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
protected void doUpdate(@NotNull CosmeticUser user) {
|
||||||
Player player = user.getPlayer();
|
Player player = user.getPlayer();
|
||||||
|
|
||||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
|
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
|
||||||
|
|||||||
Reference in New Issue
Block a user