From 8e92f3e6895fef5002b435e2a7ec5ad112f65acc Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sun, 4 Feb 2024 20:04:33 -0600 Subject: [PATCH] fix: hidden reasons for gamemodes + world not working, spawning entity cosmetics while hidden --- .../hmccosmetics/database/types/Data.java | 36 +++++++++++++++++-- .../listener/PlayerConnectionListener.java | 16 --------- .../hmccosmetics/user/CosmeticUser.java | 18 +++++----- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java index e298053f..e5be6e61 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java @@ -59,6 +59,7 @@ public abstract class Data { Map> cosmetics = new HashMap<>(); String[] rawData = raw.split(","); + CosmeticUser.HiddenReason hiddenReason = null; for (String a : rawData) { if (a == null || a.isEmpty()) continue; String[] splitData = a.split("="); @@ -68,9 +69,7 @@ public abstract class Data { if (splitData[0].equalsIgnoreCase("HIDDEN")) { if (EnumUtils.isValidEnum(CosmeticUser.HiddenReason.class, splitData[1])) { if (Settings.isForceShowOnJoin()) continue; - Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> { - user.hideCosmetics(CosmeticUser.HiddenReason.valueOf(splitData[1])); - }); + hiddenReason = CosmeticUser.HiddenReason.valueOf(splitData[1]); } continue; } @@ -98,6 +97,37 @@ public abstract class Data { cosmetics.put(slot, cosmeticColorHashMap); } } + + MessagesUtil.sendDebugMessages("Hidden Reason: " + hiddenReason); + // if else this, if else that, if else I got to deal with this anymore i'll lose my mind + if (hiddenReason != null) { + user.hideCosmetics(hiddenReason); + } else { + Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> { + // Handle gamemode check + if (user.getPlayer() != null && Settings.getDisabledGamemodes().contains(user.getPlayer().getGameMode().toString())) { + MessagesUtil.sendDebugMessages("Hiding Cosmetics due to gamemode"); + user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE); + return; + } else { + if (user.getHiddenReason() != null && user.getHiddenReason().equals(CosmeticUser.HiddenReason.GAMEMODE)) { + MessagesUtil.sendDebugMessages("Join Gamemode Check: Showing Cosmetics"); + user.showCosmetics(); + return; + } + } + // Handle world check + if (Settings.getDisabledWorlds().contains(user.getPlayer().getWorld().getName())) { + MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world"); + user.hideCosmetics(CosmeticUser.HiddenReason.WORLD); + } else { + if (user.getHiddenReason() != null && user.getHiddenReason().equals(CosmeticUser.HiddenReason.WORLD)) { + MessagesUtil.sendDebugMessages("Join World Check: Showing Cosmetics"); + user.showCosmetics(); + } + } + }); + } return cosmetics; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java index 3a43361a..886d6b48 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java @@ -38,22 +38,6 @@ public class PlayerConnectionListener implements Listener { CosmeticUsers.addUser(user); MessagesUtil.sendDebugMessages("Run User Join"); - // Handle gamemode check - if (Settings.getDisabledGamemodes().contains(user.getPlayer().getGameMode().toString())) { - user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE); - } else { - if (user.getHiddenReason() != null && user.getHiddenReason().equals(CosmeticUser.HiddenReason.GAMEMODE)) { - user.showCosmetics(); - } - } - // Handle world check - if (Settings.getDisabledWorlds().contains(user.getPlayer().getWorld().getName())) { - user.hideCosmetics(CosmeticUser.HiddenReason.WORLD); - } else { - if (user.getHiddenReason() != null && user.getHiddenReason().equals(CosmeticUser.HiddenReason.WORLD)) { - user.showCosmetics(); - } - } // And finally, launch an update for the cosmetics they have. Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { if (user.getPlayer() == null) return; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index 525856fa..36b902ff 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -114,14 +114,16 @@ public class CosmeticUser { playerCosmetics.put(cosmetic.getSlot(), cosmetic); if (color != null) colors.put(cosmetic.getSlot(), color); MessagesUtil.sendDebugMessages("addPlayerCosmetic[id=" + cosmetic.getId() + "]"); - if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) { - CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic; - spawnBackpack(backpackType); - MessagesUtil.sendDebugMessages("addPlayerCosmetic[spawnBackpack,id=" + cosmetic.getId() + "]"); - } - if (cosmetic.getSlot() == CosmeticSlot.BALLOON) { - CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic; - spawnBalloon(balloonType); + if (!getHidden()) { + if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) { + CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic; + spawnBackpack(backpackType); + MessagesUtil.sendDebugMessages("addPlayerCosmetic[spawnBackpack,id=" + cosmetic.getId() + "]"); + } + if (cosmetic.getSlot() == CosmeticSlot.BALLOON) { + CosmeticBalloonType balloonType = (CosmeticBalloonType) cosmetic; + spawnBalloon(balloonType); + } } // API PlayerCosmeticPostEquipEvent postEquipEvent = new PlayerCosmeticPostEquipEvent(this, cosmetic);