Add a toggle option for toggling chat (#89)

* Add moderated mode toggle option

* Add new messages to messages.yml for modmode toggle

* Add block_on_modmode list for commands to block, should be separate from block_on_mute so pms can still work

* Implement the restricted chat toggle

* Add the restricted chat toggle to the toggle gui

* Add the restricted chat toggle to the consoles version of the command as well

* Update toggles.yml / requested changes

* Update messages.yml / requested changes

* Update commands.yml / requested changes

* Update ToggleMenu.java / requested changes

* Update TogglesListener.java / requested changes

* Update ToggleCMD.java / requested changes

* Update messages.yml / requested changes

* Update ToggleMenu.java / requested changes

* Update ToggleCMD.java / requested changes
This commit is contained in:
Deauthorized 2024-04-28 13:04:18 -04:00 committed by GitHub
parent 315e16488b
commit 357683a0f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 86 additions and 3 deletions

View File

@ -32,6 +32,7 @@ public class ToggleCMD extends PlexCommand
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Fluidspread" + status("fluidspread")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Drops" + status("drops")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone"))); sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Redstone" + status("redstone")));
sender.sendMessage(PlexUtils.mmDeserialize("<gray> - Chat" + status("chat")));
return null; return null;
} }
switch (args[0].toLowerCase()) switch (args[0].toLowerCase())
@ -52,6 +53,11 @@ public class ToggleCMD extends PlexCommand
{ {
return toggle("redstone"); return toggle("redstone");
} }
case "chat" ->
{
PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", sender.getName(), plugin.toggles.getBoolean("chat") ? "off" : "on"));
return toggle("chat");
}
default -> default ->
{ {
return messageComponent("invalidToggle"); return messageComponent("invalidToggle");

View File

@ -1,6 +1,12 @@
package dev.plex.listener.impl; package dev.plex.listener.impl;
import dev.plex.Plex;
import dev.plex.listener.PlexListener; 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.EventHandler;
import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockFromToEvent; 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.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.List;
public class TogglesListener extends PlexListener public class TogglesListener extends PlexListener
{ {
List<String> commands = plugin.commands.getStringList("block_on_mute");
@EventHandler @EventHandler
public void onExplosionPrime(ExplosionPrimeEvent event) 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 /* 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 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. and re-enabling redstone, you are unable to recreate the loop with a lever. Using a redstone torch works fine.

View File

@ -24,6 +24,7 @@ public class ToggleMenu extends AbstractMenu
resetFluidspreadItem(this.inventory()); resetFluidspreadItem(this.inventory());
resetDropsItem(this.inventory()); resetDropsItem(this.inventory());
resetRedstoneItem(this.inventory()); resetRedstoneItem(this.inventory());
resetChatItem(this.inventory());
} }
private void resetExplosionItem(Inventory inventory) private void resetExplosionItem(Inventory inventory)
@ -66,6 +67,16 @@ public class ToggleMenu extends AbstractMenu
inventory.setItem(3, redstone); inventory.setItem(3, redstone);
} }
private void resetChatItem(Inventory inventory)
{
ItemStack chat = new ItemStack(Material.OAK_SIGN);
ItemMeta chatItemMeta = chat.getItemMeta();
chatItemMeta.displayName(PlexUtils.mmDeserialize("<!italic><light_purple>Toggle chat"));
chatItemMeta.lore(List.of(PlexUtils.mmDeserialize("<!italic><yellow>Chat is currently " + (plugin.toggles.getBoolean("chat") ? "<green>on" : "<red>off"))));
chat.setItemMeta(chatItemMeta);
inventory.setItem(4, chat);
}
@Override @Override
public boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked) public boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked)
{ {
@ -93,6 +104,13 @@ public class ToggleMenu extends AbstractMenu
resetRedstoneItem(inventory); resetRedstoneItem(inventory);
player.sendMessage(PlexUtils.mmDeserialize("<gray>Toggled redstone.")); player.sendMessage(PlexUtils.mmDeserialize("<gray>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("<gray>Toggled chat."));
}
return true; return true;
} }
} }

View File

@ -54,7 +54,7 @@ commands:
- "r:a:^(co|core|coreprotect) (rb|rollback|l|lookup|rl|reload):_" - "r:a:^(co|core|coreprotect) (rb|rollback|l|lookup|rl|reload):_"
- "r:e:^[A-z]*:[A-z]*::<gray>Plugin specific commands are disabled." - "r:e:^[A-z]*:[A-z]*::<gray>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: block_on_mute:
- me - me
- say - say

View File

@ -110,6 +110,10 @@ playerFrozen: "<red>That player is already frozen!"
playerMuted: "<red>That player is already muted!" playerMuted: "<red>That player is already muted!"
playerLockedUp: "<red>That player is already locked up!" playerLockedUp: "<red>That player is already locked up!"
muted: "<red>You are currently muted - STFU!" muted: "<red>You are currently muted - STFU!"
chatIsOff: "<red>Chat is currently toggled off!"
# 0 - The command sender
# 1 - The set value of the chat toggle
chatToggled: "<red>{0} - Toggled chat {1}"
# 0 - The command sender # 0 - The command sender
# 1 - The player # 1 - The player
kickedPlayer: "<red>{0} - Kicking {1}" kickedPlayer: "<red>{0} - Kicking {1}"

View File

@ -11,3 +11,6 @@ drops: true
# Should redstone be enabled? # Should redstone be enabled?
redstone: true redstone: true
# Is chat enabled?
chat: true