Cleanup debug message, code tidy.

This commit is contained in:
KHobbits 2011-10-25 22:18:28 +01:00
parent 9af6bdb1d6
commit 5a54ef355f
6 changed files with 87 additions and 64 deletions

View File

@ -97,7 +97,6 @@ public class EssentialsEntityListener extends EntityListener
@Override @Override
public void onFoodLevelChange(FoodLevelChangeEvent event) public void onFoodLevelChange(FoodLevelChangeEvent event)
{ {
LOGGER.log(Level.INFO, "Getting hungry...");
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{ {
event.setCancelled(true); event.setCancelled(true);

View File

@ -9,20 +9,23 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
public class Spawn implements IConf {
public class Spawn implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
private final EssentialsConf config; private final EssentialsConf config;
private final Server server; private final Server server;
public Spawn(Server server, File dataFolder) { public Spawn(Server server, File dataFolder)
{
File configFile = new File(dataFolder, "spawn.yml"); File configFile = new File(dataFolder, "spawn.yml");
this.server = server; this.server = server;
config = new EssentialsConf(configFile); config = new EssentialsConf(configFile);
config.load(); config.load();
} }
public void setSpawn(Location loc, String group) { public void setSpawn(Location loc, String group)
{
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("world", loc.getWorld().getName()); map.put("world", loc.getWorld().getName());
map.put("x", loc.getX()); map.put("x", loc.getX());
@ -33,18 +36,24 @@ public class Spawn implements IConf {
config.setProperty(group, map); config.setProperty(group, map);
config.save(); config.save();
if ("default".equals(group)) { if ("default".equals(group))
{
loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
} }
} }
public Location getSpawn(String group) { public Location getSpawn(String group)
if (config.getProperty(group) == null) { {
if (config.getProperty(group) == null)
{
group = "default"; group = "default";
} }
if (config.getProperty(group) == null) { if (config.getProperty(group) == null)
for (World w : server.getWorlds()) { {
if (w.getEnvironment() != Environment.NORMAL) { for (World w : server.getWorlds())
{
if (w.getEnvironment() != Environment.NORMAL)
{
continue; continue;
} }
return w.getSpawnLocation(); return w.getSpawnLocation();
@ -52,15 +61,19 @@ public class Spawn implements IConf {
} }
String worldId = config.getString(group + ".world", ""); String worldId = config.getString(group + ".world", "");
World world = server.getWorlds().get(server.getWorlds().size() > 1 ? 1 : 0); World world = server.getWorlds().get(server.getWorlds().size() > 1 ? 1 : 0);
for (World w : server.getWorlds()) { for (World w : server.getWorlds())
if (w.getEnvironment() != Environment.NORMAL) { {
if (w.getEnvironment() != Environment.NORMAL)
{
continue; continue;
} }
world = w; world = w;
break; break;
} }
for (World w : server.getWorlds()) { for (World w : server.getWorlds())
if (!w.getName().equals(worldId)) { {
if (!w.getName().equals(worldId))
{
continue; continue;
} }
world = w; world = w;
@ -70,18 +83,20 @@ public class Spawn implements IConf {
double x = config.getDouble(group + ".x", config.getDouble("default.x", 0)); double x = config.getDouble(group + ".x", config.getDouble("default.x", 0));
double y = config.getDouble(group + ".y", config.getDouble("default.y", 0)); double y = config.getDouble(group + ".y", config.getDouble("default.y", 0));
double z = config.getDouble(group + ".z", config.getDouble("default.z", 0)); double z = config.getDouble(group + ".z", config.getDouble("default.z", 0));
float yaw = (float) config.getDouble(group + ".yaw", config.getDouble("default.yaw", 0)); float yaw = (float)config.getDouble(group + ".yaw", config.getDouble("default.yaw", 0));
float pitch = (float) config.getDouble(group + ".pitch", config.getDouble("default.pitch", 0)); float pitch = (float)config.getDouble(group + ".pitch", config.getDouble("default.pitch", 0));
Location retval = new Location(world, x, y, z, yaw, pitch); Location retval = new Location(world, x, y, z, yaw, pitch);
if (y < 1) { if (y < 1)
{
retval.setY(world.getHighestBlockYAt(retval)); retval.setY(world.getHighestBlockYAt(retval));
} }
return retval; return retval;
} }
public void reloadConfig() { public void reloadConfig()
{
config.load(); config.load();
} }
} }

View File

@ -37,7 +37,8 @@ public class TNTExplodeListener extends EntityListener implements Runnable
timer = ess.scheduleSyncDelayedTask(this, 1000); timer = ess.scheduleSyncDelayedTask(this, 1000);
return; return;
} }
if (timer != -1) { if (timer != -1)
{
ess.getScheduler().cancelTask(timer); ess.getScheduler().cancelTask(timer);
timer = ess.scheduleSyncDelayedTask(this, 1000); timer = ess.scheduleSyncDelayedTask(this, 1000);
} }
@ -54,28 +55,31 @@ public class TNTExplodeListener extends EntityListener implements Runnable
{ {
return; return;
} }
try { try
final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
final Player[] players = ess.getServer().getOnlinePlayers();
final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
final Location loc = event.getLocation();
for (Player player : players)
{ {
if (player.getWorld().equals(loc.getWorld())) final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
final Player[] players = ess.getServer().getOnlinePlayers();
final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
final Location loc = event.getLocation();
for (Player player : players)
{ {
blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ())); if (player.getWorld().equals(loc.getWorld()))
{
blocksUnderPlayers.add(new ChunkPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ()));
}
} }
for (Block block : event.blockList())
{
final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
if (!blocksUnderPlayers.contains(cp))
{
set.add(cp);
}
}
((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set));
} }
for (Block block : event.blockList()) catch (Throwable ex)
{ {
final ChunkPosition cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
if (!blocksUnderPlayers.contains(cp))
{
set.add(cp);
}
}
((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set));
} catch (Throwable ex) {
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
} }
event.setCancelled(true); event.setCancelled(true);

View File

@ -18,22 +18,22 @@ public class Trade
private final transient Double money; private final transient Double money;
private final transient ItemStack itemStack; private final transient ItemStack itemStack;
private final transient IEssentials ess; private final transient IEssentials ess;
public Trade(final String command, final IEssentials ess) public Trade(final String command, final IEssentials ess)
{ {
this(command, null, null, ess); this(command, null, null, ess);
} }
public Trade(final double money, final IEssentials ess) public Trade(final double money, final IEssentials ess)
{ {
this(null, money, null, ess); this(null, money, null, ess);
} }
public Trade(final ItemStack items, final IEssentials ess) public Trade(final ItemStack items, final IEssentials ess)
{ {
this(null, null, items, ess); this(null, null, items, ess);
} }
private Trade(final String command, final Double money, final ItemStack item, final IEssentials ess) private Trade(final String command, final Double money, final ItemStack item, final IEssentials ess)
{ {
this.command = command; this.command = command;
@ -41,7 +41,7 @@ public class Trade
this.itemStack = item; this.itemStack = item;
this.ess = ess; this.ess = ess;
} }
public void isAffordableFor(final IUser user) throws ChargeException public void isAffordableFor(final IUser user) throws ChargeException
{ {
final double mon = user.getMoney(); final double mon = user.getMoney();
@ -52,13 +52,13 @@ public class Trade
{ {
throw new ChargeException(Util.i18n("notEnoughMoney")); throw new ChargeException(Util.i18n("notEnoughMoney"));
} }
if (getItemStack() != null if (getItemStack() != null
&& !InventoryWorkaround.containsItem(user.getInventory(), true, itemStack)) && !InventoryWorkaround.containsItem(user.getInventory(), true, itemStack))
{ {
throw new ChargeException(Util.format("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase().replace("_", " "))); throw new ChargeException(Util.format("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase().replace("_", " ")));
} }
if (command != null && !command.isEmpty() if (command != null && !command.isEmpty()
&& !user.isAuthorized("essentials.nocommandcost.all") && !user.isAuthorized("essentials.nocommandcost.all")
&& !user.isAuthorized("essentials.nocommandcost." + command) && !user.isAuthorized("essentials.nocommandcost." + command)
@ -69,12 +69,12 @@ public class Trade
throw new ChargeException(Util.i18n("notEnoughMoney")); throw new ChargeException(Util.i18n("notEnoughMoney"));
} }
} }
public void pay(final IUser user) public void pay(final IUser user)
{ {
pay(user, true); pay(user, true);
} }
public boolean pay(final IUser user, final boolean dropItems) public boolean pay(final IUser user, final boolean dropItems)
{ {
boolean success = true; boolean success = true;
@ -100,7 +100,7 @@ public class Trade
} }
return success; return success;
} }
public void charge(final IUser user) throws ChargeException public void charge(final IUser user) throws ChargeException
{ {
if (getMoney() != null) if (getMoney() != null)
@ -134,18 +134,18 @@ public class Trade
user.takeMoney(cost); user.takeMoney(cost);
} }
} }
public Double getMoney() public Double getMoney()
{ {
return money; return money;
} }
public ItemStack getItemStack() public ItemStack getItemStack()
{ {
return itemStack; return itemStack;
} }
private static FileWriter fw = null; private static FileWriter fw = null;
public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess) public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
{ {
if (!ess.getSettings().isEcoLogEnabled()) if (!ess.getSettings().isEcoLogEnabled())
@ -239,7 +239,7 @@ public class Trade
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
} }
} }
public static void closeLog() public static void closeLog()
{ {
if (fw != null) if (fw != null)

View File

@ -52,7 +52,7 @@ public class UserMap implements Function<String, User>, IConf
} }
catch (ComputationException ex) catch (ComputationException ex)
{ {
Bukkit.getLogger().log(Level.INFO, "Failed to preload user "+name, ex); Bukkit.getLogger().log(Level.INFO, "Failed to preload user " + name, ex);
} }
} }
} }

View File

@ -21,28 +21,34 @@ public class Worth implements IConf
{ {
String itemname = itemStack.getType().toString().toLowerCase().replace("_", ""); String itemname = itemStack.getType().toString().toLowerCase().replace("_", "");
double result; double result;
result = config.getDouble("worth."+itemname+"."+itemStack.getDurability(), Double.NaN); result = config.getDouble("worth." + itemname + "." + itemStack.getDurability(), Double.NaN);
if (Double.isNaN(result)) { if (Double.isNaN(result))
result = config.getDouble("worth."+itemname+".0", Double.NaN); {
result = config.getDouble("worth." + itemname + ".0", Double.NaN);
} }
if (Double.isNaN(result)) { if (Double.isNaN(result))
result = config.getDouble("worth."+itemname, Double.NaN); {
result = config.getDouble("worth." + itemname, Double.NaN);
} }
if (Double.isNaN(result)) { if (Double.isNaN(result))
result = config.getDouble("worth-"+itemStack.getTypeId(), Double.NaN); {
result = config.getDouble("worth-" + itemStack.getTypeId(), Double.NaN);
} }
return result; return result;
} }
public void setPrice(ItemStack itemStack, double price) public void setPrice(ItemStack itemStack, double price)
{ {
if (itemStack.getType().getData() == null) { if (itemStack.getType().getData() == null)
{
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price); config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price);
} else {
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0.
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), price);
} }
config.removeProperty("worth-"+itemStack.getTypeId()); else
{
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0.
config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "") + "." + itemStack.getDurability(), price);
}
config.removeProperty("worth-" + itemStack.getTypeId());
config.save(); config.save();
} }
@ -50,5 +56,4 @@ public class Worth implements IConf
{ {
config.load(); config.load();
} }
} }