mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-17 21:12:13 +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) {
|
while (pollCount < 50 && getScheduler().getActiveWorkers().size() > 0) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {}
|
||||||
}
|
|
||||||
pollCount++;
|
pollCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ 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;
|
||||||
|
@ -36,6 +36,7 @@ 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 {
|
||||||
|
@ -27,9 +27,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ 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) {
|
||||||
|
@ -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) {
|
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());
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ 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();
|
||||||
}
|
}
|
||||||
@ -71,6 +72,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@ -125,6 +127,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
@ -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,6 +217,7 @@ 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);
|
||||||
|
@ -5,6 +5,7 @@ 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) {
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -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) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,6 +207,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@ -235,6 +235,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@ -333,6 +334,7 @@ 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());
|
||||||
}
|
}
|
||||||
@ -359,6 +361,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ 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);
|
||||||
}
|
}
|
||||||
@ -101,10 +102,12 @@ 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) {
|
if (value != null) {
|
||||||
synchronized (strongReferenceQueue) {
|
synchronized (strongReferenceQueue) {
|
||||||
strongReferenceQueue.addFirst(value);
|
strongReferenceQueue.addFirst(value);
|
||||||
@ -166,6 +169,7 @@ public class ConcurrentSoftMap<K,V> {
|
|||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -174,6 +178,7 @@ public class ConcurrentSoftMap<K,V> {
|
|||||||
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);
|
||||||
|
|
||||||
@ -219,6 +224,7 @@ 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,7 +245,6 @@ 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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user