Merge pull request #302 from MinelinkNetwork/plot-chat

Add command to toggle plot chat
This commit is contained in:
Jesse Boyd 2015-05-09 12:23:24 +10:00
commit d6500873cf
5 changed files with 43 additions and 2 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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);