Switch AFK check to use UUID.

This commit is contained in:
KHobbits 2014-04-27 01:10:44 +01:00
parent b40aa43872
commit 0557aa58b0
2 changed files with 25 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import net.ess3.api.IEssentials;
import org.bukkit.entity.Player;
@ -12,7 +13,7 @@ import org.bukkit.entity.Player;
public class EssentialsTimer implements Runnable
{
private final transient IEssentials ess;
private final transient Set<String> onlineUsers = new HashSet<String>();
private final transient Set<UUID> onlineUsers = new HashSet<UUID>();
private transient long lastPoll = System.nanoTime();
private final LinkedList<Double> history = new LinkedList<Double>();
private int skip1 = 0;
@ -66,7 +67,7 @@ public class EssentialsTimer implements Runnable
try
{
final User user = ess.getUser(player);
onlineUsers.add(user.getName());
onlineUsers.add(user.getBase().getUniqueId());
user.setLastOnlineActivity(currentTime);
user.checkActivity();
}
@ -77,7 +78,7 @@ public class EssentialsTimer implements Runnable
}
count = 0;
final Iterator<String> iterator = onlineUsers.iterator();
final Iterator<UUID> iterator = onlineUsers.iterator();
while (iterator.hasNext())
{
count++;

View file

@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.utils.FormatUtil;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.logging.Logger;
import net.ess3.api.IEssentials;
import org.bukkit.Server;
@ -86,8 +87,27 @@ public abstract class EssentialsCommand implements IEssentialsCommand
private User getPlayer(final Server server, final User sourceUser, final String searchTerm, boolean getHidden, final boolean getOffline) throws PlayerNotFoundException
{
final User user;
Player exPlayer;
try
{
exPlayer = server.getPlayer(UUID.fromString(searchTerm));
}
catch (IllegalArgumentException ex)
{
exPlayer = server.getPlayer(searchTerm);
}
if (exPlayer != null)
{
user = ess.getUser(exPlayer);
}
else
{
user = ess.getUser(searchTerm);
}
final User user = ess.getUser(searchTerm);
if (user != null)
{
if (!getOffline && !user.getBase().isOnline())