use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class PlotCommand method onTabComplete.
/**
* Overridden method custom for this command set.
*
*/
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
LinkedList<String> output = new LinkedList<String>();
String lastArg = "";
// Get the last argument
if (args.length > 0) {
lastArg = args[args.length - 1].toLowerCase();
}
if (!lastArg.equalsIgnoreCase("")) {
// Match residents
for (Resident resident : TownyUniverse.getDataSource().getResidents()) {
if (resident.getName().toLowerCase().startsWith(lastArg)) {
output.add(resident.getName());
}
}
}
return output;
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class PlotCommand method plotTestOwner.
/**
* Test the townBlock to ensure we are either the plot owner, or the
* mayor/assistant
*
* @param resident
* @param townBlock
* @throws TownyException
*/
public TownBlockOwner plotTestOwner(Resident resident, TownBlock townBlock) throws TownyException {
Player player = BukkitTools.getPlayer(resident.getName());
boolean isAdmin = TownyUniverse.getPermissionSource().isTownyAdmin(player);
if (townBlock.hasResident()) {
Resident owner = townBlock.getResident();
boolean isSameTown = (resident.hasTown()) ? resident.getTown() == owner.getTown() : false;
if ((resident == owner) || ((isSameTown) && (player.hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode()))) || isAdmin) {
return owner;
}
// Not the plot owner or the towns mayor or an admin.
throw new TownyException(TownySettings.getLangString("msg_area_not_own"));
} else {
Town owner = townBlock.getTown();
boolean isSameTown = (resident.hasTown()) ? resident.getTown() == owner : false;
if (isSameTown && !BukkitTools.getPlayer(resident.getName()).hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode()))
throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
if (!isSameTown && !isAdmin)
throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
return owner;
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class ResidentCommand method residentSet.
/**
*
* Command: /resident set [] ... []
*
* @param player
* @param split
* @throws TownyException
*/
/*
* perm [resident/outsider] [build/destroy] [on/off]
*/
public void residentSet(Player player, String[] split) throws TownyException {
if (split.length == 0) {
player.sendMessage(ChatTools.formatCommand("", "/resident set", "perm ...", "'/resident set perm' " + TownySettings.getLangString("res_5")));
player.sendMessage(ChatTools.formatCommand("", "/resident set", "mode ...", "'/resident set mode' " + TownySettings.getLangString("res_5")));
} else {
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
if (!TownyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_SET.getNode(split[0].toLowerCase())))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
if (split[0].equalsIgnoreCase("perm")) {
String[] newSplit = StringMgmt.remFirstArg(split);
TownCommand.setTownBlockPermissions(player, resident, resident.getPermissions(), newSplit, true);
} else if (split[0].equalsIgnoreCase("mode")) {
String[] newSplit = StringMgmt.remFirstArg(split);
setMode(player, newSplit);
} else {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "town"));
return;
}
TownyUniverse.getDataSource().saveResident(resident);
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class ResidentCommand method residentFriend.
public void residentFriend(Player player, String[] split) {
if (split.length == 0) {
player.sendMessage(ChatTools.formatCommand("", "/resident friend", "add " + TownySettings.getLangString("res_2"), ""));
player.sendMessage(ChatTools.formatCommand("", "/resident friend", "remove " + TownySettings.getLangString("res_2"), ""));
player.sendMessage(ChatTools.formatCommand("", "/resident friend", "clear", ""));
} else {
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
} catch (TownyException x) {
TownyMessaging.sendErrorMsg(player, x.getMessage());
return;
}
// TODO: Let admin's call a subfunction of this.
if (split[0].equalsIgnoreCase("add")) {
String[] names = StringMgmt.remFirstArg(split);
residentFriendAdd(player, resident, TownyUniverse.getDataSource().getResidents(player, names));
} else if (split[0].equalsIgnoreCase("remove")) {
String[] names = StringMgmt.remFirstArg(split);
residentFriendRemove(player, resident, TownyUniverse.getDataSource().getResidents(player, names));
} else if (split[0].equalsIgnoreCase("clearlist") || split[0].equalsIgnoreCase("clear")) {
residentFriendRemove(player, resident, resident.getFriends());
}
}
}
use of com.palmergames.bukkit.towny.object.Resident in project Towny by ElgarL.
the class ResidentCommand method residentSpawn.
/**
* Attempt to send player to bed spawn.
*
* @param player
*/
public void residentSpawn(Player player) {
boolean isTownyAdmin = TownyUniverse.getPermissionSource().isTownyAdmin(player);
Resident resident;
try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
Town town;
Location spawnLoc;
String notAffordMSG;
TownSpawnLevel townSpawnPermission;
// Set target town and affiliated messages.
town = resident.getTown();
notAffordMSG = TownySettings.getLangString("msg_err_cant_afford_tp");
if (TownySettings.getBedUse() && player.getBedSpawnLocation() != null) {
spawnLoc = player.getBedSpawnLocation();
} else {
spawnLoc = town.getSpawn();
}
if (isTownyAdmin) {
townSpawnPermission = TownSpawnLevel.ADMIN;
} else {
townSpawnPermission = TownSpawnLevel.TOWN_RESIDENT;
}
if (!isTownyAdmin) {
// Prevent spawn travel while in disallowed zones (if
// configured)
List<String> disallowedZones = TownySettings.getDisallowedTownSpawnZones();
if (!disallowedZones.isEmpty()) {
String inTown = null;
try {
Location loc = plugin.getCache(player).getLastLocation();
inTown = TownyUniverse.getTownName(loc);
} catch (NullPointerException e) {
inTown = TownyUniverse.getTownName(player.getLocation());
}
if (inTown == null && disallowedZones.contains("unclaimed"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "the Wilderness"));
if (inTown != null && resident.hasNation() && TownyUniverse.getDataSource().getTown(inTown).hasNation()) {
Nation inNation = TownyUniverse.getDataSource().getTown(inTown).getNation();
Nation playerNation = resident.getTown().getNation();
if (inNation.hasEnemy(playerNation) && disallowedZones.contains("enemy"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Enemy areas"));
if (!inNation.hasAlly(playerNation) && !inNation.hasEnemy(playerNation) && disallowedZones.contains("neutral"))
throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Neutral towns"));
}
}
}
double travelCost = townSpawnPermission.getCost();
// Check if need/can pay
if (travelCost > 0 && TownySettings.isUsingEconomy() && (resident.getHoldingBalance() < travelCost))
throw new TownyException(notAffordMSG);
// Used later to make sure the chunk we teleport to is loaded.
Chunk chunk = spawnLoc.getChunk();
// Essentials tests
boolean UsingESS = plugin.isEssentials();
if (UsingESS && !isTownyAdmin) {
try {
User user = plugin.getEssentials().getUser(player);
if (!user.isJailed()) {
Teleport teleport = user.getTeleport();
if (!chunk.isLoaded())
chunk.load();
// Cause an essentials exception if in cooldown.
teleport.cooldown(true);
teleport.teleport(spawnLoc, null);
}
} catch (Exception e) {
TownyMessaging.sendErrorMsg(player, "Error: " + e.getMessage());
// cooldown?
return;
}
}
// travel.
if (travelCost > 0 && TownySettings.isUsingEconomy() && resident.payTo(travelCost, town, String.format("Resident Spawn (%s)", townSpawnPermission))) {
// +
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_cost_spawn"), TownyEconomyHandler.getFormattedBalance(travelCost)));
// TownyEconomyObject.getEconomyCurrency()));
}
// If an Admin or Essentials teleport isn't being used, use our own.
if (isTownyAdmin) {
if (player.getVehicle() != null)
player.getVehicle().eject();
if (!chunk.isLoaded())
chunk.load();
player.teleport(spawnLoc, TeleportCause.COMMAND);
return;
}
if (!UsingESS) {
if (TownyTimerHandler.isTeleportWarmupRunning()) {
// Use teleport warmup
player.sendMessage(String.format(TownySettings.getLangString("msg_town_spawn_warmup"), TownySettings.getTeleportWarmupTime()));
plugin.getTownyUniverse().requestTeleport(player, spawnLoc, travelCost);
} else {
// Don't use teleport warmup
if (player.getVehicle() != null)
player.getVehicle().eject();
if (!chunk.isLoaded())
chunk.load();
player.teleport(spawnLoc, TeleportCause.COMMAND);
}
}
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
} catch (EconomyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
}
Aggregations