9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-23 17:09:24 +00:00

Compare commits

...

31 Commits

Author SHA1 Message Date
LoJoSho
bebee807bc fix: fix possible database memory leak (as well as improvements in code) 2025-05-29 14:59:57 -05:00
LoJoSho
26c579b69f chore: add cosmetic passengers to dump command 2025-05-25 14:02:04 -05:00
LoJoSho
ef665e7e83 fix: improper call to getEntity when not needed 2025-05-23 13:22:29 -05:00
LoJoSho
7a6475c467 chore: update LuckPerms 2025-05-22 21:07:12 -05:00
LoJoSho
63963cccc3 clean: server listener priorities 2025-05-21 23:56:30 -05:00
Logan
7cf6a3c75c Merge pull request #182 from HibiscusMC/refactorio
refactor: improve worldguard listener
2025-05-18 08:33:37 -05:00
Boy0000
22a5bb4cf1 refactor: improve worldguard listener 2025-05-18 13:22:38 +02:00
Logan
148d163d9c Merge pull request #181 from DebitCardz/fix-add-user
add user to pre unload
2025-05-16 14:50:22 -05:00
Tech
ef36e66c51 add user to pre unload 2025-05-16 15:13:38 -04:00
Logan
e5fda588c3 Merge pull request #179 from DebitCardz/constructor
expose constructor
2025-05-11 18:46:12 -05:00
Logan
3baf2694be Merge pull request #177 from DebitCardz/connection-update
add unload
2025-05-11 15:08:25 -05:00
Tech
a1dafdee5b expose constructor 2025-05-11 14:40:08 -04:00
Tech
e3a42d8b4a add unload 2025-05-10 10:40:30 -04:00
Boy0000
b366f5930b fix: dyed cosmetic item not updated 2025-05-10 00:07:19 +02:00
lojosho
45eb1fa668 chore: update HibiscusCommons 2025-05-09 11:35:13 -05:00
Logan
c466405a81 Merge pull request #176 from HibiscusMC/le-epic-minor-tweaks-again-we-love-it
feat: dyeable click-type & color changes
2025-05-09 10:56:31 -05:00
Boy0000
172ffc0333 refactor: swap to commons color api 2025-05-09 16:00:26 +02:00
Boy0000
41ac857a11 feat: determine color based on new HMCColor API to allow any Material to be dyable 2025-05-09 14:32:29 +02:00
Boy0000
737d63642c feat: add dye-click to settings 2025-05-09 13:46:12 +02:00
Boy
7b9b7678a3 chore: crucial typo fix 2025-05-09 11:42:45 +02:00
Boy
fe88d0c608 fix: bump hmccolor 2025-05-09 11:42:45 +02:00
lojosho
e14935af7b feat: add new processItemMeta implementation that respects MiniMessage/Components as best it can 2025-05-07 22:22:16 -05:00
lojosho
3e83d370f8 chore: update HibiscusCommons 2025-05-03 09:55:01 -05:00
lojosho
874a7f5624 fix: menu packet changes in 1.21.5 2025-05-02 10:50:21 -05:00
lojosho
3af992a291 chore: remove default emote in defaultcosmetics.yml 2025-05-02 10:43:17 -05:00
Logan
9ef7791998 Merge pull request #174 from HibiscusMC/minor-tweaks
Minor tweaks
2025-04-26 09:39:00 -05:00
Boy
1cbe17ddd4 chore: bump triumph-gui 2025-04-26 13:53:09 +02:00
Boy
2841742af9 fix: allow id to be specified in menu-config, default to filename 2025-04-26 12:16:41 +02:00
LoJoSho
6e2f333404 chore: add more debugging for balloon updating 2025-04-19 16:44:03 -05:00
lojosho
af8949b713 chore: remove emotes 2025-04-14 16:35:25 -05:00
lojosho
d6f7d0fcb3 version bump (2.7.8) 2025-04-14 16:34:48 -05:00
39 changed files with 375 additions and 933 deletions

View File

@@ -8,7 +8,7 @@ plugins {
}
group = "com.hibiscusmc"
version = "2.7.7${getGitCommitHash()}"
version = "2.7.8${getGitCommitHash()}"
allprojects {
apply(plugin = "java")
@@ -86,7 +86,7 @@ allprojects {
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.6.2-d21ebed8")
compileOnly("me.lojosho:HibiscusCommons:0.6.3-0f0baaf4")
// Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.19.0")
@@ -97,7 +97,7 @@ allprojects {
testCompileOnly("org.projectlombok:lombok:1.18.36")
testAnnotationProcessor("org.projectlombok:lombok:1.18.36")
implementation("dev.triumphteam:triumph-gui:3.1.12-SNAPSHOT") {
implementation("dev.triumphteam:triumph-gui:3.2.0-SNAPSHOT") {
exclude("net.kyori") // Already have adventure API
}
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
@@ -139,7 +139,7 @@ tasks {
downloadPlugins {
hangar("PlaceholderAPI", "2.11.6")
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar")
url("https://download.luckperms.net/1582/bukkit/loader/LuckPerms-Bukkit-5.4.165.jar")
}
}

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics;
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
@@ -10,7 +9,6 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.hooks.items.HookHMCCosmetics;
@@ -26,7 +24,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
import com.ticxo.playeranimator.PlayerAnimatorImpl;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.HibiscusPlugin;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
@@ -68,9 +65,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
// Player Animator ~ Do no longer support running this on a version that PlayerAnimator is supported
// if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
// Configuration Sync
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile();
@@ -125,9 +119,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
for (Player player : Bukkit.getOnlinePlayers()) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) continue;
if (user.getUserEmoteManager().isPlayingEmote()) {
player.setInvisible(false);
}
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
}
@@ -229,8 +220,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
}
}
//if (Settings.isEmotesEnabled() && (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1"))) EmoteManager.loadEmotes(); // PlayerAnimator does not support 1.20.2 yet
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");

View File

@@ -1,54 +0,0 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player starts playing an emote.
*/
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final String animationId;
private boolean cancel = false;
public PlayerEmoteStartEvent(@NotNull CosmeticUser who, @NotNull String animationId) {
super(who);
this.animationId = animationId;
}
/**
* Gets the animation id of the emote the player started playing.
*
* @implNote The returned string of this method may be an invalid animation id.
* Make sure to validate it before use by calling {@link com.hibiscusmc.hmccosmetics.emotes.EmoteManager#get(String)}.
*
* @return the animation id of the emote which the player started playing
*/
@NotNull
public String getAnimationId() {
return animationId;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -1,64 +0,0 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player stops playing an emote.
*/
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final UserEmoteManager.StopEmoteReason reason;
private boolean cancel = false;
public PlayerEmoteStopEvent(@NotNull CosmeticUser who, @NotNull UserEmoteManager.StopEmoteReason reason) {
super(who);
this.reason = reason;
}
/**
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
*
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
*/
@Deprecated(forRemoval = true)
@NotNull
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
return reason;
}
/**
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing.
*
* @return the reason why the emote has stopped playing
* @since 2.2.5
*/
public @NotNull UserEmoteManager.StopEmoteReason getReason() {
return reason;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -0,0 +1,43 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* Called before a player's data is un-loaded from the plugin.
*
* <p>
* If this event is cancelled, the player's data will not be un-loaded,
* and will be kept in memory.
* </p>
*/
public class PlayerPreUnloadEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled = false;
public PlayerPreUnloadEvent(@NotNull CosmeticUser who) {
super(who);
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@@ -10,9 +10,7 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
@@ -23,7 +21,6 @@ import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.OfflinePlayer;
@@ -403,6 +400,7 @@ public class CosmeticCommand implements CommandExecutor {
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
}
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
player.sendMessage("Cosmetics -> " + user.getCosmetics());
player.sendMessage("EntityId -> " + player.getEntityId());
return true;
@@ -464,59 +462,6 @@ public class CosmeticCommand implements CommandExecutor {
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
}
}
case ("emote") -> {
if (!sender.hasPermission("hmccosmetics.cmd.emote")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
return true;
}
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
cosmeticEmoteType.run(user);
return true;
}
case ("playemote") -> {
// /cosmetic playEmote <emoteId> [playerName]
if (!sender.hasPermission("hmccosmetics.cmd.playemote")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true;
}
if (args.length < 2) {
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
return true;
}
if (!EmoteManager.has(args[1])) {
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
return true;
}
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
}
if (player == null) {
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
return true;
}
CosmeticUser user = CosmeticUsers.getUser(player);
user.getUserEmoteManager().playEmote(args[1]);
return true;
}
case "disableall" -> {
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");

View File

@@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -44,8 +43,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (hasPermission(sender, "hmccosmetics.cmd.hide")) completions.add("hide");
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
@@ -74,7 +71,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
}
}
case "dataclear", "hide", "show", "emote", "hiddenreasons", "clearhiddenreasons" -> {
case "dataclear", "hide", "show", "hiddenreasons", "clearhiddenreasons" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}
@@ -102,7 +99,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
completions.add(wardrobe.getId());
}
}
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
}
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
}
@@ -112,7 +108,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
case "dye" -> {
completions.add("#FFFFFF");
}
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
case "menu", "wardrobe", "apply", "unapply" -> {
for (Player player : Bukkit.getOnlinePlayers()) {
completions.add(player.getName());
}

View File

@@ -35,7 +35,6 @@ public class Settings {
private static final String ITEM_PROCESS_LORE_PATH = "lore";
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
private static final String HOOK_SETTING_PATH = "hook-settings";
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
private static final String HOOK_NEXO_PATH = "nexo";
@@ -43,13 +42,6 @@ public class Settings {
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
private static final String COSMETIC_EMOTE_ENABLE = "emote-enable";
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
@@ -61,6 +53,7 @@ public class Settings {
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
private static final String EQUIP_CLICK_TYPE = "equip-click";
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
private static final String DYE_CLICK_TYPE = "dye-click";
private static final String SHADING_PATH = "shading";
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
@@ -104,22 +97,12 @@ public class Settings {
private static boolean nexoChangeReload;
@Getter
private static boolean worldGuardMoveCheck;
@Getter
private static boolean cosmeticEmoteBlockCheck;
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
@Getter
private static boolean emoteAirCheck;
@Getter
private static boolean emoteDamageLeave;
@Getter
private static boolean emoteInvincible;
@Getter
private static boolean destroyLooseCosmetics;
@Getter
private static boolean backpackForceRidingEnabled;
@Getter
private static boolean emotesEnabled;
@Getter
private static boolean disabledGamemodesEnabled;
@Getter
private static boolean balloonHeadForward;
@@ -148,6 +131,8 @@ public class Settings {
@Getter
private static String cosmeticUnEquipClickType;
@Getter
private static String cosmeticDyeClickType;
@Getter
private static boolean defaultShading;
@Getter
private static String firstRowShift;
@@ -165,10 +150,6 @@ public class Settings {
private static String equipableCosmeticColor;
@Getter
private static String lockedCosmeticColor;
@Getter
private static boolean emoteCameraEnabled;
@Getter
private static boolean emoteMoveCheck;
@Getter @Setter
private static boolean allPlayersHidden;
@Getter
@@ -209,12 +190,6 @@ public class Settings {
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
@@ -231,8 +206,6 @@ public class Settings {
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
@@ -257,6 +230,7 @@ public class Settings {
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ALL");
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
balloonOffset = loadVector(balloonSection);

View File

@@ -2,33 +2,59 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.shaded.configurate.ConfigurationNode;
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.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.logging.Level;
@Getter
@Setter
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;
@Getter @Setter
private String permission;
private ItemStack item;
@Getter @Setter
private String material;
@Getter @Setter
private CosmeticSlot slot;
@Getter @Setter
private boolean dyable;
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
/** Permission to use the cosmetic. */
private String permission;
/** The display {@link ItemStack} of the cosmetic. */
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private ItemStack item;
/** The material string of the cosmetic. */
private String material;
/** The {@link CosmeticSlot} this cosmetic occupies. */
private CosmeticSlot slot;
/** Whether the cosmetic is dyeable or not. */
private boolean dyeable;
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
this.id = id;
if (!config.node("permission").virtual()) {
@@ -39,23 +65,49 @@ public abstract class Cosmetic {
if (!config.node("item").virtual()) {
this.material = config.node("item", "material").getString();
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());
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
setDyable(config.node("dyeable").getBoolean(false));
this.dyeable = config.node("dyeable").getBoolean(false);
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
}
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
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() {
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
public ItemStack getItem() {
@@ -63,6 +115,11 @@ public abstract class Cosmetic {
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) {
try {
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);

View File

@@ -28,9 +28,7 @@ public abstract class CosmeticProvider {
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new),
Map.entry(CosmeticSlot.EMOTE, CosmeticEmoteType::new)
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new)
);
private static final String EXCEPTION_MESSAGE = "Unknown slot %s provided for mapping, if you registered your own CosmeticSlot please ensure that you've also registered a custom CosmeticProvider! Or if you have already registered a custom CosmeticProvider ensure it is registered in your plugins `onLoad` method instead of `onEnable`!";

View File

@@ -20,7 +20,6 @@ public class CosmeticSlot {
public static final CosmeticSlot OFFHAND = register("OFFHAND");
public static final CosmeticSlot BACKPACK = register("BACKPACK");
public static final CosmeticSlot BALLOON = register("BALLOON");
public static final CosmeticSlot EMOTE = register("EMOTE");
private final String name;

View File

@@ -31,8 +31,8 @@ public class CosmeticArmorType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) return;
protected void doUpdate(@NotNull CosmeticUser user) {
if (user.isInWardrobe()) return;
Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return;
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {

View File

@@ -40,7 +40,7 @@ public class CosmeticBackpackType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
protected void doUpdate(@NotNull CosmeticUser user) {
Entity entity = user.getEntity();
if (entity == null) return;

View File

@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.shaded.configurate.ConfigurationNode;
@@ -22,7 +23,7 @@ public class CosmeticBalloonType extends Cosmetic {
@Getter
private final String modelName;
@Getter
private List<String> dyableParts;
private List<String> dyeableParts;
@Getter
private final boolean showLead;
@Getter
@@ -41,8 +42,8 @@ public class CosmeticBalloonType extends Cosmetic {
balloonOffset = Settings.loadVector(balloonOffsetNode);
try {
if (!config.node("dyable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class);
if (!config.node("dyeable-parts").virtual()) {
dyeableParts = config.node("dyeable-parts").getList(String.class);
}
} catch (SerializationException e) {
// Seriously?
@@ -53,7 +54,7 @@ public class CosmeticBalloonType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
protected void doUpdate(@NotNull CosmeticUser user) {
Entity entity = Bukkit.getEntity(user.getUniqueId());
UserBalloonManager userBalloonManager = user.getBalloonManager();
@@ -82,6 +83,11 @@ public class CosmeticBalloonType extends Cosmetic {
userBalloonManager.setLocation(newLocation);
userBalloonManager.setVelocity(velocity.multiply(1.1));
MessagesUtil.sendDebugMessages("Balloon Cosmetic Update for " + user.getEntity().getName());
MessagesUtil.sendDebugMessages("Ballon previous location is " + currentLocation);
MessagesUtil.sendDebugMessages("Balloon location set to " + newLocation);
MessagesUtil.sendDebugMessages("Balloon velocity set to " + velocity);
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
if (user.isHidden()) {
@@ -95,10 +101,10 @@ public class CosmeticBalloonType extends Cosmetic {
}
}
public boolean isDyablePart(String name) {
public boolean isDyeablePart(String name) {
// If player does not define parts, dye whole model
if (dyableParts == null) return true;
if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name);
if (dyeableParts == null) return true;
if (dyeableParts.isEmpty()) return true;
return dyeableParts.contains(name);
}
}

View File

@@ -1,38 +0,0 @@
package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.jetbrains.annotations.NotNull;
public class CosmeticEmoteType extends Cosmetic {
private final String animationId;
private final String text;
public CosmeticEmoteType(String id, ConfigurationNode config) {
super(id, config);
animationId = config.node("animation").getString();
text = config.node("text").getString();
MessagesUtil.sendDebugMessages("CosmeticEmoteType Animation id " + animationId);
}
@Override
public void update(CosmeticUser user) {
// Nothing
}
public void run(@NotNull CosmeticUser user) {
user.getUserEmoteManager().playEmote(this);
}
public String getAnimationId() {
return animationId;
}
public String getText() {
return text;
}
}

View File

@@ -15,7 +15,7 @@ public class CosmeticMainhandType extends Cosmetic {
}
@Override
public void update(@NotNull CosmeticUser user) {
protected void doUpdate(@NotNull CosmeticUser user) {
Player player = user.getPlayer();
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));

View File

@@ -39,10 +39,12 @@ public class MySQLData extends SQLData {
try {
openConnection();
if (connection == null) throw new NullPointerException("Connection is null");
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
");")) {
preparedStatement.execute();
}
} catch (SQLException | NullPointerException e) {
plugin.getLogger().severe("");
plugin.getLogger().severe("");
@@ -60,17 +62,11 @@ public class MySQLData extends SQLData {
@Override
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
});
}

View File

@@ -23,22 +23,17 @@ public abstract class SQLData extends Data {
return CompletableFuture.supplyAsync(() -> {
UserData data = new UserData(uniqueId);
PreparedStatement preparedStatement = null;
try {
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery();
try (ResultSet rs = preparedStatement.executeQuery()) {
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
data.setCosmetics(cosmetics);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null) preparedStatement.close();
} catch (SQLException e) {}
}
return data;
});
@@ -48,18 +43,12 @@ public abstract class SQLData extends Data {
@SuppressWarnings("resource")
public void save(CosmeticUser user) {
Runnable run = () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
};
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {

View File

@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
openConnection();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " +
");").execute();
");")) {
preparedStatement.execute();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
@@ -48,17 +50,11 @@ public class SQLiteData extends SQLData {
@SuppressWarnings("resource")
public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null;
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
}
});
}

View File

@@ -1,85 +0,0 @@
package com.hibiscusmc.hmccosmetics.emotes;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.ticxo.playeranimator.api.PlayerAnimator;
import com.ticxo.playeranimator.api.animation.pack.AnimationPack;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Manages Emotes
*/
@SuppressWarnings("SpellCheckingInspection")
public class EmoteManager {
private static final @NotNull Map<String, String> emotes = new HashMap<>();
/**
* Loads all BlockBench animations from the emotes folder and puts it into the animation manager registry and local registry
*/
public static void loadEmotes() {
// Clear the PlayerAnimator and local registries
PlayerAnimator.api.getAnimationManager().clearRegistry();
emotes.clear();
// Get the emote directory and check if it exists
File emoteDir = new File(HMCCosmeticsPlugin.getInstance().getDataFolder().getPath() + "/emotes/");
if (!emoteDir.exists()) return;
// Get all the files inside the directory and check if it isn't 0
File[] emoteFiles = emoteDir.listFiles();
if (emoteFiles == null || emoteFiles.length == 0) return;
// Remove any files that don't have the file extension ".bbmodel" and check if there are still resulting files
emoteFiles = Arrays.stream(emoteFiles).filter(file -> file.getPath().endsWith(".bbmodel")).distinct().toArray(File[]::new);
if (emoteFiles.length == 0) return;
// Loop through all files, importing all block bench animations into the registry
for (File animationFile : emoteFiles) {
String animationKey = FilenameUtils.removeExtension(animationFile.getName());
PlayerAnimator.api.getAnimationManager().importAnimations(animationKey, animationFile);
}
// Loops through all the entries in the registries and unpacks any animation packs to ensure if there were multiple animations
// inside a singular file, that they are added to the local registry individually for tab completion
for (Map.Entry<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
packEntry.getValue().getAnimations().keySet().forEach(animationName -> {
// API key is the format "animationKey.animationFileName.animationName"
String apiKey = packEntry.getKey().replace(":", ".") + "." + animationName;
emotes.put(animationName, apiKey);
});
}
}
/**
* Returns true if there is an animation with the specified name
* @param animationName Name whose presence is to be tested
* @return True if this registry contains a mapping for the specified name
*/
public static boolean has(@NotNull String animationName) {
return emotes.containsKey(animationName);
}
/**
* Returns the {@code API key} to which the specified name is mapped, or {@code null} if this map contains no mapping for the name.
* @param animationName Name whose {@code API key} is to be fetched
* @return The {@code API key} of the specified name or {@code null} if there was no animation name found
*/
public static @Nullable String get(@NotNull String animationName) {
return emotes.get(animationName);
}
/**
* Gets a set of all the laoded animation names
* @return A set of all loaded animation names
*/
public static @NotNull Set<String> getAllNames() {
return emotes.keySet();
}
}

View File

@@ -57,7 +57,7 @@ public class Menu {
private final boolean shading;
public Menu(String id, @NotNull ConfigurationNode config) {
this.id = id;
this.id = config.node("id").getString(id);
this.config = config;
title = config.node("title").getString("chest");
@@ -154,8 +154,7 @@ public class Menu {
Gui gui = Gui.gui()
.title(component)
.type(GuiType.CHEST)
.rows(this.rows)
.inventory((title, owner, rows) -> Bukkit.createInventory(owner, rows, title))
.inventory((title, owner, type) -> Bukkit.createInventory(owner, rows * 9, title))
.create();
gui.setDefaultClickAction(event -> event.setCancelled(true));
@@ -248,7 +247,7 @@ public class Menu {
}
}
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(viewer, title.toString())));
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, title.toString())));
} else {
for (int i = 0; i < gui.getInventory().getSize(); i++) {
if (items.containsKey(i)) {

View File

@@ -9,12 +9,14 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ColorBuilder;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.hibiscuscommons.util.StringUtils;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,31 +27,17 @@ public class DyeMenu {
return;
}
ItemStack originalItem = cosmetic.getItem();
if (originalItem == null || !cosmetic.isDyable()) return;
if (originalItem == null || !cosmetic.isDyeable()) return;
Gui gui = HMCColorApi.createColorMenu(viewer);
gui.updateTitle(Hooks.processPlaceholders(viewer, StringUtils.parseStringToString(Settings.getDyeMenuName())));
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, StringUtils.parseStringToString(Settings.getDyeMenuName()))));
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
gui.setDefaultTopClickAction(event -> {
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
if (item == null) return;
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
Color color = null;
if (meta instanceof LeatherArmorMeta leatherMeta) {
color = leatherMeta.getColor();
} else if (meta instanceof PotionMeta potionMeta) {
color = potionMeta.getColor();
} else if (meta instanceof MapMeta mapMeta) {
color = mapMeta.getColor();
} else if (meta instanceof FireworkEffectMeta fireworkEffectMeta) {
FireworkEffect effect = fireworkEffectMeta.getEffect();
if (effect != null) {
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
}
}
Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
if (color == null) return;
addCosmetic(viewer, cosmeticHolder, cosmetic, color);

View File

@@ -2,10 +2,22 @@ package com.hibiscusmc.hmccosmetics.gui.type;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class Type {
@@ -48,4 +60,59 @@ public abstract class Type {
* @deprecated Override {@link #setItem(Player, CosmeticHolder, ConfigurationNode, ItemStack, int)} instead.
*/
public abstract ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot);
@Contract("_, _ -> param2")
@NotNull
@SuppressWarnings("Duplicates")
protected ItemMeta processItemMeta(Player viewer, @NotNull ItemMeta itemMeta) {
// New implementation - Paper and forks
// I know this is a kinda batshit way to do it (with serializing and deserializing MiniMessage)
// But currently I can't think of another good way of doing it without a big refactor. I'll come back to this
// At a later date.
if (HibiscusCommonsPlugin.isOnPaper()) {
List<Component> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
String displayName = MiniMessage.miniMessage().serialize(itemMeta.displayName());
displayName = Hooks.processPlaceholders(viewer, displayName);
itemMeta.displayName(MiniMessage.miniMessage().deserialize(displayName).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
}
if (itemMeta.hasLore()) {
for (Component loreLine : itemMeta.lore()) {
String loreStringLine = MiniMessage.miniMessage().serialize(loreLine);
loreStringLine = Hooks.processPlaceholders(viewer, loreStringLine);
processedLore.add(MiniMessage.miniMessage().deserialize(loreStringLine).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.lore(processedLore);
} else {
// Legacy implementation - Spigot
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
}
return itemMeta;
}
}

View File

@@ -20,9 +20,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -62,17 +59,22 @@ public class TypeCosmetic extends Type {
boolean isUnEquippingCosmetic = false;
if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
String dyeClick = Settings.getCosmeticDyeClickType();
String requiredClick;
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
else requiredClick = Settings.getCosmeticEquipClickType();
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
if (!isRequiredClick && !isDyeClick) {
MessagesUtil.sendMessage(viewer.getPlayer(), "invalid-click-type");
return;
}
if (!isRequiredClick && isDyeClick) isUnEquippingCosmetic = false;
List<String> actionStrings = new ArrayList<>();
ConfigurationNode actionConfig = config.node("actions");
@@ -104,9 +106,9 @@ public class TypeCosmetic extends Type {
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
MessagesUtil.sendDebugMessages("on-equip");
// TODO: Redo this
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
if (cosmetic.isDyeable() && isDyeClick && Hooks.isActiveHook("HMCColor")) {
DyeMenu.openMenu(viewer, cosmeticHolder, cosmetic);
} else {
} else if (isRequiredClick) {
cosmeticHolder.addCosmetic(cosmetic);
}
}
@@ -139,7 +141,7 @@ public class TypeCosmetic extends Type {
@Override
public ItemStack setItem(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(viewer, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
if (config.node("cosmetic").virtual()) {
@@ -164,7 +166,7 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(viewer, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
return itemStack;
}
@@ -182,35 +184,10 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) {
throw new RuntimeException(e);
}
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(viewer, itemStack.getItemMeta()));
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
return itemStack;
}
return itemStack;
}
@Contract("_, _ -> param2")
@NotNull
@SuppressWarnings("Duplicates")
private ItemMeta processLoreLines(Player viewer, @NotNull ItemMeta itemMeta) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
return itemMeta;
}
}

View File

@@ -4,14 +4,12 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
import com.hibiscusmc.hmccosmetics.gui.type.Type;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -78,27 +76,9 @@ public class TypeEmpty extends Type {
@Override
@SuppressWarnings("Duplicates")
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
List<String> processedLore = new ArrayList<>();
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasDisplayName()) {
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
}
}
if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
}
}
itemMeta.setLore(processedLore);
itemStack.setItemMeta(itemMeta);
itemStack.setItemMeta(processItemMeta(viewer, itemMeta));
return itemStack;
}

View File

@@ -1,6 +1,5 @@
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -8,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
@@ -20,32 +20,44 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
*/
public class WGListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
Player player = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
Location location = event.getPlayer().getLocation();
Location location = player.getLocation();
ApplicableRegionSet set = getRegions(location);
if (user.isHidden()) {
if (set.getRegions().isEmpty()) {
if (user.isHidden() && set.getRegions().isEmpty()) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
Set<String> wardrobeNames = WardrobeSettings.getWardrobeNames();
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
Map<Flag<?>, Object> flags = protectedRegion.getFlags();
if (flags.containsKey(WGHook.getCosmeticEnableFlag())) {
if (flags.get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
} else {
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
}
}
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
if (flags.containsKey(WGHook.getCosmeticWardrobeFlag())) {
String wardrobeName = flags.getOrDefault(WGHook.getCosmeticWardrobeFlag(), "").toString();
if (wardrobeName.isEmpty() || !wardrobeNames.contains(wardrobeName)) return;
Wardrobe wardrobe = WardrobeSettings.getWardrobe(wardrobeName);
if (wardrobe == null) return;
user.enterWardrobe(wardrobe, true);
}
}
@@ -79,23 +91,6 @@ public class WGListener implements Listener {
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerEmote(PlayerEmoteStartEvent event) {
Player player = event.getUser().getPlayer();
if (player == null) return;
Location location = player.getLocation();
ApplicableRegionSet set = getRegions(location);
for (ProtectedRegion protectedRegion : set.getRegions()) {
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
event.setCancelled(true);
return;
}
return;
}
}
}
private ApplicableRegionSet getRegions(Location location) {
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();

View File

@@ -3,15 +3,16 @@ package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerLoadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreLoadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreUnloadEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerUnloadEvent;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -22,43 +23,37 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class PlayerConnectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
MessagesUtil.sendMessageNoKey(
event.getPlayer(),
"<br>" +
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
"<br>"
if (DatabaseSettings.isEnabledDelay()) {
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
Bukkit.getScheduler().runTaskLater(
HMCCosmeticsPlugin.getInstance(),
() -> this.loadUserData(event.getPlayer()),
DatabaseSettings.getDelayLength()
);
} else {
this.loadUserData(event.getPlayer());
}
}
// This literally makes me want to end it all but I can't do that so I'll just cry instead
Runnable run = () -> {
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
UUID uuid = event.getPlayer().getUniqueId();
private void loadUserData(final Player player) {
if(!player.isOnline()) return;
final UUID playerId = player.getUniqueId();
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(uuid);
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(playerId);
Bukkit.getPluginManager().callEvent(preLoadEvent);
if (preLoadEvent.isCancelled()) return;
Database.get(uuid).thenAccept(userData -> {
if (userData == null) {
return;
}
Database.get(playerId).thenAccept(userData -> {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
.createCosmeticUser(uuid)
.createCosmeticUser(playerId)
.initialize(userData);
cosmeticUser.startTicking();
CosmeticUsers.addUser(cosmeticUser);
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
MessagesUtil.sendDebugMessages("Run User Join for " + playerId);
PlayerLoadEvent playerLoadEvent = new PlayerLoadEvent(cosmeticUser);
Bukkit.getPluginManager().callEvent(playerLoadEvent);
@@ -70,17 +65,9 @@ public class PlayerConnectionListener implements Listener {
}, 4);
});
}).exceptionally(ex -> {
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + uuid + ". Exception: " + ex.getMessage());
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + playerId + ". Exception: " + ex.getMessage());
return null;
});
};
if (DatabaseSettings.isEnabledDelay()) {
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, DatabaseSettings.getDelayLength());
} else {
run.run();
}
}
@EventHandler(priority = EventPriority.MONITOR)
@@ -88,20 +75,37 @@ public class PlayerConnectionListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return; // Player never initialized, don't do anything
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
Bukkit.getPluginManager().callEvent(preUnloadEvent);
if (preUnloadEvent.isCancelled()) return;
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
user.getPlayer().setInvisible(false);
}
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
event.getPlayer().setInvisible(false);
final Player player = user.getPlayer();
if(player != null) player.setInvisible(false);
}
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
Database.save(user);
user.destroy();
CosmeticUsers.removeUser(user.getUniqueId());
}
@EventHandler(priority = EventPriority.MONITOR)
public void notifyAdminUpdate(final PlayerJoinEvent event) {
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
MessagesUtil.sendMessageNoKey(
event.getPlayer(),
"<br>" +
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
"<br>"
);
}
}
}

View File

@@ -14,17 +14,17 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.hibiscuscommons.api.events.*;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -95,10 +95,6 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
if (event.isSneaking()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
}
if (!event.isSneaking()) return;
if (!user.isInWardrobe()) return;
@@ -136,9 +132,6 @@ public class PlayerGameListener implements Listener {
}, 2);
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@@ -180,14 +173,6 @@ public class PlayerGameListener implements Listener {
if (!(event.getEntity() instanceof Player player)) return;
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
if (Settings.isEmoteInvincible()) {
event.setCancelled(true);
}
if (Settings.isEmoteDamageLeave()) {
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
}
}
if (user.isInWardrobe()) {
if (WardrobeSettings.isPreventDamage()) {
event.setCancelled(true);
@@ -202,10 +187,6 @@ public class PlayerGameListener implements Listener {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (!Settings.isEmoteMoveCheck() && user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
user.updateCosmetic(CosmeticSlot.BACKPACK);
user.updateCosmetic(CosmeticSlot.BALLOON);
}
@@ -269,12 +250,6 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
// Really need to look into optimization of this
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) {
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
cosmeticEmoteType.run(user);
event.setCancelled(true);
return;
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (user.getEntity() == null) return; // Player has likely logged off
user.updateCosmetic(CosmeticSlot.OFFHAND);
@@ -457,7 +432,12 @@ public class PlayerGameListener implements Listener {
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
int invTypeClicked = event.getPacket().getIntegers().read(0);
int slotClicked = event.getPacket().getIntegers().read(2);
int slotClicked = -999;
if (NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_5)) {
slotClicked = event.getPacket().getShorts().read(0);
} else {
slotClicked = event.getPacket().getIntegers().read(2);
}
// Must be a player inventory.
if (invTypeClicked != 0) return;
@@ -666,10 +646,6 @@ public class PlayerGameListener implements Listener {
Player player = event.getPlayer();
CosmeticUser user = CosmeticUsers.getUser(player);
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) {
event.setCancelled(true);
return;
}
if (!user.isInWardrobe()) return;
if (!user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
@@ -688,7 +664,7 @@ public class PlayerGameListener implements Listener {
if (event.getPlayer() == null) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
if (user.isInWardrobe()) {
event.setCancelled(true);
}
}

View File

@@ -10,13 +10,15 @@ import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
public class ServerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHookReload(HibiscusHookReload event) {
Hook hook = event.getHook();
HibiscusHookReload.ReloadType reloadType = event.getReloadType();
@EventHandler(priority = EventPriority.LOW)
public void onHookReload(@NotNull HibiscusHookReload event) {
final Hook hook = event.getHook();
final HibiscusHookReload.ReloadType reloadType = event.getReloadType();
if (hook instanceof HookItemAdder) {
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
if (!Settings.isItemsAdderChangeReload()) return;
@@ -31,8 +33,8 @@ public class ServerListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAllHooksReady(HibiscusHooksAllActiveEvent event) {
@EventHandler(priority = EventPriority.NORMAL)
public void onAllHooksReady(@NotNull HibiscusHooksAllActiveEvent event) {
HMCCosmeticsPlugin.setup();
}
}

View File

@@ -18,13 +18,14 @@ import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.nms.NMSHandler;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.InventoryUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit;
@@ -54,8 +55,6 @@ public class CosmeticUser implements CosmeticHolder {
private UserBalloonManager userBalloonManager;
@Getter
private UserBackpackManager userBackpackManager;
@Getter
private final UserEmoteManager userEmoteManager;
// Cosmetic Settings/Toggles
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
@@ -74,7 +73,6 @@ public class CosmeticUser implements CosmeticHolder {
public CosmeticUser(@NotNull UUID uuid) {
this.uniqueId = uuid;
this.userEmoteManager = new UserEmoteManager(this);
}
/**
@@ -146,7 +144,7 @@ public class CosmeticUser implements CosmeticHolder {
showCosmetics(HiddenReason.GAMEMODE);
}
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(getEntity().getLocation().getWorld().getName())) {
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(bukkitPlayer.getLocation().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else if (this.isHidden(HiddenReason.WORLD)) {
@@ -194,7 +192,7 @@ public class CosmeticUser implements CosmeticHolder {
this.updateCosmetic();
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !playerCosmetics.isEmpty()) {
if(isHidden() && !playerCosmetics.isEmpty()) {
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
}
}
@@ -282,9 +280,6 @@ public class CosmeticUser implements CosmeticHolder {
if (slot == CosmeticSlot.BALLOON) {
despawnBalloon();
}
if (slot == CosmeticSlot.EMOTE) {
if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP);
}
colors.remove(slot);
playerCosmetics.remove(slot);
removeArmor(slot);
@@ -317,7 +312,7 @@ public class CosmeticUser implements CosmeticHolder {
for (Cosmetic cosmetic : playerCosmetics.values()) {
if (cosmetic instanceof CosmeticArmorType armorType) {
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
if (isInWardrobe()) return;
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
@@ -412,29 +407,15 @@ public class CosmeticUser implements CosmeticHolder {
}
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
if (itemMeta instanceof LeatherArmorMeta leatherMeta) {
leatherMeta.setColor(color);
} else if (itemMeta instanceof PotionMeta potionMeta) {
potionMeta.setColor(color);
} else if (itemMeta instanceof MapMeta mapMeta) {
mapMeta.setColor(color);
} else if (itemMeta instanceof FireworkEffectMeta fireworkMeta) {
fireworkMeta.setEffect(
FireworkEffect.builder()
.with(FireworkEffect.Type.BALL)
.withColor(color)
.trail(false)
.flicker(false)
.build()
);
}
}
itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
item.setItemMeta(itemMeta);
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
item = NMSHandlers.getHandler().getUtilHandler().setColor(item, color);
}
}
return item;
}
@@ -630,13 +611,13 @@ public class CosmeticUser implements CosmeticHolder {
}
public List<CosmeticSlot> getDyeableSlots() {
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>();
ArrayList<CosmeticSlot> dyeableSlots = new ArrayList<>();
for (Cosmetic cosmetic : playerCosmetics.values()) {
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
if (cosmetic.isDyeable()) dyeableSlots.add(cosmetic.getSlot());
}
return dyableSlots;
return dyeableSlots;
}
@Override

View File

@@ -84,7 +84,7 @@ public class UserBackpackManager {
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
HMCCPacketManager.sendRidingPacket(particleCloud.getLast(), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.isHidden()) PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner);
}
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);

View File

@@ -11,7 +11,6 @@ import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.nms.RenderParsers;
import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
@@ -82,7 +81,7 @@ public class UserBalloonManager {
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) {
if (cosmeticBalloonType.isDyeablePart(d)) {
singleModel.setDefaultTint(color);
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers());
}

View File

@@ -1,94 +0,0 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStopEvent;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class UserEmoteManager {
private CosmeticUser user;
private UserEmoteModel model;
private Entity textEntity;
public UserEmoteManager(CosmeticUser user) {
this.user = user;
}
public void playEmote(String animationId) {
MessagesUtil.sendDebugMessages("playEmote " + animationId);
playEmote(EmoteManager.get(animationId), null);
}
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
playEmote(EmoteManager.get(cosmeticEmoteType.getAnimationId()), cosmeticEmoteType.getText());
}
public void playEmote(String emoteAnimation, String text) {
if (isPlayingEmote()) return;
if (user.isInWardrobe()) return;
// API
PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, emoteAnimation);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Internal
try {
model = new UserEmoteModel(user);
// Play animation id
if (emoteAnimation != null) {
model.playAnimation(emoteAnimation);
}
// Show the text
if (text != null && textEntity == null) {
// removed in 2.7.0
//textEntity = HMCCNMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean isPlayingEmote() {
if (model == null) return false;
return model.isPlayingAnimation();
}
public void stopEmote(StopEmoteReason emoteReason) {
if (!isPlayingEmote()) return;
// API
PlayerEmoteStopEvent event = new PlayerEmoteStopEvent(user, emoteReason);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Internal
model.stopAnimation();
if (textEntity != null) {
textEntity.remove();
textEntity = null;
}
}
public void despawnTextEntity() {
if (textEntity != null) {
textEntity.remove();
textEntity = null;
}
}
public enum StopEmoteReason {
SNEAK,
DAMAGE,
CONNECTION,
TELEPORT,
UNEQUIP
}
}

View File

@@ -1,134 +0,0 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.playeranimator.api.model.player.PlayerModel;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class UserEmoteModel extends PlayerModel {
private final CosmeticUser user;
private String emotePlaying;
private final int armorStandId;
private GameMode originalGamemode;
public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer());
this.user = user;
armorStandId = ServerUtils.getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@Override
public void playAnimation(@NotNull String id) {
super.playAnimation(id);
emotePlaying = id;
// Add config option that either allows player to move or forces them into a spot.
Player player = user.getPlayer();
List<Player> viewer = Collections.singletonList(user.getPlayer());
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
// Send equipment packet to the player as well (Fixes Optifine still rendering armor when emoting)
HMCCPacketManager.equipmentSlotUpdate(player, true, outsideViewers);
outsideViewers.remove(player);
user.getPlayer().setInvisible(true);
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
originalGamemode = player.getGameMode();
if (Settings.isEmoteCameraEnabled()) {
Location newLocation = player.getLocation().clone();
newLocation.setPitch(0);
double DISTANCE = Settings.getEmoteDistance();
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
if (DISTANCE > 0) {
MessagesUtil.sendDebugMessages("Yaw " + (int) thirdPersonLocation.getYaw());
MessagesUtil.sendDebugMessages("New Yaw " + ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
thirdPersonLocation.setYaw(ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
}
if (Settings.isCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
return;
}
// Check if block below player is an air block
if (Settings.isEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) {
stopAnimation();
MessagesUtil.sendMessage(player, "emote-blocked");
}
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
HMCCPacketManager.sendInvisibilityPacket(armorStandId, viewer);
HMCCPacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(armorStandId, viewer);
}
MessagesUtil.sendDebugMessages("playAnimation run");
}
@Override
public boolean update() {
if (super.getAnimationProperty() == null) {
stopAnimation();
return false;
}
boolean update = (super.update() && isPlayingAnimation());
if (!update) {
stopAnimation();
}
return update;
}
public void stopAnimation() {
emotePlaying = null;
despawn();
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
Player player = user.getPlayer();
if (player == null) return;
List<Player> viewer = Collections.singletonList(player);
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
// Send Equipment packet to all (Fixes Optifine Issue)
HMCCPacketManager.equipmentSlotUpdate(player, false, outsideViewers);
outsideViewers.remove(player);
int entityId = player.getEntityId();
HMCCPacketManager.sendCameraPacket(entityId, viewer);
HMCCPacketManager.sendEntityDestroyPacket(armorStandId, viewer);
if (this.originalGamemode != null) {
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode));
player.setGameMode(this.originalGamemode);
}
if (user.getPlayer() != null) player.setInvisible(false);
user.getUserEmoteManager().despawnTextEntity();
user.showPlayer();
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
});
}
public boolean isPlayingAnimation() {
return emotePlaying != null;
}
}

View File

@@ -40,17 +40,6 @@ cosmetic-settings:
gamemodes:
- "SPECTATOR"
# This disables the entire internal emote system within the plugin. This option requires a restart.
emote-enable: true
emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player.
emote-block-check: true # If the server should check if the block is open where the camera is placed (prevents players viewing through blocks)
emote-air-check: true # Check if there is air under a player, if there is, don't play emote
emote-damage-leave: true # If the player should leave the emote when they take damage
emote-invincible: false # If the player should not take damage while doing an emote
# If a player should be put into camera mode when looking at an emote. Highly recommend keeping it as true.
emote-camera: true
# If a player should be able to move in an emote. This option really only affects if "emote-camera" is false
emote-move: false
# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
backpack-force-riding-packet: false
# This prevents the backpack from being dark when the player is below a block at the expense of making the backpack bright

View File

@@ -108,15 +108,6 @@ kite:
model-data: 7
name: "<blue>Kite"
amount: 1
handstand:
slot: EMOTE
animation: handstand
meditate:
slot: EMOTE
animation: meditate
thinking:
slot: EMOTE
animation: thinking
explorer_backpack:
slot: BACKPACK
permission: "hmccosmetics.explorer_backpack"

View File

@@ -134,31 +134,6 @@ items:
- "<gray>Allowed: <#6D9DC5>%HMCCosmetics_unlocked_kite%"
type: cosmetic
cosmetic: kite
# EMOTES DO NOT WORK IN RECENT HMCCOSMETICS VERSIONS.
# handstand:
# slots:
# - 12
# item:
# material: PAPER
# name: "<blue>Handstand Emote"
# type: cosmetic
# cosmetic: handstand
# meditate:
# slots:
# - 13
# item:
# material: PAPER
# name: "<blue>Meditate Emote"
# type: cosmetic
# cosmetic: meditate
# thinking:
# slots:
# - 14
# item:
# material: PAPER
# name: "<blue>Thinking Emote"
# type: cosmetic
# cosmetic: thinking
explorer_backpack:
slots:
- 12

Binary file not shown.

BIN
lib/HMCColor-2.4-all.jar Normal file

Binary file not shown.