diff --git a/src/protocol/swg/ChatFriendsListUpdate.java b/src/protocol/swg/ChatFriendsListUpdate.java index bd6debb0..962b2ad2 100644 --- a/src/protocol/swg/ChatFriendsListUpdate.java +++ b/src/protocol/swg/ChatFriendsListUpdate.java @@ -6,9 +6,6 @@ import main.NGECore; import org.apache.mina.core.buffer.IoBuffer; -import engine.resources.config.Config; -import engine.resources.config.DefaultConfig; - public class ChatFriendsListUpdate extends SWGMessage { private String friendName; diff --git a/src/protocol/swg/SetWaypointColor.java b/src/protocol/swg/SetWaypointColor.java index bb53cd75..f7a418d9 100644 --- a/src/protocol/swg/SetWaypointColor.java +++ b/src/protocol/swg/SetWaypointColor.java @@ -26,8 +26,6 @@ import java.nio.ByteBuffer; import org.apache.mina.core.buffer.IoBuffer; -import resources.common.StringUtilities; - public class SetWaypointColor extends SWGMessage { private long objectId; diff --git a/src/protocol/swg/objectControllerObjects/Animation.java b/src/protocol/swg/objectControllerObjects/Animation.java index 0997a01f..957cf7d2 100644 --- a/src/protocol/swg/objectControllerObjects/Animation.java +++ b/src/protocol/swg/objectControllerObjects/Animation.java @@ -26,7 +26,6 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; -import protocol.swg.SWGMessage; public class Animation extends ObjControllerObject { diff --git a/src/protocol/swg/objectControllerObjects/ChangeRoleIconChoice.java b/src/protocol/swg/objectControllerObjects/ChangeRoleIconChoice.java index 2cb16f10..7a458ead 100644 --- a/src/protocol/swg/objectControllerObjects/ChangeRoleIconChoice.java +++ b/src/protocol/swg/objectControllerObjects/ChangeRoleIconChoice.java @@ -21,12 +21,8 @@ ******************************************************************************/ package protocol.swg.objectControllerObjects; -import java.nio.ByteOrder; - import org.apache.mina.core.buffer.IoBuffer; -import engine.resources.common.Utilities; - public class ChangeRoleIconChoice extends ObjControllerObject { private long objectId = 0; diff --git a/src/resources/common/Stf.java b/src/resources/common/Stf.java index 191b2a60..1ebfc72a 100644 --- a/src/resources/common/Stf.java +++ b/src/resources/common/Stf.java @@ -23,7 +23,6 @@ package resources.common; import org.apache.mina.core.buffer.IoBuffer; -import resources.z.exp.objects.Baseline; import resources.objects.Delta; import com.sleepycat.persist.model.Persistent; @@ -85,7 +84,7 @@ public class Stf extends Delta { synchronized(objectMutex) { int size = stfFilename.getBytes().length + 4 + stfName.getBytes().length; - IoBuffer buffer = Baseline.createBuffer(size); + IoBuffer buffer = createBuffer(size); buffer.put(stfFilename.getBytes()); buffer.putInt(spacer); buffer.put(stfName.getBytes()); diff --git a/src/resources/common/StringUtilities.java b/src/resources/common/StringUtilities.java index a28bf368..e7d34d3a 100644 --- a/src/resources/common/StringUtilities.java +++ b/src/resources/common/StringUtilities.java @@ -27,6 +27,8 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; +import engine.resources.common.Utilities; + public class StringUtilities { final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; @@ -166,16 +168,20 @@ public class StringUtilities { } public static String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - int v; - - for ( int j = 0; j < bytes.length; j++ ) { - v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - - return new String(hexChars); + char[] hexChars = new char[bytes.length * 2]; + int v; + + for ( int j = 0; j < bytes.length; j++ ) { + v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + + return new String(hexChars); + } + + public static void printBytes(byte[] bytes) { + System.out.println(Utilities.getHexString(bytes)); } } diff --git a/src/resources/common/UString.java b/src/resources/common/UString.java index 5aa290dc..dec215af 100644 --- a/src/resources/common/UString.java +++ b/src/resources/common/UString.java @@ -22,9 +22,6 @@ package resources.common; import java.io.UnsupportedEncodingException; -import java.nio.ByteOrder; - -import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; @@ -64,7 +61,7 @@ public final class UString extends Delta { public byte[] getBytes() { synchronized(objectMutex) { try { - return IoBuffer.allocate(4 + string.length(), false).order(ByteOrder.LITTLE_ENDIAN).putInt(string.length()).put(string.getBytes("UTF-16LE")).flip().array(); + return createBuffer(4 + (string.length() * 2)).putInt(string.length()).put(string.getBytes("UTF-16LE")).flip().array(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return new byte[] { 0x00, 0x00, 0x00, 0x00 }; diff --git a/src/resources/gcw/CurrentServerGCWZoneHistory.java b/src/resources/gcw/CurrentServerGCWZoneHistory.java index a7a77e98..66874d64 100644 --- a/src/resources/gcw/CurrentServerGCWZoneHistory.java +++ b/src/resources/gcw/CurrentServerGCWZoneHistory.java @@ -21,15 +21,13 @@ ******************************************************************************/ package resources.gcw; -import java.nio.ByteOrder; - import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; -@Persistent +@Persistent(version=0) public class CurrentServerGCWZoneHistory extends Delta implements Cloneable { private int lastUpdateTime; @@ -40,6 +38,10 @@ public class CurrentServerGCWZoneHistory extends Delta implements Cloneable { this.lastUpdateTime = zone.getLastUpdateTime(); } + public CurrentServerGCWZoneHistory() { + + } + public int getLastUpdateTime() { synchronized(objectMutex) { return lastUpdateTime; @@ -54,7 +56,7 @@ public class CurrentServerGCWZoneHistory extends Delta implements Cloneable { public byte[] getBytes() { synchronized(objectMutex) { - IoBuffer buffer = bufferPool.allocate((8), false).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = createBuffer(8); buffer.putInt(lastUpdateTime); buffer.putInt(percent); return buffer.array(); diff --git a/src/resources/gcw/CurrentServerGCWZonePercent.java b/src/resources/gcw/CurrentServerGCWZonePercent.java index 09034cf6..ea825d7a 100644 --- a/src/resources/gcw/CurrentServerGCWZonePercent.java +++ b/src/resources/gcw/CurrentServerGCWZonePercent.java @@ -23,7 +23,6 @@ package resources.gcw; import java.math.BigDecimal; import java.math.MathContext; -import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; @@ -33,7 +32,7 @@ import engine.resources.scene.Point2D; import resources.objects.Delta; -@Persistent +@Persistent(version=0) public class CurrentServerGCWZonePercent extends Delta implements Cloneable { private Point2D position; @@ -53,6 +52,10 @@ public class CurrentServerGCWZonePercent extends Delta implements Cloneable { this.percent = new BigDecimal("50.0", MathContext.DECIMAL128); } + public CurrentServerGCWZonePercent() { + + } + public Point2D getPosition() { synchronized(objectMutex) { return position.clone(); @@ -148,7 +151,7 @@ public class CurrentServerGCWZonePercent extends Delta implements Cloneable { public byte[] getBytes() { synchronized(objectMutex) { - IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = createBuffer(4); buffer.putInt(percent.intValue()); return buffer.array(); } diff --git a/src/resources/gcw/OtherServerGCWZonePercent.java b/src/resources/gcw/OtherServerGCWZonePercent.java index a006d7a8..ab8048eb 100644 --- a/src/resources/gcw/OtherServerGCWZonePercent.java +++ b/src/resources/gcw/OtherServerGCWZonePercent.java @@ -21,15 +21,13 @@ ******************************************************************************/ package resources.gcw; -import java.nio.ByteOrder; - import org.apache.mina.core.buffer.IoBuffer; import com.sleepycat.persist.model.Persistent; import resources.objects.Delta; -@Persistent +@Persistent(version=0) public class OtherServerGCWZonePercent extends Delta implements Cloneable { private String zone = ""; @@ -39,6 +37,10 @@ public class OtherServerGCWZonePercent extends Delta implements Cloneable { this.zone = zone; } + public OtherServerGCWZonePercent() { + + } + public String getZone() { synchronized(objectMutex) { return zone; @@ -60,7 +62,7 @@ public class OtherServerGCWZonePercent extends Delta implements Cloneable { public byte[] getBytes() { synchronized(objectMutex) { - IoBuffer buffer = bufferPool.allocate((2 + zone.length() + 4), false).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = createBuffer((2 + zone.length() + 4)); buffer.put(getAsciiString(zone)); buffer.putInt(percent); return buffer.array(); diff --git a/src/resources/guild/Guild.java b/src/resources/guild/Guild.java index 1cebf0f6..5651c2d0 100644 --- a/src/resources/guild/Guild.java +++ b/src/resources/guild/Guild.java @@ -21,15 +21,17 @@ ******************************************************************************/ package resources.guild; -import java.nio.ByteOrder; import java.util.List; import org.apache.mina.core.buffer.IoBuffer; +import com.sleepycat.persist.model.Persistent; + import resources.objects.Delta; import engine.resources.objects.SWGObject; +@Persistent(version=0) public class Guild extends Delta { private int id; @@ -46,6 +48,10 @@ public class Guild extends Delta { this.members.add(leader); } + public Guild() { + + } + public int getId() { synchronized(objectMutex) { return id; @@ -83,17 +89,19 @@ public class Guild extends Delta { } public String getString() { - synchronized(objectMutex) { - return (Integer.toString(id) + ":" + abbreviation); - } + return (Integer.toString(getId()) + ":" + getAbbreviation()); } public SWGObject getLeader() { - return leader; + synchronized(objectMutex) { + return leader; + } } public void setLeader(SWGObject leader) { - this.leader = leader; + synchronized(objectMutex) { + this.leader = leader; + } } public List getMembers() { @@ -102,7 +110,7 @@ public class Guild extends Delta { public byte[] getBytes() { synchronized(objectMutex) { - IoBuffer buffer = bufferPool.allocate((getString().length() + 2), false).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = createBuffer((getString().length() + 2)); buffer.put(getAsciiString(getString())); return buffer.array(); } diff --git a/src/resources/objects/Delta.java b/src/resources/objects/Delta.java index f33de22c..31782741 100644 --- a/src/resources/objects/Delta.java +++ b/src/resources/objects/Delta.java @@ -22,8 +22,10 @@ package resources.objects; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.buffer.SimpleBufferAllocator; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; @@ -34,10 +36,12 @@ import resources.common.StringUtilities; public abstract class Delta implements IDelta { @NotPersistent - protected final Object objectMutex; + protected final Object objectMutex = new Object(); + @NotPersistent + private static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); public Delta() { - objectMutex = new Object(); + } protected String getAsciiString(ByteBuffer buffer) { @@ -61,7 +65,7 @@ public abstract class Delta implements IDelta { } public static IoBuffer createBuffer(int size) { - return Baseline.createBuffer(size); + return bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); } } diff --git a/src/services/travel/TravelPoint.java b/src/services/travel/TravelPoint.java index 2d76137c..bf2977dc 100644 --- a/src/services/travel/TravelPoint.java +++ b/src/services/travel/TravelPoint.java @@ -23,7 +23,6 @@ package services.travel; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import resources.common.Console; import resources.common.SpawnPoint;