Making PS2 the defacto standard by renaming it to PS and fix issues that occurred.

This commit is contained in:
Olof Larsson 2013-03-12 20:13:10 +01:00
parent 3b0a3eff59
commit b324024c20
27 changed files with 285 additions and 1173 deletions

View File

@ -13,13 +13,12 @@ import org.bukkit.inventory.ItemStack;
import com.massivecraft.mcore.adapter.InventoryAdapter; import com.massivecraft.mcore.adapter.InventoryAdapter;
import com.massivecraft.mcore.adapter.ItemStackAdapter; import com.massivecraft.mcore.adapter.ItemStackAdapter;
import com.massivecraft.mcore.adapter.MongoURIAdapter; import com.massivecraft.mcore.adapter.MongoURIAdapter;
import com.massivecraft.mcore.adapter.PSAdapter;
import com.massivecraft.mcore.cmd.CmdMcore; import com.massivecraft.mcore.cmd.CmdMcore;
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures; import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
import com.massivecraft.mcore.mixin.ScheduledTeleportEngine; import com.massivecraft.mcore.mixin.ScheduledTeleportEngine;
import com.massivecraft.mcore.mixin.SenderIdMixinDefault; import com.massivecraft.mcore.mixin.SenderIdMixinDefault;
import com.massivecraft.mcore.ps.PS2; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PS2Adapter; import com.massivecraft.mcore.ps.PSAdapter;
import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Db; import com.massivecraft.mcore.store.Db;
import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.store.MStore;
@ -67,8 +66,7 @@ public class MCore extends MPlugin
.registerTypeAdapter(MongoURI.class, MongoURIAdapter.get()) .registerTypeAdapter(MongoURI.class, MongoURIAdapter.get())
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get()) .registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())
.registerTypeAdapter(Inventory.class, InventoryAdapter.get()) .registerTypeAdapter(Inventory.class, InventoryAdapter.get())
.registerTypeAdapter(PS.class, new PSAdapter()) .registerTypeAdapter(PS.class, PSAdapter.get());
.registerTypeAdapter(PS2.class, PS2Adapter.get());
} }
public static String getServerId() { return Conf.serverid; } public static String getServerId() { return Conf.serverid; }

View File

@ -1,848 +0,0 @@
package com.massivecraft.mcore;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.mixin.TeleportMixinDefault;
import com.massivecraft.mcore.mixin.TeleporterException;
import com.massivecraft.mcore.usys.Aspect;
import com.massivecraft.mcore.usys.Multiverse;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.Txt;
import com.massivecraft.mcore.xlib.gson.annotations.SerializedName;
/**
* PS stands for PhysicalState.
* This class stores data related to just that.
* When coding plugins you may find yourself wanting to store a player location.
* Another time you may want to store the player location but without the worldName info.
* Another time you may want to store pitch and yaw only.
* This class is supposed to be usable in all those cases.
* Hopefully this class will save you from implementing special classes for all those combinations.
*/
public class PS implements Cloneable, Serializable
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
private static final transient long serialVersionUID = 1L;
public static final transient String UNKNOWN_WORLD_NAME = "?";
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// Field: worldName
@SerializedName("w")
protected String worldName = null;
public String getWorldName() { return this.worldName; }
public void setWorldName(String worldName) { this.worldName = worldName; }
// FakeField: world
public World getWorld()
{
if (this.worldName == null) return null;
return Bukkit.getWorld(this.worldName);
}
public void setWorld(World val)
{
this.worldName = val.getName();
}
// ---------------------
// Field: blockX
@SerializedName("bx")
protected Integer blockX = null;
public Integer getBlockX() { return this.blockX; }
public void setBlockX(Integer blockX) { this.blockX = blockX; }
public Integer calcBlockX()
{
return calcBlock(this.locationX, this.blockX, this.chunkX);
}
// Field: blockY
@SerializedName("by")
protected Integer blockY = null;
public Integer getBlockY() { return this.blockY; }
public void setBlockY(Integer blockY) { this.blockY = blockY; }
public Integer calcBlockY()
{
return calcBlock(this.locationY, this.blockY, null);
}
// Field: blockZ
@SerializedName("bz")
protected Integer blockZ = null;
public Integer getBlockZ() { return this.blockZ; }
public void setBlockZ(Integer blockZ) { this.blockZ = blockZ; }
public Integer calcBlockZ()
{
return calcBlock(this.locationZ, this.blockZ, this.chunkZ);
}
protected static synchronized Integer calcBlock(Double location, Integer block, Integer chunk)
{
if (block != null) return block;
if (location != null) return (int) Math.floor(location);
if (chunk != null) return chunk * 16;
return null;
}
// ---------------------
// Field: locationX
@SerializedName("lx")
protected Double locationX = null;
public Double getLocationX() { return this.locationX; }
public void setLocationX(Double locationX) { this.locationX = locationX; }
public Double calcLocationX()
{
return calcLocation(this.locationX, this.blockX, this.chunkX);
}
// Field: locationY
@SerializedName("ly")
protected Double locationY = null;
public Double getLocationY() { return this.locationY; }
public void setLocationY(Double locationY) { this.locationY = locationY; }
public Double calcLocationY()
{
return calcLocation(this.locationY, this.blockY, null);
}
// Field: locationZ
@SerializedName("lz")
protected Double locationZ = null;
public Double getLocationZ() { return this.locationZ; }
public void setLocationZ(Double locationZ) { this.locationZ = locationZ; }
public Double calcLocationZ()
{
return calcLocation(this.locationZ, this.blockZ, this.chunkZ);
}
protected static synchronized Double calcLocation(Double location, Integer block, Integer chunk)
{
if (location != null) return location;
if (block != null) return (double) block;
if (chunk != null) return chunk * 16D;
return null;
}
// ---------------------
// Field: chunkX
@SerializedName("cx")
protected Integer chunkX = null;
public Integer getChunkX() { return this.chunkX; }
public void setChunkX(Integer chunkX) { this.chunkX = chunkX; }
public Integer calcChunkX()
{
return calcChunk(this.locationX, this.blockX, this.chunkX);
}
// Field: chunkZ
@SerializedName("cz")
protected Integer chunkZ = null;
public Integer getChunkZ() { return this.chunkZ; }
public void setChunkZ(Integer chunkZ) { this.chunkZ = chunkZ; }
public Integer calcChunkZ()
{
return calcChunk(this.locationZ, this.blockZ, this.chunkZ);
}
protected static synchronized Integer calcChunk(Double location, Integer block, Integer chunk)
{
if (chunk != null) return chunk;
if (location != null) return location.intValue() >> 4;
if (block != null) return block >> 4;
return null;
}
// ---------------------
// Field: pitch
@SerializedName("p")
protected Float pitch = null;
public Float getPitch() { return this.pitch; }
public void setPitch(Float pitch) { this.pitch = pitch; }
// Field: yaw
@SerializedName("y")
protected Float yaw = null;
public Float getYaw() { return this.yaw; }
public void setYaw(Float yaw) { this.yaw = yaw; }
// ---------------------
// Field: velocityX
@SerializedName("vx")
protected Double velocityX = null;
public Double getVelocityX() { return this.velocityX; }
public void setVelocityX(Double velocityX) { this.velocityX = velocityX; }
public Double calcVelocityX()
{
return calcVelocity(this.locationX, this.blockX, this.chunkX, this.velocityX);
}
// Field: velocityY
@SerializedName("vy")
protected Double velocityY = null;
public Double getVelocityY() { return this.velocityY; }
public void setVelocityY(Double velocityY) { this.velocityY = velocityY; }
public Double calcVelocityY()
{
return calcVelocity(this.locationY, this.blockY, 0, this.velocityY);
}
// Field: velocityZ
@SerializedName("vz")
protected Double velocityZ = null;
public Double getVelocityZ() { return this.velocityZ; }
public void setVelocityZ(Double velocityZ) { this.velocityZ = velocityZ; }
public Double calcVelocityZ()
{
return calcVelocity(this.locationZ, this.blockZ, this.chunkZ, this.velocityZ);
}
protected static synchronized Double calcVelocity(Double location, Integer block, Integer chunk, Double velocity)
{
if (velocity != null) return velocity;
if (location != null) return location;
if (block != null) return (double) block;
if (chunk != null) return chunk * 16D;
return null;
}
//----------------------------------------------//
// GET / CALC
//----------------------------------------------//
public synchronized Location getLocation()
{
return this.innerLocation(this.getLocationX(), this.getLocationY(), this.getLocationZ());
}
public synchronized Location calcLocation()
{
return this.innerLocation(this.calcLocationX(), this.calcLocationY(), this.calcLocationZ());
}
protected synchronized Location innerLocation(Double x, Double y, Double z)
{
World world = this.getWorld();
if (world == null) return null;
if (x == null) return null;
if (y == null) return null;
if (z == null) return null;
Float pitch = this.getPitch();
if (pitch == null) pitch = 0F;
Float yaw = this.getYaw();
if (yaw == null) yaw = 0F;
return new Location(world, x, y, z, yaw, pitch);
}
public synchronized Block getBlock()
{
return this.innerBlock(this.getBlockX(), this.getBlockY(), this.getBlockZ());
}
public synchronized Block calcBlock()
{
return this.innerBlock(this.calcBlockX(), this.calcBlockY(), this.calcBlockZ());
}
protected synchronized Block innerBlock(Integer x, Integer y, Integer z)
{
World world = this.getWorld();
if (world == null) return null;
if (x == null) return null;
if (y == null) return null;
if (z == null) return null;
return world.getBlockAt(x, y, z);
}
public synchronized Chunk getChunk()
{
return this.innerChunk(this.getChunkX(), this.getChunkZ());
}
public synchronized Chunk calcChunk()
{
return this.innerChunk(this.calcChunkX(), this.calcChunkZ());
}
protected synchronized Chunk innerChunk(Integer x, Integer z)
{
World world = this.getWorld();
if (world == null) return null;
if (x == null) return null;
if (z == null) return null;
return world.getChunkAt(x, z);
}
public synchronized Vector getVelocity()
{
return this.innerVelocity(this.getVelocityX(), this.getVelocityY(), this.getVelocityZ());
}
public synchronized Vector calcVelocity()
{
return this.innerVelocity(this.calcVelocityX(), this.calcVelocityY(), this.calcVelocityZ());
}
protected synchronized Vector innerVelocity(Double x, Double y, Double z)
{
if (x == null) return null;
if (y == null) return null;
if (z == null) return null;
return new Vector(x, y, z);
}
//----------------------------------------------//
// SET
//----------------------------------------------//
public synchronized void setDefault()
{
this.worldName = null;
this.blockX = null;
this.blockY = null;
this.blockZ = null;
this.locationX = null;
this.locationY = null;
this.locationZ = null;
this.chunkX = null;
this.chunkZ = null;
this.pitch = null;
this.yaw = null;
this.velocityX = null;
this.velocityY = null;
this.velocityZ = null;
}
public synchronized void setPSTransparent(PS ps)
{
if (ps.worldName != null) this.worldName = ps.worldName;
if (ps.blockX != null) this.blockX = ps.blockX;
if (ps.blockY != null) this.blockY = ps.blockY;
if (ps.blockZ != null) this.blockZ = ps.blockZ;
if (ps.locationX != null) this.locationX = ps.locationX;
if (ps.locationY != null) this.locationY = ps.locationY;
if (ps.locationZ != null) this.locationZ = ps.locationZ;
if (ps.chunkX != null) this.chunkX = ps.chunkX;
if (ps.chunkZ != null) this.chunkZ = ps.chunkZ;
if (ps.pitch != null) this.pitch = ps.pitch;
if (ps.yaw != null) this.yaw = ps.yaw;
if (ps.velocityX != null) this.velocityX = ps.velocityX;
if (ps.velocityY != null) this.velocityY = ps.velocityY;
if (ps.velocityZ != null) this.velocityZ = ps.velocityZ;
}
public synchronized void setPS(PS ps)
{
this.worldName = ps.worldName;
this.blockX = ps.blockX;
this.blockY = ps.blockY;
this.blockZ = ps.blockZ;
this.locationX = ps.locationX;
this.locationY = ps.locationY;
this.locationZ = ps.locationZ;
this.chunkX = ps.chunkX;
this.chunkZ = ps.chunkZ;
this.pitch = ps.pitch;
this.yaw = ps.yaw;
this.velocityX = ps.velocityX;
this.velocityY = ps.velocityY;
this.velocityZ = ps.velocityZ;
}
// ---------------------
public synchronized void setLocation(Location location)
{
this.setDefault();
this.setLocationTransparent(location);
}
public synchronized void setLocationTransparent(Location location)
{
this.worldName = location.getWorld().getName();
this.locationX = location.getX();
this.locationY = location.getY();
this.locationZ = location.getZ();
this.setPitch(location.getPitch());
this.yaw = location.getYaw();
}
// ---------------------
public synchronized void setVelocity(Vector vector)
{
this.setDefault();
this.setVelocityTransparent(vector);
}
public synchronized void setVelocityTransparent(Vector vector)
{
this.velocityX = vector.getX();
this.velocityY = vector.getY();
this.velocityZ = vector.getZ();
}
// ---------------------
public synchronized void setEntity(Entity entity)
{
this.setDefault();
this.setEntityTransparent(entity);
}
public synchronized void setEntityTransparent(Entity entity)
{
this.setLocationTransparent(entity.getLocation());
this.setVelocityTransparent(entity.getVelocity());
}
// ---------------------
public synchronized void setBlock(Block block)
{
this.setDefault();
this.setBlockTransparent(block);
}
public synchronized void setBlockTransparent(Block block)
{
this.worldName = block.getWorld().getName();
this.blockX = block.getX();
this.blockY = block.getY();
this.blockZ = block.getZ();
}
// ---------------------
public synchronized void setChunk(Chunk chunk)
{
this.setDefault();
this.setChunkTransparent(chunk);
}
public synchronized void setChunkTransparent(Chunk chunk)
{
this.worldName = chunk.getWorld().getName();
this.chunkX = chunk.getX();
this.chunkZ = chunk.getZ();
}
// ---------------------
public synchronized void setOldString(String str)
{
this.setDefault();
this.setOldStringTransparent(str);
}
public synchronized void setOldStringTransparent(String str)
{
String[] parts = str.split("\\|");
if (parts.length == 4)
{
this.worldName = parts[0];
this.blockX = Integer.parseInt(parts[1]);
this.blockY = Integer.parseInt(parts[2]);
this.blockZ = Integer.parseInt(parts[3]);
}
else if (parts.length == 6)
{
this.worldName = parts[0];
this.locationX = Double.parseDouble(parts[1]);
this.locationY = Double.parseDouble(parts[2]);
this.locationZ = Double.parseDouble(parts[3]);
this.pitch = Float.parseFloat(parts[4]);
this.yaw = Float.parseFloat(parts[5]);
}
}
//----------------------------------------------//
// WRITERS
//----------------------------------------------//
public synchronized void write(Entity entity) throws TeleporterException
{
if (entity instanceof Player)
{
Mixin.teleport((Player)entity, this);
}
else
{
TeleportMixinDefault.teleportEntity(entity, this);
}
}
//----------------------------------------------//
// CONSTRUCTORS
//----------------------------------------------//
public PS()
{
}
public PS(PS ps)
{
this.setPS(ps);
}
public PS(Location location)
{
this.setLocationTransparent(location);
}
public PS(Vector velocity)
{
this.setVelocityTransparent(velocity);
}
public PS(Entity entity)
{
this.setEntityTransparent(entity);
}
public PS(Block block)
{
this.setBlockTransparent(block);
}
public PS(Chunk chunk)
{
this.setChunkTransparent(chunk);
}
public PS(String oldString)
{
this.setOldStringTransparent(oldString);
}
//----------------------------------------------//
// TO STRING
//----------------------------------------------//
@Override
public synchronized String toString()
{
return this.getClass().getSimpleName()+MCore.gson.toJson(this);
}
protected final transient static DecimalFormat twoDForm = new DecimalFormat("#.##");
public List<String> getDesc()
{
// ret.add("<h>World <a>"+this.worldName);
return this.getDesc("<k>%s <v>%s");
}
public List<String> getDesc(String format)
{
List<String> ret = new ArrayList<String>();
if (this.worldName != null) ret.add(Txt.parse(format, "World", this.worldName));
if (this.blockX != null) ret.add(Txt.parse(format, "Block X", this.blockX));
if (this.blockY != null) ret.add(Txt.parse(format, "Block Y", this.blockY));
if (this.blockZ != null) ret.add(Txt.parse(format, "Block Z", this.blockZ));
if (this.locationX != null) ret.add(Txt.parse(format, "Location X", twoDForm.format(this.locationX)));
if (this.locationY != null) ret.add(Txt.parse(format, "Location Y", twoDForm.format(this.locationY)));
if (this.locationZ != null) ret.add(Txt.parse(format, "Location Z", twoDForm.format(this.locationZ)));
if (this.chunkX != null) ret.add(Txt.parse(format, "Chunk X", this.chunkX));
if (this.chunkZ != null) ret.add(Txt.parse(format, "Chunk Z", this.chunkZ));
if (this.pitch != null) ret.add(Txt.parse(format, "Pitch", twoDForm.format(this.pitch)));
if (this.yaw != null) ret.add(Txt.parse(format, "Yaw", twoDForm.format(this.yaw)));
if (this.velocityX != null) ret.add(Txt.parse(format, "Velocity X", twoDForm.format(this.velocityX)));
if (this.velocityY != null) ret.add(Txt.parse(format, "Velocity Y", twoDForm.format(this.velocityY)));
if (this.velocityZ != null) ret.add(Txt.parse(format, "Velocity Z", twoDForm.format(this.velocityZ)));
return ret;
}
public String getShortDesc()
{
return this.getShortDesc("<k>%s <v>%s ");
}
public String getShortDesc(String format)
{
List<String> ret = new ArrayList<String>();
if (this.worldName != null) ret.add(Txt.parse(format, "w", this.worldName));
if (this.blockX != null) ret.add(Txt.parse(format, "bx", this.blockX));
if (this.blockY != null) ret.add(Txt.parse(format, "by", this.blockY));
if (this.blockZ != null) ret.add(Txt.parse(format, "bz", this.blockZ));
if (this.locationX != null) ret.add(Txt.parse(format, "lx", twoDForm.format(this.locationX)));
if (this.locationY != null) ret.add(Txt.parse(format, "ly", twoDForm.format(this.locationY)));
if (this.locationZ != null) ret.add(Txt.parse(format, "lz", twoDForm.format(this.locationZ)));
if (this.chunkX != null) ret.add(Txt.parse(format, "cx", this.chunkX));
if (this.chunkZ != null) ret.add(Txt.parse(format, "cz", this.chunkZ));
if (this.pitch != null) ret.add(Txt.parse(format, "p", twoDForm.format(this.pitch)));
if (this.yaw != null) ret.add(Txt.parse(format, "y", twoDForm.format(this.yaw)));
if (this.velocityX != null) ret.add(Txt.parse(format, "vx", twoDForm.format(this.velocityX)));
if (this.velocityY != null) ret.add(Txt.parse(format, "vy", twoDForm.format(this.velocityY)));
if (this.velocityZ != null) ret.add(Txt.parse(format, "vz", twoDForm.format(this.velocityZ)));
return Txt.implode(ret, "").trim();
}
//----------------------------------------------//
// CLONE
//----------------------------------------------//
@Override
public PS clone()
{
return new PS(this);
}
//----------------------------------------------//
// EQUALS AND HASH CODE
//----------------------------------------------//
// Generated by eclipse
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((blockX == null) ? 0 : blockX.hashCode());
result = prime * result + ((blockY == null) ? 0 : blockY.hashCode());
result = prime * result + ((blockZ == null) ? 0 : blockZ.hashCode());
result = prime * result + ((chunkX == null) ? 0 : chunkX.hashCode());
result = prime * result + ((chunkZ == null) ? 0 : chunkZ.hashCode());
result = prime * result
+ ((locationX == null) ? 0 : locationX.hashCode());
result = prime * result
+ ((locationY == null) ? 0 : locationY.hashCode());
result = prime * result
+ ((locationZ == null) ? 0 : locationZ.hashCode());
result = prime * result + ((pitch == null) ? 0 : pitch.hashCode());
result = prime * result
+ ((velocityX == null) ? 0 : velocityX.hashCode());
result = prime * result
+ ((velocityY == null) ? 0 : velocityY.hashCode());
result = prime * result
+ ((velocityZ == null) ? 0 : velocityZ.hashCode());
result = prime * result
+ ((worldName == null) ? 0 : worldName.hashCode());
result = prime * result + ((yaw == null) ? 0 : yaw.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
PS other = (PS) obj;
if (blockX == null)
{
if (other.blockX != null) return false;
}
else if (!blockX.equals(other.blockX)) return false;
if (blockY == null)
{
if (other.blockY != null) return false;
}
else if (!blockY.equals(other.blockY)) return false;
if (blockZ == null)
{
if (other.blockZ != null) return false;
}
else if (!blockZ.equals(other.blockZ)) return false;
if (chunkX == null)
{
if (other.chunkX != null) return false;
}
else if (!chunkX.equals(other.chunkX)) return false;
if (chunkZ == null)
{
if (other.chunkZ != null) return false;
}
else if (!chunkZ.equals(other.chunkZ)) return false;
if (locationX == null)
{
if (other.locationX != null) return false;
}
else if (!locationX.equals(other.locationX)) return false;
if (locationY == null)
{
if (other.locationY != null) return false;
}
else if (!locationY.equals(other.locationY)) return false;
if (locationZ == null)
{
if (other.locationZ != null) return false;
}
else if (!locationZ.equals(other.locationZ)) return false;
if (pitch == null)
{
if (other.pitch != null) return false;
}
else if (!pitch.equals(other.pitch)) return false;
if (velocityX == null)
{
if (other.velocityX != null) return false;
}
else if (!velocityX.equals(other.velocityX)) return false;
if (velocityY == null)
{
if (other.velocityY != null) return false;
}
else if (!velocityY.equals(other.velocityY)) return false;
if (velocityZ == null)
{
if (other.velocityZ != null) return false;
}
else if (!velocityZ.equals(other.velocityZ)) return false;
if (worldName == null)
{
if (other.worldName != null) return false;
}
else if (!worldName.equals(other.worldName)) return false;
if (yaw == null)
{
if (other.yaw != null) return false;
}
else if (!yaw.equals(other.yaw)) return false;
return true;
}
//----------------------------------------------//
// STATIC COMPARISON TOOLS
//----------------------------------------------//
public static Double locationDistanceSquared(PS one, PS two)
{
if (one == null) return null;
if (two == null) return null;
String w1 = one.getWorldName();
String w2 = two.getWorldName();
if (!MUtil.equals(w1, w2)) return null;
Double x1 = one.calcLocationX();
if (x1 == null) return null;
Double y1 = one.calcLocationY();
if (y1 == null) return null;
Double z1 = one.calcLocationZ();
if (z1 == null) return null;
Double x2 = two.calcLocationX();
if (x2 == null) return null;
Double y2 = two.calcLocationY();
if (y2 == null) return null;
Double z2 = two.calcLocationZ();
if (z2 == null) return null;
return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2);
}
public static Double locationDistance(PS one, PS two)
{
Double ret = locationDistanceSquared(one, two);
if (ret == null) return null;
return Math.sqrt(ret);
}
public static boolean inSameWorld(PS one, PS two)
{
if (one == null) return false;
if (two == null) return false;
String w1 = one.getWorldName();
String w2 = two.getWorldName();
if (w1 == null) return false;
if (w2 == null) return false;
return w1.equalsIgnoreCase(w2);
}
public static boolean inSameUniverse(PS one, PS two, Multiverse multiverse)
{
if (one == null) return false;
if (two == null) return false;
String w1 = one.getWorldName();
String w2 = two.getWorldName();
if (w1 == null) return false;
if (w2 == null) return false;
String m1 = multiverse.getUniverseForWorldName(w1);
String m2 = multiverse.getUniverseForWorldName(w2);
return m1.equalsIgnoreCase(m2);
}
public static boolean inSameUniverse(PS one, PS two, Aspect aspect)
{
return inSameUniverse(one, two, aspect.multiverse());
}
}

View File

@ -1,51 +0,0 @@
package com.massivecraft.mcore.adapter;
import java.lang.reflect.Type;
import com.massivecraft.mcore.PS;
import com.massivecraft.mcore.xlib.gson.Gson;
import com.massivecraft.mcore.xlib.gson.JsonDeserializationContext;
import com.massivecraft.mcore.xlib.gson.JsonDeserializer;
import com.massivecraft.mcore.xlib.gson.JsonElement;
import com.massivecraft.mcore.xlib.gson.JsonParseException;
import com.massivecraft.mcore.xlib.gson.JsonPrimitive;
import com.massivecraft.mcore.xlib.mongodb.MongoURI;
public class PSAdapter implements JsonDeserializer<PS>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public PS deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
if (json.isJsonPrimitive())
{
return new PS(json.getAsString());
}
return new Gson().fromJson(json, typeOfT);
}
// -------------------------------------------- //
// STATIC LOGIC
// -------------------------------------------- //
public static JsonElement serialize(MongoURI mongoURI)
{
return new JsonPrimitive(mongoURI.toString());
}
public static MongoURI deserialize(JsonElement json)
{
return new MongoURI(json.getAsString());
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
public static PSAdapter i = new PSAdapter();
public static PSAdapter get() { return i; }
}

View File

@ -5,7 +5,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Runnable public class MCorePlayerPSTeleportEvent extends Event implements Cancellable, Runnable
{ {

View File

@ -10,9 +10,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.PS;
import com.massivecraft.mcore.Predictate; import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent; import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore.ps.PS;
public class Mixin public class Mixin
{ {

View File

@ -1,6 +1,6 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public class ScheduledTeleport implements Runnable public class ScheduledTeleport implements Runnable
{ {

View File

@ -1,6 +1,6 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public interface SenderPsMixin public interface SenderPsMixin
{ {

View File

@ -3,7 +3,7 @@ package com.massivecraft.mcore.mixin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public class SenderPsMixinDefault extends SenderPsMixinAbstract public class SenderPsMixinDefault extends SenderPsMixinAbstract
{ {
@ -23,7 +23,7 @@ public class SenderPsMixinDefault extends SenderPsMixinAbstract
{ {
Player player = Bukkit.getPlayerExact(senderId); Player player = Bukkit.getPlayerExact(senderId);
if (player == null) return null; if (player == null) return null;
return new PS(player.getLocation()); return PS.valueOf(player.getLocation());
} }
@Override @Override

View File

@ -3,7 +3,7 @@ package com.massivecraft.mcore.mixin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public interface TeleportMixin public interface TeleportMixin
{ {

View File

@ -4,7 +4,7 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.Conf; import com.massivecraft.mcore.Conf;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SenderUtil;
public abstract class TeleportMixinAbstract implements TeleportMixin public abstract class TeleportMixinAbstract implements TeleportMixin

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.massivecraft.mcore.PS;
import com.massivecraft.mcore.event.MCorePlayerPSTeleportEvent; import com.massivecraft.mcore.event.MCorePlayerPSTeleportEvent;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SenderUtil;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
@ -25,22 +25,33 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
public static void teleportEntity(Entity entity, PS ps) throws TeleporterException public static void teleportEntity(Entity entity, PS ps) throws TeleporterException
{ {
ps = ps.clone(); // Base the PS location on the entity location
ps = ps.getEntity(true);
ps = PS.valueOf(entity.getLocation()).with(ps);
// Ensure the ps has a world name // Bukkit Location
if (ps.getWorldName() == null) Location location = null;
try
{ {
ps.setWorldName(entity.getWorld().getName()); location = ps.asBukkitLocation();
}
catch (Exception e)
{
throw new TeleporterException(Txt.parse("<b>Could not calculate the location: %s", e.getMessage()));
} }
Location location = ps.calcLocation();
if (location == null) throw new TeleporterException(Txt.parse("<b>Could not calculate the location."));
entity.teleport(location); entity.teleport(location);
Vector velocity = ps.getVelocity(); // Bukkit velocity
if (velocity == null) return; Vector velocity = null;
try
{
velocity = ps.asBukkitVelocity();
}
catch (Exception e)
{
return;
}
entity.setVelocity(velocity); entity.setVelocity(velocity);
} }
@ -72,11 +83,11 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
// Without delay AKA "now"/"at once" // Without delay AKA "now"/"at once"
// Run event // Run event
MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleporteeId, Mixin.getSenderPs(teleporteeId), destinationPs.clone()); MCorePlayerPSTeleportEvent event = new MCorePlayerPSTeleportEvent(teleporteeId, Mixin.getSenderPs(teleporteeId), destinationPs);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (event.getTo() == null) return; if (event.getTo() == null) return;
destinationPs = event.getTo().clone(); destinationPs = event.getTo();
if (destinationDesc != null) if (destinationDesc != null)
{ {
@ -90,7 +101,7 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
} }
else else
{ {
Mixin.setSenderPs(teleporteeId, destinationPs.clone()); Mixin.setSenderPs(teleporteeId, destinationPs);
} }
} }
} }

View File

@ -6,7 +6,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
public interface WorldMixin public interface WorldMixin
{ {

View File

@ -10,7 +10,8 @@ import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PSFormatDesc;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
public class WorldMixinDefault extends WorldMixinAbstract public class WorldMixinDefault extends WorldMixinAbstract
@ -60,7 +61,7 @@ public class WorldMixinDefault extends WorldMixinAbstract
{ {
World world = Bukkit.getWorld(worldId); World world = Bukkit.getWorld(worldId);
if (world == null) return null; if (world == null) return null;
return new PS(world.getSpawnLocation()); return PS.valueOf(world.getSpawnLocation());
} }
@Override @Override
@ -69,10 +70,17 @@ 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.clone(); spawnPs = spawnPs.withWorld(world);
spawnPs.setWorldName(worldId);
Location location = spawnPs.calcLocation(); Location location = null;
if (location == null) return; try
{
location = spawnPs.asBukkitLocation(true);
}
catch (Exception e)
{
return;
}
world.setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); world.setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());
} }
@ -93,8 +101,8 @@ public class WorldMixinDefault extends WorldMixinAbstract
// Pre Calculations // Pre Calculations
String worldDisplayName = Mixin.getWorldDisplayName(worldId); String worldDisplayName = Mixin.getWorldDisplayName(worldId);
PS current = this.getWorldSpawnPs(worldId); PS current = this.getWorldSpawnPs(worldId);
String currentFormatted = current.getShortDesc(); String currentFormatted = current.toString(PSFormatDesc.get());
String goalFormatted = goal.getShortDesc(); String goalFormatted = goal.toString(PSFormatDesc.get());
// No change? // No change?
if (MUtil.equals(goal, current)) if (MUtil.equals(goal, current))

View File

@ -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 PS2 implements Cloneable, Serializable public final class PS implements Serializable
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS // CONSTANTS
@ -103,7 +103,7 @@ public final class PS2 implements Cloneable, Serializable
// STANDARD INSTANCES // STANDARD INSTANCES
// -------------------------------------------- // // -------------------------------------------- //
public static final transient PS2 NULL = new PS2(null, null, null, null, null, null, null, null, null, null, null, null, null, null); public static final transient PS NULL = new PS(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS: RAW // FIELDS: RAW
@ -169,25 +169,25 @@ public final class PS2 implements Cloneable, Serializable
// FIELDS: WITH // FIELDS: WITH
// -------------------------------------------- // // -------------------------------------------- //
public PS2 withWorld(String world) { return new PS2(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 PS2 withWorld(World world) { return new PS2(calcWorldName(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 PS2 withBlockX(Integer blockX) { return new PS2(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 PS2 withBlockY(Integer blockY) { return new PS2(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 PS2 withBlockZ(Integer blockZ) { return new PS2(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 PS2 withLocationX(Double locationX) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withLocationX(Double locationX) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withLocationY(Double locationY) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withLocationY(Double locationY) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withLocationZ(Double locationZ) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withLocationZ(Double locationZ) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withChunkX(Integer chunkX) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withChunkX(Integer chunkX) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withChunkZ(Integer chunkZ) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withChunkZ(Integer chunkZ) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withPitch(Float pitch) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withPitch(Float pitch) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withYaw(Float yaw) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withYaw(Float yaw) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withVelocityX(Double velocityX) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withVelocityX(Double velocityX) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withVelocityY(Double velocityY) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withVelocityY(Double velocityY) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 withVelocityZ(Double velocityZ) { return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); } public PS withVelocityZ(Double velocityZ) { return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); }
public PS2 with(PS2 ps) public PS with(PS ps)
{ {
PS2Builder builder = this.builder(); PSBuilder builder = this.builder();
if (ps.getWorld() != null) builder.world(ps.getWorld()); if (ps.getWorld() != null) builder.world(ps.getWorld());
if (ps.getBlockX() != null) builder.blockX(ps.getBlockX()); if (ps.getBlockX() != null) builder.blockX(ps.getBlockX());
@ -211,7 +211,7 @@ public final class PS2 implements Cloneable, Serializable
// PRIVATE CONSTRUCTOR // PRIVATE CONSTRUCTOR
// -------------------------------------------- // // -------------------------------------------- //
private PS2(String worldName, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ) private PS(String worldName, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ)
{ {
this.world = worldName; this.world = worldName;
this.blockX = blockX; this.blockX = blockX;
@ -233,21 +233,21 @@ public final class PS2 implements Cloneable, Serializable
// BUILDER // BUILDER
// -------------------------------------------- // // -------------------------------------------- //
public PS2Builder builder() public PSBuilder builder()
{ {
return new PS2Builder(this); return new PSBuilder(this);
} }
// -------------------------------------------- // // -------------------------------------------- //
// FACTORY: VALUE OF // FACTORY: VALUE OF
// -------------------------------------------- // // -------------------------------------------- //
public static PS2 valueOf(String world, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ) public static PS valueOf(String world, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ)
{ {
return new PS2(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); return new PS(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ);
} }
public static PS2 valueOf(Location location) public static PS valueOf(Location location)
{ {
if (location == null) return null; if (location == null) return null;
String world = calcWorldName(location.getWorld()); String world = calcWorldName(location.getWorld());
@ -259,7 +259,7 @@ public final class PS2 implements Cloneable, Serializable
return valueOf(world, null, null, null, locationX, locationY, locationZ, null, null, pitch, yaw, null, null, null); return valueOf(world, null, null, null, locationX, locationY, locationZ, null, null, pitch, yaw, null, null, null);
} }
public static PS2 valueOf(Vector velocity) public static PS valueOf(Vector velocity)
{ {
if (velocity == null) return null; if (velocity == null) return null;
Double velocityX = velocity.getX(); Double velocityX = velocity.getX();
@ -268,7 +268,7 @@ public final class PS2 implements Cloneable, Serializable
return valueOf(null, null, null, null, null, null, null, null, null, null, null, velocityX, velocityY, velocityZ); return valueOf(null, null, null, null, null, null, null, null, null, null, null, velocityX, velocityY, velocityZ);
} }
public static PS2 valueOf(Entity entity) public static PS valueOf(Entity entity)
{ {
if (entity == null) return null; if (entity == null) return null;
@ -288,7 +288,7 @@ public final class PS2 implements Cloneable, Serializable
return valueOf(world, null, null, null, locationX, locationY, locationZ, null, null, pitch, yaw, velocityX, velocityY, velocityZ); return valueOf(world, null, null, null, locationX, locationY, locationZ, null, null, pitch, yaw, velocityX, velocityY, velocityZ);
} }
public static PS2 valueOf(Block block) public static PS valueOf(Block block)
{ {
if (block == null) return null; if (block == null) return null;
String world = calcWorldName(block.getWorld()); String world = calcWorldName(block.getWorld());
@ -298,7 +298,7 @@ public final class PS2 implements Cloneable, Serializable
return valueOf(world, blockX, blockY, blockZ, null, null, null, null, null, null, null, null, null, null); return valueOf(world, blockX, blockY, blockZ, null, null, null, null, null, null, null, null, null, null);
} }
public static PS2 valueOf(Chunk chunk) public static PS valueOf(Chunk chunk)
{ {
if (chunk == null) return null; if (chunk == null) return null;
String world = calcWorldName(chunk.getWorld()); String world = calcWorldName(chunk.getWorld());
@ -307,13 +307,13 @@ public final class PS2 implements Cloneable, Serializable
return valueOf(world, null, null, null, null, null, null, chunkX, chunkZ, null, null, null, null, null); return valueOf(world, null, null, null, null, null, null, chunkX, chunkZ, null, null, null, null, null);
} }
public static PS2 valueOf(final JsonElement jsonElement) public static PS valueOf(final JsonElement jsonElement)
{ {
if (jsonElement == null) return null; if (jsonElement == null) return null;
if (jsonElement.isJsonNull()) return null; if (jsonElement.isJsonNull()) return null;
final JsonObject jsonObject = jsonElement.getAsJsonObject(); final JsonObject jsonObject = jsonElement.getAsJsonObject();
final PS2Builder builder = new PS2Builder(); final PSBuilder builder = new PSBuilder();
for (Entry<String, JsonElement> entry : jsonObject.entrySet()) for (Entry<String, JsonElement> entry : jsonObject.entrySet())
{ {
final String key = entry.getKey(); final String key = entry.getKey();
@ -438,58 +438,58 @@ public final class PS2 implements Cloneable, Serializable
// GET FIELD GROUPS // GET FIELD GROUPS
// -------------------------------------------- // // -------------------------------------------- //
public PS2 getVelocity() { return this.getVelocity(false); } public PS getVelocity() { return this.getVelocity(false); }
public PS2 getVelocity(boolean calc) public PS getVelocity(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.velocityX(this.getVelocityX(calc)) .velocityX(this.getVelocityX(calc))
.velocityY(this.getVelocityY(calc)) .velocityY(this.getVelocityY(calc))
.velocityZ(this.getVelocityZ(calc)) .velocityZ(this.getVelocityZ(calc))
.build(); .build();
} }
public PS2 getBlockCoords() { return this.getBlockCoords(false); } public PS getBlockCoords() { return this.getBlockCoords(false); }
public PS2 getBlockCoords(boolean calc) public PS getBlockCoords(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.blockX(this.getBlockX(calc)) .blockX(this.getBlockX(calc))
.blockY(this.getBlockY(calc)) .blockY(this.getBlockY(calc))
.blockZ(this.getBlockZ(calc)) .blockZ(this.getBlockZ(calc))
.build(); .build();
} }
public PS2 getLocationCoords() { return this.getLocationCoords(false); } public PS getLocationCoords() { return this.getLocationCoords(false); }
public PS2 getLocationCoords(boolean calc) public PS getLocationCoords(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.locationX(this.getLocationX(calc)) .locationX(this.getLocationX(calc))
.locationY(this.getLocationY(calc)) .locationY(this.getLocationY(calc))
.locationZ(this.getLocationZ(calc)) .locationZ(this.getLocationZ(calc))
.build(); .build();
} }
public PS2 getChunkCoords() { return this.getChunkCoords(false); } public PS getChunkCoords() { return this.getChunkCoords(false); }
public PS2 getChunkCoords(boolean calc) public PS getChunkCoords(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.chunkX(this.getChunkX(calc)) .chunkX(this.getChunkX(calc))
.chunkZ(this.getChunkZ(calc)) .chunkZ(this.getChunkZ(calc))
.build(); .build();
} }
public PS2 getHead() { return this.getHead(false); } public PS getHead() { return this.getHead(false); }
public PS2 getHead(boolean calc) public PS getHead(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.pitch(this.getPitch(calc)) .pitch(this.getPitch(calc))
.yaw(this.getYaw(calc)) .yaw(this.getYaw(calc))
.build(); .build();
} }
public PS2 getBlock() { return this.getBlock(false); } public PS getBlock() { return this.getBlock(false); }
public PS2 getBlock(boolean calc) public PS getBlock(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.world(this.getWorld(calc)) .world(this.getWorld(calc))
.blockX(this.getBlockX(calc)) .blockX(this.getBlockX(calc))
.blockY(this.getBlockY(calc)) .blockY(this.getBlockY(calc))
@ -497,10 +497,10 @@ public final class PS2 implements Cloneable, Serializable
.build(); .build();
} }
public PS2 getLocation() { return this.getLocation(false); } public PS getLocation() { return this.getLocation(false); }
public PS2 getLocation(boolean calc) public PS getLocation(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.world(this.getWorld(calc)) .world(this.getWorld(calc))
.locationX(this.getLocationX(calc)) .locationX(this.getLocationX(calc))
.locationY(this.getLocationY(calc)) .locationY(this.getLocationY(calc))
@ -510,29 +510,29 @@ public final class PS2 implements Cloneable, Serializable
.build(); .build();
} }
public PS2 getChunk() { return this.getChunk(false); } public PS getChunk() { return this.getChunk(false); }
public PS2 getChunk(boolean calc) public PS getChunk(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.world(this.getWorld(calc)) .world(this.getWorld(calc))
.chunkX(this.getChunkX(calc)) .chunkX(this.getChunkX(calc))
.chunkZ(this.getChunkZ(calc)) .chunkZ(this.getChunkZ(calc))
.build(); .build();
} }
public PS2 getEntity() { return this.getEntity(false); } public PS getEntity() { return this.getEntity(false); }
public PS2 getEntity(boolean calc) public PS getEntity(boolean calc)
{ {
return new PS2Builder() return new PSBuilder()
.world(this.getWorld(calc)) .world(this.getWorld(calc))
.locationX(this.getLocationX(calc)) .locationX(this.getLocationX(calc))
.locationY(this.getLocationY(calc)) .locationY(this.getLocationY(calc))
.locationZ(this.getLocationZ(calc)) .locationZ(this.getLocationZ(calc))
.pitch(this.getPitch(calc)) .pitch(this.getPitch(calc))
.yaw(this.getYaw(calc)) .yaw(this.getYaw(calc))
.velocityX(this.getVelocityX(calc)) .velocityX(this.getVelocityX(false))
.velocityY(this.getVelocityY(calc)) .velocityY(this.getVelocityY(false))
.velocityZ(this.getVelocityZ(calc)) .velocityZ(this.getVelocityZ(false))
.build(); .build();
} }
@ -563,7 +563,7 @@ public final class PS2 implements Cloneable, Serializable
return ret; return ret;
} }
public static Block asBukkitBlock(PS2 ps) throws IllegalStateException public static Block asBukkitBlock(PS ps) throws IllegalStateException
{ {
World world = ps.asBukkitWorld(); World world = ps.asBukkitWorld();
@ -579,7 +579,7 @@ public final class PS2 implements Cloneable, Serializable
return world.getBlockAt(blockX, blockY, blockZ); return world.getBlockAt(blockX, blockY, blockZ);
} }
public static Location asBukkitLocation(PS2 ps) throws IllegalStateException public static Location asBukkitLocation(PS ps) throws IllegalStateException
{ {
World world = ps.asBukkitWorld(); World world = ps.asBukkitWorld();
@ -601,7 +601,7 @@ public final class PS2 implements Cloneable, Serializable
return new Location(world, locationX, locationY, locationZ, yaw, pitch); return new Location(world, locationX, locationY, locationZ, yaw, pitch);
} }
public static Chunk asBukkitChunk(PS2 ps) throws IllegalStateException public static Chunk asBukkitChunk(PS ps) throws IllegalStateException
{ {
World world = ps.asBukkitWorld(); World world = ps.asBukkitWorld();
@ -614,7 +614,7 @@ public final class PS2 implements Cloneable, Serializable
return world.getChunkAt(chunkX, chunkZ); return world.getChunkAt(chunkX, chunkZ);
} }
public static Vector asBukkitVelocity(PS2 ps) throws IllegalStateException public static Vector asBukkitVelocity(PS ps) throws IllegalStateException
{ {
Double velocityX = ps.getVelocityX(); Double velocityX = ps.getVelocityX();
if (velocityX == null) throw new IllegalStateException(NAME_FULL_VELOCITYX + SPACE_WASNT_SET); if (velocityX == null) throw new IllegalStateException(NAME_FULL_VELOCITYX + SPACE_WASNT_SET);
@ -632,7 +632,6 @@ public final class PS2 implements Cloneable, Serializable
// ASSORTED // ASSORTED
// -------------------------------------------- // // -------------------------------------------- //
// TODO: Malplaced?
public static String calcWorldName(World world) public static String calcWorldName(World world)
{ {
if (world == null) return null; if (world == null) return null;
@ -643,25 +642,18 @@ public final class PS2 implements Cloneable, Serializable
// TO STRING // TO STRING
// -------------------------------------------- // // -------------------------------------------- //
// TODO: Remove this alias!
public String getShortDesc()
{
return this.toString(PS2FormatDesc.get());
}
@Override @Override
public String toString() public String toString()
{ {
return this.toString(PS2FormatFormal.get()); return this.toString(PSFormatFormal.get());
} }
public String toString(PS2Format format) public String toString(PSFormat format)
{ {
return format.format(this); return format.format(this);
} }
public static String toString(PS2 ps, PS2Format format) public static String toString(PS ps, PSFormat format)
{ {
return format.format(ps); return format.format(ps);
} }
@ -670,7 +662,7 @@ public final class PS2 implements Cloneable, Serializable
// PARTIAL COMPARES // PARTIAL COMPARES
// -------------------------------------------- // // -------------------------------------------- //
public static Double locationDistanceSquared(PS2 one, PS2 two) public static Double locationDistanceSquared(PS one, PS two)
{ {
if (one == null) return null; if (one == null) return null;
if (two == null) return null; if (two == null) return null;
@ -701,14 +693,14 @@ public final class PS2 implements Cloneable, Serializable
return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2); return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) + Math.pow(z1 - z2, 2);
} }
public static Double locationDistance(PS2 one, PS2 two) public static Double locationDistance(PS one, PS two)
{ {
Double ret = locationDistanceSquared(one, two); Double ret = locationDistanceSquared(one, two);
if (ret == null) return null; if (ret == null) return null;
return Math.sqrt(ret); return Math.sqrt(ret);
} }
public static boolean inSameWorld(PS2 one, PS2 two) public static boolean inSameWorld(PS one, PS two)
{ {
if (one == null) return false; if (one == null) return false;
if (two == null) return false; if (two == null) return false;
@ -722,7 +714,7 @@ public final class PS2 implements Cloneable, Serializable
return w1.equalsIgnoreCase(w2); return w1.equalsIgnoreCase(w2);
} }
public static boolean inSameUniverse(PS2 one, PS2 two, Multiverse multiverse) public static boolean inSameUniverse(PS one, PS two, Multiverse multiverse)
{ {
if (one == null) return false; if (one == null) return false;
if (two == null) return false; if (two == null) return false;
@ -739,7 +731,7 @@ public final class PS2 implements Cloneable, Serializable
return m1.equalsIgnoreCase(m2); return m1.equalsIgnoreCase(m2);
} }
public static boolean inSameUniverse(PS2 one, PS2 two, Aspect aspect) public static boolean inSameUniverse(PS one, PS two, Aspect aspect)
{ {
return inSameUniverse(one, two, aspect.multiverse()); return inSameUniverse(one, two, aspect.multiverse());
} }
@ -764,10 +756,10 @@ public final class PS2 implements Cloneable, Serializable
public int calcHashCode() public int calcHashCode()
{ {
return PS2.calcHashCode(this); return PS.calcHashCode(this);
} }
public static int calcHashCode(PS2 ps) public static int calcHashCode(PS ps)
{ {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
@ -795,16 +787,16 @@ public final class PS2 implements Cloneable, Serializable
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
return PS2.equals(this, obj); return PS.equals(this, obj);
} }
public static boolean equals(PS2 ps, Object obj) public static boolean equals(PS ps, Object obj)
{ {
if (ps == obj) return true; if (ps == obj) return true;
if (ps == null) return false; if (ps == null) return false;
if (obj == null) return false; if (obj == null) return false;
if (!(obj instanceof PS2)) return false; if (!(obj instanceof PS)) return false;
PS2 derp = (PS2) obj; PS derp = (PS) obj;
if (ps.blockX == null) if (ps.blockX == null)
{ {
@ -882,11 +874,11 @@ public final class PS2 implements Cloneable, Serializable
// -------------------------------------------- // // -------------------------------------------- //
// CLONE // CLONE
// -------------------------------------------- // // -------------------------------------------- //
/*
@Override @Override
protected PS2 clone() public PS clone()
{ {
return this; return this;
} }*/
} }

View File

@ -1,6 +0,0 @@
package com.massivecraft.mcore.ps;
public interface PS2Format
{
public String format(PS2 ps);
}

View File

@ -1,36 +0,0 @@
package com.massivecraft.mcore.ps;
import com.massivecraft.mcore.util.Txt;
public class PS2FormatDesc extends PS2FormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PS2FormatDesc i = new PS2FormatDesc();
public static PS2FormatDesc get() { return i; }
private PS2FormatDesc()
{
super(
Txt.parse("<silver><em>NULL"),
"",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_WORLD + Txt.parse(" <v>") + "%s",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKX + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKY + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKZ + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONX + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONY + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONZ + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_CHUNKX + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_CHUNKZ + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_PITCH + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_YAW + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYX + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYY + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYZ + Txt.parse(" <v>") + "%.2f",
" ",
""
);
}
}

View File

@ -1,34 +0,0 @@
package com.massivecraft.mcore.ps;
public class PS2FormatFormal extends PS2FormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PS2FormatFormal i = new PS2FormatFormal();
public static PS2FormatFormal get() { return i; }
private PS2FormatFormal()
{
super(
"PS{NULL}",
"PS{",
PS2.NAME_SERIALIZED_WORLD + ": %s",
PS2.NAME_SERIALIZED_BLOCKX + ": %d",
PS2.NAME_SERIALIZED_BLOCKY + ": %d",
PS2.NAME_SERIALIZED_BLOCKZ + ": %d",
PS2.NAME_SERIALIZED_LOCATIONX + ": %.2f",
PS2.NAME_SERIALIZED_LOCATIONY + ": %.2f",
PS2.NAME_SERIALIZED_LOCATIONZ + ": %.2f",
PS2.NAME_SERIALIZED_CHUNKX + ": %d",
PS2.NAME_SERIALIZED_CHUNKZ + ": %d",
PS2.NAME_SERIALIZED_PITCH + ": %.2f",
PS2.NAME_SERIALIZED_YAW + ": %.2f",
PS2.NAME_SERIALIZED_VELOCITYX + ": %.2f",
PS2.NAME_SERIALIZED_VELOCITYY + ": %.2f",
PS2.NAME_SERIALIZED_VELOCITYZ + ": %.2f",
", ",
"}"
);
}
}

View File

@ -1,36 +0,0 @@
package com.massivecraft.mcore.ps;
import com.massivecraft.mcore.util.Txt;
public class PS2FormatSlug extends PS2FormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PS2FormatSlug i = new PS2FormatSlug();
public static PS2FormatSlug get() { return i; }
private PS2FormatSlug()
{
super(
Txt.parse("<silver><em>NULL"),
"",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_WORLD + Txt.parse("<v>") + "%s",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKX + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKY + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_BLOCKZ + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONX + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONY + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_LOCATIONZ + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_CHUNKX + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_CHUNKZ + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_PITCH + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_YAW + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYX + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYY + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS2.NAME_SERIALIZED_VELOCITYZ + Txt.parse("<v>") + "%.2f",
"",
""
);
}
}

View File

@ -7,22 +7,22 @@ import com.massivecraft.mcore.xlib.gson.JsonDeserializer;
import com.massivecraft.mcore.xlib.gson.JsonElement; import com.massivecraft.mcore.xlib.gson.JsonElement;
import com.massivecraft.mcore.xlib.gson.JsonParseException; import com.massivecraft.mcore.xlib.gson.JsonParseException;
public class PS2Adapter implements JsonDeserializer<PS2> public class PSAdapter implements JsonDeserializer<PS>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static PS2Adapter i = new PS2Adapter(); private static PSAdapter i = new PSAdapter();
public static PS2Adapter get() { return i; } public static PSAdapter get() { return i; }
private PS2Adapter() {} private PSAdapter() {}
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public PS2 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException public PS deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{ {
return deserialize(json); return deserialize(json);
} }
@ -31,9 +31,9 @@ public class PS2Adapter implements JsonDeserializer<PS2>
// STATIC LOGIC // STATIC LOGIC
// -------------------------------------------- // // -------------------------------------------- //
public static PS2 deserialize(JsonElement json) public static PS deserialize(JsonElement json)
{ {
return PS2.valueOf(json); return PS.valueOf(json);
} }
} }

View File

@ -2,7 +2,7 @@ package com.massivecraft.mcore.ps;
import org.bukkit.World; import org.bukkit.World;
public class PS2Builder public class PSBuilder
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -10,66 +10,66 @@ public class PS2Builder
private String world = null; private String world = null;
public String world() { return this.world; } public String world() { return this.world; }
public PS2Builder world(String worldName) { this.world = worldName; return this; } public PSBuilder world(String worldName) { this.world = worldName; return this; }
public PS2Builder world(World world) { this.world = PS2.calcWorldName(world); return this; } public PSBuilder world(World world) { this.world = PS.calcWorldName(world); return this; }
private Integer blockX = null; private Integer blockX = null;
public Integer blockX() { return this.blockX; } public Integer blockX() { return this.blockX; }
public PS2Builder blockX(Integer blockX) { this.blockX = blockX; return this; } public PSBuilder blockX(Integer blockX) { this.blockX = blockX; return this; }
private Integer blockY = null; private Integer blockY = null;
public Integer blockY() { return this.blockY; } public Integer blockY() { return this.blockY; }
public PS2Builder blockY(Integer blockY) { this.blockY = blockY; return this; } public PSBuilder blockY(Integer blockY) { this.blockY = blockY; return this; }
private Integer blockZ = null; private Integer blockZ = null;
public Integer blockZ() { return this.blockZ; } public Integer blockZ() { return this.blockZ; }
public PS2Builder blockZ(Integer blockZ) { this.blockZ = blockZ; return this; } public PSBuilder blockZ(Integer blockZ) { this.blockZ = blockZ; return this; }
private Double locationX = null; private Double locationX = null;
public Double locationX() { return this.locationX; } public Double locationX() { return this.locationX; }
public PS2Builder locationX(Double locationX) { this.locationX = locationX; return this; } public PSBuilder locationX(Double locationX) { this.locationX = locationX; return this; }
private Double locationY = null; private Double locationY = null;
public Double locationY() { return this.locationY; } public Double locationY() { return this.locationY; }
public PS2Builder locationY(Double locationY) { this.locationY = locationY; return this; } public PSBuilder locationY(Double locationY) { this.locationY = locationY; return this; }
private Double locationZ = null; private Double locationZ = null;
public Double locationZ() { return this.locationZ; } public Double locationZ() { return this.locationZ; }
public PS2Builder locationZ(Double locationZ) { this.locationZ = locationZ; return this; } public PSBuilder locationZ(Double locationZ) { this.locationZ = locationZ; return this; }
private Integer chunkX = null; private Integer chunkX = null;
public Integer chunkX() { return this.chunkX; } public Integer chunkX() { return this.chunkX; }
public PS2Builder chunkX(Integer chunkX) { this.chunkX = chunkX; return this; } public PSBuilder chunkX(Integer chunkX) { this.chunkX = chunkX; return this; }
private Integer chunkZ = null; private Integer chunkZ = null;
public Integer chunkZ() { return this.chunkZ; } public Integer chunkZ() { return this.chunkZ; }
public PS2Builder chunkZ(Integer chunkZ) { this.chunkZ = chunkZ; return this; } public PSBuilder chunkZ(Integer chunkZ) { this.chunkZ = chunkZ; return this; }
private Float pitch = null; private Float pitch = null;
public Float pitch() { return this.pitch; } public Float pitch() { return this.pitch; }
public PS2Builder pitch(Float pitch) { this.pitch = pitch; return this; } public PSBuilder pitch(Float pitch) { this.pitch = pitch; return this; }
private Float yaw = null; private Float yaw = null;
public Float yaw() { return this.yaw; } public Float yaw() { return this.yaw; }
public PS2Builder yaw(Float yaw) { this.yaw = yaw; return this; } public PSBuilder yaw(Float yaw) { this.yaw = yaw; return this; }
private Double velocityX = null; private Double velocityX = null;
public Double velocityX() { return this.velocityX; } public Double velocityX() { return this.velocityX; }
public PS2Builder velocityX(Double velocityX) { this.velocityX = velocityX; return this; } public PSBuilder velocityX(Double velocityX) { this.velocityX = velocityX; return this; }
private Double velocityY = null; private Double velocityY = null;
public Double velocityY() { return this.velocityY; } public Double velocityY() { return this.velocityY; }
public PS2Builder velocityY(Double velocityY) { this.velocityY = velocityY; return this; } public PSBuilder velocityY(Double velocityY) { this.velocityY = velocityY; return this; }
private Double velocityZ = null; private Double velocityZ = null;
public Double velocityZ() { return this.velocityZ; } public Double velocityZ() { return this.velocityZ; }
public PS2Builder velocityZ(Double velocityZ) { this.velocityZ = velocityZ; return this; } public PSBuilder velocityZ(Double velocityZ) { this.velocityZ = velocityZ; return this; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public PS2Builder(String world, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ) public PSBuilder(String world, Integer blockX, Integer blockY, Integer blockZ, Double locationX, Double locationY, Double locationZ, Integer chunkX, Integer chunkZ, Float pitch, Float yaw, Double velocityX, Double velocityY, Double velocityZ)
{ {
this.world = world; this.world = world;
this.blockX = blockX; this.blockX = blockX;
@ -87,12 +87,12 @@ public class PS2Builder
this.velocityZ = velocityZ; this.velocityZ = velocityZ;
} }
public PS2Builder(PS2 ps) public PSBuilder(PS ps)
{ {
this(ps.getWorld(), ps.getBlockX(), ps.getBlockY(), ps.getBlockZ(), ps.getLocationX(), ps.getLocationY(), ps.getLocationZ(), ps.getChunkX(), ps.getChunkZ(), ps.getPitch(), ps.getYaw(), ps.getVelocityX(), ps.getVelocityY(), ps.getVelocityZ()); this(ps.getWorld(), ps.getBlockX(), ps.getBlockY(), ps.getBlockZ(), ps.getLocationX(), ps.getLocationY(), ps.getLocationZ(), ps.getChunkX(), ps.getChunkZ(), ps.getPitch(), ps.getYaw(), ps.getVelocityX(), ps.getVelocityY(), ps.getVelocityZ());
} }
public PS2Builder() public PSBuilder()
{ {
} }
@ -101,9 +101,9 @@ public class PS2Builder
// BUILD // BUILD
// -------------------------------------------- // // -------------------------------------------- //
public PS2 build() public PS build()
{ {
return PS2.valueOf(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ); return PS.valueOf(world, blockX, blockY, blockZ, locationX, locationY, locationZ, chunkX, chunkZ, pitch, yaw, velocityX, velocityY, velocityZ);
} }
} }

View File

@ -0,0 +1,6 @@
package com.massivecraft.mcore.ps;
public interface PSFormat
{
public String format(PS ps);
}

View File

@ -5,7 +5,7 @@ import java.util.List;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.Txt;
public class PS2FormatAbstract implements PS2Format public class PSFormatAbstract implements PSFormat
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
@ -36,7 +36,7 @@ public class PS2FormatAbstract implements PS2Format
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public PS2FormatAbstract(String strNull, String strStart, String formatWorld, String formatBlockX, String formatBlockY, String formatBlockZ, String formatLocationX, String formatLocationY, String formatLocationZ, String formatChunkX, String formatChunkZ, String formatPitch, String formatYaw, String formatVelocityX, String formatVelocityY, String formatVelocityZ, String strGlue, String strStop) public PSFormatAbstract(String strNull, String strStart, String formatWorld, String formatBlockX, String formatBlockY, String formatBlockZ, String formatLocationX, String formatLocationY, String formatLocationZ, String formatChunkX, String formatChunkZ, String formatPitch, String formatYaw, String formatVelocityX, String formatVelocityY, String formatVelocityZ, String strGlue, String strStop)
{ {
this.strNull = strNull; this.strNull = strNull;
this.strStart = strStart; this.strStart = strStart;
@ -63,7 +63,7 @@ public class PS2FormatAbstract implements PS2Format
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String format(PS2 ps) public String format(PS ps)
{ {
if (ps == null) return this.strNull; if (ps == null) return this.strNull;
@ -76,7 +76,7 @@ public class PS2FormatAbstract implements PS2Format
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
public List<String> formatEntries(PS2 ps) public List<String> formatEntries(PS ps)
{ {
List<String> ret = new ArrayList<String>(); List<String> ret = new ArrayList<String>();

View File

@ -0,0 +1,36 @@
package com.massivecraft.mcore.ps;
import com.massivecraft.mcore.util.Txt;
public class PSFormatDesc extends PSFormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PSFormatDesc i = new PSFormatDesc();
public static PSFormatDesc get() { return i; }
private PSFormatDesc()
{
super(
Txt.parse("<silver><em>NULL"),
"",
Txt.parse("<k>") + PS.NAME_SERIALIZED_WORLD + Txt.parse(" <v>") + "%s",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKX + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKY + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKZ + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONX + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONY + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONZ + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_CHUNKX + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_CHUNKZ + Txt.parse(" <v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_PITCH + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_YAW + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYX + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYY + Txt.parse(" <v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYZ + Txt.parse(" <v>") + "%.2f",
" ",
""
);
}
}

View File

@ -0,0 +1,34 @@
package com.massivecraft.mcore.ps;
public class PSFormatFormal extends PSFormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PSFormatFormal i = new PSFormatFormal();
public static PSFormatFormal get() { return i; }
private PSFormatFormal()
{
super(
"PS{NULL}",
"PS{",
PS.NAME_SERIALIZED_WORLD + ": %s",
PS.NAME_SERIALIZED_BLOCKX + ": %d",
PS.NAME_SERIALIZED_BLOCKY + ": %d",
PS.NAME_SERIALIZED_BLOCKZ + ": %d",
PS.NAME_SERIALIZED_LOCATIONX + ": %.2f",
PS.NAME_SERIALIZED_LOCATIONY + ": %.2f",
PS.NAME_SERIALIZED_LOCATIONZ + ": %.2f",
PS.NAME_SERIALIZED_CHUNKX + ": %d",
PS.NAME_SERIALIZED_CHUNKZ + ": %d",
PS.NAME_SERIALIZED_PITCH + ": %.2f",
PS.NAME_SERIALIZED_YAW + ": %.2f",
PS.NAME_SERIALIZED_VELOCITYX + ": %.2f",
PS.NAME_SERIALIZED_VELOCITYY + ": %.2f",
PS.NAME_SERIALIZED_VELOCITYZ + ": %.2f",
", ",
"}"
);
}
}

View File

@ -0,0 +1,36 @@
package com.massivecraft.mcore.ps;
import com.massivecraft.mcore.util.Txt;
public class PSFormatSlug extends PSFormatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PSFormatSlug i = new PSFormatSlug();
public static PSFormatSlug get() { return i; }
private PSFormatSlug()
{
super(
Txt.parse("<silver><em>NULL"),
"",
Txt.parse("<k>") + PS.NAME_SERIALIZED_WORLD + Txt.parse("<v>") + "%s",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKX + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKY + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_BLOCKZ + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONX + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONY + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_LOCATIONZ + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_CHUNKX + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_CHUNKZ + Txt.parse("<v>") + "%d",
Txt.parse("<k>") + PS.NAME_SERIALIZED_PITCH + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_YAW + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYX + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYY + Txt.parse("<v>") + "%.2f",
Txt.parse("<k>") + PS.NAME_SERIALIZED_VELOCITYZ + Txt.parse("<v>") + "%.2f",
"",
""
);
}
}

View File

@ -314,11 +314,13 @@ public class MUtil
// SIMPLE CONSTRUCTORS // SIMPLE CONSTRUCTORS
// -------------------------------------------- // // -------------------------------------------- //
@SafeVarargs
public static <T> List<T> list(T... items) public static <T> List<T> list(T... items)
{ {
return new ArrayList<T>(Arrays.asList(items)); return new ArrayList<T>(Arrays.asList(items));
} }
@SafeVarargs
public static <T> Set<T> set(T... items) public static <T> Set<T> set(T... items)
{ {
return new LinkedHashSet<T>(Arrays.asList(items)); return new LinkedHashSet<T>(Arrays.asList(items));

View File

@ -25,7 +25,7 @@ import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEvent; import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
import com.massivecraft.mcore.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.store.SenderEntity;
import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SenderUtil;
@ -133,7 +133,7 @@ public class ExtractorLogic
public static World world(Location o) { return o.getWorld(); } public static World world(Location o) { return o.getWorld(); }
public static World world(Entity o) { return o.getWorld(); } public static World world(Entity o) { return o.getWorld(); }
public static World world(PlayerEvent o) { return world(o.getPlayer()); } public static World world(PlayerEvent o) { return world(o.getPlayer()); }
public static World world(PS o) { return o.getWorld(); } public static World world(PS o) { try { return o.asBukkitWorld(true); } catch (Exception e) { return null; }}
public static World worldFromObject(Object o) public static World worldFromObject(Object o)
{ {
@ -155,7 +155,7 @@ public class ExtractorLogic
public static String worldNameFromObject(Object o) public static String worldNameFromObject(Object o)
{ {
if (o instanceof String) return (String)o; if (o instanceof String) return (String)o;
if (o instanceof PS) return ((PS)o).getWorldName(); if (o instanceof PS) return ((PS)o).getWorld();
World world = worldFromObject(o); World world = worldFromObject(o);
if (world == null) return null; if (world == null) return null;
return world.getName(); return world.getName();