Assorted cleanup.

This commit is contained in:
GJ
2014-02-27 10:56:21 -05:00
parent 1d7e034d5e
commit 0056be2d5f
33 changed files with 55 additions and 187 deletions

View File

@ -498,11 +498,7 @@ public final class ItemUtils {
}
public static boolean isSmeltable(ItemStack item) {
if (item == null) {
return false;
}
return MaterialUtils.isOre(item.getData());
return item != null && MaterialUtils.isOre(item.getData());
}
public static boolean isSmelted(ItemStack item) {

View File

@ -64,11 +64,7 @@ public final class Misc {
* @return true if the distance between {@code first} and {@code second} is less than {@code maxDistance}, false otherwise
*/
public static boolean isNear(Location first, Location second, double maxDistance) {
if (first.getWorld() != second.getWorld()) {
return false;
}
return first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0;
return (first.getWorld() == second.getWorld()) && (first.distanceSquared(second) < (maxDistance * maxDistance) || maxDistance == 0);
}
public static void dropItems(Location location, Collection<ItemStack> drops) {
@ -90,41 +86,6 @@ public final class Misc {
}
}
/**
* Randomly drop an item at a given location.
*
* @param location The location to drop the items at
* @param is The item to drop
* @param chance The percentage chance for the item to drop
*/
public static void randomDropItem(Location location, ItemStack is, double chance) {
if (random.nextInt(100) < chance) {
dropItem(location, is);
}
}
/**
* Drop items with random quantity at a given location.
*
* @param location The location to drop the items at
* @param is The item to drop
* @param quantity The amount of items to drop
*/
public static void randomDropItems(Location location, ItemStack is, int quantity) {
int dropCount = random.nextInt(quantity + 1);
if (dropCount > 0) {
is.setAmount(dropCount);
dropItem(location, is);
}
}
public static void randomDropItems(Location location, Collection<ItemStack> drops, double chance) {
for (ItemStack item : drops) {
randomDropItem(location, item, chance);
}
}
/**
* Drop an item at a given location.
*

View File

@ -90,28 +90,16 @@ public final class UserManager {
return retrieveMcMMOPlayer(playerName, false);
}
/**
* Get the McMMOPlayer of a player.
*
* @param player The player whose McMMOPlayer to retrieve
* @return the player's McMMOPlayer object
*/
public static McMMOPlayer getPlayer(OfflinePlayer player) {
public static McMMOPlayer getOfflinePlayer(OfflinePlayer player) {
if (player instanceof Player) {
return getPlayer((Player) player);
}
return retrieveMcMMOPlayer(player.getName(), false);
return retrieveMcMMOPlayer(player.getName(), true);
}
public static McMMOPlayer getPlayer(OfflinePlayer player, boolean offlineValid) {
if (player instanceof Player) {
return getPlayer((Player) player);
}
return retrieveMcMMOPlayer(player.getName(), offlineValid);
}
public static McMMOPlayer getPlayer(String playerName, boolean offlineValid) {
return retrieveMcMMOPlayer(playerName, offlineValid);
public static McMMOPlayer getOfflinePlayer(String playerName) {
return retrieveMcMMOPlayer(playerName, true);
}
public static McMMOPlayer getPlayer(Player player) {
@ -133,10 +121,6 @@ public final class UserManager {
}
public static boolean hasPlayerDataKey(Entity entity) {
if (entity == null) {
return false;
}
return entity.hasMetadata(mcMMO.playerDataKey);
return entity != null && entity.hasMetadata(mcMMO.playerDataKey);
}
}

View File

@ -329,7 +329,7 @@ public class ScoreboardManager {
}
for (String playerName : dirtyPowerLevels) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
if (mcMMOPlayer == null) {
continue;