Fix NPE when reading old player files

This commit is contained in:
snowleo 2011-11-29 00:30:06 +01:00
parent 91cdff955a
commit 4bacdb327a
2 changed files with 21 additions and 10 deletions

View File

@ -232,21 +232,25 @@ public class EssentialsConf extends Configuration
Material.valueOf(getString(path + ".type", "AIR")), Material.valueOf(getString(path + ".type", "AIR")),
getInt(path + ".amount", 1), getInt(path + ".amount", 1),
(short)getInt(path + ".damage", 0)); (short)getInt(path + ".damage", 0));
List<String> enchants = getKeys(path + ".enchant"); final List<String> enchants = getKeys(path + ".enchant");
for (String enchant : enchants) if (enchants != null)
{ {
Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH)); for (String enchant : enchants)
if (enchantment == null) { {
continue; final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
if (enchantment == null)
{
continue;
}
final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
stack.addUnsafeEnchantment(enchantment, level);
} }
int level = getInt(path+ ".enchant."+enchant, enchantment.getStartLevel());
stack.addUnsafeEnchantment(enchantment, level);
} }
return stack; return stack;
/* /*
* , * ,
* (byte)getInt(path + ".data", 0) * (byte)getInt(path + ".data", 0)
*/ */
} }
public void setProperty(final String path, final ItemStack stack) public void setProperty(final String path, final ItemStack stack)

View File

@ -4,11 +4,14 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.collect.ConcurrentHashMultiset; import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -67,6 +70,10 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{ {
throw new NullPointerException(); throw new NullPointerException();
} }
catch (UncheckedExecutionException ex)
{
throw new NullPointerException();
}
} }
@Override @Override