From 977b5e388a9a1e988549e9a7b74e611892cb60d3 Mon Sep 17 00:00:00 2001 From: HeroBrineGoat <76707404+MasterOfTheFish@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:59:55 -0500 Subject: [PATCH] Added command to open other player's wardrobe --- common/build.gradle.kts | 4 ++++ .../command/CosmeticsCommand.java | 21 +++++++++++++++++-- .../hmccosmetics/config/WardrobeSettings.java | 6 +++--- .../hmccosmetics/message/Messages.java | 2 ++ .../hmccosmetics/message/Permission.java | 1 + .../fisher2911/hmccosmetics/user/User.java | 1 + common/src/main/resources/messages.yml | 1 + 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 9b644906..783e44f0 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -114,5 +114,9 @@ bukkit { default = BukkitPluginDescription.Permission.Default.OP description = "Permission to view the wardrobe" } + register("hmccosmetics.cmd.wardrobe.other") { + default = BukkitPluginDescription.Permission.Default.OP + description = "Permission to open another player's wardrobe" + } } } \ No newline at end of file diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java index 6766f533..5fd79897 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java @@ -24,6 +24,7 @@ import me.mattstudios.mf.annotations.Permission; import me.mattstudios.mf.annotations.SubCommand; import me.mattstudios.mf.base.CommandBase; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -214,7 +215,22 @@ public class CosmeticsCommand extends CommandBase { @SubCommand("wardrobe") @Permission(io.github.fisher2911.hmccosmetics.message.Permission.WARDROBE) - public void openWardrobe(final Player player) { + public void openWardrobe(Player player, @me.mattstudios.mf.annotations.Optional final Player other) { + if (other != null) { + if (!player.hasPermission(io.github.fisher2911.hmccosmetics.message.Permission.OPEN_OTHER_WARDROBE)) { + this.messageHandler.sendMessage( + player, + Messages.NO_PERMISSION + ); + return; + } + this.messageHandler.sendMessage( + player, + Messages.OPENED_OTHER_WARDROBE, + Map.of(Placeholder.PLAYER, other.getName()) + ); + player = other; + } final Optional optionalUser = this.plugin.getUserManager().get(player.getUniqueId()); if (optionalUser.isEmpty()) return; @@ -254,9 +270,10 @@ public class CosmeticsCommand extends CommandBase { wardrobe.setActive(true); + final Player finalPlayer = player; Bukkit.getScheduler().runTaskAsynchronously( this.plugin, - () -> wardrobe.spawnFakePlayer(player) + () -> wardrobe.spawnFakePlayer(finalPlayer) ); this.cosmeticsMenu.openDefault(player); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java index cefa0d6b..5fc0908f 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java @@ -55,9 +55,9 @@ public class WardrobeSettings { @Nullable private Location loadLocation(final ConfigurationSection section) { final String worldName = section.getString(WORLD_PATH); - final int x = section.getInt(X_PATH); - final int y = section.getInt(Y_PATH); - final int z = section.getInt(Z_PATH); + final double x = section.getDouble(X_PATH); + final double y = section.getDouble(Y_PATH); + final double z = section.getDouble(Z_PATH); final float yaw = (float) section.getDouble(YAW_PATH); final float pitch = (float) section.getDouble(PITCH_PATH); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java index ef6d488d..b094c85a 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java @@ -60,6 +60,8 @@ public class Messages { new Message("not-near-wardrobe", ChatColor.RED + "You are not near the wardrobe!"); public static final Message CANNOT_USE_PORTABLE_WARDROBE = new Message("cannot-use-portable-wardrobe", ChatColor.RED + "You cannot use the portable wardrobe!"); + public static final Message OPENED_OTHER_WARDROBE = + new Message("opened-other-wardrobe", ChatColor.GREEN + "Opening " + Placeholder.PLAYER + "'s wardrobe."); public static final Message SET_OTHER_BACKPACK = new Message( "set-other-backpack", ChatColor.GREEN + "You have set the backpack of " + diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Permission.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Permission.java index aaa2ddcc..eb52ea09 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Permission.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Permission.java @@ -9,5 +9,6 @@ public class Permission { public static final String SET_COSMETIC_COMMAND = "hmccosmetics.cmd.set"; public static final String PORTABLE_WARDROBE = "hmccosmetics.cmd.wardrobe.portable"; public static final String WARDROBE = "hmccosmetics.cmd.wardrobe"; + public static final String OPEN_OTHER_WARDROBE = "hmccosmetics.cmd.wardrobe.other"; } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java index 89e153f0..0fcab501 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java @@ -172,6 +172,7 @@ public class User { new ItemStack(Material.AIR) )); + if (!this.uuid.equals(other.getUniqueId())) return; PacketManager.sendPacket(other, PacketManager.getEquipmentPacket(equipmentList, this.armorStandId)); } } diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 4f6738b8..a93be4e7 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -19,6 +19,7 @@ closed-wardrobe: "%prefix% Closed wardrobe!" wardrobe-already-open: "%prefix% The wardrobe is already open!" not-near-wardrobe: "%prefix% You are not near the wardrobe!" cannot-use-portable-wardrobe: "%prefix% You cannot use the portable wardrobe!" +opened-other-wardrobe: "%prefix% Opening %player%'s wardrobe." help-command: "<#6D9DC5> %prefix% HMCCosmetics - Help %prefix% <#6D9DC5>