Add previous account tracking to /seen

This commit is contained in:
KHobbits 2014-04-18 04:48:34 +01:00
parent 3c613fd59b
commit b080187808
4 changed files with 57 additions and 11 deletions

View File

@ -562,7 +562,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
sender.sendMessage(tl("errorWithMessage", exception.getMessage()));
if (getSettings().isDebug())
{
LOGGER.log(Level.WARNING, tl("errorCallingCommand", commandLabel), exception);
LOGGER.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception);
}
}
@ -649,10 +649,19 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
@Override
public User getOfflineUser(final String name)
{
final User user = userMap.getUser(name);
final User user = userMap.getUser(name);
if (user != null && user.getBase() instanceof OfflinePlayer)
{
((OfflinePlayer)user.getBase()).setName(name);
//This code should attempt to use the last known name of a user, if Bukkit returns name as null.
final String lastName = user.getLastAccountName();
if (lastName != null)
{
((OfflinePlayer)user.getBase()).setName(lastName);
}
else
{
((OfflinePlayer)user.getBase()).setName(name);
}
}
return user;
}

View File

@ -7,6 +7,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListMap;
@ -36,9 +37,8 @@ public class UUIDMap
}
public void loadAllUsers(final ConcurrentSkipListMap<String, UUID> names)
public void loadAllUsers(final ConcurrentSkipListMap<String, UUID> names, final ConcurrentSkipListMap<UUID, ArrayList<String>> history)
{
try
{
if (!userList.exists())
@ -49,7 +49,7 @@ public class UUIDMap
final BufferedReader reader = new BufferedReader(new FileReader(userList));
try
{
do
while (true)
{
final String line = reader.readLine();
if (line == null)
@ -58,14 +58,25 @@ public class UUIDMap
}
else
{
String[] values = splitPattern.split(line);
final String[] values = splitPattern.split(line);
if (values.length == 2)
{
names.put(values[0], UUID.fromString(values[1]));
final String name = values[0];
final UUID uuid = UUID.fromString(values[1]);
names.put(name, uuid);
if (!history.containsKey(uuid))
{
final ArrayList<String> list = new ArrayList<String>();
list.add(name);
history.put(uuid, list);
}
else
{
history.get(uuid).add(name);
}
}
}
}
while (true);
}
finally
{
@ -76,7 +87,6 @@ public class UUIDMap
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}
public void writeUUIDMap()

View File

@ -6,7 +6,9 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListMap;
@ -22,6 +24,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
private final transient Cache<UUID, User> users;
private final transient ConcurrentSkipListSet<UUID> keys = new ConcurrentSkipListSet<UUID>();
private final transient ConcurrentSkipListMap<String, UUID> names = new ConcurrentSkipListMap<String, UUID>();
private final transient ConcurrentSkipListMap<UUID, ArrayList<String>> history = new ConcurrentSkipListMap<UUID, ArrayList<String>>();
private UUIDMap uuidMap;
public UserMap(final IEssentials ess)
@ -65,7 +68,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
}
}
uuidMap.loadAllUsers(names);
uuidMap.loadAllUsers(names, history);
}
});
@ -205,6 +208,16 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
return names;
}
public ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
{
return history;
}
public List<String> getUserHistory(final UUID uuid)
{
return history.get(uuid);
}
public UUIDMap getUUIDMap()
{
return uuidMap;

View File

@ -72,6 +72,13 @@ public class Commandseen extends EssentialsCommand
user.setDisplayNick();
sender.sendMessage(tl("seenOnline", user.getDisplayName(), DateUtil.formatDateDiff(user.getLastLogin())));
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history.size() > 1)
{
sender.sendMessage("User has also been known as: " + StringUtil.joinList(history)); //TODO: TL
}
if (user.isAfk())
{
sender.sendMessage(tl("whoisAFK", tl("true")));
@ -110,6 +117,13 @@ public class Commandseen extends EssentialsCommand
{
sender.sendMessage(tl("userUnknown", user.getName()));
}
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history.size() > 1)
{
sender.sendMessage("User has also been known as: " + StringUtil.joinList(history)); //TODO: TL
}
if (user.getBase().isBanned())
{
sender.sendMessage(tl("whoisBanned", showBan ? user.getBanReason() : tl("true")));