From af4f7fadc1967669aa67e0cb41ce80db52695fe1 Mon Sep 17 00:00:00 2001 From: Byteflux Date: Fri, 8 May 2015 13:58:21 -0700 Subject: [PATCH] Add command to toggle plot chat --- .../intellectualcrafters/plot/BukkitMain.java | 2 ++ .../plot/commands/Chat.java | 34 +++++++++++++++++++ .../plot/commands/Command.java | 3 +- .../intellectualcrafters/plot/config/C.java | 3 ++ .../plot/listeners/PlayerEvents.java | 3 +- 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Chat.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index dc82b4408..5b7d78cf0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -22,6 +22,7 @@ import org.bukkit.plugin.java.JavaPlugin; import com.intellectualcrafters.plot.commands.Auto; import com.intellectualcrafters.plot.commands.BukkitCommand; import com.intellectualcrafters.plot.commands.Buy; +import com.intellectualcrafters.plot.commands.Chat; import com.intellectualcrafters.plot.commands.Claim; import com.intellectualcrafters.plot.commands.Clear; import com.intellectualcrafters.plot.commands.Comment; @@ -261,6 +262,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { MainCommand.subCommands.add(new Condense()); MainCommand.subCommands.add(new Confirm()); MainCommand.subCommands.add(new Copy()); + MainCommand.subCommands.add(new Chat()); final BukkitCommand bcmd = new BukkitCommand(); final PluginCommand plotCommand = getCommand("plots"); plotCommand.setExecutor(bcmd); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Chat.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Chat.java new file mode 100644 index 000000000..96badc9a1 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Chat.java @@ -0,0 +1,34 @@ +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; + +public class Chat extends SubCommand { + public Chat() { + super(Command.CHAT, "Toggle plot chat on or off", "chat", CommandCategory.ACTIONS, true); + } + + @Override + public boolean execute(PlotPlayer plr, String... args) { + final String world = plr.getLocation().getWorld(); + if (!PlotSquared.isPlotWorld(world)) { + return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); + } + boolean enable = !(plr.getMeta("chat") != null && (Boolean) plr.getMeta("chat")); + if (args.length > 0) { + if (args[0].equalsIgnoreCase("on")) { + enable = true; + } else if (args[0].equalsIgnoreCase("off")) { + enable = false; + } + } + final PlotWorld plotworld = PlotSquared.getPlotWorld(world); + if (!enable && plotworld.PLOT_CHAT) { + return !sendMessage(plr, C.PLOT_CHAT_FORCED); + } + plr.setMeta("chat", enable); + return sendMessage(plr, enable ? C.PLOT_CHAT_ON : C.PLOT_CHAT_OFF); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java index c2a120566..18746cef7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java @@ -76,7 +76,8 @@ public enum Command { UNBAN("unban", "unblock"), DATABASE("database", "convert"), CONFIRM("confirm"), - TP("tp", "tp"); + TP("tp", "tp"), + CHAT("chat", "on|off", new CommandPermission("plots.chat")); /** * Command */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 4bb2abe49..7598e8787 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -402,6 +402,9 @@ public enum C { * Chat */ PLOT_CHAT_FORMAT("$2[$1Plot Chat$2][$1%plot_id%$2] $1%sender%$2: $1%msg%"), + PLOT_CHAT_FORCED("$2This world forces everyone to use plot chat."), + PLOT_CHAT_ON("$4Plot chat enabled."), + PLOT_CHAT_OFF("$4Plot chat disabled."), /* * Denied */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 2c76f6318..919bf21c9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -354,7 +354,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - if (!plotworld.PLOT_CHAT) { + final PlotPlayer plr = BukkitUtil.getPlayer(player); + if (!plotworld.PLOT_CHAT && (plr.getMeta("chat") == null || !(Boolean) plr.getMeta("chat"))) { return; } final Location loc = BukkitUtil.getLocation(player);