1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-10-02 17:16:59 +02:00

Cleanup debug message, code tidy.

This commit is contained in:
KHobbits
2011-10-25 22:18:28 +01:00
parent bb7183deeb
commit 1b1501c504
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,7 +55,8 @@ public class TNTExplodeListener extends EntityListener implements Runnable
{ {
return; return;
} }
try { try
{
final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
final Player[] players = ess.getServer().getOnlinePlayers(); final Player[] players = ess.getServer().getOnlinePlayers();
final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length); final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length);
@@ -75,7 +77,9 @@ public class TNTExplodeListener extends EntityListener implements Runnable
} }
} }
((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)); ((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) { }
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

@@ -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();
} }
} }