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;
|
// COMPARE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(PS derp)
|
||||||
|
{
|
||||||
|
return compareTo(this, derp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int compareTo(PS herp, Object derpObject)
|
||||||
|
{
|
||||||
|
if (herp == null && derpObject == null) return 0;
|
||||||
|
if (herp == null) return -1;
|
||||||
|
if (derpObject == null) return +1;
|
||||||
|
|
||||||
if (ps.blockX == null)
|
if (!(derpObject instanceof PS)) return -1;
|
||||||
{
|
PS derp = (PS) derpObject;
|
||||||
if (derp.blockX != null) return false;
|
|
||||||
}
|
int ret;
|
||||||
else if (!ps.blockX.equals(derp.blockX)) return false;
|
|
||||||
if (ps.blockY == null)
|
ret = MUtil.compare(herp.world, derp.world);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.blockY != null) return false;
|
|
||||||
}
|
ret = MUtil.compare(herp.chunkX, derp.chunkX);
|
||||||
else if (!ps.blockY.equals(derp.blockY)) return false;
|
if (ret != 0) return ret;
|
||||||
if (ps.blockZ == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.chunkZ, derp.chunkZ);
|
||||||
if (derp.blockZ != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.blockZ.equals(derp.blockZ)) return false;
|
ret = MUtil.compare(herp.blockX, derp.blockX);
|
||||||
if (ps.chunkX == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.chunkX != null) return false;
|
ret = MUtil.compare(herp.blockY, derp.blockY);
|
||||||
}
|
if (ret != 0) return ret;
|
||||||
else if (!ps.chunkX.equals(derp.chunkX)) return false;
|
|
||||||
if (ps.chunkZ == null)
|
ret = MUtil.compare(herp.blockZ, derp.blockZ);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.chunkZ != null) return false;
|
|
||||||
}
|
ret = MUtil.compare(herp.locationX, derp.locationX);
|
||||||
else if (!ps.chunkZ.equals(derp.chunkZ)) return false;
|
if (ret != 0) return ret;
|
||||||
if (ps.locationX == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.locationX, derp.locationX);
|
||||||
if (derp.locationX != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.locationX.equals(derp.locationX)) return false;
|
ret = MUtil.compare(herp.locationZ, derp.locationZ);
|
||||||
if (ps.locationY == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.locationY != null) return false;
|
ret = MUtil.compare(herp.pitch, derp.pitch);
|
||||||
}
|
if (ret != 0) return ret;
|
||||||
else if (!ps.locationY.equals(derp.locationY)) return false;
|
|
||||||
if (ps.locationZ == null)
|
ret = MUtil.compare(herp.yaw, derp.yaw);
|
||||||
{
|
if (ret != 0) return ret;
|
||||||
if (derp.locationZ != null) return false;
|
|
||||||
}
|
ret = MUtil.compare(herp.velocityX, derp.velocityX);
|
||||||
else if (!ps.locationZ.equals(derp.locationZ)) return false;
|
if (ret != 0) return ret;
|
||||||
if (ps.pitch == null)
|
|
||||||
{
|
ret = MUtil.compare(herp.velocityY, derp.velocityY);
|
||||||
if (derp.pitch != null) return false;
|
if (ret != 0) return ret;
|
||||||
}
|
|
||||||
else if (!ps.pitch.equals(derp.pitch)) return false;
|
ret = MUtil.compare(herp.velocityZ, derp.velocityZ);
|
||||||
if (ps.velocityX == null)
|
if (ret != 0) return ret;
|
||||||
{
|
|
||||||
if (derp.velocityX != null) return false;
|
return 0;
|
||||||
}
|
|
||||||
else if (!ps.velocityX.equals(derp.velocityX)) return false;
|
|
||||||
if (ps.velocityY == null)
|
|
||||||
{
|
|
||||||
if (derp.velocityY != null) return false;
|
|
||||||
}
|
|
||||||
else if (!ps.velocityY.equals(derp.velocityY)) return false;
|
|
||||||
if (ps.velocityZ == null)
|
|
||||||
{
|
|
||||||
if (derp.velocityZ != null) return false;
|
|
||||||
}
|
|
||||||
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