Small refactoring

This commit is contained in:
filoghost 2021-05-04 20:37:51 +02:00
parent aacc7fdeb4
commit de3f967a21
21 changed files with 67 additions and 60 deletions

View File

@ -9,6 +9,10 @@ import me.filoghost.fcommons.Strings;
public class Utils {
public static double distanceSquared(double locX1, double locX2, double locZ1, double locZ2) {
return square(locX1 - locX2) + square(locZ1 - locZ2);
}
public static double square(double num) {
return num * num;
}

View File

@ -215,12 +215,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -53,12 +53,12 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
// Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}

View File

@ -12,6 +12,7 @@ import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.DamageSource;
import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityDamageSource;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.EntitySlime;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
@ -55,12 +56,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
// Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}

View File

@ -215,12 +215,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -215,12 +215,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -217,12 +217,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -217,12 +217,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -219,12 +219,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.getPlayers()) {
for (EntityHuman humanEntity : super.world.getPlayers()) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -219,12 +219,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.getPlayers()) {
for (EntityHuman humanEntity : super.world.getPlayers()) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ());
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -219,12 +219,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.getPlayers()) {
for (EntityHuman humanEntity : super.world.getPlayers()) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ());
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -219,12 +219,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.getPlayers()) {
for (EntityHuman humanEntity : super.world.getPlayers()) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ());
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -219,12 +219,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.getPlayers()) {
for (EntityHuman humanEntity : super.world.getPlayers()) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX() - super.locX()) + Utils.square(nmsPlayer.locZ() - super.locZ());
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX(), super.locX(), nmsPlayer.locZ(), super.locZ());
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -204,12 +204,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -204,12 +204,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -216,12 +216,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -53,12 +53,12 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
// Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}

View File

@ -12,6 +12,7 @@ import net.minecraft.server.v1_9_R1.AxisAlignedBB;
import net.minecraft.server.v1_9_R1.DamageSource;
import net.minecraft.server.v1_9_R1.Entity;
import net.minecraft.server.v1_9_R1.EntityDamageSource;
import net.minecraft.server.v1_9_R1.EntityHuman;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.EntitySlime;
import net.minecraft.server.v1_9_R1.NBTTagCompound;
@ -55,12 +56,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
// Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}

View File

@ -216,12 +216,12 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private void broadcastLocationPacketNMS() {
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 8192 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 64 * 64 * 2 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(teleportPacket);
}
}

View File

@ -53,12 +53,12 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
// Send a packet near to "remind" players that the item is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}

View File

@ -12,6 +12,7 @@ import net.minecraft.server.v1_9_R2.AxisAlignedBB;
import net.minecraft.server.v1_9_R2.DamageSource;
import net.minecraft.server.v1_9_R2.Entity;
import net.minecraft.server.v1_9_R2.EntityDamageSource;
import net.minecraft.server.v1_9_R2.EntityHuman;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.EntitySlime;
import net.minecraft.server.v1_9_R2.NBTTagCompound;
@ -55,12 +56,12 @@ public class EntityNMSSlime extends EntitySlime implements NMSSlime {
// Send a packet near to "remind" players that the slime is riding the armor stand (Spigot bug or client bug)
PacketPlayOutMount mountPacket = new PacketPlayOutMount(vehicle);
for (Object humanEntity : super.world.players) {
for (EntityHuman humanEntity : super.world.players) {
if (humanEntity instanceof EntityPlayer) {
EntityPlayer nmsPlayer = (EntityPlayer) humanEntity;
double distanceSquared = Utils.square(nmsPlayer.locX - super.locX) + Utils.square(nmsPlayer.locZ - super.locZ);
if (distanceSquared < 1024 && nmsPlayer.playerConnection != null) {
double distanceSquared = Utils.distanceSquared(nmsPlayer.locX, super.locX, nmsPlayer.locZ, super.locZ);
if (distanceSquared < 32 * 32 && nmsPlayer.playerConnection != null) {
nmsPlayer.playerConnection.sendPacket(mountPacket);
}
}