diff --git a/server/src/main/java/dev/plex/command/impl/ToggleCMD.java b/server/src/main/java/dev/plex/command/impl/ToggleCMD.java index 152df22..d152967 100644 --- a/server/src/main/java/dev/plex/command/impl/ToggleCMD.java +++ b/server/src/main/java/dev/plex/command/impl/ToggleCMD.java @@ -32,6 +32,7 @@ public class ToggleCMD extends PlexCommand sender.sendMessage(PlexUtils.mmDeserialize(" - Fluidspread" + status("fluidspread"))); sender.sendMessage(PlexUtils.mmDeserialize(" - Drops" + status("drops"))); sender.sendMessage(PlexUtils.mmDeserialize(" - Redstone" + status("redstone"))); + sender.sendMessage(PlexUtils.mmDeserialize(" - Chat" + status("chat"))); return null; } switch (args[0].toLowerCase()) @@ -52,6 +53,11 @@ public class ToggleCMD extends PlexCommand { return toggle("redstone"); } + case "chat" -> + { + PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", sender.getName(), plugin.toggles.getBoolean("chat") ? "off" : "on")); + return toggle("chat"); + } default -> { return messageComponent("invalidToggle"); diff --git a/server/src/main/java/dev/plex/listener/impl/TogglesListener.java b/server/src/main/java/dev/plex/listener/impl/TogglesListener.java index 4cd7565..5196d29 100644 --- a/server/src/main/java/dev/plex/listener/impl/TogglesListener.java +++ b/server/src/main/java/dev/plex/listener/impl/TogglesListener.java @@ -1,6 +1,12 @@ package dev.plex.listener.impl; +import dev.plex.Plex; import dev.plex.listener.PlexListener; +import dev.plex.util.PlexUtils; +import io.papermc.paper.event.player.AsyncChatEvent; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockFromToEvent; @@ -8,9 +14,13 @@ import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.List; public class TogglesListener extends PlexListener { + List commands = plugin.commands.getStringList("block_on_mute"); @EventHandler public void onExplosionPrime(ExplosionPrimeEvent event) { @@ -58,6 +68,48 @@ public class TogglesListener extends PlexListener } } + @EventHandler + public void onChat(AsyncChatEvent event) + { + Player player = event.getPlayer(); + if (!plugin.toggles.getBoolean("chat") && !Plex.get().getPermissions().has(player, "plex.mute.bypass")) + { + event.getPlayer().sendMessage(PlexUtils.messageComponent("chatIsOff")); + event.setCancelled(true); + } + } + + @EventHandler + public void onCommand(PlayerCommandPreprocessEvent event) + { + Player player = event.getPlayer(); + if (!plugin.toggles.getBoolean("chat") && !Plex.get().getPermissions().has(player, "plex.mute.bypass")) + { + String message = event.getMessage(); + message = message.replaceAll("\\s.*", "").replaceFirst("/", ""); + if (commands.contains(message.toLowerCase())) + { + event.getPlayer().sendMessage(PlexUtils.messageComponent("chatIsOff")); + event.setCancelled(true); + return; + } + + for (String command : commands) + { + Command cmd = Bukkit.getCommandMap().getCommand(command); + if (cmd == null) { + return; + } + if (cmd.getAliases().contains(message.toLowerCase())) { + event.getPlayer().sendMessage(PlexUtils.messageComponent("chatIsOff")); + event.setCancelled(true); + return; + } + } + } + + } + /* I have no idea if this is the best way to do this There is a very weird bug where if you try to create a loop using two repeaters and a lever, after disabling and re-enabling redstone, you are unable to recreate the loop with a lever. Using a redstone torch works fine. diff --git a/server/src/main/java/dev/plex/menu/impl/ToggleMenu.java b/server/src/main/java/dev/plex/menu/impl/ToggleMenu.java index 4f0bf06..0f9b71a 100644 --- a/server/src/main/java/dev/plex/menu/impl/ToggleMenu.java +++ b/server/src/main/java/dev/plex/menu/impl/ToggleMenu.java @@ -24,6 +24,7 @@ public class ToggleMenu extends AbstractMenu resetFluidspreadItem(this.inventory()); resetDropsItem(this.inventory()); resetRedstoneItem(this.inventory()); + resetChatItem(this.inventory()); } private void resetExplosionItem(Inventory inventory) @@ -66,6 +67,16 @@ public class ToggleMenu extends AbstractMenu inventory.setItem(3, redstone); } + private void resetChatItem(Inventory inventory) + { + ItemStack chat = new ItemStack(Material.OAK_SIGN); + ItemMeta chatItemMeta = chat.getItemMeta(); + chatItemMeta.displayName(PlexUtils.mmDeserialize("Toggle chat")); + chatItemMeta.lore(List.of(PlexUtils.mmDeserialize("Chat is currently " + (plugin.toggles.getBoolean("chat") ? "on" : "off")))); + chat.setItemMeta(chatItemMeta); + inventory.setItem(4, chat); + } + @Override public boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked) { @@ -93,6 +104,13 @@ public class ToggleMenu extends AbstractMenu resetRedstoneItem(inventory); player.sendMessage(PlexUtils.mmDeserialize("Toggled redstone.")); } + if (clicked.getType() == Material.OAK_SIGN) + { + plugin.toggles.set("chat", !plugin.toggles.getBoolean("chat")); + PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", player.getName(), plugin.toggles.getBoolean("chat") ? "on" : "off")); + resetChatItem(inventory); + player.sendMessage(PlexUtils.mmDeserialize("Toggled chat.")); + } return true; } } diff --git a/server/src/main/resources/commands.yml b/server/src/main/resources/commands.yml index c42f2d4..e199468 100644 --- a/server/src/main/resources/commands.yml +++ b/server/src/main/resources/commands.yml @@ -54,10 +54,10 @@ commands: - "r:a:^(co|core|coreprotect) (rb|rollback|l|lookup|rl|reload):_" - "r:e:^[A-z]*:[A-z]*::Plugin specific commands are disabled." -# These commands will be blocked when a player is muted +# These commands will be blocked when a player is muted or when chat is toggled off. block_on_mute: - me - say - msg - reply - - mail \ No newline at end of file + - mail diff --git a/server/src/main/resources/messages.yml b/server/src/main/resources/messages.yml index 992e927..9b97556 100644 --- a/server/src/main/resources/messages.yml +++ b/server/src/main/resources/messages.yml @@ -110,6 +110,10 @@ playerFrozen: "That player is already frozen!" playerMuted: "That player is already muted!" playerLockedUp: "That player is already locked up!" muted: "You are currently muted - STFU!" +chatIsOff: "Chat is currently toggled off!" +# 0 - The command sender +# 1 - The set value of the chat toggle +chatToggled: "{0} - Toggled chat {1}" # 0 - The command sender # 1 - The player kickedPlayer: "{0} - Kicking {1}" diff --git a/server/src/main/resources/toggles.yml b/server/src/main/resources/toggles.yml index 5baf5ea..55c2437 100644 --- a/server/src/main/resources/toggles.yml +++ b/server/src/main/resources/toggles.yml @@ -10,4 +10,7 @@ fluidspread: true drops: true # Should redstone be enabled? -redstone: true \ No newline at end of file +redstone: true + +# Is chat enabled? +chat: true