From b270d022d4ab7a61af9e1bdb003a55c95c0938ff Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 09:10:00 -0500 Subject: [PATCH 01/30] feat: Check if there is air below emote usage --- .../java/com/hibiscusmc/hmccosmetics/config/Settings.java | 7 +++++++ .../hmccosmetics/user/manager/UserEmoteModel.java | 5 +++++ common/src/main/resources/config.yml | 1 + 3 files changed, 13 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java index c941049a..63cf694e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -42,6 +42,7 @@ public class Settings { 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_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_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments"; @@ -70,6 +71,7 @@ public class Settings { private static boolean addChestplateEnchants; private static boolean addLeggingEnchants; private static boolean addBootsEnchants; + private static boolean emoteAirCheck; private static boolean emoteDamageLeave; private static boolean emoteInvincible; private static boolean destroyLooseCosmetics; @@ -105,6 +107,7 @@ public class Settings { forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false); 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); @@ -263,6 +266,10 @@ public class Settings { return cosmeticEmoteBlockCheck; } + public static boolean getEmoteAirCheck() { + return emoteAirCheck; + } + public static boolean isEmoteDamageLeave() { return emoteDamageLeave; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java index 403d5055..e7455cf7 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java @@ -67,6 +67,11 @@ public class UserEmoteModel extends PlayerModel { MessagesUtil.sendMessage(player, "emote-blocked"); return; } + // Check if block below player is an air block + if (Settings.getEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) { + stopAnimation(); + MessagesUtil.sendMessage(player, "emote-blocked"); + } user.getPlayer().setInvisible(true); user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 6739cedf..353f3f07 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -25,6 +25,7 @@ cosmetic-settings: 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 From 54e8e5102abc368d4d01b8c5ef5f28a1e3137088 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 10:50:09 -0500 Subject: [PATCH 02/30] feat: Multiple Wardrobes --- .../hmccosmetics/HMCCosmeticsPlugin.java | 1 + .../api/PlayerWardrobeEnterEvent.java | 15 +- .../hmccosmetics/command/CosmeticCommand.java | 40 +++-- .../command/CosmeticCommandTabComplete.java | 22 ++- .../hmccosmetics/config/Wardrobe.java | 65 ++++++++ .../hmccosmetics/config/WardrobeSettings.java | 146 +++++++++--------- .../hmccosmetics/hooks/worldguard/WGHook.java | 7 +- .../hooks/worldguard/WGListener.java | 7 +- .../hmccosmetics/user/CosmeticUser.java | 35 ++--- .../user/manager/UserWardrobeManager.java | 20 ++- common/src/main/resources/config.yml | 44 +++--- common/src/main/resources/messages.yml | 2 + 12 files changed, 254 insertions(+), 150 deletions(-) create mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index c56d2dfa..8bf05ecc 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -242,6 +242,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { getInstance().getLogger().info("Successfully Enabled HMCCosmetics"); getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup"); getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup"); + getInstance().getLogger().info(WardrobeSettings.getWardrobes().size() + " Wardrobes Successfully Setup"); getInstance().getLogger().info("Data storage is set to " + DatabaseSettings.getDatabaseType()); Bukkit.getPluginManager().callEvent(new HMCCosmeticSetupEvent()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerWardrobeEnterEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerWardrobeEnterEvent.java index f1b1c126..f5e39a5b 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerWardrobeEnterEvent.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerWardrobeEnterEvent.java @@ -1,5 +1,6 @@ package com.hibiscusmc.hmccosmetics.api; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import org.bukkit.event.Cancellable; @@ -12,11 +13,11 @@ import org.jetbrains.annotations.NotNull; public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; - private WardrobeLocation wardrobeLocation; + private Wardrobe wardrobe; - public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull WardrobeLocation wardrobeLocation) { + public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) { super(who); - this.wardrobeLocation = wardrobeLocation; + this.wardrobe = wardrobe; } @Override @@ -49,11 +50,11 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can return handlers; } - public void setWardrobeLocation(WardrobeLocation wardrobeLocation) { - this.wardrobeLocation = wardrobeLocation; + public void setWardrobe(Wardrobe wardrobe) { + this.wardrobe = wardrobe; } - public WardrobeLocation getWardrobeLocation() { - return wardrobeLocation; + public Wardrobe getWardrobe() { + return wardrobe; } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index 6b57af5d..c3340340 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.command; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; @@ -194,8 +195,14 @@ public class CosmeticCommand implements CommandExecutor { } case ("wardrobe") -> { if (sender instanceof Player) player = ((Player) sender).getPlayer(); + + if (args.length == 1) { + if (!silent) MessagesUtil.sendMessage(player, "not-enough-args"); + return true; + } + if (sender.hasPermission("hmccosmetics.cmd.wardrobe.other")) { - if (args.length >= 2) player = Bukkit.getPlayer(args[1]); + if (args.length >= 3) player = Bukkit.getPlayer(args[2]); } if (!sender.hasPermission("hmccosmetics.cmd.wardrobe")) { @@ -208,9 +215,19 @@ public class CosmeticCommand implements CommandExecutor { return true; } + if (!WardrobeSettings.getWardrobeNames().contains(args[1])) { + if (!silent) MessagesUtil.sendMessage(sender, "no-wardrobes"); + return true; + } + Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]); + CosmeticUser user = CosmeticUsers.getUser(player); - user.toggleWardrobe(); + if (user.isInWardrobe()) { + user.leaveWardrobe(); + } else { + user.enterWardrobe(false, wardrobe); + } return true; } // cosmetic menu exampleMenu playerName @@ -297,25 +314,30 @@ public class CosmeticCommand implements CommandExecutor { if (player == null) return true; - if (args.length < 2) { + if (args.length < 3) { if (!silent) MessagesUtil.sendMessage(player, "not-enough-args"); return true; } + Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]); + if (wardrobe == null) { + MessagesUtil.sendMessage(player, "not-enough-args"); + return true; + } - if (args[1].equalsIgnoreCase("wardrobelocation")) { - WardrobeSettings.setNPCLocation(player.getLocation()); + if (args[2].equalsIgnoreCase("npclocation")) { + WardrobeSettings.setNPCLocation(wardrobe, player.getLocation()); if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-location"); return true; } - if (args[1].equalsIgnoreCase("viewerlocation")) { - WardrobeSettings.setViewerLocation(player.getLocation()); + if (args[2].equalsIgnoreCase("viewerlocation")) { + WardrobeSettings.setViewerLocation(wardrobe, player.getLocation()); if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-viewing"); return true; } - if (args[1].equalsIgnoreCase("leavelocation")) { - WardrobeSettings.setLeaveLocation(player.getLocation()); + if (args[2].equalsIgnoreCase("leavelocation")) { + WardrobeSettings.setLeaveLocation(wardrobe, player.getLocation()); if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-leaving"); return true; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java index 03445bdd..5766fb3d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -1,5 +1,7 @@ package com.hibiscusmc.hmccosmetics.command; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; +import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; @@ -66,20 +68,25 @@ public class CosmeticCommandTabComplete implements TabCompleter { if (menu.canOpen(user.getPlayer())) completions.add(menu.getId()); } } - case "dataclear", "wardrobe", "hide", "show", "emote" -> { + case "dataclear", "hide", "show", "emote" -> { for (Player player : Bukkit.getOnlinePlayers()) { completions.add(player.getName()); } } + case "wardrobe" -> { + for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) { + completions.add(wardrobe.getId()); + } + } case "dye" -> { for (CosmeticSlot slot : user.getDyeableSlots()) { completions.add(slot.name()); } } case "setlocation" -> { - completions.add("wardrobelocation"); - completions.add("viewerlocation"); - completions.add("leavelocation"); + for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) { + completions.add(wardrobe.getId()); + } } case "playemote" -> completions.addAll(EmoteManager.getAllNames()); } @@ -91,11 +98,16 @@ public class CosmeticCommandTabComplete implements TabCompleter { case "dye" -> { completions.add("#FFFFFF"); } - case "menu", "apply", "unapply", "playemote" -> { + case "menu", "wardrobe", "apply", "unapply", "playemote" -> { for (Player player : Bukkit.getOnlinePlayers()) { completions.add(player.getName()); } } + case "setlocation" -> { + completions.add("npclocation"); + completions.add("viewerlocation"); + completions.add("leavelocation"); + } } StringUtil.copyPartialMatches(args[2], completions, finalCompletions); } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java new file mode 100644 index 00000000..b01fea44 --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java @@ -0,0 +1,65 @@ +package com.hibiscusmc.hmccosmetics.config; + +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import org.bukkit.Location; + +import javax.annotation.Nullable; +import java.util.List; + +public class Wardrobe { + + private String id; + private int distance = WardrobeSettings.getDefaultDistance(); + private String permission; + private List players; + private WardrobeLocation location; + + public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance, @Nullable List players) { + this.id = id; + this.location = location; + if (permission != null) this.permission = permission; + if (distance != -1) this.distance = distance; + if (players != null) this.players = players; + } + + public String getId() { + return id; + } + + public WardrobeLocation getLocation() { + return location; + } + + public boolean hasPermission() { + return permission != null; + } + + public boolean hasPlayers() { + return players != null; + } + + public List getPlayers() { + return players; + } + + public int getDistance() { + return distance; + } + + public String getPermission() { + return permission; + } + + public void setLocation(WardrobeLocation location) { + this.location = location; + } + + public boolean canEnter(CosmeticUser user) { + Location wardrobeLocation = location.getNpcLocation(); + Location location = user.getPlayer().getLocation(); + if (wardrobeLocation == null) return false; + if (distance == -1) return true; + if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false; + return wardrobeLocation.distanceSquared(location) <= distance * distance; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 07cc3c02..a25f0bd3 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -11,6 +11,9 @@ import org.bukkit.Location; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; +import java.util.*; +import java.util.logging.Level; + public class WardrobeSettings { private static final String WARDROBE_PATH = "wardrobe"; @@ -25,7 +28,7 @@ public class WardrobeSettings { private static final String APPLY_COSMETICS_ON_CLOSE = "apply-cosmetics-on-close"; private static final String OPEN_SOUND = "open-sound"; private static final String CLOSE_SOUND = "close-sound"; - private static final String STATIC_LOCATION_PATH = "wardrobe-location"; + private static final String NPC_LOCATION_PATH = "npc-location"; private static final String VIEWER_LOCATION_PATH = "viewer-location"; private static final String LEAVE_LOCATION_PATH = "leave-location"; private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin"; @@ -63,7 +66,7 @@ public class WardrobeSettings { private static boolean enabledBossbar; private static boolean forceExitGamemode; private static GameMode exitGamemode; - private static WardrobeLocation wardrobeLocation; + private static HashMap wardrobes; private static String bossbarMessage; private static BossBar.Overlay bossbarOverlay; private static BossBar.Color bossbarColor; @@ -117,17 +120,37 @@ public class WardrobeSettings { transitionStay = transitionNode.node(TRANSITION_STAY_PATH).getInt(2000); transitionFadeOut = transitionNode.node(TRANSITION_FADE_OUT_PATH).getInt(2000); - try { - Location npcLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(STATIC_LOCATION_PATH)); - MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation); - Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(VIEWER_LOCATION_PATH)); - MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation); - Location leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, source.node(LEAVE_LOCATION_PATH)), viewerLocation); - MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation); - wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation); - } catch (SerializationException e) { - throw new RuntimeException(e); + wardrobes = new HashMap<>(); + for (ConfigurationNode wardrobesNode : source.node("wardrobes").childrenMap().values()) { + String id = wardrobesNode.key().toString(); + try { + Location npcLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(NPC_LOCATION_PATH)); + MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation); + Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH)); + MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation); + Location leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH)), viewerLocation); + MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation); + WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation); + + String permission = null; + int distance = -1; + List playerNames = null; + if (!wardrobesNode.node("permission").virtual()) permission = wardrobesNode.node("permission").getString(); + if (!wardrobesNode.node("int").virtual()) distance = wardrobesNode.node("int").getInt(); + if (!wardrobesNode.node("players").virtual()) playerNames = wardrobesNode.node("players").getList(String.class); + + Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, playerNames); + wardrobes.put(id, wardrobe); + } catch (Exception e) { + MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE); + } } + + //throw new RuntimeException(e); + } + + public static int getDefaultDistance() { + return staticRadius; } public static boolean getDisableOnDamage() { @@ -172,33 +195,16 @@ public class WardrobeSettings { return returnLastLocation; } - /** - * - * @Deprecated use {@link #getLocation()} - */ - @Deprecated (since = "2.3.2", forRemoval = true) - public static Location getWardrobeLocation() { - return wardrobeLocation.getNpcLocation().clone(); - } - /** - * - * @Deprecated use {@link #getLocation()} - */ - @Deprecated (since = "2.3.2", forRemoval = true) - public static Location getViewerLocation() { - return wardrobeLocation.getViewerLocation().clone(); - } - /** - * - * @Deprecated use {@link #getLocation()} - */ - @Deprecated (since = "2.3.2", forRemoval = true) - public static Location getLeaveLocation() { - return wardrobeLocation.getLeaveLocation().clone(); + public static Wardrobe getWardrobe(String key) { + return wardrobes.get(key); } - public static WardrobeLocation getLocation() { - return wardrobeLocation; + public static Set getWardrobeNames() { + return wardrobes.keySet(); + } + + public static Collection getWardrobes() { + return wardrobes.values(); } public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) { @@ -207,11 +213,12 @@ public class WardrobeSettings { return playerLocation.distanceSquared(wardrobeLocation) <= displayRadius * displayRadius; } - public static boolean inDistanceOfStatic(final Location location) { + public static boolean inDistanceOfStatic(Wardrobe wardrobe, final Location location) { + Location wardrobeLocation = wardrobe.getLocation().getNpcLocation(); if (wardrobeLocation == null) return false; if (staticRadius == -1) return true; - if (!getWardrobeLocation().getWorld().equals(location.getWorld())) return false; - return getWardrobeLocation().distanceSquared(location) <= staticRadius * staticRadius; + if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false; + return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius; } public static boolean getEnabledBossbar() { @@ -262,32 +269,21 @@ public class WardrobeSettings { return exitGamemode; } - /** - * Sets where the NPC will spawn in the wardrobe - * - * @Deprecated use {@link #setNPCLocation(Location)} - * @param newLocation - */ - @Deprecated (since = "2.3.2", forRemoval = true) - public static void setWardrobeLocation(Location newLocation) { - setNPCLocation(newLocation); - } - /** * Sets where the NPC/Mannequin will spawn in the wardrobe * @param newLocation */ - public static void setNPCLocation(Location newLocation) { - wardrobeLocation.setNPCLocation(newLocation); + public static void setNPCLocation(Wardrobe wardrobe, Location newLocation) { + wardrobe.getLocation().setNPCLocation(newLocation); HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); - plugin.getConfig().set("wardrobe.wardrobe-location." + "world", newLocation.getWorld().getName()); - plugin.getConfig().set("wardrobe.wardrobe-location." + "x", newLocation.getX()); - plugin.getConfig().set("wardrobe.wardrobe-location." + "y", newLocation.getY()); - plugin.getConfig().set("wardrobe.wardrobe-location." + "z", newLocation.getZ()); - plugin.getConfig().set("wardrobe.wardrobe-location." + "yaw", newLocation.getYaw()); - plugin.getConfig().set("wardrobe.wardrobe-location." + "pitch", newLocation.getPitch()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "world", newLocation.getWorld().getName()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "x", newLocation.getX()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "y", newLocation.getY()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "z", newLocation.getZ()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "yaw", newLocation.getYaw()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "pitch", newLocation.getPitch()); HMCCosmeticsPlugin.getInstance().saveConfig(); } @@ -296,17 +292,17 @@ public class WardrobeSettings { * Sets where the player will view the wardrobe * @param newLocation */ - public static void setViewerLocation(Location newLocation) { - wardrobeLocation.setViewerLocation(newLocation); + public static void setViewerLocation(Wardrobe wardrobe, Location newLocation) { + wardrobe.getLocation().setViewerLocation(newLocation); HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); - plugin.getConfig().set("wardrobe.viewer-location." + "world", newLocation.getWorld().getName()); - plugin.getConfig().set("wardrobe.viewer-location." + "x", newLocation.getX()); - plugin.getConfig().set("wardrobe.viewer-location." + "y", newLocation.getY()); - plugin.getConfig().set("wardrobe.viewer-location." + "z", newLocation.getZ()); - plugin.getConfig().set("wardrobe.viewer-location." + "yaw", newLocation.getYaw()); - plugin.getConfig().set("wardrobe.viewer-location." + "pitch", newLocation.getPitch()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.world", newLocation.getWorld().getName()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.x", newLocation.getX()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.y", newLocation.getY()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.z", newLocation.getZ()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.yaw", newLocation.getYaw()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.pitch", newLocation.getPitch()); HMCCosmeticsPlugin.getInstance().saveConfig(); } @@ -315,17 +311,17 @@ public class WardrobeSettings { * Sets where a player will leave the wardrobe from * @param newLocation */ - public static void setLeaveLocation(Location newLocation) { - wardrobeLocation.setLeaveLocation(newLocation); + public static void setLeaveLocation(Wardrobe wardrobe, Location newLocation) { + wardrobe.getLocation().setLeaveLocation(newLocation); HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); - plugin.getConfig().set("wardrobe.leave-location." + "world", newLocation.getWorld().getName()); - plugin.getConfig().set("wardrobe.leave-location." + "x", newLocation.getX()); - plugin.getConfig().set("wardrobe.leave-location." + "y", newLocation.getY()); - plugin.getConfig().set("wardrobe.leave-location." + "z", newLocation.getZ()); - plugin.getConfig().set("wardrobe.leave-location." + "yaw", newLocation.getYaw()); - plugin.getConfig().set("wardrobe.leave-location." + "pitch", newLocation.getPitch()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.world", newLocation.getWorld().getName()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.x", newLocation.getX()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.y", newLocation.getY()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.z", newLocation.getZ()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.yaw", newLocation.getYaw()); + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.pitch", newLocation.getPitch()); HMCCosmeticsPlugin.getInstance().saveConfig(); } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java index 60f4b3ce..027bd5d5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java @@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StringFlag; import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; @@ -21,13 +22,13 @@ public class WGHook { /** * @implNote Please use {@link #getCosmeticWardrobeFlag()} instead */ - public static StateFlag COSMETIC_WARDROBE_FLAG; + public static StringFlag COSMETIC_WARDROBE_FLAG; public WGHook() { FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); try { StateFlag cosmeticFlag = new StateFlag("cosmetic-enable", false); - StateFlag wardrobeFlag = new StateFlag("cosmetic-wardrobe", false); + StringFlag wardrobeFlag = new StringFlag("cosmetic-wardrobe"); registry.register(cosmeticFlag); registry.register(wardrobeFlag); COSMETIC_ENABLE_FLAG = cosmeticFlag; @@ -56,7 +57,7 @@ public class WGHook { * Gets the cosmetic wardrobe {@link StateFlag} * @return The cosmetic wardrobe {@link StateFlag} */ - public static StateFlag getCosmeticWardrobeFlag() { + public static StringFlag getCosmeticWardrobeFlag() { return COSMETIC_WARDROBE_FLAG; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java index 5d4bdd7e..01a514d6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java @@ -1,5 +1,7 @@ package com.hibiscusmc.hmccosmetics.hooks.worldguard; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; +import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -39,8 +41,9 @@ public class WGListener implements Listener { return; } if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) { - if (!protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString().equalsIgnoreCase("ALLOW")) return; - user.enterWardrobe(); + if (!WardrobeSettings.getWardrobes().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return; + Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString()); + user.enterWardrobe(true, wardrobe); } } } 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 9a055a30..b3c8aa19 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.api.*; import com.hibiscusmc.hmccosmetics.config.Settings; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; @@ -243,28 +244,28 @@ public class CosmeticUser { return userEmoteManager; } - public void enterWardrobe() { - enterWardrobe(false); - } - - public void enterWardrobe(boolean ignoreDistance) { - enterWardrobe(ignoreDistance, WardrobeSettings.getLocation()); - } - - public void enterWardrobe(boolean ignoreDistance, WardrobeLocation wardrobeLocation) { - if (!WardrobeSettings.inDistanceOfStatic(getPlayer().getLocation()) && !ignoreDistance) { + public void enterWardrobe(boolean ignoreDistance, Wardrobe wardrobe) { + if (wardrobe.hasPlayers() && !wardrobe.getPlayers().contains(getPlayer().getName())) { + MessagesUtil.sendMessage(getPlayer(), "wardrobe-not-included"); + return; + } + if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) { + MessagesUtil.sendMessage(getPlayer(), "no-permission"); + return; + } + if (!wardrobe.canEnter(this) && !ignoreDistance) { MessagesUtil.sendMessage(getPlayer(), "not-near-wardrobe"); return; } - PlayerWardrobeEnterEvent event = new PlayerWardrobeEnterEvent(this, wardrobeLocation); + PlayerWardrobeEnterEvent event = new PlayerWardrobeEnterEvent(this, wardrobe); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - wardrobeLocation = event.getWardrobeLocation(); + wardrobe = event.getWardrobe(); if (userWardrobeManager == null) { - userWardrobeManager = new UserWardrobeManager(this, wardrobeLocation); + userWardrobeManager = new UserWardrobeManager(this, wardrobe); userWardrobeManager.start(); } } @@ -303,14 +304,6 @@ public class CosmeticUser { return true; } - public void toggleWardrobe() { - if (isInWardrobe()) { - leaveWardrobe(); - } else { - enterWardrobe(); - } - } - public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { if (this.userBackpackManager != null) return; this.userBackpackManager = new UserBackpackManager(this, cosmeticBackpackType.getBackpackType()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java index a7168f5f..f73c95c9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java @@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.user.manager; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; +import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; @@ -39,6 +40,8 @@ public class UserWardrobeManager { private String npcName; private GameMode originalGamemode; private final CosmeticUser user; + private final Wardrobe wardrobe; + private final WardrobeLocation wardrobeLocation; private final Location viewingLocation; private final Location npcLocation; private Location exitLocation; @@ -46,15 +49,18 @@ public class UserWardrobeManager { private boolean active; private WardrobeStatus wardrobeStatus; - public UserWardrobeManager(CosmeticUser user, WardrobeLocation location) { + public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) { NPC_ID = NMSHandlers.getHandler().getNextEntityId(); ARMORSTAND_ID = NMSHandlers.getHandler().getNextEntityId(); WARDROBE_UUID = UUID.randomUUID(); this.user = user; - this.exitLocation = location.getLeaveLocation(); - this.viewingLocation = location.getViewerLocation(); - this.npcLocation = location.getNpcLocation(); + this.wardrobe = wardrobe; + this.wardrobeLocation = wardrobe.getLocation(); + + this.exitLocation = wardrobeLocation.getLeaveLocation(); + this.viewingLocation = wardrobeLocation.getViewerLocation(); + this.npcLocation = wardrobeLocation.getNpcLocation(); wardrobeStatus = WardrobeStatus.SETUP; } @@ -236,7 +242,7 @@ public class UserWardrobeManager { List outsideViewers = PacketManager.getViewers(viewingLocation); outsideViewers.remove(player); - Location location = WardrobeSettings.getLocation().getNpcLocation(); + Location location = npcLocation; int yaw = data.get(); location.setYaw(yaw); @@ -260,8 +266,8 @@ public class UserWardrobeManager { } if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getLocation().getNpcLocation().add(Settings.getBalloonOffset()), false, viewer); - user.getBalloonManager().getModelEntity().teleport(WardrobeSettings.getLocation().getNpcLocation().add(Settings.getBalloonOffset())); + PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.add(Settings.getBalloonOffset()), false, viewer); + user.getBalloonManager().getModelEntity().teleport(npcLocation.add(Settings.getBalloonOffset())); user.getBalloonManager().sendRemoveLeashPacket(outsideViewers); PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers); user.getBalloonManager().sendLeashPacket(NPC_ID); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 353f3f07..52910a5d 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -92,24 +92,26 @@ wardrobe: title-fade-in: 1000 # milliseconds title-stay: 500 # milliseconds title-fade-out: 1000 # milliseconds - wardrobe-location: - world: "World" - x: 0 - y: 0 - z: 0 - yaw: 0 - pitch: 0 - viewer-location: - world: "World" - x: 5 - y: 0 - z: 5 - yaw: 0 - pitch: 0 - leave-location: - world: "World" - x: 5 - y: 5 - z: 5 - yaw: 0 - pitch: 0 + wardrobes: + default: + npc-location: + world: "world" + x: 0 + y: 0 + z: 0 + yaw: 0 + pitch: 0 + viewer-location: + world: "world" + x: 5 + y: 0 + z: 5 + yaw: 0 + pitch: 0 + leave-location: + world: "world" + x: 5 + y: 5 + z: 5 + yaw: 0 + pitch: 0 diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 53216d1d..fcf69423 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -11,6 +11,8 @@ not-near-wardrobe: "%prefix% You are not near the wardrobe!" set-wardrobe-location: "%prefix% Set new wardrobe location!" set-wardrobe-viewing: "%prefix% Set new wardrobe viewing location!" set-wardrobe-leaving: "%prefix% Set new wardrobe leaving location!" +no-wardrobes: "%prefix% There are no wardrobes with that name!" +wardrobe-not-included: "%prefix% You are not allowed in this wardrobe!" equip-cosmetic: "%prefix% You have equipped !" unequip-cosmetic: "%prefix% You have unequipped !" From 7c95d9614da40216cbff8fe620465bc680593e33 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 10:53:37 -0500 Subject: [PATCH 03/30] clean: remove players list, just use permissions if you wish to limit it to a certain group. --- .../hibiscusmc/hmccosmetics/config/Wardrobe.java | 14 +------------- .../hmccosmetics/config/WardrobeSettings.java | 3 +-- .../hibiscusmc/hmccosmetics/user/CosmeticUser.java | 4 ---- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java index b01fea44..6cea4aa2 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java @@ -4,22 +4,19 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import org.bukkit.Location; import javax.annotation.Nullable; -import java.util.List; public class Wardrobe { private String id; private int distance = WardrobeSettings.getDefaultDistance(); private String permission; - private List players; private WardrobeLocation location; - public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance, @Nullable List players) { + public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance) { this.id = id; this.location = location; if (permission != null) this.permission = permission; if (distance != -1) this.distance = distance; - if (players != null) this.players = players; } public String getId() { @@ -33,15 +30,6 @@ public class Wardrobe { public boolean hasPermission() { return permission != null; } - - public boolean hasPlayers() { - return players != null; - } - - public List getPlayers() { - return players; - } - public int getDistance() { return distance; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index a25f0bd3..85ecb9d6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -137,9 +137,8 @@ public class WardrobeSettings { List playerNames = null; if (!wardrobesNode.node("permission").virtual()) permission = wardrobesNode.node("permission").getString(); if (!wardrobesNode.node("int").virtual()) distance = wardrobesNode.node("int").getInt(); - if (!wardrobesNode.node("players").virtual()) playerNames = wardrobesNode.node("players").getList(String.class); - Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, playerNames); + Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance); wardrobes.put(id, wardrobe); } catch (Exception e) { MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE); 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 b3c8aa19..5f9add77 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -245,10 +245,6 @@ public class CosmeticUser { } public void enterWardrobe(boolean ignoreDistance, Wardrobe wardrobe) { - if (wardrobe.hasPlayers() && !wardrobe.getPlayers().contains(getPlayer().getName())) { - MessagesUtil.sendMessage(getPlayer(), "wardrobe-not-included"); - return; - } if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) { MessagesUtil.sendMessage(getPlayer(), "no-permission"); return; From 6e2278f4f029b1f1d319ef65cc800f8c9f12394d Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 10:58:42 -0500 Subject: [PATCH 04/30] clean: loose message --- common/src/main/resources/messages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index fcf69423..c14ac1fa 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -12,7 +12,6 @@ set-wardrobe-location: "%prefix% Set new wardrobe loca set-wardrobe-viewing: "%prefix% Set new wardrobe viewing location!" set-wardrobe-leaving: "%prefix% Set new wardrobe leaving location!" no-wardrobes: "%prefix% There are no wardrobes with that name!" -wardrobe-not-included: "%prefix% You are not allowed in this wardrobe!" equip-cosmetic: "%prefix% You have equipped !" unequip-cosmetic: "%prefix% You have unequipped !" From f072f0e04432f6ea6caea9167e0e34f73e472372 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 11:06:05 -0500 Subject: [PATCH 05/30] clean: old variable --- .../com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 85ecb9d6..45fbff69 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -134,7 +134,6 @@ public class WardrobeSettings { String permission = null; int distance = -1; - List playerNames = null; if (!wardrobesNode.node("permission").virtual()) permission = wardrobesNode.node("permission").getString(); if (!wardrobesNode.node("int").virtual()) distance = wardrobesNode.node("int").getInt(); From 04810b91efdefd6702691c4aa0e24e619adeac7a Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 11:11:24 -0500 Subject: [PATCH 06/30] feat: add ability to select any cosmetic in wardrobe, resolves #55 --- .../hibiscusmc/hmccosmetics/config/WardrobeSettings.java | 7 +++++++ .../com/hibiscusmc/hmccosmetics/user/CosmeticUser.java | 1 + .../hmccosmetics/user/manager/UserWardrobeManager.java | 4 +--- common/src/main/resources/config.yml | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 45fbff69..92ab5333 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -32,6 +32,7 @@ public class WardrobeSettings { private static final String VIEWER_LOCATION_PATH = "viewer-location"; private static final String LEAVE_LOCATION_PATH = "leave-location"; private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin"; + private static final String TRY_COSMETICS_WARDROBE = "unchecked-wardrobe-cosmetics"; private static final String RETURN_LAST_LOCATION = "return-last-location"; private static final String GAMEMODE_OPTIONS_PATH = "gamemode-options"; private static final String FORCE_EXIT_GAMEMODE_PATH = "exit-gamemode-enabled"; @@ -61,6 +62,7 @@ public class WardrobeSettings { private static int despawnDelay; private static float bossbarProgress; private static boolean applyCosmeticsOnClose; + private static boolean tryCosmeticsInWardrobe; private static boolean equipPumpkin; private static boolean returnLastLocation; private static boolean enabledBossbar; @@ -91,6 +93,7 @@ public class WardrobeSettings { applyCosmeticsOnClose = source.node(APPLY_COSMETICS_ON_CLOSE).getBoolean(); equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean(); returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false); + tryCosmeticsInWardrobe = source.node(TRY_COSMETICS_WARDROBE).getBoolean(false); ConfigurationNode gamemodeNode = source.node(GAMEMODE_OPTIONS_PATH); forceExitGamemode = gamemodeNode.node(FORCE_EXIT_GAMEMODE_PATH).getBoolean(false); @@ -267,6 +270,10 @@ public class WardrobeSettings { return exitGamemode; } + public static boolean isTryCosmeticsInWardrobe() { + return tryCosmeticsInWardrobe; + } + /** * Sets where the NPC/Mannequin will spawn in the wardrobe * @param newLocation 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 5f9add77..b5244c07 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -376,6 +376,7 @@ public class CosmeticUser { public boolean canEquipCosmetic(Cosmetic cosmetic) { if (!cosmetic.requiresPermission()) return true; + if (isInWardrobe() && WardrobeSettings.isTryCosmeticsInWardrobe()) return true; if (getPlayer().hasPermission(cosmetic.getPermission())) return true; return false; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java index f73c95c9..a59bd4d0 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java @@ -215,9 +215,7 @@ public class UserWardrobeManager { // For Wardrobe Temp Cosmetics for (Cosmetic cosmetic : user.getCosmetics()) { - if (cosmetic.requiresPermission()) { - if (!player.hasPermission(cosmetic.getPermission())) user.removeCosmeticSlot(cosmetic.getSlot()); - } + if (!user.canEquipCosmetic(cosmetic)) user.removeCosmeticSlot(cosmetic.getSlot()); } user.updateCosmetic(); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 52910a5d..2ccdabf9 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -71,6 +71,8 @@ wardrobe: equip-pumpkin: false # Rather than having a set exit location, this will send the player back to where they entered the wardrobe. Not recommended for WG regions return-last-location: false + # If players in wardrobes should be able to equip any cosmetic, regardless of permission (Cosmetics they do not have access to will be removed when they leave the wardrobe) + unchecked-wardrobe-cosmetics: false gamemode-options: exit-gamemode-enabled: false # Setting this to false will set the gamemode the player came in as. True sets to exit-gamemode gamemode From 0aac0a23779399fe06977783996d181da16f80a1 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 14:30:58 -0500 Subject: [PATCH 07/30] clean: deprecate inDistanceOfWardrobe and inDistanceOfStatic --- .../com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 92ab5333..5e0d56e6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -208,12 +208,14 @@ public class WardrobeSettings { return wardrobes.values(); } + @Deprecated public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) { if (displayRadius == -1) return true; if (!wardrobeLocation.getWorld().equals(playerLocation.getWorld())) return false; return playerLocation.distanceSquared(wardrobeLocation) <= displayRadius * displayRadius; } + @Deprecated public static boolean inDistanceOfStatic(Wardrobe wardrobe, final Location location) { Location wardrobeLocation = wardrobe.getLocation().getNpcLocation(); if (wardrobeLocation == null) return false; From 0b1ed0fbebc71bd4ce5736ebf8de47a887b34ddc Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 14:33:36 -0500 Subject: [PATCH 08/30] clean: create path variables to be more in line with existing code --- .../hmccosmetics/config/WardrobeSettings.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 5e0d56e6..94adcb61 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -9,7 +9,6 @@ import org.apache.commons.lang3.EnumUtils; import org.bukkit.GameMode; import org.bukkit.Location; import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; import java.util.*; import java.util.logging.Level; @@ -37,6 +36,9 @@ public class WardrobeSettings { private static final String GAMEMODE_OPTIONS_PATH = "gamemode-options"; private static final String FORCE_EXIT_GAMEMODE_PATH = "exit-gamemode-enabled"; private static final String EXIT_GAMEMODE_PATH = "exit-gamemode"; + private static final String WARDROBES_PATH = "wardrobes"; + private static final String PERMISSION_PATH = "permission"; + private static final String DISTANCE_PATH = "distance"; private static final String BOSSBAR_PATH = "bossbar"; private static final String BOSSBAR_ENABLE_PATH = "enabled"; private static final String BOSSBAR_TEXT_PATH = "text"; @@ -124,7 +126,7 @@ public class WardrobeSettings { transitionFadeOut = transitionNode.node(TRANSITION_FADE_OUT_PATH).getInt(2000); wardrobes = new HashMap<>(); - for (ConfigurationNode wardrobesNode : source.node("wardrobes").childrenMap().values()) { + for (ConfigurationNode wardrobesNode : source.node(WARDROBES_PATH).childrenMap().values()) { String id = wardrobesNode.key().toString(); try { Location npcLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(NPC_LOCATION_PATH)); @@ -137,8 +139,8 @@ public class WardrobeSettings { String permission = null; int distance = -1; - if (!wardrobesNode.node("permission").virtual()) permission = wardrobesNode.node("permission").getString(); - if (!wardrobesNode.node("int").virtual()) distance = wardrobesNode.node("int").getInt(); + if (!wardrobesNode.node(PERMISSION_PATH).virtual()) permission = wardrobesNode.node(PERMISSION_PATH).getString(); + if (!wardrobesNode.node(DISTANCE_PATH).virtual()) distance = wardrobesNode.node(DISTANCE_PATH).getInt(); Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance); wardrobes.put(id, wardrobe); From 7ea4ccccefe488e513e8d7920e4bfeca032b0753 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 09:56:46 -0500 Subject: [PATCH 09/30] feat: config updater --- build.gradle.kts | 2 ++ common/build.gradle.kts | 1 + .../hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index c9921606..f2250ca0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -101,6 +101,7 @@ dependencies { implementation("com.jeff_media:SpigotUpdateChecker:3.0.0") implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT") implementation("com.ticxo:PlayerAnimator:R1.2.6") + implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT") //implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5") } @@ -142,6 +143,7 @@ tasks { relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker") relocate("com.owen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper") relocate("com.ticxo.playeranimator", "com.hisbiscusmc.hmccosmetics.playeranimator") + relocate("com.bgsoftware", "com.hisbiscusmc.hmccosmetics.configupdater") archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar") dependencies { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index d4f52858..f97b01dc 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { implementation("com.jeff_media:SpigotUpdateChecker:3.0.0") implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT") implementation("com.ticxo:PlayerAnimator:R1.2.6") + implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT") //implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5") } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 8bf05ecc..1b29585e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -1,5 +1,6 @@ package com.hibiscusmc.hmccosmetics; +import com.bgsoftware.common.config.CommentedConfiguration; import com.hibiscusmc.hmccosmetics.api.HMCCosmeticSetupEvent; import com.hibiscusmc.hmccosmetics.command.CosmeticCommand; import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete; @@ -100,6 +101,14 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { // Player Animator PlayerAnimatorImpl.initialize(this); + // Configuration Sync + final File file = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile(); + try { + CommentedConfiguration.loadConfiguration(file).syncWithConfig(file, getInstance().getResource("config.yml"), + "database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location"); + } catch (Exception e) {} + + // Setup setup(); // Commands @@ -170,7 +179,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { WardrobeSettings.load(loader.load().node("wardrobe")); DatabaseSettings.load(loader.load().node("database-settings")); configLoader = loader; - } catch (ConfigurateException e) { + } catch (Exception e) { throw new RuntimeException(e); } From 9c2120d13d4cf449df8fa86dd9babca29afbc9be Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 09:57:03 -0500 Subject: [PATCH 10/30] version bump (2.4.0-DEV) --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index f2250ca0..00a8640b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.hibiscusmc" -version = "2.3.2-DEV" +version = "2.4.0-DEV" allprojects { apply(plugin = "java") From a661ea09e1cb9992467db69c09389b34133bce73 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 10:11:02 -0500 Subject: [PATCH 11/30] feat: better file generating logic --- .../hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 1b29585e..7d83b0bb 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -87,13 +87,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { .checkNow(); onLatestVersion = checker.isUsingLatestVersion(); // File setup - if (!getDataFolder().exists()) { - saveDefaultConfig(); - //saveResource("translations.yml", false); - saveResource("messages.yml", false); - saveResource("cosmetics/defaultcosmetics.yml", false); - saveResource("menus/defaultmenu.yml", false); - } + saveDefaultConfig(); + //saveResource("translations.yml", false); + if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false); + 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); + // Emote folder setup File emoteFile = new File(getDataFolder().getPath() + "/emotes"); if (!emoteFile.exists()) emoteFile.mkdir(); From 8e33b2022bea799bdfcaa08f0d2187e5376e4ffe Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 10:58:34 -0500 Subject: [PATCH 12/30] fix: going to another wg region while cosmetic hidden from wg causes cosmetics to stay hidden --- .../hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java index 01a514d6..ee23df03 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java @@ -36,7 +36,10 @@ public class WGListener implements Listener { } for (ProtectedRegion protectedRegion : set.getRegions()) { if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) { - if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) return; + if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) { + if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD) user.showCosmetics(); + return; + } user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD); return; } From 8ee1400f85c2e499101396d65251d6a24136685a Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 11:03:40 -0500 Subject: [PATCH 13/30] feat: menu permissions added to registered permissions --- .../com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 7d83b0bb..873f0ec0 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -13,6 +13,7 @@ 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.Hooks; import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook; @@ -244,6 +245,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { getInstance().getServer().getPluginManager().addPermission(new Permission(cosmetic.getPermission())); } } + for (Menu menu : Menus.values()) { + if (menu.getPermissionNode() != null) { + if (getInstance().getServer().getPluginManager().getPermission(menu.getPermissionNode()) != null) continue; + getInstance().getServer().getPluginManager().addPermission(new Permission(menu.getPermissionNode())); + } + } EmoteManager.loadEmotes(); From f084d9e7823bad562b3f309e71be402925b521d8 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 11:03:54 -0500 Subject: [PATCH 14/30] feat: add values method to Menus class --- .../src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java index 0e988cb5..fcab856d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java @@ -56,6 +56,10 @@ public class Menus { return names; } + public static List values() { + return Menus.values(); + } + public static void setup() { MENUS.clear(); From 9b607a099ee3417069cde0fd9274d3894b76cd51 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 12:20:39 -0500 Subject: [PATCH 15/30] fix: unlocked placeholder producing out of bounds expection --- .../hooks/placeholders/HMCPlaceholderExpansion.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java index 95f065c2..5380d8ba 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java @@ -109,13 +109,15 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { } if (placeholderArgs.get(1) != null) { Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1)); - if (cosmetic == null) { + if (cosmetic == null && placeholderArgs.size() >= 3) { Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2)); if (secondAttemptCosmetic == null) { return "INVALID_COSMETIC"; } else { cosmetic = secondAttemptCosmetic; } + } else { + return "INVALID_COSMETIC"; } return TranslationUtil.getTranslation("unlockedCosmetic", String.valueOf(user.canEquipCosmetic(cosmetic))); } From 538edb67dd52c9519291b5885c0b2cca1a337306 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 12:41:43 -0500 Subject: [PATCH 16/30] fix: placeholders out of bounds slight rework --- .../placeholders/HMCPlaceholderExpansion.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java index 5380d8ba..db37c550 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/placeholders/HMCPlaceholderExpansion.java @@ -109,15 +109,17 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion { } if (placeholderArgs.get(1) != null) { Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1)); - if (cosmetic == null && placeholderArgs.size() >= 3) { - Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2)); - if (secondAttemptCosmetic == null) { - return "INVALID_COSMETIC"; + if (cosmetic == null) { + if (placeholderArgs.size() >= 3) { + Cosmetic secondAttemptCosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1) + "_" + placeholderArgs.get(2)); + if (secondAttemptCosmetic == null) { + return "INVALID_COSMETIC"; + } else { + cosmetic = secondAttemptCosmetic; + } } else { - cosmetic = secondAttemptCosmetic; + return "INVALID_COSMETIC"; } - } else { - return "INVALID_COSMETIC"; } return TranslationUtil.getTranslation("unlockedCosmetic", String.valueOf(user.canEquipCosmetic(cosmetic))); } From 128a33a21fc5f1af520fb2de90a2b1088fc6d027 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 12:41:58 -0500 Subject: [PATCH 17/30] fix: Menus being janky --- .../com/hibiscusmc/hmccosmetics/gui/Menu.java | 23 ++++++++----------- .../hibiscusmc/hmccosmetics/gui/Menus.java | 4 ++-- .../gui/type/types/TypeCosmetic.java | 11 ++++----- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java index 51ed9c0d..8572b1b9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java @@ -105,7 +105,7 @@ public class Menu { for (ConfigurationNode config : config.node("items").childrenMap().values()) { - List slotString = null; + List slotString; try { slotString = config.node("slots").getList(String.class); } catch (SerializationException e) { @@ -126,7 +126,6 @@ public class Menu { ItemStack item; try { item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item")); - //item = config.node("item").get(ItemStack.class); } catch (SerializationException e) { throw new RuntimeException(e); } @@ -144,8 +143,8 @@ public class Menu { } for (int slot : slots) { - ItemStack originalItem = updateItem(user, item, type, config, slot).clone(); - GuiItem guiItem = ItemBuilder.from(originalItem).asGuiItem(); + ItemStack modifiedItem = getMenuItem(user, type, config, item.clone(), slot).clone(); + GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem(); Type finalType = type; guiItem.setAction(event -> { @@ -153,11 +152,9 @@ public class Menu { final ClickType clickType = event.getClick(); if (finalType != null) finalType.run(user, config, clickType); // Need to delay the update by a tick so it will actually update with new values - Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { - for (int guiSlot : slots) { - gui.updateItem(guiSlot, updateItem(user, originalItem, finalType, config, guiSlot)); - } - }, 1); + for (int guiSlot : slots) { + gui.updateItem(guiSlot, getMenuItem(user, finalType, config, item.clone(), guiSlot)); + } MessagesUtil.sendDebugMessages("Updated slot " + slot); }); @@ -196,11 +193,9 @@ public class Menu { @Contract("_, _, _, _ -> param2") @NotNull - private ItemStack updateItem(CosmeticUser user, @NotNull ItemStack itemStack, Type type, ConfigurationNode config, int slot) { - if (itemStack.hasItemMeta()) { - itemStack = type.setItem(user, config, itemStack, slot); - } - return itemStack; + private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) { + if (!itemStack.hasItemMeta()) return itemStack; + return type.setItem(user, config, itemStack, slot); } public String getPermissionNode() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java index fcab856d..f539dfc2 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java @@ -56,8 +56,8 @@ public class Menus { return names; } - public static List values() { - return Menus.values(); + public static Collection values() { + return MENUS.values(); } public static void setup() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/type/types/TypeCosmetic.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/type/types/TypeCosmetic.java index 5722938f..ad170aa5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/type/types/TypeCosmetic.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/type/types/TypeCosmetic.java @@ -75,7 +75,7 @@ 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()) { + if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) { DyeMenu.openMenu(user, cosmetic); } else { user.addPlayerCosmetic(cosmetic); @@ -99,12 +99,11 @@ public class TypeCosmetic extends Type { @Override public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) { - ItemMeta itemMeta = itemStack.getItemMeta(); - itemStack.setItemMeta(processLoreLines(user, itemMeta)); + itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta())); if (config.node("cosmetic").virtual()) { return itemStack; - }; + } String cosmeticName = config.node("cosmetic").getString(); Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName); if (cosmetic == null) { @@ -155,12 +154,10 @@ public class TypeCosmetic extends Type { if (itemMeta.hasLore()) { for (String loreLine : itemMeta.getLore()) { - if (Hooks.isActiveHook("PlaceholderAPI")) - loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine); + if (Hooks.isActiveHook("PlaceholderAPI")) loreLine = PlaceholderAPI.setPlaceholders(user.getPlayer(), loreLine); processedLore.add(loreLine); } } - itemMeta.setLore(processedLore); return itemMeta; } From 70b97667c37764da7d96563d5bf3e2ef2931468e Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 14:38:01 -0500 Subject: [PATCH 18/30] feat: only show wardrobes player has access to --- .../hmccosmetics/command/CosmeticCommandTabComplete.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java index 5766fb3d..09b8c641 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -75,7 +75,11 @@ public class CosmeticCommandTabComplete implements TabCompleter { } case "wardrobe" -> { for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) { - completions.add(wardrobe.getId()); + if (wardrobe.hasPermission()) { + if (user.getPlayer().hasPermission(wardrobe.getPermission())) completions.add(wardrobe.getId()); + } else { + completions.add(wardrobe.getId()); + } } } case "dye" -> { From c189424aa8e1d19b495f1133474a6dddb251774f Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 14:44:38 -0500 Subject: [PATCH 19/30] fix: setlocation command now shows no-wardrobes message when there is no wardrobe with inputted name --- .../com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index c3340340..1d576c0e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -320,7 +320,7 @@ public class CosmeticCommand implements CommandExecutor { } Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]); if (wardrobe == null) { - MessagesUtil.sendMessage(player, "not-enough-args"); + MessagesUtil.sendMessage(player, "no-wardrobes"); return true; } From 50bda8343cd8e0312dbcc59ba38ca80dfdf1823d Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 14:53:16 -0500 Subject: [PATCH 20/30] fix: wardrobe region not entering wardrobe --- .../hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java index ee23df03..ca0228e7 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java @@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; +import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.ApplicableRegionSet; @@ -44,7 +45,7 @@ public class WGListener implements Listener { return; } if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) { - if (!WardrobeSettings.getWardrobes().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return; + if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return; Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString()); user.enterWardrobe(true, wardrobe); } From 7439aabfd1e93c75d8237d365bc49cade134e2be Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 14:53:59 -0500 Subject: [PATCH 21/30] clean: random space in wardrobe debug message --- .../hmccosmetics/user/manager/UserWardrobeManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java index a59bd4d0..177b2b3f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java @@ -235,7 +235,7 @@ public class UserWardrobeManager { this.cancel(); return; } - MessagesUtil.sendDebugMessages("WardrobeUpdate[user= " + user.getUniqueId() + ",status=" + getWardrobeStatus() + "]"); + MessagesUtil.sendDebugMessages("WardrobeUpdate[user=" + user.getUniqueId() + ",status=" + getWardrobeStatus() + "]"); List viewer = Collections.singletonList(player); List outsideViewers = PacketManager.getViewers(viewingLocation); outsideViewers.remove(player); From a92b4c15f5c7712375fd8606cca3b9de9ee82019 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 15:03:13 -0500 Subject: [PATCH 22/30] feat: check if wardrobe locations are not null --- .../com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java index fc34072d..dff6b5b5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java @@ -26,6 +26,11 @@ public class WardrobeLocation { return leaveLocation.clone(); } + public boolean hasAllLocations() { + if (npcLocation == null || viewerLocation == null || leaveLocation == null) return false; + return true; + } + public void setNPCLocation(Location wardrobeLocation) { this.npcLocation = wardrobeLocation; } From 7fcbbd6b5ab62ceb86eeef76cdbdba8b1378b2b3 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 15:03:23 -0500 Subject: [PATCH 23/30] feat: add wardrobes to internal map --- .../hibiscusmc/hmccosmetics/config/WardrobeSettings.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 94adcb61..8aa3c696 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -143,7 +143,7 @@ public class WardrobeSettings { if (!wardrobesNode.node(DISTANCE_PATH).virtual()) distance = wardrobesNode.node(DISTANCE_PATH).getInt(); Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance); - wardrobes.put(id, wardrobe); + addWardrobe(wardrobe); } catch (Exception e) { MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE); } @@ -210,6 +210,10 @@ public class WardrobeSettings { return wardrobes.values(); } + public static void addWardrobe(Wardrobe wardrobe) { + wardrobes.put(wardrobe.getId(), wardrobe); + } + @Deprecated public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) { if (displayRadius == -1) return true; From fcde8e7f25d3f43914131d83bf1db620626e1756 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 15:03:41 -0500 Subject: [PATCH 24/30] feat: send message if locations are not all setup --- .../java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java | 4 ++++ 1 file changed, 4 insertions(+) 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 b5244c07..25f73ecc 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -253,6 +253,10 @@ public class CosmeticUser { MessagesUtil.sendMessage(getPlayer(), "not-near-wardrobe"); return; } + if (!wardrobe.getLocation().hasAllLocations()) { + MessagesUtil.sendMessage(getPlayer(), "wardrobe-not-setup"); + return; + } PlayerWardrobeEnterEvent event = new PlayerWardrobeEnterEvent(this, wardrobe); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { From e9c79463192ac5278536162f0bb07c6cefed9dc9 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 15:05:13 -0500 Subject: [PATCH 25/30] feat: create new wardrobes in-game --- .../hibiscusmc/hmccosmetics/command/CosmeticCommand.java | 7 +++++-- common/src/main/resources/messages.yml | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index 1d576c0e..e0df47de 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.command; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Wardrobe; +import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; @@ -320,8 +321,10 @@ public class CosmeticCommand implements CommandExecutor { } Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]); if (wardrobe == null) { - MessagesUtil.sendMessage(player, "no-wardrobes"); - return true; + wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1); + WardrobeSettings.addWardrobe(wardrobe); + //MessagesUtil.sendMessage(player, "no-wardrobes"); + //return true; } if (args[2].equalsIgnoreCase("npclocation")) { diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index c14ac1fa..ca862e4a 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -12,6 +12,7 @@ set-wardrobe-location: "%prefix% Set new wardrobe loca set-wardrobe-viewing: "%prefix% Set new wardrobe viewing location!" set-wardrobe-leaving: "%prefix% Set new wardrobe leaving location!" no-wardrobes: "%prefix% There are no wardrobes with that name!" +wardrobe-not-setup: "%prefix% This wardrobe does not have all required locations set!" equip-cosmetic: "%prefix% You have equipped !" unequip-cosmetic: "%prefix% You have unequipped !" From 5c6bb93e6c7475cb93f11e82b48be8206113cec1 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 15:08:43 -0500 Subject: [PATCH 26/30] feat: add removeWardrobe method --- .../com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 8aa3c696..6d712add 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -214,6 +214,10 @@ public class WardrobeSettings { wardrobes.put(wardrobe.getId(), wardrobe); } + public static void removeWardrobe(String id) { + wardrobes.remove(id); + } + @Deprecated public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) { if (displayRadius == -1) return true; From 455b8cd1a122373c357468d5505bbaa2ecce6889 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 16:29:07 -0500 Subject: [PATCH 27/30] version bump (2.4.0) --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 00a8640b..32373940 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.hibiscusmc" -version = "2.4.0-DEV" +version = "2.4.0" allprojects { apply(plugin = "java") From cc08cc6537441ad1cb1ad3cba271646d09814514 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 16:36:47 -0500 Subject: [PATCH 28/30] feat: message.yml to sync as well --- .../com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 873f0ec0..2f8b45d6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -102,10 +102,12 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { PlayerAnimatorImpl.initialize(this); // Configuration Sync - final File file = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile(); + final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile(); + final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile(); try { - CommentedConfiguration.loadConfiguration(file).syncWithConfig(file, getInstance().getResource("config.yml"), + CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"), "database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location"); + CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml")); } catch (Exception e) {} // Setup From 1e0ffdc08b053c7a2bd102c10318c3ff1d9054e3 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 16:41:54 -0500 Subject: [PATCH 29/30] clean: summer cleaning of CosmeticUser.java --- .../hmccosmetics/user/CosmeticUser.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) 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 25f73ecc..96a96f6d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.api.*; import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Wardrobe; -import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; @@ -32,7 +31,7 @@ import java.util.logging.Level; public class CosmeticUser { - private UUID uniqueId; + private final UUID uniqueId; private int taskId; private HashMap playerCosmetics = new HashMap<>(); private UserWardrobeManager userWardrobeManager; @@ -160,10 +159,7 @@ public class CosmeticUser { public boolean hasCosmeticInSlot(Cosmetic cosmetic) { if (getCosmetic(cosmetic.getSlot()) == null) return false; - if (cosmetic.getId() == getCosmetic(cosmetic.getSlot()).getId()) { - return true; - } - return false; + return Objects.equals(cosmetic.getId(), getCosmetic(cosmetic.getSlot()).getId()); } public Set getSlotsWithCosmetics() { @@ -300,8 +296,7 @@ public class CosmeticUser { } public boolean isInWardrobe() { - if (userWardrobeManager == null) return false; - return true; + return userWardrobeManager != null; } public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { @@ -317,8 +312,7 @@ public class CosmeticUser { } public boolean isBackpackSpawned() { - if (this.userBackpackManager == null) return false; - return true; + return this.userBackpackManager != null; } public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { @@ -369,7 +363,7 @@ public class CosmeticUser { } public List getDyeableSlots() { - ArrayList dyableSlots = new ArrayList(); + ArrayList dyableSlots = new ArrayList<>(); for (Cosmetic cosmetic : getCosmetics()) { if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot()); @@ -381,8 +375,7 @@ public class CosmeticUser { public boolean canEquipCosmetic(Cosmetic cosmetic) { if (!cosmetic.requiresPermission()) return true; if (isInWardrobe() && WardrobeSettings.isTryCosmeticsInWardrobe()) return true; - if (getPlayer().hasPermission(cosmetic.getPermission())) return true; - return false; + return getPlayer().hasPermission(cosmetic.getPermission()); } public void hidePlayer() { @@ -404,7 +397,7 @@ public class CosmeticUser { } public void hideCosmetics(HiddenReason reason) { - if (hideCosmetics == true) return; + if (hideCosmetics) return; PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { From 0528ebfa84ffb838436e911b989c8d2c8621e896 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 24 May 2023 16:56:06 -0500 Subject: [PATCH 30/30] feat: rename setlocation to setwardrobesetting to allow modification of permission and distance ingame --- build.gradle.kts | 2 +- .../hmccosmetics/command/CosmeticCommand.java | 17 ++++++++++-- .../command/CosmeticCommandTabComplete.java | 8 +++--- .../hmccosmetics/config/Wardrobe.java | 8 ++++++ .../hmccosmetics/config/WardrobeSettings.java | 26 ++++++++++++++++--- common/src/main/resources/messages.yml | 2 ++ 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 32373940..9ac08224 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -213,7 +213,7 @@ bukkit { register("hmccosmetics.cmd.emote.other") { default = BukkitPluginDescription.Permission.Default.OP } - register("hmccosmetics.cmd.setlocation") { + register("hmccosmetics.cmd.setwardrobesetting") { default = BukkitPluginDescription.Permission.Default.OP } register("hmccosmetics.cmd.dataclear") { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index e0df47de..71184d71 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -307,8 +307,8 @@ public class CosmeticCommand implements CommandExecutor { DyeMenu.openMenu(user, cosmetic); } } - case ("setlocation") -> { - if (!sender.hasPermission("hmccosmetics.cmd.setlocation")) { + case ("setwardrobesetting") -> { + if (!sender.hasPermission("hmccosmetics.cmd.setwardrobesetting")) { if (!silent) MessagesUtil.sendMessage(sender, "no-permission"); return true; } @@ -344,6 +344,19 @@ public class CosmeticCommand implements CommandExecutor { if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-leaving"); return true; } + + if (args.length >= 4) { + if (args[2].equalsIgnoreCase("permission")) { + WardrobeSettings.setWardrobePermission(wardrobe, args[3]); + if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-permission"); + return true; + } + if (args[2].equalsIgnoreCase("distance")) { + WardrobeSettings.setWardrobeDistance(wardrobe, Integer.valueOf(args[3])); + if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance"); + return true; + } + } } case ("dump") -> { if (player == null) return true; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java index 09b8c641..c2c86b4a 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -38,7 +38,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { if (hasPermission(sender, "hmccosmetics.cmd.wardrobe")) completions.add("wardrobe"); if (hasPermission(sender, "hmccosmetics.cmd.dataclear")) completions.add("dataclear"); if (hasPermission(sender, "hmccosmetics.cmd.dye")) completions.add("dye"); - if (hasPermission(sender, "hmccosmetics.cmd.setlocation")) completions.add("setlocation"); + if (hasPermission(sender, "hmccosmetics.cmd.setwardrobesetting")) completions.add("setwardrobesetting"); 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"); @@ -87,7 +87,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add(slot.name()); } } - case "setlocation" -> { + case "setwardrobesetting" -> { for (Wardrobe wardrobe : WardrobeSettings.getWardrobes()) { completions.add(wardrobe.getId()); } @@ -107,10 +107,12 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add(player.getName()); } } - case "setlocation" -> { + case "setwardrobesetting" -> { completions.add("npclocation"); completions.add("viewerlocation"); completions.add("leavelocation"); + completions.add("permission"); + completions.add("distance"); } } StringUtil.copyPartialMatches(args[2], completions, finalCompletions); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java index 6cea4aa2..1d080173 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java @@ -27,6 +27,14 @@ public class Wardrobe { return location; } + public void setDistance(int distance) { + this.distance = distance; + } + + public void setPermission(String permission) { + this.permission = permission; + } + public boolean hasPermission() { return permission != null; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java index 6d712add..1dca8c97 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeSettings.java @@ -302,7 +302,7 @@ public class WardrobeSettings { plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "yaw", newLocation.getYaw()); plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".npc-location." + "pitch", newLocation.getPitch()); - HMCCosmeticsPlugin.getInstance().saveConfig(); + plugin.saveConfig(); } /** @@ -321,7 +321,7 @@ public class WardrobeSettings { plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.yaw", newLocation.getYaw()); plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".viewer-location.pitch", newLocation.getPitch()); - HMCCosmeticsPlugin.getInstance().saveConfig(); + plugin.saveConfig(); } /** @@ -340,6 +340,26 @@ public class WardrobeSettings { plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.yaw", newLocation.getYaw()); plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".leave-location.pitch", newLocation.getPitch()); - HMCCosmeticsPlugin.getInstance().saveConfig(); + plugin.saveConfig(); + } + + public static void setWardrobePermission(Wardrobe wardrobe, String permission) { + wardrobe.setPermission(permission); + + HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); + + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".permission", permission); + + plugin.saveConfig(); + } + + public static void setWardrobeDistance(Wardrobe wardrobe, int distance) { + wardrobe.setDistance(distance); + + HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); + + plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".distance", distance); + + plugin.saveConfig(); } } diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index ca862e4a..32b6b734 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -11,6 +11,8 @@ not-near-wardrobe: "%prefix% You are not near the wardrobe!" set-wardrobe-location: "%prefix% Set new wardrobe location!" set-wardrobe-viewing: "%prefix% Set new wardrobe viewing location!" set-wardrobe-leaving: "%prefix% Set new wardrobe leaving location!" +set-wardrobe-permission: "%prefix% Set new wardrobe permission!" +set-wardrobe-distance: "%prefix% Set new wardrobe distance!" no-wardrobes: "%prefix% There are no wardrobes with that name!" wardrobe-not-setup: "%prefix% This wardrobe does not have all required locations set!"