mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-29 17:02:51 +00:00
UserMap.getUser() will return null on failure.
This commit is contained in:
parent
4bacdb327a
commit
525fefc484
3 changed files with 16 additions and 32 deletions
|
@ -345,7 +345,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
{
|
{
|
||||||
sender.sendMessage(command.getDescription());
|
sender.sendMessage(command.getDescription());
|
||||||
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
|
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
|
||||||
if (!ex.getMessage().isEmpty()) {
|
if (!ex.getMessage().isEmpty())
|
||||||
|
{
|
||||||
sender.sendMessage(ex.getMessage());
|
sender.sendMessage(ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -420,14 +421,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
}
|
}
|
||||||
if (base instanceof String)
|
if (base instanceof String)
|
||||||
{
|
{
|
||||||
try
|
return userMap.getUser((String)base);
|
||||||
{
|
|
||||||
return userMap.getUser((String)base);
|
|
||||||
}
|
|
||||||
catch (NullPointerException ex)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -443,27 +437,19 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
{
|
{
|
||||||
return (User)base;
|
return (User)base;
|
||||||
}
|
}
|
||||||
try
|
User user = userMap.getUser(base.getName()).update(base);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
{
|
{
|
||||||
return userMap.getUser(base.getName()).update(base);
|
user = new User(base, this);
|
||||||
}
|
|
||||||
catch (NullPointerException ex)
|
|
||||||
{
|
|
||||||
return new User(base, this);
|
|
||||||
}
|
}
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getOfflineUser(final String name)
|
public User getOfflineUser(final String name)
|
||||||
{
|
{
|
||||||
try
|
return userMap.getUser(name);
|
||||||
{
|
|
||||||
return userMap.getUser(name);
|
|
||||||
}
|
|
||||||
catch (NullPointerException ex)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
return keys.contains(name.toLowerCase(Locale.ENGLISH));
|
return keys.contains(name.toLowerCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(final String name) throws NullPointerException
|
public User getUser(final String name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -68,11 +68,11 @@ public class UserMap extends CacheLoader<String, User> implements IConf
|
||||||
}
|
}
|
||||||
catch (ExecutionException ex)
|
catch (ExecutionException ex)
|
||||||
{
|
{
|
||||||
throw new NullPointerException();
|
return null;
|
||||||
}
|
}
|
||||||
catch (UncheckedExecutionException ex)
|
catch (UncheckedExecutionException ex)
|
||||||
{
|
{
|
||||||
throw new NullPointerException();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -15,7 +16,6 @@ public class Commandbalancetop extends EssentialsCommand
|
||||||
{
|
{
|
||||||
super("balancetop");
|
super("balancetop");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int CACHETIME = 5 * 60 * 1000;
|
private static final int CACHETIME = 5 * 60 * 1000;
|
||||||
public static final int MINUSERS = 50;
|
public static final int MINUSERS = 50;
|
||||||
private static List<String> cache = new ArrayList<String>();
|
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>();
|
final Map<String, Double> balances = new HashMap<String, Double>();
|
||||||
for (String u : ess.getUserMap().getAllUniqueUsers())
|
for (String u : ess.getUserMap().getAllUniqueUsers())
|
||||||
{
|
{
|
||||||
try
|
final User user = ess.getUserMap().getUser(u);
|
||||||
{
|
if (user != null)
|
||||||
balances.put(u, ess.getUserMap().getUser(u).getMoney());
|
|
||||||
}
|
|
||||||
catch (NullPointerException ex)
|
|
||||||
{
|
{
|
||||||
|
balances.put(u, user.getMoney());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue