Tidied up session management

This commit is contained in:
Robin Kupper
2011-10-17 11:51:40 +02:00
parent ef85b0ad0e
commit 7985b72aaf
2 changed files with 8 additions and 8 deletions

View File

@@ -101,7 +101,7 @@ class LBToolListener extends PlayerListener
@Override
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
final Player player = event.getPlayer();
final Session session = logblock.getSessions().get(player.getName().hashCode());
final Session session = logblock.getSession(player.getName(), false);
if (session != null)
for (final Entry<Tool, ToolData> entry : session.toolData.entrySet()) {
final Tool tool = entry.getKey();

View File

@@ -41,7 +41,7 @@ public class LogBlock extends JavaPlugin
private Timer timer = null;
private PermissionHandler permissions = null;
private boolean errorAtLoading = false;
private final Map<Integer, Session> sessions = new HashMap<Integer, Session>();
private final Map<String, Session> sessions = new HashMap<String, Session>();
public Config getLBConfig() {
return config;
@@ -297,15 +297,15 @@ public class LogBlock extends JavaPlugin
}
}
public Map<Integer, Session> getSessions() {
return sessions;
public Session getSession(String playerName) {
return getSession(playerName, true);
}
public Session getSession(String playerName) {
Session session = sessions.get(playerName.hashCode());
if (session == null) {
public Session getSession(String playerName, boolean create) {
Session session = sessions.get(playerName.toLowerCase());
if (session == null && create) {
session = new Session(this, getServer().getPlayer(playerName));
sessions.put(playerName.hashCode(), session);
sessions.put(playerName.toLowerCase(), session);
}
return session;
}