UserMap.getUser() will return null on failure.

This commit is contained in:
snowleo 2011-11-29 00:36:36 +01:00
parent 4bacdb327a
commit 525fefc484
3 changed files with 16 additions and 32 deletions

View File

@ -345,7 +345,8 @@ public class Essentials extends JavaPlugin implements IEssentials
{
sender.sendMessage(command.getDescription());
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
if (!ex.getMessage().isEmpty()) {
if (!ex.getMessage().isEmpty())
{
sender.sendMessage(ex.getMessage());
}
return true;
@ -420,14 +421,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
if (base instanceof String)
{
try
{
return userMap.getUser((String)base);
}
catch (NullPointerException ex)
{
return null;
}
return userMap.getUser((String)base);
}
return null;
}
@ -443,27 +437,19 @@ public class Essentials extends JavaPlugin implements IEssentials
{
return (User)base;
}
try
User user = userMap.getUser(base.getName()).update(base);
if (user == null)
{
return userMap.getUser(base.getName()).update(base);
}
catch (NullPointerException ex)
{
return new User(base, this);
user = new User(base, this);
}
return user;
}
@Override
public User getOfflineUser(final String name)
{
try
{
return userMap.getUser(name);
}
catch (NullPointerException ex)
{
return null;
}
return userMap.getUser(name);
}
@Override

View File

@ -60,7 +60,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return keys.contains(name.toLowerCase(Locale.ENGLISH));
}
public User getUser(final String name) throws NullPointerException
public User getUser(final String name)
{
try
{
@ -68,11 +68,11 @@ public class UserMap extends CacheLoader<String, User> implements IConf
}
catch (ExecutionException ex)
{
throw new NullPointerException();
return null;
}
catch (UncheckedExecutionException ex)
{
throw new NullPointerException();
return null;
}
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import java.util.*;
@ -15,7 +16,6 @@ public class Commandbalancetop extends EssentialsCommand
{
super("balancetop");
}
private static final int CACHETIME = 5 * 60 * 1000;
public static final int MINUSERS = 50;
private static List<String> cache = new ArrayList<String>();
@ -107,12 +107,10 @@ public class Commandbalancetop extends EssentialsCommand
final Map<String, Double> balances = new HashMap<String, Double>();
for (String u : ess.getUserMap().getAllUniqueUsers())
{
try
{
balances.put(u, ess.getUserMap().getUser(u).getMoney());
}
catch (NullPointerException ex)
final User user = ess.getUserMap().getUser(u);
if (user != null)
{
balances.put(u, user.getMoney());
}
}