From 54e8e5102abc368d4d01b8c5ef5f28a1e3137088 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 23 May 2023 10:50:09 -0500 Subject: [PATCH] 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 !"