From 93a40653c0d8def43290d6c23bbbd32a5db3e618 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 5 Jun 2015 23:05:17 +1000 Subject: [PATCH] Added toggle command for titles --- .../intellectualcrafters/plot/BukkitMain.java | 2 + .../plot/commands/Command.java | 2 + .../plot/commands/Toggle.java | 74 +++++++++++++++++++ .../intellectualcrafters/plot/config/C.java | 5 ++ .../plot/object/BukkitPlayer.java | 12 +-- 5 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Toggle.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 92081bad4..61e55b86b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -72,6 +72,7 @@ import com.intellectualcrafters.plot.commands.Swap; import com.intellectualcrafters.plot.commands.TP; import com.intellectualcrafters.plot.commands.Target; import com.intellectualcrafters.plot.commands.Template; +import com.intellectualcrafters.plot.commands.Toggle; import com.intellectualcrafters.plot.commands.Trim; import com.intellectualcrafters.plot.commands.Trust; import com.intellectualcrafters.plot.commands.Unclaim; @@ -250,6 +251,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { MainCommand.subCommands.add(new Visit()); MainCommand.subCommands.add(new TP()); MainCommand.subCommands.add(new Set()); + MainCommand.subCommands.add(new Toggle()); MainCommand.subCommands.add(new Clear()); MainCommand.subCommands.add(new Delete()); MainCommand.subCommands.add(new SetOwner()); 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 40e609f91..5521b76da 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java @@ -43,6 +43,8 @@ public enum Command { UNTRUST("untrust", "ut"), UNDENY("undeny", "ud"), + TOGGLE("toggle", "attribute"), + MOVE("move"), FLAG("flag", "f"), TARGET("target"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Toggle.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Toggle.java new file mode 100644 index 000000000..22eba8e1e --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Toggle.java @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class Toggle extends SubCommand { + public Toggle() { + super(Command.TOGGLE, "Toggle per user settings", "toggle ", CommandCategory.ACTIONS, true); + } + + public void noArgs(PlotPlayer player) { + MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot toggle "); + MainUtil.sendMessage(player, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + "titles"); + } + + @Override + public boolean execute(final PlotPlayer player, final String... args) { + if (args.length == 0) { + noArgs(player); + return false; + } + switch (args[0].toLowerCase()) { + case "titles": { + if (toggle(player, "disabletitles")) { + MainUtil.sendMessage(player, C.TOGGLE_ENABLED, args[0]); + } + else { + MainUtil.sendMessage(player, C.TOGGLE_DISABLED, args[0]); + } + return true; + } + default: { + return false; + } + } + } + + public boolean toggle(PlotPlayer player, String key) { + if (player.getAttribute(key)) { + player.removeAttribute(key); + return true; + } + else { + player.setAttribute(key); + return false; + } + } +} 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 7528b3172..797f3d723 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -143,6 +143,11 @@ public enum C { PASTE_FAILED("$2Failed to paste the selection. Reason: $2%s", "Clipboard"), NO_CLIPBOARD("$2You don't have a selection in your clipboard", "Clipboard"), CLIPBOARD_INFO("$2Current Selection - Plot ID: $1%id$2, Width: $1%width$2, Total Blocks: $1%total$2", "Clipboard"), + /* + * + */ + TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"), + TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"), /* * Ratings */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index abb1073f2..b4c47f206 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -157,18 +157,18 @@ public class BukkitPlayer implements PlotPlayer { @Override public void setAttribute(String key) { key = "plotsquared_user_attributes." + key; - Permission perm = Bukkit.getServer().getPluginManager().getPermission(key); - if (perm == null) { - perm = new Permission(key, PermissionDefault.FALSE); - Bukkit.getServer().getPluginManager().addPermission(perm); - Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm); - } EconHandler.manager.setPermission(this, key, true); } @Override public boolean getAttribute(String key) { key = "plotsquared_user_attributes." + key; + Permission perm = Bukkit.getServer().getPluginManager().getPermission(key); + if (perm == null) { + perm = new Permission(key, PermissionDefault.FALSE); + Bukkit.getServer().getPluginManager().addPermission(perm); + Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm); + } return player.hasPermission(key); }