Skip to content

Commit

Permalink
Merge pull request #5273 from TownyAdvanced/feature/resident-isonline
Browse files Browse the repository at this point in the history
Add Resident#isOnline
  • Loading branch information
LlmDl authored Sep 12, 2021
2 parents 09206df + 3e228aa commit b8de0eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/com/palmergames/bukkit/towny/object/Resident.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public Player getPlayer() {
public boolean addTownRank(String rank) {
if (!hasTownRank(rank)) {
townRanks.add(rank);
if (BukkitTools.isOnline(this.getName()))
if (isOnline())
TownyPerms.assignPermissions(this, null);
BukkitTools.getPluginManager().callEvent(new TownAddResidentRankEvent(this, rank, town));
return true;
Expand Down Expand Up @@ -571,7 +571,7 @@ public boolean removeTownRank(String rank) {

if (hasTownRank(rank)) {
townRanks.remove(rank);
if (BukkitTools.isOnline(this.getName()))
if (isOnline())
TownyPerms.assignPermissions(this, null);

BukkitTools.getPluginManager().callEvent(new TownRemoveResidentRankEvent(this, rank, town));
Expand All @@ -585,7 +585,7 @@ public boolean addNationRank(String rank) {

if (!hasNationRank(rank)) {
nationRanks.add(rank);
if (BukkitTools.isOnline(this.getName()))
if (isOnline())
TownyPerms.assignPermissions(this, null);
return true;
}
Expand Down Expand Up @@ -835,6 +835,10 @@ public Nation getNationOrNull() {
else
return null;
}

public boolean isOnline() {
return BukkitTools.isOnline(getName());
}

/**
* @deprecated As of 0.96.0.0+ please use {@link EconomyAccount#getWorld()} instead.
Expand Down
10 changes: 3 additions & 7 deletions src/com/palmergames/bukkit/util/BukkitTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,11 @@ public static Player getPlayer(UUID playerUUID) {
/**
* Tests if this player is online.
*
* @param playerId the UUID or name of the player.
* @param name the name of the player.
* @return a true value if online
*/
public static boolean isOnline(String playerId) {
for (Player players : getOnlinePlayers()) {
if (players.getName().equals(playerId))
return true;
}
return false;
public static boolean isOnline(String name) {
return Bukkit.getPlayer(name) != null;
}

public static List<World> getWorlds() {
Expand Down

0 comments on commit b8de0eb

Please sign in to comment.