diff --git a/src/network/packets/soe/DataChannelA.java b/src/network/packets/soe/DataChannelA.java index 57b509d10..de968483a 100644 --- a/src/network/packets/soe/DataChannelA.java +++ b/src/network/packets/soe/DataChannelA.java @@ -160,6 +160,18 @@ public class DataChannelA extends Packet implements Comparable { return 0; return 1; } + + @Override + public boolean equals(Object o) { + if (!(o instanceof DataChannelA)) + return false; + return ((DataChannelA) o).sequence == sequence; + } + + @Override + public int hashCode() { + return sequence; + } public void setSequence(short sequence) { this.sequence = sequence; } diff --git a/src/resources/Location.java b/src/resources/Location.java index 70896efc0..8d065c9b3 100644 --- a/src/resources/Location.java +++ b/src/resources/Location.java @@ -219,6 +219,12 @@ public class Location implements Encodable, Serializable { return x*x; } + public boolean equals(Object o) { + if (!(o instanceof Location)) + return false; + return equals((Location) o); + } + public boolean equals(Location l) { if (terrain != l.terrain) return false; diff --git a/src/resources/buildout/BuildoutArea.java b/src/resources/buildout/BuildoutArea.java index b533c5d6e..bab10af20 100644 --- a/src/resources/buildout/BuildoutArea.java +++ b/src/resources/buildout/BuildoutArea.java @@ -64,9 +64,9 @@ public class BuildoutArea implements Comparable { BuildoutArea area = (BuildoutArea) o; if (!terrain.equals(area.terrain)) return false; - if (x1 != area.x1) + if (Double.compare(x1, area.x1) != 0) return false; - if (z1 != area.z1) + if (Double.compare(z1, area.z1) != 0) return false; return true; } diff --git a/src/resources/chat/ChatAvatar.java b/src/resources/chat/ChatAvatar.java index 8d3beaa46..994fffa06 100644 --- a/src/resources/chat/ChatAvatar.java +++ b/src/resources/chat/ChatAvatar.java @@ -31,8 +31,11 @@ import network.packets.Packet; import resources.encodables.Encodable; import resources.player.Player; +import java.io.IOException; +import java.io.ObjectInputStream; import java.io.Serializable; import java.nio.ByteBuffer; +import java.util.Locale; /** * @author Waverunner @@ -52,6 +55,8 @@ public class ChatAvatar implements Encodable, Serializable { public ChatAvatar() { modified = true; + data = null; + size = 0; } public ChatAvatar(long networkId, String name, String galaxy) { @@ -60,6 +65,13 @@ public class ChatAvatar implements Encodable, Serializable { this.name = name; this.galaxy = galaxy; } + + private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { + ois.defaultReadObject(); + modified = true; + data = null; + size = 0; + } public String getName() { return name; @@ -119,7 +131,7 @@ public class ChatAvatar implements Encodable, Serializable { public void decode(ByteBuffer data) { game = Packet.getAscii(data); galaxy = Packet.getAscii(data); - name = Packet.getAscii(data).toLowerCase(); + name = Packet.getAscii(data).toLowerCase(Locale.US); } @Override @@ -150,7 +162,7 @@ public class ChatAvatar implements Encodable, Serializable { } public static ChatAvatar getFromPlayer(Player player) { - return new ChatAvatar(player.getNetworkId(), player.getCharacterName().split(" ")[0].toLowerCase(), player.getGalaxyName()); + return new ChatAvatar(player.getNetworkId(), player.getCharacterName().split(" ")[0].toLowerCase(Locale.US), player.getGalaxyName()); } public static ChatAvatar getSystemAvatar(String galaxy) { diff --git a/src/resources/client_info/ClientFactory.java b/src/resources/client_info/ClientFactory.java index 9d79bc4ba..df8c5f895 100644 --- a/src/resources/client_info/ClientFactory.java +++ b/src/resources/client_info/ClientFactory.java @@ -42,7 +42,8 @@ import resources.client_info.visitors.SlotDescriptorData; import resources.client_info.visitors.WorldSnapshotData; public class ClientFactory extends DataFactory { - private static ClientFactory instance; + + private static final ClientFactory INSTANCE = new ClientFactory(); private Map > dataMap = new HashMap<>(); private Map typeMap = new HashMap<>(); @@ -119,7 +120,7 @@ public class ClientFactory extends DataFactory { if (original.contains("shared_")) return original; - int index = original.lastIndexOf("/"); + int index = original.lastIndexOf('/'); return original.substring(0, index) + "/shared_" + original.substring(index+1); } @@ -195,8 +196,6 @@ public class ClientFactory extends DataFactory { } private static ClientFactory getInstance() { - if (instance == null) - instance = new ClientFactory(); - return instance; + return INSTANCE; } } diff --git a/src/resources/client_info/IffNode.java b/src/resources/client_info/IffNode.java index 83e005616..f56f6fb25 100644 --- a/src/resources/client_info/IffNode.java +++ b/src/resources/client_info/IffNode.java @@ -30,6 +30,7 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; @@ -50,16 +51,16 @@ public class IffNode { private Iterator childrenItr; public IffNode() { + children = new LinkedList<>(); } public IffNode(String tag, boolean isForm) { + this(); this.tag = tag; this.isForm = isForm; } public void addChild(IffNode child) { - if (children == null) - children = new LinkedList<>(); children.add(child); } @@ -261,8 +262,7 @@ public class IffNode { read += child.populateFromBuffer(bb); addChild(child); } - if (children != null) - childrenItr = children.listIterator(); + childrenItr = children.listIterator(); return 4 + size; } @@ -292,7 +292,7 @@ public class IffNode { private String getTag(ByteBuffer bb) { byte[] tagBytes = new byte[4]; bb.get(tagBytes); - return new String(tagBytes); + return new String(tagBytes, StandardCharsets.UTF_8); } @Override diff --git a/src/resources/client_info/SWGFile.java b/src/resources/client_info/SWGFile.java index ccf822a8b..d180e0111 100644 --- a/src/resources/client_info/SWGFile.java +++ b/src/resources/client_info/SWGFile.java @@ -33,11 +33,13 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; /** * Created by Waverunner on 6/4/2015 */ public class SWGFile { + private String type; private IffNode master; private IffNode currentForm; @@ -57,9 +59,9 @@ public class SWGFile { } public void save(File file) throws IOException { - FileOutputStream outputStream = new FileOutputStream(file, false); - outputStream.write(getData()); - outputStream.close(); + try (FileOutputStream outputStream = new FileOutputStream(file, false)) { + outputStream.write(getData()); + } } public void read(File file) throws IOException { @@ -101,7 +103,7 @@ public class SWGFile { byte[] tag = new byte[4]; buffer.get(tag); - String root = new String(tag); + String root = new String(tag, StandardCharsets.UTF_8); if (!root.equals("FORM")) return false; diff --git a/src/resources/client_info/visitors/WorldSnapshotData.java b/src/resources/client_info/visitors/WorldSnapshotData.java index 752e001e1..c0bf838ad 100644 --- a/src/resources/client_info/visitors/WorldSnapshotData.java +++ b/src/resources/client_info/visitors/WorldSnapshotData.java @@ -204,5 +204,10 @@ public class WorldSnapshotData extends ClientData { public boolean equals(Object o) { return o instanceof Node && id == ((Node) o).getId(); } + + @Override + public int hashCode() { + return id; + } } } diff --git a/src/resources/collections/SWGBitSet.java b/src/resources/collections/SWGBitSet.java index 4a768bfb2..c8fd204a6 100644 --- a/src/resources/collections/SWGBitSet.java +++ b/src/resources/collections/SWGBitSet.java @@ -32,16 +32,17 @@ import resources.encodables.Encodable; import resources.network.DeltaBuilder; import resources.objects.SWGObject; -import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Arrays; import java.util.BitSet; /** * @author Waverunner */ -public class SWGBitSet extends BitSet implements Encodable, Serializable { +public class SWGBitSet extends BitSet implements Encodable { + private static final long serialVersionUID = 200L; private final Baseline.BaselineType baseline; @@ -80,6 +81,18 @@ public class SWGBitSet extends BitSet implements Encodable, Serializable { // TODO: Decode method for SWGBitSet throw new UnsupportedOperationException("Unable to decode bitset!"); } + + @Override + public boolean equals(Object o) { + if (!(o instanceof SWGBitSet)) + return super.equals(o); + return Arrays.equals(toList(), ((SWGBitSet)o).toList()); + } + + @Override + public int hashCode() { + return Arrays.hashCode(toList()); + } public void sendDeltaMessage(SWGObject target) { if (target.getOwner() == null) { diff --git a/src/resources/common/CRC.java b/src/resources/common/CRC.java index 31631849e..867e6741c 100644 --- a/src/resources/common/CRC.java +++ b/src/resources/common/CRC.java @@ -27,6 +27,8 @@ ***********************************************************************************/ package resources.common; +import java.nio.charset.StandardCharsets; + public class CRC { private static final int CRC_TABLE[] = { @@ -131,7 +133,7 @@ public class CRC { }; public static int getCrc(String input) { - byte [] bytes = input.getBytes(); + byte [] bytes = input.getBytes(StandardCharsets.UTF_8); int crc = 0xffffffff; for (int i = 0; i < bytes.length; ++i) { @@ -141,7 +143,7 @@ public class CRC { } public static int memcrc(String input) { - byte [] bytes = input.getBytes(); + byte [] bytes = input.getBytes(StandardCharsets.UTF_8); int crc = 0xffffffff; for (int i = 0; i < bytes.length; ++i) { diff --git a/src/resources/encodables/ProsePackage.java b/src/resources/encodables/ProsePackage.java index c231bd38d..0d59d33d9 100644 --- a/src/resources/encodables/ProsePackage.java +++ b/src/resources/encodables/ProsePackage.java @@ -246,7 +246,9 @@ public class ProsePackage implements OutOfBandData, Serializable { "]"; } - private class Prose implements Encodable { + private static class Prose implements Encodable, Serializable { + + private static final long serialVersionUID = 1L; private long objectId; private StringId stringId; diff --git a/src/resources/encodables/player/Equipment.java b/src/resources/encodables/player/Equipment.java index 702a3dfc0..c2dd768f6 100644 --- a/src/resources/encodables/player/Equipment.java +++ b/src/resources/encodables/player/Equipment.java @@ -141,4 +141,9 @@ public class Equipment implements Encodable, Serializable { return ((SWGObject) o).getObjectId() == objectId; } + + @Override + public int hashCode() { + return Long.hashCode(objectId); + } } diff --git a/src/resources/objects/buildouts/SwgBuildoutArea.java b/src/resources/objects/buildouts/SwgBuildoutArea.java index 294bd3900..536a51e5c 100644 --- a/src/resources/objects/buildouts/SwgBuildoutArea.java +++ b/src/resources/objects/buildouts/SwgBuildoutArea.java @@ -102,7 +102,7 @@ public class SwgBuildoutArea { private void calculate(int sceneNumber, int areaNumber) { index = sceneNumber * 100 + areaNumber; - buildingObjectId = -(index + 1) * 30000; + buildingObjectId = -(index + 1) * 30000L; objectIdBase = buildingObjectId + 2000; } diff --git a/src/resources/objects/installation/InstallationObject.java b/src/resources/objects/installation/InstallationObject.java index 931639662..b336e4495 100644 --- a/src/resources/objects/installation/InstallationObject.java +++ b/src/resources/objects/installation/InstallationObject.java @@ -37,8 +37,8 @@ public class InstallationObject extends TangibleObject { private static final long serialVersionUID = 1L; private boolean activated = false; - private float power = 0; - private float powerRate = 0; + private double power = 0; + private double powerRate = 0; public InstallationObject(long objectId) { super(objectId, BaselineType.INSO); @@ -48,7 +48,7 @@ public class InstallationObject extends TangibleObject { return activated; } - public float getPower() { + public double getPower() { return power; } @@ -60,11 +60,11 @@ public class InstallationObject extends TangibleObject { this.activated = activated; } - public void setPower(float power) { + public void setPower(double power) { this.power = power; } - public void setPowerRate(float powerRate) { + public void setPowerRate(double powerRate) { this.powerRate = powerRate; } @@ -72,10 +72,29 @@ public class InstallationObject extends TangibleObject { super.createBaseline3(target, bb); bb.addBoolean(activated); - bb.addFloat(power); - bb.addFloat(powerRate); + bb.addFloat((float) power); + bb.addFloat((float) powerRate); bb.incrementOperandCount(3); } + @Override + public boolean equals(Object o) { + if (!(o instanceof InstallationObject)) + return super.equals(o); + InstallationObject inso = (InstallationObject) o; + if (!super.equals(o)) + return false; + return activated == inso.activated && Double.compare(power, inso.power) == 0 && Double.compare(powerRate, inso.powerRate) == 0; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = (hash << 1) | (activated?1:0); + hash ^= Double.hashCode(power); + hash ^= Double.hashCode(powerRate); + return hash; + } + } diff --git a/src/resources/objects/quadtree/QuadTree.java b/src/resources/objects/quadtree/QuadTree.java index 10f0c4713..7fba1c265 100644 --- a/src/resources/objects/quadtree/QuadTree.java +++ b/src/resources/objects/quadtree/QuadTree.java @@ -29,6 +29,7 @@ package resources.objects.quadtree; import java.util.ArrayList; import java.util.List; +import java.util.NoSuchElementException; public class QuadTree { @@ -337,6 +338,8 @@ public class QuadTree { @Override public T next() { + if (!hasNext()) + throw new NoSuchElementException("Reached the end of the iterator!"); T node = subnodes[x][y]; if (y + 1 < subnodes.length) y++; diff --git a/src/resources/objects/resource/ResourceContainerObject.java b/src/resources/objects/resource/ResourceContainerObject.java index 545dc3de6..aad4b1155 100644 --- a/src/resources/objects/resource/ResourceContainerObject.java +++ b/src/resources/objects/resource/ResourceContainerObject.java @@ -113,4 +113,23 @@ public class ResourceContainerObject extends TangibleObject { bb.incrementOperandCount(4); } + @Override + public boolean equals(Object o) { + if (!(o instanceof ResourceContainerObject)) + return super.equals(o); + ResourceContainerObject rcno = (ResourceContainerObject) o; + if (!super.equals(o)) + return false; + return maxQuantity == rcno.maxQuantity && parentName.equals(rcno.parentName) && resourceName.equals(rcno.resourceName); + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash ^= maxQuantity; + hash ^= parentName.hashCode(); + hash ^= resourceName.hashCode(); + return hash; + } + } diff --git a/src/resources/server_info/ConfigData.java b/src/resources/server_info/ConfigData.java index 7fd4e84ac..6a2cc2fce 100644 --- a/src/resources/server_info/ConfigData.java +++ b/src/resources/server_info/ConfigData.java @@ -30,9 +30,12 @@ package resources.server_info; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.HashMap; @@ -74,7 +77,7 @@ class ConfigData { delta.putAll(data); // Copy the current data try { - reader = new BufferedReader(new FileReader(file)); + reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); String line = reader.readLine(); while (line != null) { loadLine(line); @@ -102,7 +105,7 @@ class ConfigData { public boolean save() { BufferedWriter writer = null; try { - writer = new BufferedWriter(new FileWriter(file)); + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); writer.write("# "+FORMAT.format(System.currentTimeMillis())); writer.newLine(); for (Entry e : data.entrySet()) { diff --git a/src/resources/server_info/Log.java b/src/resources/server_info/Log.java index 0296ad5fb..e730c3108 100644 --- a/src/resources/server_info/Log.java +++ b/src/resources/server_info/Log.java @@ -29,8 +29,10 @@ package resources.server_info; import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -50,7 +52,7 @@ public class Log { private synchronized void open() throws IOException { if (!open) - writer = new BufferedWriter(new FileWriter(file)); + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); open = true; } @@ -93,7 +95,10 @@ public class Log { * @param args the string format arguments, if specified */ public static final void log(LogLevel level, String tag, String str, Object ... args) { - String date = LOG_FORMAT.format(System.currentTimeMillis()); + String date; + synchronized (LOG_FORMAT) { + date = LOG_FORMAT.format(System.currentTimeMillis()); + } String logStr = String.format(str, args); String log = String.format("%s %c/[%s]: %s", date, level.getChar(), tag, logStr); synchronized (LOG) { diff --git a/src/resources/server_info/ObjectDatabase.java b/src/resources/server_info/ObjectDatabase.java index 2db6452fb..9037b1eb4 100644 --- a/src/resources/server_info/ObjectDatabase.java +++ b/src/resources/server_info/ObjectDatabase.java @@ -39,7 +39,6 @@ import utilities.ThreadUtilities; public abstract class ObjectDatabase { private final File file; - private final long autosaveInterval; private final ScheduledExecutorService autosaveService; private final Runnable autosaveRunnable; @@ -56,7 +55,6 @@ public abstract class ObjectDatabase { this.file = new File(filename); if (autosaveInterval < 60000) autosaveInterval = 60000; - this.autosaveInterval = autosaveInterval; this.autosaveService = Executors.newSingleThreadScheduledExecutor(ThreadUtilities.newThreadFactory("odb-autosave-"+file.getName())); this.autosaveRunnable = new Runnable() { public void run() { @@ -64,7 +62,7 @@ public abstract class ObjectDatabase { } }; // Setup - setupAutosave(); + autosaveService.scheduleAtFixedRate(autosaveRunnable, autosaveInterval, autosaveInterval, TimeUnit.MILLISECONDS); try { createFilesAndDirectories(); } catch (IOException e) { @@ -72,12 +70,6 @@ public abstract class ObjectDatabase { } } - private void setupAutosave() { - synchronized (autosaveService) { - autosaveService.scheduleAtFixedRate(autosaveRunnable, autosaveInterval, autosaveInterval, TimeUnit.MILLISECONDS); - } - } - private void autosavePeriodic() { save(); } diff --git a/src/resources/server_info/RelationalDatabase.java b/src/resources/server_info/RelationalDatabase.java index b9204922f..3baaf9756 100644 --- a/src/resources/server_info/RelationalDatabase.java +++ b/src/resources/server_info/RelationalDatabase.java @@ -158,8 +158,9 @@ public abstract class RelationalDatabase implements Closeable { if (connection == null) return 0; try { - Statement s = connection.createStatement(); - return s.executeUpdate(query); + try (Statement s = connection.createStatement()) { + return s.executeUpdate(query); + } } catch (SQLException e) { e.printStackTrace(); return 0; diff --git a/src/resources/sui/SuiBaseWindow.java b/src/resources/sui/SuiBaseWindow.java index 04b7535e5..531f88538 100644 --- a/src/resources/sui/SuiBaseWindow.java +++ b/src/resources/sui/SuiBaseWindow.java @@ -32,6 +32,7 @@ import resources.encodables.Encodable; import resources.server_info.Log; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -285,7 +286,7 @@ public class SuiBaseWindow implements Encodable { } private String getWrappedEventString(int event) { - return new String(new byte[]{(byte) event}); + return new String(new byte[]{(byte) event}, StandardCharsets.UTF_8); } @Override diff --git a/src/resources/sui/SuiComponent.java b/src/resources/sui/SuiComponent.java index 55d8427e3..07fc4cbb3 100644 --- a/src/resources/sui/SuiComponent.java +++ b/src/resources/sui/SuiComponent.java @@ -33,6 +33,7 @@ import resources.server_info.Log; import utilities.Encoder; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -127,7 +128,7 @@ public class SuiComponent implements Encodable { if (size < 3) { Log.w("SuiComponent", "Tried to get subscribed event type when there is none for target %s", getTarget()); } else { - byte[] bytes = narrowParams.get(1).getBytes(); + byte[] bytes = narrowParams.get(1).getBytes(StandardCharsets.UTF_8); if (bytes.length > 1) { Log.w("SuiComponent", "Tried to get eventType but narrowparams string byte array length is more than 1"); return -1; diff --git a/src/resources/zone/NameFilter.java b/src/resources/zone/NameFilter.java index 3778dac08..5bbf1687b 100644 --- a/src/resources/zone/NameFilter.java +++ b/src/resources/zone/NameFilter.java @@ -29,11 +29,14 @@ package resources.zone; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class NameFilter { @@ -71,14 +74,15 @@ public class NameFilter { if (!file.exists()) return false; try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = ""; - list.clear(); - while ((line = reader.readLine()) != null) { - if (!line.isEmpty() && !list.contains(line.toLowerCase())) - list.add(line.toLowerCase()); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { + String line = ""; + list.clear(); + while ((line = reader.readLine()) != null) { + line = line.toLowerCase(Locale.US); + if (!line.isEmpty() && !list.contains(line)) + list.add(line); + } } - reader.close(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); @@ -169,7 +173,7 @@ public class NameFilter { } private boolean contains(List list, String name) { - name = name.toLowerCase(); + name = name.toLowerCase(Locale.US); for (String str : list) if (name.length() >= str.length() && (name.startsWith(str) || name.endsWith(str))) return true; diff --git a/src/services/EngineManager.java b/src/services/EngineManager.java index 08961089a..7a084d0c4 100644 --- a/src/services/EngineManager.java +++ b/src/services/EngineManager.java @@ -35,6 +35,7 @@ import resources.client_info.ServerFactory; import resources.config.ConfigFile; import resources.control.Manager; import resources.server_info.Config; +import resources.server_info.Log; import services.network.NetworkManager; public class EngineManager extends Manager { @@ -71,9 +72,15 @@ public class EngineManager extends Manager { private void wipeOdbFiles() { File directory = new File("./odb"); - for (File f : directory.listFiles()) { + File [] files = directory.listFiles(); + if (files == null) + return; + for (File f : files) { if (!f.isDirectory() && (f.getName().endsWith(".db") || f.getName().endsWith(".db.tmp"))) { - f.delete(); + if (!f.delete()) { + System.err.println("EngineManager: Failed to delete ODB: " + f); + Log.e("EngineManager", "Failed to delete ODB: %s", f); + } } } } diff --git a/src/services/objects/ObjectCreator.java b/src/services/objects/ObjectCreator.java index d52318df7..99561fc80 100644 --- a/src/services/objects/ObjectCreator.java +++ b/src/services/objects/ObjectCreator.java @@ -106,8 +106,8 @@ public final class ObjectCreator { switch(key) { case ObjectData.OBJ_STF: object.setStringId(value); break; case ObjectData.DETAIL_STF: object.setDetailStringId(value); break; - case ObjectData.VOLUME_LIMIT: object.setVolume(Integer.valueOf(value)); break; - case ObjectData.CONTAINER_TYPE: object.setContainerType(Integer.valueOf(value)); break; + case ObjectData.VOLUME_LIMIT: object.setVolume(Integer.parseInt(value)); break; + case ObjectData.CONTAINER_TYPE: object.setContainerType(Integer.parseInt(value)); break; default: break; } } diff --git a/src/utilities/BuildoutGenerator.java b/src/utilities/BuildoutGenerator.java index ec405d730..1e4331411 100644 --- a/src/utilities/BuildoutGenerator.java +++ b/src/utilities/BuildoutGenerator.java @@ -179,7 +179,10 @@ public class BuildoutGenerator { public GenBuildoutArea(SwgBuildoutArea area, Terrain terrain, double x1, double z1, double x2, double z2, int id, boolean adjust) { this.area = area; this.terrain = terrain; - this.index = area.getIndex(); + if (area != null) + this.index = area.getIndex(); + else + this.index = -1; this.x1 = (int) x1; this.z1 = (int) z1; this.x2 = (int) x2; diff --git a/src/utilities/Scripts.java b/src/utilities/Scripts.java index c50258e2a..cbb2f0ffb 100644 --- a/src/utilities/Scripts.java +++ b/src/utilities/Scripts.java @@ -27,8 +27,10 @@ ***********************************************************************************/ package utilities; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import javax.script.Invocable; @@ -70,7 +72,7 @@ public class Scripts { @SuppressWarnings("unchecked") public static T invoke(String script, String function, Object... args) { try { - ENGINE.eval(new FileReader(SCRIPTS + script + EXTENSION)); + ENGINE.eval(new InputStreamReader(new FileInputStream(SCRIPTS + script + EXTENSION), StandardCharsets.UTF_8)); return (T) INVOCABLE.invokeFunction(function, args); } catch (FileNotFoundException e) { // No need to print anything, this is a common error. diff --git a/src/utilities/namegen/SWGNameGenerator.java b/src/utilities/namegen/SWGNameGenerator.java index b1d46ff90..e1c5e1ef2 100644 --- a/src/utilities/namegen/SWGNameGenerator.java +++ b/src/utilities/namegen/SWGNameGenerator.java @@ -34,8 +34,10 @@ import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; public class SWGNameGenerator { @@ -213,7 +215,7 @@ public class SWGNameGenerator { } private RaceNameRule createRaceRule(FileInputStream stream) { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); RaceNameRule rule = new RaceNameRule(); boolean success = false; @@ -290,14 +292,14 @@ public class SWGNameGenerator { switch (key) { case "SurnameChance": - rule.setSurnameChance(Integer.valueOf(value)); + rule.setSurnameChance(Integer.parseInt(value)); break; default: return; } } private String firstCharUppercase(String name) { - return Character.toString(name.charAt(0)).toUpperCase() + name.substring(1); + return Character.toString(name.charAt(0)).toUpperCase(Locale.US) + name.substring(1); } private String removeExcessDuplications(List list, String orig, String n) {