Make PS comparable and have equals make use of the compare methods.
This commit is contained in:
parent
95f1dc8dd0
commit
6d0e2f7669
@ -70,7 +70,7 @@ public class WorldMixinDefault extends WorldMixinAbstract
|
|||||||
World world = Bukkit.getWorld(worldId);
|
World world = Bukkit.getWorld(worldId);
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
|
|
||||||
spawnPs = spawnPs.withWorld(world);
|
spawnPs = spawnPs.withWorld(world.getName());
|
||||||
|
|
||||||
Location location = null;
|
Location location = null;
|
||||||
try
|
try
|
||||||
|
@ -41,7 +41,7 @@ import com.massivecraft.mcore.xlib.gson.annotations.SerializedName;
|
|||||||
* entity: world, locationX, locationY, locationZ, pitch, yaw, velocityX, velocityY, velocityZ
|
* entity: world, locationX, locationY, locationZ, pitch, yaw, velocityX, velocityY, velocityZ
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class PS implements Cloneable, Serializable
|
public final class PS implements Cloneable, Serializable, Comparable<PS>
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
@ -170,7 +170,6 @@ public final class PS implements Cloneable, Serializable
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public PS withWorld(String world) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
public PS withWorld(String world) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
||||||
public PS withWorld(World world) { return new PS(calcWorldName(world), blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
|
||||||
public PS withBlockX(Integer blockX) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
public PS withBlockX(Integer blockX) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
||||||
public PS withBlockY(Integer blockY) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
public PS withBlockY(Integer blockY) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
||||||
public PS withBlockZ(Integer blockZ) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
public PS withBlockZ(Integer blockZ) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
|
||||||
@ -796,90 +795,80 @@ public final class PS implements Cloneable, Serializable
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object derpObject)
|
||||||
{
|
{
|
||||||
return PS.equals(this, obj);
|
return equals(this, derpObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(PS ps, Object obj)
|
public static boolean equals(PS herp, Object derpObject)
|
||||||
{
|
{
|
||||||
if (ps == obj) return true;
|
return compareTo(herp, derpObject) == 0;
|
||||||
if (ps == null) return false;
|
}
|
||||||
if (obj == null) return false;
|
|
||||||
if (!(obj instanceof PS)) return false;
|
|
||||||
PS derp = (PS) obj;
|
|
||||||
|
|
||||||
if (ps.blockX == null)
|
// -------------------------------------------- //
|
||||||
|
// COMPARE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(PS derp)
|
||||||
{
|
{
|
||||||
if (derp.blockX != null) return false;
|
return compareTo(this, derp);
|
||||||
}
|
}
|
||||||
else if (!ps.blockX.equals(derp.blockX)) return false;
|
|
||||||
if (ps.blockY == null)
|
public static int compareTo(PS herp, Object derpObject)
|
||||||
{
|
{
|
||||||
if (derp.blockY != null) return false;
|
if (herp == null && derpObject == null) return 0;
|
||||||
}
|
if (herp == null) return -1;
|
||||||
else if (!ps.blockY.equals(derp.blockY)) return false;
|
if (derpObject == null) return +1;
|
||||||
if (ps.blockZ == null)
|
|
||||||
{
|
if (!(derpObject instanceof PS)) return -1;
|
||||||
if (derp.blockZ != null) return false;
|
PS derp = (PS) derpObject;
|
||||||
}
|
|
||||||
else if (!ps.blockZ.equals(derp.blockZ)) return false;
|
int ret;
|
||||||
if (ps.chunkX == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.world, derp.world);
|
||||||
if (derp.chunkX != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.chunkX.equals(derp.chunkX)) return false;
|
ret = MUtil.compare(herp.chunkX, derp.chunkX);
|
||||||
if (ps.chunkZ == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.chunkZ != null) return false;
|
ret = MUtil.compare(herp.chunkZ, derp.chunkZ);
|
||||||
}
|
if (ret != 0) return ret;
|
||||||
else if (!ps.chunkZ.equals(derp.chunkZ)) return false;
|
|
||||||
if (ps.locationX == null)
|
ret = MUtil.compare(herp.blockX, derp.blockX);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.locationX != null) return false;
|
|
||||||
}
|
ret = MUtil.compare(herp.blockY, derp.blockY);
|
||||||
else if (!ps.locationX.equals(derp.locationX)) return false;
|
if (ret != 0) return ret;
|
||||||
if (ps.locationY == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.blockZ, derp.blockZ);
|
||||||
if (derp.locationY != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.locationY.equals(derp.locationY)) return false;
|
ret = MUtil.compare(herp.locationX, derp.locationX);
|
||||||
if (ps.locationZ == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.locationZ != null) return false;
|
ret = MUtil.compare(herp.locationX, derp.locationX);
|
||||||
}
|
if (ret != 0) return ret;
|
||||||
else if (!ps.locationZ.equals(derp.locationZ)) return false;
|
|
||||||
if (ps.pitch == null)
|
ret = MUtil.compare(herp.locationZ, derp.locationZ);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.pitch != null) return false;
|
|
||||||
}
|
ret = MUtil.compare(herp.pitch, derp.pitch);
|
||||||
else if (!ps.pitch.equals(derp.pitch)) return false;
|
if (ret != 0) return ret;
|
||||||
if (ps.velocityX == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.yaw, derp.yaw);
|
||||||
if (derp.velocityX != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.velocityX.equals(derp.velocityX)) return false;
|
ret = MUtil.compare(herp.velocityX, derp.velocityX);
|
||||||
if (ps.velocityY == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.velocityY != null) return false;
|
ret = MUtil.compare(herp.velocityY, derp.velocityY);
|
||||||
}
|
if (ret != 0) return ret;
|
||||||
else if (!ps.velocityY.equals(derp.velocityY)) return false;
|
|
||||||
if (ps.velocityZ == null)
|
ret = MUtil.compare(herp.velocityZ, derp.velocityZ);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.velocityZ != null) return false;
|
|
||||||
}
|
return 0;
|
||||||
else if (!ps.velocityZ.equals(derp.velocityZ)) return false;
|
|
||||||
if (ps.world == null)
|
|
||||||
{
|
|
||||||
if (derp.world != null) return false;
|
|
||||||
}
|
|
||||||
else if (!ps.world.equals(derp.world)) return false;
|
|
||||||
if (ps.yaw == null)
|
|
||||||
{
|
|
||||||
if (derp.yaw != null) return false;
|
|
||||||
}
|
|
||||||
else if (!ps.yaw.equals(derp.yaw)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user