Search in sources :

Example 16 with TownyWorld

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

the class TownyFormatter method getStatus.

/**
	 * 
	 * @param townBlock
	 * @return a string list containing the results.
	 */
public static List<String> getStatus(TownBlock townBlock) {
    List<String> out = new ArrayList<String>();
    try {
        TownBlockOwner owner;
        Town town = townBlock.getTown();
        TownyWorld world = townBlock.getWorld();
        if (townBlock.hasResident()) {
            owner = townBlock.getResident();
        } else {
            owner = townBlock.getTown();
        }
        out.add(ChatTools.formatTitle(TownyFormatter.getFormattedName(owner) + ((BukkitTools.isOnline(owner.getName())) ? Colors.LightGreen + " (Online)" : "")));
        out.add(Colors.Green + " Perm: " + ((owner instanceof Resident) ? townBlock.getPermissions().getColourString() : townBlock.getPermissions().getColourString().replace("f", "r")));
        out.add(Colors.Green + "PvP: " + ((town.isPVP() || world.isForcePVP() || townBlock.getPermissions().pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Explosions: " + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Firespread: " + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
    } catch (NotRegisteredException e) {
        out.add("Error: " + e.getMessage());
    }
    return out;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) TownBlockOwner(com.palmergames.bukkit.towny.object.TownBlockOwner) ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld)

Example 17 with TownyWorld

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

the class TownyFormatter method getStatus.

/**
	 * 
	 * @param town
	 * @return a string list containing the results.
	 */
public static List<String> getStatus(Town town) {
    List<String> out = new ArrayList<String>();
    TownyWorld world = town.getWorld();
    // ___[ Raccoon City (PvP) (Open) ]___
    String title = getFormattedName(town);
    title += ((!town.isAdminDisabledPVP()) && ((town.isPVP() || town.getWorld().isForcePVP())) ? Colors.Red + " (PvP)" : "");
    title += (town.isOpen() ? Colors.LightBlue + " (Open)" : "");
    out.add(ChatTools.formatTitle(title));
    // Board: Get your fried chicken
    try {
        out.add(Colors.Green + "Board: " + Colors.LightGreen + town.getTownBoard());
    } catch (NullPointerException e) {
    }
    // Town Size: 0 / 16 [Bought: 0/48] [Bonus: 0] [Home: 33,44]
    try {
        out.add(Colors.Green + "Town Size: " + Colors.LightGreen + town.getTownBlocks().size() + " / " + TownySettings.getMaxTownBlocks(town) + (TownySettings.isSellingBonusBlocks() ? Colors.LightBlue + " [Bought: " + town.getPurchasedBlocks() + "/" + TownySettings.getMaxPurchedBlocks() + "]" : "") + (town.getBonusBlocks() > 0 ? Colors.LightBlue + " [Bonus: " + town.getBonusBlocks() + "]" : "") + ((TownySettings.getNationBonusBlocks(town) > 0) ? Colors.LightBlue + " [NationBonus: " + TownySettings.getNationBonusBlocks(town) + "]" : "") + (town.isPublic() ? Colors.LightGray + " [Home: " + (town.hasHomeBlock() ? town.getHomeBlock().getCoord().toString() : "None") + "]" : ""));
    } catch (TownyException e) {
    }
    if (town.hasOutpostSpawn())
        out.add(Colors.Green + "Outposts: " + Colors.LightGreen + town.getMaxOutpostSpawn());
    // Permissions: B=rao D=--- S=ra-
    out.add(Colors.Green + "Permissions: " + town.getPermissions().getColourString().replace("f", "r"));
    out.add(Colors.Green + "Explosions: " + ((town.isBANG() || world.isForceExpl()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Firespread: " + ((town.isFire() || world.isForceFire()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs()) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));
    // | Bank: 534 coins
    String bankString = "";
    if (TownySettings.isUsingEconomy()) {
        if (TownyEconomyHandler.isActive()) {
            bankString = Colors.Green + "Bank: " + Colors.LightGreen + town.getHoldingFormattedBalance();
            if (town.hasUpkeep())
                bankString += Colors.Gray + " | " + Colors.Green + "Daily upkeep: " + Colors.Red + TownySettings.getTownUpkeepCost(town);
            bankString += Colors.Gray + " | " + Colors.Green + "Tax: " + Colors.Red + town.getTaxes() + (town.isTaxPercentage() ? "%" : "");
        }
        out.add(bankString);
    }
    // Mayor: MrSand | Bank: 534 coins
    out.add(Colors.Green + "Mayor: " + Colors.LightGreen + getFormattedName(town.getMayor()));
    // Assistants [2]: Sammy, Ginger
    // if (town.getAssistants().size() > 0)
    // out.addAll(getFormattedResidents("Assistants",
    // town.getAssistants()));
    List<String> ranklist = new ArrayList<String>();
    List<Resident> residentss = town.getResidents();
    List<String> townranks = TownyPerms.getTownRanks();
    List<Resident> residentwithrank = new ArrayList<Resident>();
    for (String rank : townranks) {
        for (Resident r : residentss) {
            if ((r.getTownRanks() != null) && (r.getTownRanks().contains(rank))) {
                residentwithrank.add(r);
            }
        }
        ranklist.addAll(getFormattedResidents(rank, residentwithrank));
        residentwithrank.clear();
    }
    out.addAll(ranklist);
    // Nation: Azur Empire
    try {
        out.add(Colors.Green + "Nation: " + Colors.LightGreen + getFormattedName(town.getNation()));
    } catch (TownyException e) {
    }
    // Residents [12]: James, Carry, Mason
    String[] residents = getFormattedNames(town.getResidents().toArray(new Resident[0]));
    if (residents.length > 34) {
        String[] entire = residents;
        residents = new String[36];
        System.arraycopy(entire, 0, residents, 0, 35);
        residents[35] = "and more...";
    }
    out.addAll(ChatTools.listArr(residents, Colors.Green + "Residents " + Colors.LightGreen + "[" + town.getNumResidents() + "]" + Colors.Green + ":" + Colors.White + " "));
    return out;
}
Also used : ArrayList(java.util.ArrayList) Resident(com.palmergames.bukkit.towny.object.Resident) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 18 with TownyWorld

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

the class TownyWorldCommand method listWorlds.

public void listWorlds(Player player, CommandSender sender) {
    if (player == null) {
        sender.sendMessage(ChatTools.formatTitle(TownySettings.getLangString("world_plu")));
    } else
        player.sendMessage(ChatTools.formatTitle(TownySettings.getLangString("world_plu")));
    ArrayList<String> formatedList = new ArrayList<String>();
    HashMap<String, Integer> playersPerWorld = BukkitTools.getPlayersPerWorld();
    for (TownyWorld world : TownyUniverse.getDataSource().getWorlds()) {
        int numPlayers = playersPerWorld.containsKey(world.getName()) ? playersPerWorld.get(world.getName()) : 0;
        formatedList.add(Colors.LightBlue + world.getName() + Colors.Blue + " [" + numPlayers + "]" + Colors.White);
    }
    if (player == null) {
        for (String line : ChatTools.list(formatedList)) sender.sendMessage(line);
    } else
        for (String line : ChatTools.list(formatedList)) player.sendMessage(line);
}
Also used : ArrayList(java.util.ArrayList) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld)

Example 19 with TownyWorld

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

the class TownyFlatFileSource method loadPlotData.

/**
	 * Load PlotBlockData
	 * 
	 * @param worldName
	 * @param x
	 * @param z
	 * @return PlotBlockData or null
	 */
@Override
public PlotBlockData loadPlotData(String worldName, int x, int z) {
    try {
        TownyWorld world = getWorld(worldName);
        TownBlock townBlock = new TownBlock(x, z, world);
        return loadPlotData(townBlock);
    } catch (NotRegisteredException e) {
        // Failed to get world
        e.printStackTrace();
    }
    return null;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 20 with TownyWorld

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

the class TownyPerms method assignPermissions.

/**
	 * Register a specific residents permissions with Bukkit.
	 * 
	 * @param resident
	 */
public static void assignPermissions(Resident resident, Player player) {
    PermissionAttachment playersAttachment = null;
    if (resident == null) {
        try {
            resident = TownyUniverse.getDataSource().getResident(player.getName());
        } catch (NotRegisteredException e) {
            // failed to get resident
            e.printStackTrace();
            return;
        }
    } else {
        player = BukkitTools.getPlayer(resident.getName());
    }
    if ((player == null) || !player.isOnline()) {
        attachments.remove(resident.getName());
        return;
    }
    TownyWorld World = null;
    try {
        World = TownyUniverse.getDataSource().getWorld(player.getLocation().getWorld().getName());
    } catch (NotRegisteredException e) {
        // World not registered with Towny.
        e.printStackTrace();
        return;
    }
    if (attachments.containsKey(resident.getName())) {
        playersAttachment = attachments.get(resident.getName());
    } else
        playersAttachment = BukkitTools.getPlayer(resident.getName()).addAttachment(plugin);
    try {
        synchronized (playersAttachment) {
            @SuppressWarnings("unchecked") Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(playersAttachment);
            /*
				 * Clear the map (faster than removing the attachment and
				 * recalculating)
				 */
            orig.clear();
            if (World.isUsingTowny()) {
                /*
					 * Fill with the fresh perm nodes
					 */
                orig.putAll(TownyPerms.getResidentPerms(resident));
            // System.out.print("Perms set for: " + resident.getName());
            }
            /*
				 * Tell bukkit to update it's permissions
				 */
            playersAttachment.getPermissible().recalculatePermissions();
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    /*
		 * Store the attachment for future reference
		 */
    attachments.put(resident.getName(), playersAttachment);
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) PermissionAttachment(org.bukkit.permissions.PermissionAttachment) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)33 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)27 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)15 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)14 EventHandler (org.bukkit.event.EventHandler)12 Player (org.bukkit.entity.Player)11 Entity (org.bukkit.entity.Entity)9 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)7 PlayerCache (com.palmergames.bukkit.towny.object.PlayerCache)7 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)7 Location (org.bukkit.Location)7 LivingEntity (org.bukkit.entity.LivingEntity)7 Coord (com.palmergames.bukkit.towny.object.Coord)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Resident (com.palmergames.bukkit.towny.object.Resident)5 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)5 Block (org.bukkit.block.Block)5 Town (com.palmergames.bukkit.towny.object.Town)3 Projectile (org.bukkit.entity.Projectile)3