use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class TownyLoginListener method onPlayerLogin.
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
String npcPrefix = TownySettings.getNPCPrefix();
String warChest = "towny-war-chest";
String serverAccount = TownySettings.getString(ConfigNodes.ECO_CLOSED_ECONOMY_SERVER_ACCOUNT);
boolean disallowed = false;
TownyUniverse townyUniverse = TownyUniverse.getInstance();
if (event.getName().startsWith(npcPrefix)) {
Resident npcRes = townyUniverse.getResident(event.getUniqueId());
if (npcRes != null && npcRes.isMayor()) {
event.disallow(Result.KICK_OTHER, "Towny is preventing you from logging in using this account name.");
disallowed = true;
}
} else if (event.getName().equals(warChest) || event.getName().equals(warChest.replace("-", "_"))) {
// Deny because this is the warChest account.
event.disallow(Result.KICK_OTHER, "Towny is preventing you from logging in using this account name.");
disallowed = true;
} else if (event.getName().equals(serverAccount) || event.getName().equals(serverAccount.replace("-", "_"))) {
// Deny because this is the closed economy server account.
event.disallow(Result.KICK_OTHER, "Towny is preventing you from logging in using this account name.");
disallowed = true;
} else if (event.getName().startsWith(TownySettings.getTownAccountPrefix()) || event.getName().startsWith(TownySettings.getTownAccountPrefix().replace("-", "_")) || event.getName().startsWith(TownySettings.getNationAccountPrefix()) || event.getName().startsWith(TownySettings.getNationAccountPrefix().replace("-", "_"))) {
event.disallow(Result.KICK_OTHER, "Towny is preventing you from logging in using this account name.");
disallowed = true;
}
if (disallowed) {
String ip = event.getAddress().toString().substring(1);
Towny.getPlugin().getLogger().warning("A player using the IP address " + ip + " tried to log in using an account name (" + event.getName() + ") which could damage your server's economy, but was prevented by Towny. Consider banning this IP address!");
for (Player ops : Bukkit.getOnlinePlayers()) {
if (ops.isOp() || ops.hasPermission("towny.admin"))
TownyMessaging.sendMsg(ops, Translatable.of("msg_admin_blocked_login", ip, event.getName()));
}
}
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class TownyPerms method assignPermissions.
/**
* Register a specific residents permissions with Bukkit.
*
* @param resident - Resident to check if player is valid
* @param player - Player to register permission
*/
public static void assignPermissions(Resident resident, Player player) {
PermissionAttachment playersAttachment;
TownyUniverse townyUniverse = TownyUniverse.getInstance();
if (resident == null) {
if (player != null)
resident = townyUniverse.getResident(player.getUniqueId());
// failed to get resident
if (resident == null)
return;
} else {
player = BukkitTools.getPlayer(resident.getName());
}
if ((player == null) || !player.isOnline()) {
attachments.remove(resident.getName());
return;
}
TownyWorld world = TownyAPI.getInstance().getTownyWorld(player.getWorld().getName());
if (world == null)
return;
if (attachments.containsKey(resident.getName()))
playersAttachment = attachments.get(resident.getName());
else
// DungeonsXL sometimes moves players which aren't online out of dungeon worlds causing an error in the log to appear.
try {
playersAttachment = BukkitTools.getPlayer(resident.getName()).addAttachment(plugin);
} catch (Exception e) {
return;
}
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 | IllegalAccessException e) {
e.printStackTrace();
}
/*
* Store the attachment for future reference
*/
attachments.put(resident.getName(), playersAttachment);
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class SetDefaultModes method run.
@Override
public void run() {
// Is the player still available
if (!BukkitTools.isOnline(name))
return;
// setup default modes
try {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
String modeString = townyUniverse.getPermissionSource().getPlayerPermissionStringNode(name, PermissionNodes.TOWNY_DEFAULT_MODES.getNode());
if (modeString.isEmpty()) {
return;
}
String[] modes = modeString.split(",");
Resident resident = townyUniverse.getResident(name);
if (resident != null)
resident.setModes(modes, notify);
} catch (NullPointerException ignored) {
}
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class TownRuinUtil method evaluateRuinedTownRemovals.
/**
* This method cycles through all towns
* If a town is in ruins, its remaining_ruin_time_hours counter is decreased
* If a counter hits 0, the town is deleted
*/
public static void evaluateRuinedTownRemovals() {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
List<Town> towns = new ArrayList<>(townyUniverse.getTowns());
ListIterator<Town> townItr = towns.listIterator();
Town town;
while (townItr.hasNext()) {
town = townItr.next();
/*
* Only delete ruined town if it really still
* exists.
* We are running in an Async thread so MUST verify all objects.
*/
if (townyUniverse.hasTown(town.getName()) && town.isRuined() && town.getRuinedTime() != 0 && getTimeSinceRuining(town) > TownySettings.getTownRuinsMaxDurationHours()) {
// Ruin found & recently ruined end time reached. Delete town now.
townyUniverse.getDataSource().removeTown(town, false);
}
}
}
use of com.palmergames.bukkit.towny.TownyUniverse in project Towny by TownyAdvanced.
the class ResidentPurge method run.
@Override
public void run() {
int count = 0;
message(Translatable.of("msg_scanning_for_old_residents"));
TownyUniverse townyUniverse = TownyUniverse.getInstance();
List<Resident> residentList;
if (town != null) {
residentList = new ArrayList<>(town.getResidents());
} else {
residentList = new ArrayList<>(townyUniverse.getResidents());
}
for (Resident resident : residentList) {
if (!resident.isNPC() && (System.currentTimeMillis() - resident.getLastOnline() > (this.deleteTime)) && !BukkitTools.isOnline(resident.getName())) {
if (townless && resident.hasTown()) {
continue;
}
count++;
message(Translatable.of("msg_deleting_resident", resident.getName()));
townyUniverse.getDataSource().removeResident(resident);
}
}
message(Translatable.of("msg_purge_complete", count));
}
Aggregations