mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 13:36:16 +01:00
Generic cleanup of the org.bukkit.craftbukkit classes.
This commit is contained in:
parent
b042f48b24
commit
9adc03abab
@ -323,8 +323,7 @@ public final class CraftServer implements Server {
|
||||
while (pollCount < 50 && getScheduler().getActiveWorkers().size() > 0) {
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
pollCount++;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ public class TrigMath {
|
||||
|
||||
private static double mxatan(double arg) {
|
||||
double argsq = arg * arg, value;
|
||||
|
||||
value = ((((p4 * argsq + p3) * argsq + p2) * argsq + p1) * argsq + p0);
|
||||
value = value / (((((argsq + q4) * argsq + q3) * argsq + q2) * argsq + q1) * argsq + q0);
|
||||
return value * arg;
|
||||
|
@ -36,6 +36,7 @@ public class CraftDispenser extends CraftBlockState implements Dispenser {
|
||||
synchronized (block) {
|
||||
if (block.getType() == Material.DISPENSER) {
|
||||
BlockDispenser dispense = (BlockDispenser) net.minecraft.server.Block.DISPENSER;
|
||||
|
||||
dispense.dispense(world.getHandle(), getX(), getY(), getZ(), new Random());
|
||||
return true;
|
||||
} else {
|
||||
|
@ -27,9 +27,9 @@ public class ServerCommandListener implements ICommandListener {
|
||||
public String getName() {
|
||||
try {
|
||||
Method getName = commandSender.getClass().getMethod("getName");
|
||||
|
||||
return (String) getName.invoke(commandSender);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
|
||||
return this.prefix;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import net.minecraft.server.EntityChicken;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Chicken;
|
||||
|
||||
|
||||
public class CraftChicken extends CraftAnimals implements Chicken {
|
||||
|
||||
public CraftChicken(CraftServer server, EntityChicken entity) {
|
||||
|
@ -143,6 +143,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
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<org.bukkit.entity.Entity> bukkitEntityList = new java.util.ArrayList<org.bukkit.entity.Entity>(notchEntityList.size());
|
||||
|
||||
for (Entity e: notchEntityList) {
|
||||
bukkitEntityList.add(e.getBukkitEntity());
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
public Egg throwEgg() {
|
||||
net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
|
||||
EntityEgg egg = new EntityEgg(world, getHandle());
|
||||
|
||||
world.addEntity(egg);
|
||||
return (Egg) egg.getBukkitEntity();
|
||||
}
|
||||
@ -71,6 +72,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
public Snowball throwSnowball() {
|
||||
net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
|
||||
EntitySnowball snowball = new EntitySnowball(world, getHandle());
|
||||
|
||||
world.addEntity(snowball);
|
||||
return (Snowball) snowball.getBukkitEntity();
|
||||
}
|
||||
@ -125,6 +127,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
public Arrow shootArrow() {
|
||||
net.minecraft.server.World world = ((CraftWorld) getWorld()).getHandle();
|
||||
EntityArrow arrow = new EntityArrow(world, getHandle());
|
||||
|
||||
world.addEntity(arrow);
|
||||
return (Arrow) arrow.getBukkitEntity();
|
||||
}
|
||||
|
@ -147,8 +147,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
|
||||
public void playNote(Location loc, byte instrument, byte note) {
|
||||
getHandle().netServerHandler.sendPacket(
|
||||
new Packet54PlayNoteBlock(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), instrument, note));
|
||||
getHandle().netServerHandler.sendPacket(new Packet54PlayNoteBlock(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), instrument, note));
|
||||
}
|
||||
|
||||
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) {
|
||||
Packet53BlockChange packet = new Packet53BlockChange(
|
||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),
|
||||
((CraftWorld) loc.getWorld()).getHandle());
|
||||
Packet53BlockChange packet = new Packet53BlockChange(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), ((CraftWorld) loc.getWorld()).getHandle());
|
||||
|
||||
packet.d = material;
|
||||
packet.e = data;
|
||||
getHandle().netServerHandler.sendPacket(packet);
|
||||
@ -219,6 +217,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle();
|
||||
// Grab the EntityPlayer
|
||||
EntityPlayer entity = getHandle();
|
||||
|
||||
// Check if the fromWorld and toWorld are the same.
|
||||
if (fromWorld == toWorld) {
|
||||
entity.netServerHandler.teleport(to);
|
||||
|
@ -5,6 +5,7 @@ import net.minecraft.server.EntityZombie;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
|
||||
public class CraftZombie extends CraftMonster implements Zombie {
|
||||
|
||||
public CraftZombie(CraftServer server, EntityZombie entity) {
|
||||
|
@ -74,6 +74,7 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent
|
||||
|
||||
public void setArmorContents(ItemStack[] items) {
|
||||
int cnt = getSize();
|
||||
|
||||
if (items == null) {
|
||||
items = new ItemStack[4];
|
||||
}
|
||||
|
@ -95,8 +95,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
synchronized (schedulerQueue) {
|
||||
try {
|
||||
schedulerQueue.wait(sleepTime);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,6 +207,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
}
|
||||
|
||||
CraftTask newTask = new CraftTask(plugin, task, true, getCurrentTick() + delay, period);
|
||||
|
||||
synchronized (schedulerQueue) {
|
||||
schedulerQueue.put(newTask, true);
|
||||
schedulerQueue.notify();
|
||||
@ -235,6 +235,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
}
|
||||
|
||||
CraftTask newTask = new CraftTask(plugin, task, false, getCurrentTick() + delay, period);
|
||||
|
||||
synchronized (schedulerQueue) {
|
||||
schedulerQueue.put(newTask, false);
|
||||
schedulerQueue.notify();
|
||||
@ -333,6 +334,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
synchronized (craftThreadManager.workers) {
|
||||
List<BukkitWorker> workerList = new ArrayList<BukkitWorker>(craftThreadManager.workers.size());
|
||||
Iterator<CraftWorker> itr = craftThreadManager.workers.iterator();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
workerList.add((BukkitWorker) itr.next());
|
||||
}
|
||||
@ -359,6 +361,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
||||
syncedTasksLock.unlock();
|
||||
}
|
||||
List<BukkitTask> newTaskList = new ArrayList<BukkitTask>(taskList.size());
|
||||
|
||||
for (CraftTask craftTask : taskList) {
|
||||
newTaskList.add((BukkitTask) craftTask);
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class ConcurrentSoftMap<K,V> {
|
||||
|
||||
private void emptyQueue() {
|
||||
SoftMapReference ref;
|
||||
|
||||
while ((ref = (SoftMapReference) queue.poll()) != null) {
|
||||
map.remove(ref.key);
|
||||
}
|
||||
@ -101,10 +102,12 @@ public class ConcurrentSoftMap<K,V> {
|
||||
|
||||
private V fastGet(K key) {
|
||||
SoftMapReference<K, V> ref = map.get(key);
|
||||
|
||||
if (ref == null) {
|
||||
return null;
|
||||
}
|
||||
V value = ref.get();
|
||||
|
||||
if (value != null) {
|
||||
synchronized (strongReferenceQueue) {
|
||||
strongReferenceQueue.addFirst(value);
|
||||
@ -166,6 +169,7 @@ public class ConcurrentSoftMap<K,V> {
|
||||
|
||||
if (map.containsKey(key)) {
|
||||
SoftMapReference<K, V> current = map.get(key);
|
||||
|
||||
if (current != null) {
|
||||
ret = current.get();
|
||||
}
|
||||
@ -174,6 +178,7 @@ public class ConcurrentSoftMap<K,V> {
|
||||
if (ret == null) {
|
||||
SoftMapReference<K, V> newValue = new SoftMapReference<K, V>(key, value, queue);
|
||||
boolean success = false;
|
||||
|
||||
while (!success) {
|
||||
SoftMapReference<K, V> oldValue = map.putIfAbsent(key, newValue);
|
||||
|
||||
@ -219,6 +224,7 @@ public class ConcurrentSoftMap<K,V> {
|
||||
public V remove(K key) {
|
||||
emptyQueue();
|
||||
SoftMapReference<K, V> ref = map.remove(key);
|
||||
|
||||
if (ref != null) {
|
||||
return ref.get();
|
||||
}
|
||||
@ -239,7 +245,6 @@ public class ConcurrentSoftMap<K,V> {
|
||||
throw new UnsupportedOperationException("SoftMap does not support this operation, since it creates potentially stong references");
|
||||
}
|
||||
|
||||
|
||||
private static class SoftMapReference<K, V> extends SoftReference<V> {
|
||||
K key;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user