From 00cc3eef2c967ac7ae3e33505f970ae62e212fb5 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Fri, 10 Feb 2023 16:28:42 -0600 Subject: [PATCH] improve command handling and add permissions --- build.gradle.kts | 6 ++++++ .../hibiscusmc/hmccosmetics/command/CosmeticCommand.java | 9 +++++++++ .../hmccosmetics/listener/PlayerGameListener.java | 2 +- common/src/main/resources/messages.yml | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5207e524..28324d1a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -190,6 +190,12 @@ bukkit { register("hmccosmetics.cmd.menu") { default = BukkitPluginDescription.Permission.Default.TRUE } + register("hmccosmetics.cmd.emote") { + default = BukkitPluginDescription.Permission.Default.TRUE + } + register("hmccosmetics.emote.shiftrun") { + default = BukkitPluginDescription.Permission.Default.TRUE + } register("hmccosmetics.cmd.setlocation") { default = BukkitPluginDescription.Permission.Default.OP } 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 8b9c36ef..de74dc66 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -382,10 +382,19 @@ public class CosmeticCommand implements CommandExecutor { } } case ("emote") -> { + if (!sender.hasPermission("hmccosmetics.cmd.emote")) { + if (!silent) MessagesUtil.sendMessage(sender, "no-permission"); + return true; + } CosmeticUser user = CosmeticUsers.getUser(player); + if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) { + if (!silent) MessagesUtil.sendMessage(sender, "emote-none"); + return true; + } CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE); cosmeticEmoteType.run(user); + return true; } } return true; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java index 2b64a63b..74f58be9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -202,7 +202,7 @@ public class PlayerGameListener implements Listener { CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId()); if (user == null) return; // Really need to look into optimization of this - if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking()) { + if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) { CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE); cosmeticEmoteType.run(user); event.setCancelled(true); diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index d1377471..53216d1d 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -18,6 +18,7 @@ hide-cosmetic: "%prefix% Hidden cosmetics" show-cosmetic: "%prefix% Revealed cosmetics!" emote-blocked: "%prefix% You can not use your emote here!" +emote-none: "%prefix% You have no emote equipped!" invalid-slot: "%prefix% Invalid cosmetic slot!" invalid-player: "%prefix% Invalid Player!"