Added toggle command for titles

This commit is contained in:
boy0001 2015-06-05 23:05:17 +10:00
parent 7aebd7da8e
commit 93a40653c0
5 changed files with 89 additions and 6 deletions

View File

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

View File

@ -43,6 +43,8 @@ public enum Command {
UNTRUST("untrust", "ut"),
UNDENY("undeny", "ud"),
TOGGLE("toggle", "attribute"),
MOVE("move"),
FLAG("flag", "f"),
TARGET("target"),

View File

@ -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 <setting>", CommandCategory.ACTIONS, true);
}
public void noArgs(PlotPlayer player) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot toggle <setting>");
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;
}
}
}

View File

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

View File

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