Generic cleanup of the org.bukkit.craftbukkit classes.

This commit is contained in:
Erik Broes 2011-06-12 01:12:43 +02:00
parent b042f48b24
commit 9adc03abab
34 changed files with 160 additions and 145 deletions

View File

@ -35,7 +35,7 @@ public class CraftChunk implements Chunk {
public net.minecraft.server.Chunk getHandle() { public net.minecraft.server.Chunk getHandle() {
net.minecraft.server.Chunk c = weakChunk.get(); net.minecraft.server.Chunk c = weakChunk.get();
if (c == null) { if (c == null) {
c = worldServer.getChunkAt(x,z); c = worldServer.getChunkAt(x, z);
weakChunk = new WeakReference<net.minecraft.server.Chunk>(c); weakChunk = new WeakReference<net.minecraft.server.Chunk>(c);
} }
return c; return c;
@ -64,7 +64,7 @@ public class CraftChunk implements Chunk {
if (block == null) { if (block == null) {
Block newBlock = new CraftBlock(this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF)); Block newBlock = new CraftBlock(this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF));
Block oldBlock = this.cache.put(pos, newBlock); Block oldBlock = this.cache.put(pos, newBlock);
if(oldBlock == null) { if (oldBlock == null) {
block = newBlock; block = newBlock;
} else { } else {
block = oldBlock; block = oldBlock;

View File

@ -84,7 +84,7 @@ public final class CraftServer implements Server {
Logger.getLogger("Minecraft").log(Level.INFO, "This server is running " + getName() + " version " + getVersion()); Logger.getLogger("Minecraft").log(Level.INFO, "This server is running " + getName() + " version " + getVersion());
configuration = new Configuration((File)console.options.valueOf("bukkit-settings")); configuration = new Configuration((File) console.options.valueOf("bukkit-settings"));
configuration.load(); configuration.load();
loadConfigDefaults(); loadConfigDefaults();
configuration.save(); configuration.save();
@ -102,7 +102,7 @@ public final class CraftServer implements Server {
public void loadPlugins() { public void loadPlugins() {
pluginManager.registerInterface(JavaPluginLoader.class); pluginManager.registerInterface(JavaPluginLoader.class);
File pluginFolder = (File)console.options.valueOf("plugins"); File pluginFolder = (File) console.options.valueOf("plugins");
if (pluginFolder.exists()) { if (pluginFolder.exists()) {
try { try {
@ -293,7 +293,7 @@ public final class CraftServer implements Server {
} }
// See if the server can process this command // See if the server can process this command
return console.consoleCommandHandler.handle(new ServerCommand(commandLine, (ICommandListener)new ServerCommandListener(sender))); return console.consoleCommandHandler.handle(new ServerCommand(commandLine, (ICommandListener) new ServerCommandListener(sender)));
} }
public void reload() { public void reload() {
@ -320,16 +320,15 @@ public final class CraftServer implements Server {
int pollCount = 0; int pollCount = 0;
// Wait for at most 2.5 seconds for plugins to close their threads // Wait for at most 2.5 seconds for plugins to close their threads
while(pollCount < 50 && getScheduler().getActiveWorkers().size() > 0) { while (pollCount < 50 && getScheduler().getActiveWorkers().size() > 0) {
try { try {
Thread.sleep(50); Thread.sleep(50);
} catch (InterruptedException e) { } catch (InterruptedException e) {}
}
pollCount++; pollCount++;
} }
List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers(); List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers();
for(BukkitWorker worker : overdueWorkers) { for (BukkitWorker worker : overdueWorkers) {
Plugin plugin = worker.getOwner(); Plugin plugin = worker.getOwner();
String author = "<NoAuthorGiven>"; String author = "<NoAuthorGiven>";
if (plugin.getDescription().getAuthors().size() > 0) { if (plugin.getDescription().getAuthors().size() > 0) {
@ -385,7 +384,7 @@ public final class CraftServer implements Server {
internal.z = console.worlds.get(0).z; internal.z = console.worlds.get(0).z;
internal.tracker = new EntityTracker(console, dimension); internal.tracker = new EntityTracker(console, dimension);
internal.addIWorldAccess((IWorldAccess)new WorldManager(console, internal)); internal.addIWorldAccess((IWorldAccess) new WorldManager(console, internal));
internal.spawnMonsters = 1; internal.spawnMonsters = 1;
internal.setSpawnFlags(true, true); internal.setSpawnFlags(true, true);
console.worlds.add(internal); console.worlds.add(internal);
@ -492,7 +491,7 @@ public final class CraftServer implements Server {
Command command = commandMap.getCommand(name); Command command = commandMap.getCommand(name);
if (command instanceof PluginCommand) { if (command instanceof PluginCommand) {
return (PluginCommand)command; return (PluginCommand) command;
} else { } else {
return null; return null;
} }
@ -520,7 +519,7 @@ public final class CraftServer implements Server {
public boolean addRecipe(Recipe recipe) { public boolean addRecipe(Recipe recipe) {
CraftRecipe toAdd; CraftRecipe toAdd;
if(recipe instanceof CraftRecipe) { if (recipe instanceof CraftRecipe) {
toAdd = (CraftRecipe) recipe; toAdd = (CraftRecipe) recipe;
} else { } else {
if (recipe instanceof ShapedRecipe) { if (recipe instanceof ShapedRecipe) {

View File

@ -32,7 +32,7 @@ public class CraftWorld implements World {
private Environment environment; private Environment environment;
private final CraftServer server; private final CraftServer server;
private final ChunkProviderServer provider; private final ChunkProviderServer provider;
private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>(); private HashMap<Integer, CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
private final ChunkGenerator generator; private final ChunkGenerator generator;
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>(); private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
@ -91,7 +91,7 @@ public class CraftWorld implements World {
} }
public Chunk getChunkAt(int x, int z) { public Chunk getChunkAt(int x, int z) {
return this.provider.getChunkAt(x,z).bukkitChunk; return this.provider.getChunkAt(x, z).bukkitChunk;
} }
public Chunk getChunkAt(Block block) { public Chunk getChunkAt(Block block) {
@ -107,7 +107,7 @@ public class CraftWorld implements World {
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length]; org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
for (int i = 0; i < chunks.length; i++) { for (int i = 0; i < chunks.length; i++) {
net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk)chunks[i]; net.minecraft.server.Chunk chunk = (net.minecraft.server.Chunk) chunks[i];
craftChunks[i] = chunk.bukkitChunk; craftChunks[i] = chunk.bukkitChunk;
} }
@ -186,18 +186,18 @@ public class CraftWorld implements World {
return false; return false;
} }
int px = x<<4; int px = x << 4;
int pz = z<<4; int pz = z << 4;
// If there are more than 10 updates to a chunk at once, it carries out the update as a cuboid // If there are more than 10 updates to a chunk at once, it carries out the update as a cuboid
// This flags 16 blocks in a line along the bottom for update and then flags a block at the opposite corner at the top // This flags 16 blocks in a line along the bottom for update and then flags a block at the opposite corner at the top
// The cuboid that contains these 17 blocks covers the entire chunk // The cuboid that contains these 17 blocks covers the entire chunk
// The server will compress the chunk and send it to all clients // The server will compress the chunk and send it to all clients
for(int xx = px; xx < (px + 16); xx++) { for (int xx = px; xx < (px + 16); xx++) {
world.notify(xx, 0, pz); world.notify(xx, 0, pz);
} }
world.notify(px, 127, pz+15); world.notify(px, 127, pz + 15);
return true; return true;
} }
@ -526,7 +526,7 @@ public class CraftWorld implements World {
for (Object o: world.entityList) { for (Object o: world.entityList) {
if (o instanceof net.minecraft.server.Entity) { if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o; net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
Entity bukkitEntity = mcEnt.getBukkitEntity(); Entity bukkitEntity = mcEnt.getBukkitEntity();
// Assuming that bukkitEntity isn't null // Assuming that bukkitEntity isn't null
@ -544,12 +544,12 @@ public class CraftWorld implements World {
for (Object o: world.entityList) { for (Object o: world.entityList) {
if (o instanceof net.minecraft.server.Entity) { if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o; net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
Entity bukkitEntity = mcEnt.getBukkitEntity(); Entity bukkitEntity = mcEnt.getBukkitEntity();
// Assuming that bukkitEntity isn't null // Assuming that bukkitEntity isn't null
if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) { if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) {
list.add((LivingEntity)bukkitEntity); list.add((LivingEntity) bukkitEntity);
} }
} }
} }
@ -562,11 +562,11 @@ public class CraftWorld implements World {
for (Object o : world.entityList) { for (Object o : world.entityList) {
if (o instanceof net.minecraft.server.Entity) { if (o instanceof net.minecraft.server.Entity) {
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity)o; net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
Entity bukkitEntity = mcEnt.getBukkitEntity(); Entity bukkitEntity = mcEnt.getBukkitEntity();
if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) { if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
list.add((Player)bukkitEntity); list.add((Player) bukkitEntity);
} }
} }
} }

View File

@ -22,8 +22,9 @@ public class TrigMath {
private static double mxatan(double arg) { private static double mxatan(double arg) {
double argsq = arg * arg, value; double argsq = arg * arg, value;
value = ((((p4 * argsq + p3) * argsq + p2) * argsq + p1) * argsq + p0); value = ((((p4 * argsq + p3) * argsq + p2) * argsq + p1) * argsq + p0);
value = value / (((((argsq+q4)*argsq+q3)*argsq+q2)*argsq+q1)*argsq+q0); value = value / (((((argsq + q4) * argsq + q3) * argsq + q2) * argsq + q1) * argsq + q0);
return value * arg; return value * arg;
} }

View File

@ -23,13 +23,13 @@ public class CraftBlockState implements BlockState {
protected byte light; protected byte light;
public CraftBlockState(final Block block) { public CraftBlockState(final Block block) {
this.world = (CraftWorld)block.getWorld(); this.world = (CraftWorld) block.getWorld();
this.x = block.getX(); this.x = block.getX();
this.y = block.getY(); this.y = block.getY();
this.z = block.getZ(); this.z = block.getZ();
this.type = block.getTypeId(); this.type = block.getTypeId();
this.light = block.getLightLevel(); this.light = block.getLightLevel();
this.chunk = (CraftChunk)block.getChunk(); this.chunk = (CraftChunk) block.getChunk();
createData(block.getData()); createData(block.getData());
} }
@ -129,7 +129,7 @@ public class CraftBlockState implements BlockState {
public boolean setTypeId(final int type) { public boolean setTypeId(final int type) {
this.type = type; this.type = type;
createData((byte)0); createData((byte) 0);
return true; return true;
} }

View File

@ -19,8 +19,8 @@ public class CraftChest extends CraftBlockState implements Chest {
public CraftChest(final Block block) { public CraftChest(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
chest = (TileEntityChest)world.getTileEntityAt(getX(), getY(), getZ()); chest = (TileEntityChest) world.getTileEntityAt(getX(), getY(), getZ());
} }
public Inventory getInventory() { public Inventory getInventory() {

View File

@ -13,8 +13,8 @@ public class CraftCreatureSpawner extends CraftBlockState implements CreatureSpa
public CraftCreatureSpawner(final Block block) { public CraftCreatureSpawner(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
spawner = (TileEntityMobSpawner)world.getTileEntityAt(getX(), getY(), getZ()); spawner = (TileEntityMobSpawner) world.getTileEntityAt(getX(), getY(), getZ());
} }
public CreatureType getCreatureType() { public CreatureType getCreatureType() {

View File

@ -22,8 +22,8 @@ public class CraftDispenser extends CraftBlockState implements Dispenser {
public CraftDispenser(final Block block) { public CraftDispenser(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
dispenser = (TileEntityDispenser)world.getTileEntityAt(getX(), getY(), getZ()); dispenser = (TileEntityDispenser) world.getTileEntityAt(getX(), getY(), getZ());
} }
public Inventory getInventory() { public Inventory getInventory() {
@ -35,7 +35,8 @@ public class CraftDispenser extends CraftBlockState implements Dispenser {
synchronized (block) { synchronized (block) {
if (block.getType() == Material.DISPENSER) { if (block.getType() == Material.DISPENSER) {
BlockDispenser dispense = (BlockDispenser)net.minecraft.server.Block.DISPENSER; BlockDispenser dispense = (BlockDispenser) net.minecraft.server.Block.DISPENSER;
dispense.dispense(world.getHandle(), getX(), getY(), getZ(), new Random()); dispense.dispense(world.getHandle(), getX(), getY(), getZ(), new Random());
return true; return true;
} else { } else {

View File

@ -19,8 +19,8 @@ public class CraftFurnace extends CraftBlockState implements Furnace {
public CraftFurnace(final Block block) { public CraftFurnace(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
furnace = (TileEntityFurnace)world.getTileEntityAt(getX(), getY(), getZ()); furnace = (TileEntityFurnace) world.getTileEntityAt(getX(), getY(), getZ());
} }
public Inventory getInventory() { public Inventory getInventory() {
@ -39,7 +39,7 @@ public class CraftFurnace extends CraftBlockState implements Furnace {
} }
public short getBurnTime() { public short getBurnTime() {
return (short)furnace.burnTime; return (short) furnace.burnTime;
} }
public void setBurnTime(short burnTime) { public void setBurnTime(short burnTime) {
@ -47,7 +47,7 @@ public class CraftFurnace extends CraftBlockState implements Furnace {
} }
public short getCookTime() { public short getCookTime() {
return (short)furnace.cookTime; return (short) furnace.cookTime;
} }
public void setCookTime(short cookTime) { public void setCookTime(short cookTime) {

View File

@ -18,8 +18,8 @@ public class CraftNoteBlock extends CraftBlockState implements NoteBlock {
public CraftNoteBlock(final Block block) { public CraftNoteBlock(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
note = (TileEntityNote)world.getTileEntityAt(getX(), getY(), getZ()); note = (TileEntityNote) world.getTileEntityAt(getX(), getY(), getZ());
} }
public byte getNote() { public byte getNote() {

View File

@ -12,8 +12,8 @@ public class CraftSign extends CraftBlockState implements Sign {
public CraftSign(final Block block) { public CraftSign(final Block block) {
super(block); super(block);
world = (CraftWorld)block.getWorld(); world = (CraftWorld) block.getWorld();
sign = (TileEntitySign)world.getTileEntityAt(getX(), getY(), getZ()); sign = (TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
} }
public String[] getLines() { public String[] getLines() {

View File

@ -26,10 +26,10 @@ public class ServerCommandListener implements ICommandListener {
public String getName() { public String getName() {
try { try {
Method getName = commandSender.getClass().getMethod( "getName" ); Method getName = commandSender.getClass().getMethod("getName");
return (String) getName.invoke(commandSender); return (String) getName.invoke(commandSender);
} catch (Exception e) { } catch (Exception e) {}
}
return this.prefix; return this.prefix;
} }

View File

@ -4,7 +4,8 @@ import net.minecraft.server.EntityChicken;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Chicken; import org.bukkit.entity.Chicken;
public class CraftChicken extends CraftAnimals implements Chicken{
public class CraftChicken extends CraftAnimals implements Chicken {
public CraftChicken(CraftServer server, EntityChicken entity) { public CraftChicken(CraftServer server, EntityChicken entity) {
super(server, entity); super(server, entity);

View File

@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public class CraftCreature extends CraftLivingEntity implements Creature{ public class CraftCreature extends CraftLivingEntity implements Creature {
public CraftCreature(CraftServer server, EntityCreature entity) { public CraftCreature(CraftServer server, EntityCreature entity) {
super(server, entity); super(server, entity);
} }

View File

@ -32,14 +32,14 @@ public class CraftCreeper extends CraftMonster implements Creeper {
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
getHandle().Z().b(17, (byte)1); getHandle().Z().b(17, (byte) 1);
} }
} else { } else {
CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_OFF); CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_OFF);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
getHandle().Z().b(17, (byte)0); getHandle().Z().b(17, (byte) 0);
} }
} }

View File

@ -118,11 +118,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
} }
public World getWorld() { public World getWorld() {
return ((WorldServer)entity.world).getWorld(); return ((WorldServer) entity.world).getWorld();
} }
public boolean teleport(Location location) { public boolean teleport(Location location) {
entity.world = ((CraftWorld)location.getWorld()).getHandle(); entity.world = ((CraftWorld) location.getWorld()).getHandle();
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
// entity.setLocation() throws no event, and so cannot be cancelled // entity.setLocation() throws no event, and so cannot be cancelled
return true; return true;
@ -140,10 +140,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
teleport(destination); teleport(destination);
} }
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z){ public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
List<Entity> notchEntityList = entity.world.b(entity, entity.boundingBox.b(x,y,z)); List<Entity> notchEntityList = entity.world.b(entity, entity.boundingBox.b(x, y, z));
List<org.bukkit.entity.Entity> bukkitEntityList = new java.util.ArrayList<org.bukkit.entity.Entity>(notchEntityList.size()); List<org.bukkit.entity.Entity> bukkitEntityList = new java.util.ArrayList<org.bukkit.entity.Entity>(notchEntityList.size());
for (Entity e: notchEntityList){
for (Entity e: notchEntityList) {
bukkitEntityList.add(e.getBukkitEntity()); bukkitEntityList.add(e.getBukkitEntity());
} }
return bukkitEntityList; return bukkitEntityList;
@ -229,7 +230,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
} }
public boolean setPassenger(org.bukkit.entity.Entity passenger) { public boolean setPassenger(org.bukkit.entity.Entity passenger) {
if (passenger instanceof CraftEntity){ if (passenger instanceof CraftEntity) {
((CraftEntity) passenger).getHandle().setPassengerOf(getHandle()); ((CraftEntity) passenger).getHandle().setPassengerOf(getHandle());
return true; return true;
} else { } else {

View File

@ -26,7 +26,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
} }
public void setHandle(final EntityHuman entity) { public void setHandle(final EntityHuman entity) {
super.setHandle((EntityHuman)entity); super.setHandle((EntityHuman) entity);
this.entity = entity; this.entity = entity;
this.inventory = new CraftInventoryPlayer(entity.inventory); this.inventory = new CraftInventoryPlayer(entity.inventory);
} }

View File

@ -12,7 +12,7 @@ public class CraftLightningStrike extends CraftEntity implements LightningStrike
@Override @Override
public EntityWeatherStorm getHandle() { public EntityWeatherStorm getHandle() {
return (EntityWeatherStorm)super.getHandle(); return (EntityWeatherStorm) super.getHandle();
} }
public boolean isEffect() { public boolean isEffect() {

View File

@ -40,7 +40,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} }
if (entity instanceof EntityPlayer && health == 0) { if (entity instanceof EntityPlayer && health == 0) {
((EntityPlayer)entity).a((Entity)null); ((EntityPlayer) entity).a((Entity) null);
} }
getHandle().health = health; getHandle().health = health;
@ -52,7 +52,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} }
public void setHandle(final EntityLiving entity) { public void setHandle(final EntityLiving entity) {
super.setHandle((Entity)entity); super.setHandle((Entity) entity);
this.entity = entity; this.entity = entity;
} }
@ -62,15 +62,17 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} }
public Egg throwEgg() { public Egg throwEgg() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
EntityEgg egg = new EntityEgg(world, getHandle()); EntityEgg egg = new EntityEgg(world, getHandle());
world.addEntity(egg); world.addEntity(egg);
return (Egg) egg.getBukkitEntity(); return (Egg) egg.getBukkitEntity();
} }
public Snowball throwSnowball() { public Snowball throwSnowball() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
EntitySnowball snowball = new EntitySnowball(world, getHandle()); EntitySnowball snowball = new EntitySnowball(world, getHandle());
world.addEntity(snowball); world.addEntity(snowball);
return (Snowball) snowball.getBukkitEntity(); return (Snowball) snowball.getBukkitEntity();
} }
@ -101,7 +103,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
break; break;
} }
} else { } else {
if (!transparent.contains((byte)id)) { if (!transparent.contains((byte) id)) {
break; break;
} }
} }
@ -123,8 +125,9 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} }
public Arrow shootArrow() { public Arrow shootArrow() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
EntityArrow arrow = new EntityArrow(world, getHandle()); EntityArrow arrow = new EntityArrow(world, getHandle());
world.addEntity(arrow); world.addEntity(arrow);
return (Arrow) arrow.getBukkitEntity(); return (Arrow) arrow.getBukkitEntity();
} }

View File

@ -147,8 +147,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
} }
public void playNote(Location loc, byte instrument, byte note) { public void playNote(Location loc, byte instrument, byte note) {
getHandle().netServerHandler.sendPacket( getHandle().netServerHandler.sendPacket(new Packet54PlayNoteBlock(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), instrument, note));
new Packet54PlayNoteBlock(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), instrument, note));
} }
public void playEffect(Location loc, Effect effect, int data) { public void playEffect(Location loc, Effect effect, int data) {
@ -162,9 +161,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
} }
public void sendBlockChange(Location loc, int material, byte data) { public void sendBlockChange(Location loc, int material, byte data) {
Packet53BlockChange packet = new Packet53BlockChange( Packet53BlockChange packet = new Packet53BlockChange(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), ((CraftWorld) loc.getWorld()).getHandle());
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),
((CraftWorld) loc.getWorld()).getHandle());
packet.d = material; packet.d = material;
packet.e = data; packet.e = data;
getHandle().netServerHandler.sendPacket(packet); getHandle().netServerHandler.sendPacket(packet);
@ -219,8 +217,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle(); WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle();
// Grab the EntityPlayer // Grab the EntityPlayer
EntityPlayer entity = getHandle(); EntityPlayer entity = getHandle();
// Check if the fromWorld and toWorld are the same. // Check if the fromWorld and toWorld are the same.
if (fromWorld == toWorld){ if (fromWorld == toWorld) {
entity.netServerHandler.teleport(to); entity.netServerHandler.teleport(to);
} else { } else {
server.getHandle().a(entity, toWorld.dimension, to); server.getHandle().a(entity, toWorld.dimension, to);

View File

@ -12,6 +12,6 @@ public class CraftWeather extends CraftEntity implements Weather {
@Override @Override
public EntityWeather getHandle() { public EntityWeather getHandle() {
return (EntityWeather)super.getHandle(); return (EntityWeather) super.getHandle();
} }
} }

View File

@ -5,7 +5,8 @@ import net.minecraft.server.EntityZombie;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
public class CraftZombie extends CraftMonster implements Zombie{
public class CraftZombie extends CraftMonster implements Zombie {
public CraftZombie(CraftServer server, EntityZombie entity) { public CraftZombie(CraftServer server, EntityZombie entity) {
super(server, entity); super(server, entity);

View File

@ -116,7 +116,7 @@ public class CraftEventFactory {
if (type == Type.PLAYER_BUCKET_EMPTY) { if (type == Type.PLAYER_BUCKET_EMPTY) {
event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand); event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ)); ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
} else if(type == Type.PLAYER_BUCKET_FILL) { } else if (type == Type.PLAYER_BUCKET_FILL) {
event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand); event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ)); ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
} }

View File

@ -17,7 +17,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
private final Random random; private final Random random;
public CustomChunkGenerator(World world, long seed, ChunkGenerator generator) { public CustomChunkGenerator(World world, long seed, ChunkGenerator generator) {
this.world = (WorldServer)world; this.world = (WorldServer) world;
this.seed = seed; this.seed = seed;
this.generator = generator; this.generator = generator;
@ -29,7 +29,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
} }
public Chunk getOrCreateChunk(int x, int z) { public Chunk getOrCreateChunk(int x, int z) {
random.setSeed((long)x * 341873128712L + (long)z * 132897987541L); random.setSeed((long) x * 341873128712L + (long) z * 132897987541L);
byte[] types = generator.generate(world.getWorld(), random, x, z); byte[] types = generator.generate(world.getWorld(), random, x, z);
Chunk chunk = new Chunk(world, types, x, z); Chunk chunk = new Chunk(world, types, x, z);

View File

@ -22,7 +22,7 @@ public class NormalChunkGenerator extends InternalChunkGenerator {
} }
public boolean canSpawn(org.bukkit.World world, int x, int z) { public boolean canSpawn(org.bukkit.World world, int x, int z) {
return ((CraftWorld)world).getHandle().worldProvider.a(x, z); return ((CraftWorld) world).getHandle().worldProvider.a(x, z);
} }
public List<BlockPopulator> getDefaultPopulators(org.bukkit.World world) { public List<BlockPopulator> getDefaultPopulators(org.bukkit.World world) {

View File

@ -270,7 +270,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
} }
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) { public HashMap<Integer, ItemStack> removeItem(ItemStack... items) {
HashMap<Integer,ItemStack> leftover = new HashMap<Integer,ItemStack>(); HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
// TODO: optimization // TODO: optimization

View File

@ -74,6 +74,7 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent
public void setArmorContents(ItemStack[] items) { public void setArmorContents(ItemStack[] items) {
int cnt = getSize(); int cnt = getSize();
if (items == null) { if (items == null) {
items = new ItemStack[4]; items = new ItemStack[4];
} }

View File

@ -24,7 +24,7 @@ public class CraftFuture<T> implements Runnable, Future<T> {
} }
public void run() { public void run() {
synchronized(this) { synchronized (this) {
if (cancelled) { if (cancelled) {
return; return;
} }
@ -35,7 +35,7 @@ public class CraftFuture<T> implements Runnable, Future<T> {
} catch (Exception e) { } catch (Exception e) {
this.e = e; this.e = e;
} }
synchronized(this) { synchronized (this) {
running = false; running = false;
done = true; done = true;
this.notify(); this.notify();
@ -50,7 +50,7 @@ public class CraftFuture<T> implements Runnable, Future<T> {
} }
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
synchronized(this) { synchronized (this) {
if (isDone()) { if (isDone()) {
return getResult(); return getResult();
} }
@ -63,31 +63,31 @@ public class CraftFuture<T> implements Runnable, Future<T> {
if (cancelled) { if (cancelled) {
throw new CancellationException(); throw new CancellationException();
} }
if (e!=null) { if (e != null) {
throw new ExecutionException(e); throw new ExecutionException(e);
} }
return returnStore.getObject(); return returnStore.getObject();
} }
public boolean isDone() { public boolean isDone() {
synchronized(this) { synchronized (this) {
return done; return done;
} }
} }
public boolean isCancelled() { public boolean isCancelled() {
synchronized(this) { synchronized (this) {
return cancelled; return cancelled;
} }
} }
public boolean cancel(boolean mayInterruptIfRunning) { public boolean cancel(boolean mayInterruptIfRunning) {
synchronized(this) { synchronized (this) {
if (cancelled) { if (cancelled) {
return false; return false;
} }
cancelled = true; cancelled = true;
if (taskId!=-1) { if (taskId != -1) {
craftScheduler.cancelTask(taskId); craftScheduler.cancelTask(taskId);
} }
if (!running && !done) { if (!running && !done) {
@ -99,7 +99,7 @@ public class CraftFuture<T> implements Runnable, Future<T> {
} }
public void setTaskId(int taskId) { public void setTaskId(int taskId) {
synchronized(this) { synchronized (this) {
this.taskId = taskId; this.taskId = taskId;
} }
} }

View File

@ -33,7 +33,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
private final LinkedList<CraftTask> mainThreadQueue = new LinkedList<CraftTask>(); private final LinkedList<CraftTask> mainThreadQueue = new LinkedList<CraftTask>();
private final LinkedList<CraftTask> syncedTasks = new LinkedList<CraftTask>(); private final LinkedList<CraftTask> syncedTasks = new LinkedList<CraftTask>();
private final TreeMap<CraftTask,Boolean> schedulerQueue = new TreeMap<CraftTask,Boolean>(); private final TreeMap<CraftTask, Boolean> schedulerQueue = new TreeMap<CraftTask, Boolean>();
private final Object currentTickSync = new Object(); private final Object currentTickSync = new Object();
private Long currentTick = 0L; private Long currentTick = 0L;
@ -54,7 +54,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
first = null; first = null;
if (!schedulerQueue.isEmpty()) { if (!schedulerQueue.isEmpty()) {
first = schedulerQueue.firstKey(); first = schedulerQueue.firstKey();
if (first!=null) { if (first != null) {
currentTick = getCurrentTick(); currentTick = getCurrentTick();
firstTick = first.getExecutionTick(); firstTick = first.getExecutionTick();
@ -62,7 +62,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
if (currentTick >= firstTick) { if (currentTick >= firstTick) {
schedulerQueue.remove(first); schedulerQueue.remove(first);
processTask(first); processTask(first);
if (first.getPeriod()>=0) { if (first.getPeriod() >= 0) {
first.updateExecution(); first.updateExecution();
schedulerQueue.put(first, first.isSync()); schedulerQueue.put(first, first.isSync());
} }
@ -83,7 +83,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
sleepTime = 60000L; sleepTime = 60000L;
} else { } else {
currentTick = getCurrentTick(); currentTick = getCurrentTick();
sleepTime = (firstTick-currentTick)*50 + 25; sleepTime = (firstTick - currentTick) * 50 + 25;
} }
if (sleepTime < 50L) { if (sleepTime < 50L) {
@ -95,8 +95,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
synchronized (schedulerQueue) { synchronized (schedulerQueue) {
try { try {
schedulerQueue.wait(sleepTime); schedulerQueue.wait(sleepTime);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {}
}
} }
} }
} }
@ -207,7 +206,8 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
throw new IllegalArgumentException("Delay cannot be less than 0"); throw new IllegalArgumentException("Delay cannot be less than 0");
} }
CraftTask newTask = new CraftTask(plugin, task, true, getCurrentTick()+delay, period); CraftTask newTask = new CraftTask(plugin, task, true, getCurrentTick() + delay, period);
synchronized (schedulerQueue) { synchronized (schedulerQueue) {
schedulerQueue.put(newTask, true); schedulerQueue.put(newTask, true);
schedulerQueue.notify(); schedulerQueue.notify();
@ -234,7 +234,8 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
throw new IllegalArgumentException("Delay cannot be less than 0"); throw new IllegalArgumentException("Delay cannot be less than 0");
} }
CraftTask newTask = new CraftTask(plugin, task, false, getCurrentTick()+delay, period); CraftTask newTask = new CraftTask(plugin, task, false, getCurrentTick() + delay, period);
synchronized (schedulerQueue) { synchronized (schedulerQueue) {
schedulerQueue.put(newTask, false); schedulerQueue.put(newTask, false);
schedulerQueue.notify(); schedulerQueue.notify();
@ -267,7 +268,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
public void cancelTasks(Plugin plugin) { public void cancelTasks(Plugin plugin) {
syncedTasksLock.lock(); syncedTasksLock.lock();
try { try {
synchronized(schedulerQueue) { synchronized (schedulerQueue) {
mainThreadLock.lock(); mainThreadLock.lock();
try { try {
Iterator<CraftTask> itr = schedulerQueue.keySet().iterator(); Iterator<CraftTask> itr = schedulerQueue.keySet().iterator();
@ -312,7 +313,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
craftThreadManager.interruptAllTasks(); craftThreadManager.interruptAllTasks();
} }
public boolean isCurrentlyRunning(int taskId){ public boolean isCurrentlyRunning(int taskId) {
return craftThreadManager.isAlive(taskId); return craftThreadManager.isAlive(taskId);
} }
@ -333,8 +334,9 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
synchronized (craftThreadManager.workers) { synchronized (craftThreadManager.workers) {
List<BukkitWorker> workerList = new ArrayList<BukkitWorker>(craftThreadManager.workers.size()); List<BukkitWorker> workerList = new ArrayList<BukkitWorker>(craftThreadManager.workers.size());
Iterator<CraftWorker> itr = craftThreadManager.workers.iterator(); Iterator<CraftWorker> itr = craftThreadManager.workers.iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
workerList.add((BukkitWorker)itr.next()); workerList.add((BukkitWorker) itr.next());
} }
return workerList; return workerList;
} }
@ -359,8 +361,9 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
syncedTasksLock.unlock(); syncedTasksLock.unlock();
} }
List<BukkitTask> newTaskList = new ArrayList<BukkitTask>(taskList.size()); List<BukkitTask> newTaskList = new ArrayList<BukkitTask>(taskList.size());
for (CraftTask craftTask : taskList) { for (CraftTask craftTask : taskList) {
newTaskList.add((BukkitTask)craftTask); newTaskList.add((BukkitTask) craftTask);
} }
return newTaskList; return newTaskList;
} }

View File

@ -79,9 +79,9 @@ public class CraftTask implements Comparable<Object>, BukkitTask {
} else { } else {
CraftTask o = (CraftTask) other; CraftTask o = (CraftTask) other;
long timeDiff = executionTick - o.getExecutionTick(); long timeDiff = executionTick - o.getExecutionTick();
if (timeDiff>0) { if (timeDiff > 0) {
return 1; return 1;
} else if (timeDiff<0) { } else if (timeDiff < 0) {
return -1; return -1;
} else { } else {
CraftTask otherCraftTask = (CraftTask) other; CraftTask otherCraftTask = (CraftTask) other;

View File

@ -27,9 +27,9 @@ import java.lang.ref.SoftReference;
* @author raphfrk * @author raphfrk
*/ */
public class ConcurrentSoftMap<K,V> { public class ConcurrentSoftMap<K, V> {
private final ConcurrentHashMap<K,SoftMapReference<K,V>> map = new ConcurrentHashMap<K,SoftMapReference<K,V>>(); private final ConcurrentHashMap<K, SoftMapReference<K, V>> map = new ConcurrentHashMap<K, SoftMapReference<K, V>>();
private final ReferenceQueue<SoftMapReference> queue = new ReferenceQueue<SoftMapReference>(); private final ReferenceQueue<SoftMapReference> queue = new ReferenceQueue<SoftMapReference>();
private final LinkedList<V> strongReferenceQueue = new LinkedList<V>(); private final LinkedList<V> strongReferenceQueue = new LinkedList<V>();
private final int strongReferenceSize; private final int strongReferenceSize;
@ -51,13 +51,14 @@ public class ConcurrentSoftMap<K,V> {
private void emptyQueue() { private void emptyQueue() {
SoftMapReference ref; SoftMapReference ref;
while ((ref=(SoftMapReference) queue.poll()) != null) {
while ((ref = (SoftMapReference) queue.poll()) != null) {
map.remove(ref.key); map.remove(ref.key);
} }
} }
public void clear() { public void clear() {
synchronized(strongReferenceQueue) { synchronized (strongReferenceQueue) {
strongReferenceQueue.clear(); strongReferenceQueue.clear();
} }
map.clear(); map.clear();
@ -100,13 +101,15 @@ public class ConcurrentSoftMap<K,V> {
} }
private V fastGet(K key) { private V fastGet(K key) {
SoftMapReference<K,V> ref = map.get(key); SoftMapReference<K, V> ref = map.get(key);
if (ref==null) {
if (ref == null) {
return null; return null;
} }
V value = ref.get(); V value = ref.get();
if (value!=null) {
synchronized(strongReferenceQueue) { if (value != null) {
synchronized (strongReferenceQueue) {
strongReferenceQueue.addFirst(value); strongReferenceQueue.addFirst(value);
if (strongReferenceQueue.size() > strongReferenceSize) { if (strongReferenceQueue.size() > strongReferenceSize) {
strongReferenceQueue.removeLast(); strongReferenceQueue.removeLast();
@ -147,8 +150,8 @@ public class ConcurrentSoftMap<K,V> {
} }
private void fastPut(K key, V value) { private void fastPut(K key, V value) {
map.put(key, new SoftMapReference<K,V>(key, value, queue)); map.put(key, new SoftMapReference<K, V>(key, value, queue));
synchronized(strongReferenceQueue) { synchronized (strongReferenceQueue) {
strongReferenceQueue.addFirst(value); strongReferenceQueue.addFirst(value);
if (strongReferenceQueue.size() > strongReferenceSize) { if (strongReferenceQueue.size() > strongReferenceSize) {
strongReferenceQueue.removeLast(); strongReferenceQueue.removeLast();
@ -165,17 +168,19 @@ public class ConcurrentSoftMap<K,V> {
V ret = null; V ret = null;
if (map.containsKey(key)) { if (map.containsKey(key)) {
SoftMapReference<K,V> current = map.get(key); SoftMapReference<K, V> current = map.get(key);
if (current != null) { if (current != null) {
ret = current.get(); ret = current.get();
} }
} }
if (ret == null) { if (ret == null) {
SoftMapReference<K,V> newValue = new SoftMapReference<K,V>(key, value, queue); SoftMapReference<K, V> newValue = new SoftMapReference<K, V>(key, value, queue);
boolean success = false; boolean success = false;
while (!success) { while (!success) {
SoftMapReference<K,V> oldValue = map.putIfAbsent(key, newValue); SoftMapReference<K, V> oldValue = map.putIfAbsent(key, newValue);
if (oldValue == null) { // put was successful (key didn't exist) if (oldValue == null) { // put was successful (key didn't exist)
ret = null; ret = null;
@ -192,7 +197,7 @@ public class ConcurrentSoftMap<K,V> {
} }
if (ret == null) { if (ret == null) {
synchronized(strongReferenceQueue) { synchronized (strongReferenceQueue) {
strongReferenceQueue.addFirst(value); strongReferenceQueue.addFirst(value);
if (strongReferenceQueue.size() > strongReferenceSize) { if (strongReferenceQueue.size() > strongReferenceSize) {
strongReferenceQueue.removeLast(); strongReferenceQueue.removeLast();
@ -218,7 +223,8 @@ public class ConcurrentSoftMap<K,V> {
public V remove(K key) { public V remove(K key) {
emptyQueue(); emptyQueue();
SoftMapReference<K,V> ref = map.remove(key); SoftMapReference<K, V> ref = map.remove(key);
if (ref != null) { if (ref != null) {
return ref.get(); return ref.get();
} }
@ -239,8 +245,7 @@ public class ConcurrentSoftMap<K,V> {
throw new UnsupportedOperationException("SoftMap does not support this operation, since it creates potentially stong references"); throw new UnsupportedOperationException("SoftMap does not support this operation, since it creates potentially stong references");
} }
private static class SoftMapReference<K, V> extends SoftReference<V> {
private static class SoftMapReference<K,V> extends SoftReference<V> {
K key; K key;
SoftMapReference(K key, V value, ReferenceQueue queue) { SoftMapReference(K key, V value, ReferenceQueue queue) {

View File

@ -14,7 +14,7 @@ public class LongHashtable<V> extends LongHash {
if (value instanceof Chunk) { if (value instanceof Chunk) {
Chunk c = (Chunk) value; Chunk c = (Chunk) value;
if (msw != c.x || lsw != c.z) { if (msw != c.x || lsw != c.z) {
MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z +") stored at (" + msw + ", " + lsw + ")"); MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z + ") stored at (" + msw + ", " + lsw + ")");
Throwable x = new Throwable(); Throwable x = new Throwable();
x.fillInStackTrace(); x.fillInStackTrace();
x.printStackTrace(); x.printStackTrace();
@ -27,7 +27,7 @@ public class LongHashtable<V> extends LongHash {
if (value instanceof Chunk) { if (value instanceof Chunk) {
Chunk c = (Chunk) value; Chunk c = (Chunk) value;
if (msw != c.x || lsw != c.z) { if (msw != c.x || lsw != c.z) {
MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z +") stored at (" + msw + ", " + lsw + ")"); MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z + ") stored at (" + msw + ", " + lsw + ")");
Throwable x = new Throwable(); Throwable x = new Throwable();
x.fillInStackTrace(); x.fillInStackTrace();
x.printStackTrace(); x.printStackTrace();

View File

@ -21,7 +21,7 @@ public class ShortConsoleLogFormatter extends Formatter {
Object object = options.valueOf("date-format"); Object object = options.valueOf("date-format");
if ((object != null) && (object instanceof SimpleDateFormat)) { if ((object != null) && (object instanceof SimpleDateFormat)) {
date = (SimpleDateFormat)object; date = (SimpleDateFormat) object;
} }
} catch (OptionException ex) { } catch (OptionException ex) {
System.err.println("Given date format is not valid. Falling back to default."); System.err.println("Given date format is not valid. Falling back to default.");