Search in sources :

Example 1 with TownyPermission

use of com.palmergames.bukkit.towny.object.TownyPermission in project Towny by ElgarL.

the class PlotCommand method setTownBlockPermissions.

public static void setTownBlockPermissions(Player player, TownBlockOwner townBlockOwner, TownBlock townBlock, String[] split) {
    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
        player.sendMessage(ChatTools.formatTitle("/... set perm"));
        player.sendMessage(ChatTools.formatCommand("Level", "[friend/ally/outsider]", "", ""));
        player.sendMessage(ChatTools.formatCommand("Type", "[build/destroy/switch/itemuse]", "", ""));
        player.sendMessage(ChatTools.formatCommand("", "set perm", "[on/off]", "Toggle all permissions"));
        player.sendMessage(ChatTools.formatCommand("", "set perm", "[level/type] [on/off]", ""));
        player.sendMessage(ChatTools.formatCommand("", "set perm", "[level] [type] [on/off]", ""));
        player.sendMessage(ChatTools.formatCommand("", "set perm", "reset", ""));
        player.sendMessage(ChatTools.formatCommand("Eg", "/plot set perm", "friend build on", ""));
        player.sendMessage(String.format(TownySettings.getLangString("plot_perms"), "'friend'", ""));
        player.sendMessage(TownySettings.getLangString("plot_perms_1"));
    } else {
        TownyPermission perm = townBlock.getPermissions();
        if (split.length == 1) {
            if (split[0].equalsIgnoreCase("reset")) {
                // reset this townBlock permissions (by town/resident)
                townBlock.setType(townBlock.getType());
                TownyUniverse.getDataSource().saveTownBlock(townBlock);
                if (townBlockOwner instanceof Town)
                    TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_set_perms_reset"), "Town owned"));
                else
                    TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_set_perms_reset"), "your"));
                // Reset all caches as this can affect everyone.
                plugin.resetCache();
                return;
            } else {
                try {
                    boolean b = plugin.parseOnOff(split[0]);
                    for (String element : new String[] { "residentBuild", "residentDestroy", "residentSwitch", "residentItemUse", "outsiderBuild", "outsiderDestroy", "outsiderSwitch", "outsiderItemUse", "allyBuild", "allyDestroy", "allySwitch", "allyItemUse" }) perm.set(element, b);
                } catch (Exception e) {
                // invalid entry
                }
            }
        } else if (split.length == 2) {
            try {
                boolean b = plugin.parseOnOff(split[1]);
                if (split[0].equalsIgnoreCase("friend")) {
                    perm.residentBuild = b;
                    perm.residentDestroy = b;
                    perm.residentSwitch = b;
                    perm.residentItemUse = b;
                } else if (split[0].equalsIgnoreCase("outsider")) {
                    perm.outsiderBuild = b;
                    perm.outsiderDestroy = b;
                    perm.outsiderSwitch = b;
                    perm.outsiderItemUse = b;
                } else if (split[0].equalsIgnoreCase("ally")) {
                    perm.allyBuild = b;
                    perm.allyDestroy = b;
                    perm.allySwitch = b;
                    perm.allyItemUse = b;
                } else if (split[0].equalsIgnoreCase("build")) {
                    perm.residentBuild = b;
                    perm.outsiderBuild = b;
                    perm.allyBuild = b;
                } else if (split[0].equalsIgnoreCase("destroy")) {
                    perm.residentDestroy = b;
                    perm.outsiderDestroy = b;
                    perm.allyDestroy = b;
                } else if (split[0].equalsIgnoreCase("switch")) {
                    perm.residentSwitch = b;
                    perm.outsiderSwitch = b;
                    perm.allySwitch = b;
                } else if (split[0].equalsIgnoreCase("itemuse")) {
                    perm.residentItemUse = b;
                    perm.outsiderItemUse = b;
                    perm.allyItemUse = b;
                }
            } catch (Exception e) {
            }
        } else if (split.length == 3) {
            // reset the friend to resident so the perm settings don't fail
            if (split[0].equalsIgnoreCase("friend"))
                split[0] = "resident";
            try {
                boolean b = plugin.parseOnOff(split[2]);
                String s = "";
                s = split[0] + split[1];
                perm.set(s, b);
            } catch (Exception e) {
            }
        }
        townBlock.setChanged(true);
        TownyUniverse.getDataSource().saveTownBlock(townBlock);
        TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_set_perms"));
        TownyMessaging.sendMessage(player, (Colors.Green + " Perm: " + ((townBlockOwner instanceof Resident) ? perm.getColourString().replace("f", "r") : perm.getColourString())));
        TownyMessaging.sendMessage(player, Colors.Green + "PvP: " + ((perm.pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Explosions: " + ((perm.explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Firespread: " + ((perm.fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Mob Spawns: " + ((perm.mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
        // Reset all caches as this can affect everyone.
        plugin.resetCache();
    }
}
Also used : TownyPermission(com.palmergames.bukkit.towny.object.TownyPermission) Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) EconomyException(com.palmergames.bukkit.towny.exceptions.EconomyException) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 2 with TownyPermission

use of com.palmergames.bukkit.towny.object.TownyPermission in project Towny by ElgarL.

the class ResidentCommand method residentToggle.

/**
	 * Toggle modes for this player.
	 * 
	 * @param player
	 * @param newSplit
	 * @throws TownyException
	 */
private void residentToggle(Player player, String[] newSplit) throws TownyException {
    Resident resident;
    try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
    } catch (NotRegisteredException e) {
        // unknown resident
        throw new TownyException(String.format(TownySettings.getLangString("msg_err_not_registered"), player.getName()));
    }
    if (newSplit.length == 0) {
        player.sendMessage(ChatTools.formatTitle("/res toggle"));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "pvp", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "fire", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "mobs", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "plotborder", ""));
        player.sendMessage(ChatTools.formatCommand("", "/res toggle", "spy", ""));
        TownyMessaging.sendMsg(resident, ("Modes set: " + StringMgmt.join(resident.getModes(), ",")));
        return;
    }
    if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_TOGGLE.getNode(newSplit[0].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    TownyPermission perm = resident.getPermissions();
    // Special case chat spy
    if (newSplit[0].equalsIgnoreCase("spy")) {
        if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_CHAT_SPY.getNode(newSplit[0].toLowerCase())))
            throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
        resident.toggleMode(newSplit, true);
        return;
    } else if (newSplit[0].equalsIgnoreCase("pvp")) {
        perm.pvp = !perm.pvp;
    } else if (newSplit[0].equalsIgnoreCase("fire")) {
        perm.fire = !perm.fire;
    } else if (newSplit[0].equalsIgnoreCase("explosion")) {
        perm.explosion = !perm.explosion;
    } else if (newSplit[0].equalsIgnoreCase("mobs")) {
        perm.mobs = !perm.mobs;
    } else {
        resident.toggleMode(newSplit, true);
        return;
    }
    notifyPerms(player, perm);
    TownyUniverse.getDataSource().saveResident(resident);
}
Also used : TownyPermission(com.palmergames.bukkit.towny.object.TownyPermission) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)2 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)2 Resident (com.palmergames.bukkit.towny.object.Resident)2 TownyPermission (com.palmergames.bukkit.towny.object.TownyPermission)2 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)1 Town (com.palmergames.bukkit.towny.object.Town)1