diff --git a/src/intents/object/ObjectCreateIntent.java b/src/intents/object/ObjectCreateIntent.java deleted file mode 100644 index 317d7a9b4..000000000 --- a/src/intents/object/ObjectCreateIntent.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 /// Project SWG /// www.projectswg.com - * - * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on - * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. - * Our goal is to create an emulator which will provide a server for players to - * continue playing a game similar to the one they used to play. We are basing - * it on the final publish of the game prior to end-game events. - * - * This file is part of Holocore. - * - * -------------------------------------------------------------------------------- - * - * Holocore is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * Holocore is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Holocore. If not, see - ******************************************************************************/ - -package intents.object; - -import resources.control.Intent; -import resources.objects.SWGObject; - -/** - * Created by Waverunner on 8/19/2015 - */ -public class ObjectCreateIntent extends Intent { - - public static final String TYPE = "ObjectCreateIntent"; - - private SWGObject object; - - public ObjectCreateIntent(SWGObject object) { - super(TYPE); - this.object = object; - } - - public SWGObject getObject() { - return object; - } - -} \ No newline at end of file diff --git a/src/resources/objects/SWGObject.java b/src/resources/objects/SWGObject.java index 586a930b4..760e5e169 100644 --- a/src/resources/objects/SWGObject.java +++ b/src/resources/objects/SWGObject.java @@ -40,6 +40,7 @@ import network.packets.swg.zone.object_controller.DataTransformWithParent; import resources.Location; import resources.Terrain; import resources.buildout.BuildoutArea; +import resources.client_info.visitors.ObjectData.ObjectDataAttribute; import resources.common.CRC; import resources.containers.ContainerPermissions; import resources.containers.ContainerResult; @@ -62,6 +63,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -76,7 +78,7 @@ public abstract class SWGObject implements Serializable, Comparable { private final HashMap slots; // HashMap used for null value support private final Map containedObjects; private final Map attributes; - private final Map templateAttributes; + private final Map templateAttributes; private final BaselineType objectType; private ContainerPermissions containerPermissions; private transient Set objectsAware; @@ -109,8 +111,8 @@ public abstract class SWGObject implements Serializable, Comparable { this.objectsAware = new HashSet(); this.slots = new HashMap<>(); this.containedObjects = Collections.synchronizedMap(new HashMap()); - this.attributes = new LinkedHashMap(); - this.templateAttributes = new HashMap(); + this.attributes = new LinkedHashMap<>(); + this.templateAttributes = new Hashtable<>(); this.containerPermissions = new DefaultPermissions(); this.objectType = objectType; } @@ -503,11 +505,11 @@ public abstract class SWGObject implements Serializable, Comparable { return areaId; } - public Object getTemplateAttribute(String key) { + public Object getTemplateAttribute(ObjectDataAttribute key) { return templateAttributes.get(key); } - public void setTemplateAttribute(String key, Object value) { + public void setTemplateAttribute(ObjectDataAttribute key, Object value) { templateAttributes.put(key, value); } @@ -540,7 +542,7 @@ public abstract class SWGObject implements Serializable, Comparable { } public int getMaxContainerSize() { - Object volume = templateAttributes.get("containerVolumeLimit"); + Object volume = templateAttributes.get(ObjectDataAttribute.CONTAINER_VOLUME_LIMIT); if (volume == null) return 0; try { diff --git a/src/resources/objects/building/BuildingObject.java b/src/resources/objects/building/BuildingObject.java index 4b4aee3b3..d76d34974 100644 --- a/src/resources/objects/building/BuildingObject.java +++ b/src/resources/objects/building/BuildingObject.java @@ -29,8 +29,8 @@ package resources.objects.building; import network.packets.swg.zone.baselines.Baseline.BaselineType; import resources.client_info.ClientFactory; -import resources.client_info.visitors.ObjectData; import resources.client_info.visitors.PortalLayoutData; +import resources.client_info.visitors.ObjectData.ObjectDataAttribute; import resources.objects.SWGObject; import resources.objects.cell.CellObject; import resources.objects.tangible.TangibleObject; @@ -84,7 +84,7 @@ public class BuildingObject extends TangibleObject { if (!added || !(object instanceof CellObject)) return added; - String portalFile = String.valueOf(getTemplateAttribute(ObjectData.PORTAL_LAYOUT)); + String portalFile = (String) getTemplateAttribute(ObjectDataAttribute.PORTAL_LAYOUT_FILENAME); if (portalFile == null || portalFile.isEmpty()) return true; diff --git a/src/resources/objects/staticobject/StaticObject.java b/src/resources/objects/staticobject/StaticObject.java index 673525eed..a577bc8ca 100644 --- a/src/resources/objects/staticobject/StaticObject.java +++ b/src/resources/objects/staticobject/StaticObject.java @@ -27,15 +27,14 @@ ***********************************************************************************/ package resources.objects.staticobject; -import network.packets.swg.zone.baselines.Baseline.BaselineType; -import resources.objects.SWGObject; +import resources.objects.creature.CreatureObject; -public class StaticObject extends SWGObject { +public class StaticObject extends CreatureObject { private static final long serialVersionUID = 1L; public StaticObject(long objectId) { - super(objectId, BaselineType.STAO); + super(objectId); } } diff --git a/src/services/galaxy/TravelService.java b/src/services/galaxy/TravelService.java index 6c485e1e2..68d5f5f7d 100644 --- a/src/services/galaxy/TravelService.java +++ b/src/services/galaxy/TravelService.java @@ -509,11 +509,13 @@ public class TravelService extends Service { String template = object.getTemplate(); // There are non-functional shuttles, which are StaticObject. We run an instanceof check to make sure that we ignore those. - if((template.contains("shared_player_shuttle") || template.contains("shared_player_transport")) && object instanceof CreatureObject) { + if ((template.contains("shared_player_shuttle") || template.contains("shared_player_transport")) && object instanceof CreatureObject) { Location shuttleLocation = object.getLocation(); TravelPoint pointForShuttle = getNearestTravelPoint(shuttleLocation); CreatureObject shuttle = (CreatureObject) object; + if (pointForShuttle == null) + return; // Assign the shuttle to the nearest travel point pointForShuttle.setShuttle(shuttle); diff --git a/src/services/group/GroupService.java b/src/services/group/GroupService.java index 0e94283ef..e8a76a4ce 100644 --- a/src/services/group/GroupService.java +++ b/src/services/group/GroupService.java @@ -31,7 +31,7 @@ import intents.GroupEventIntent; import intents.NotifyPlayersPacketIntent; import intents.PlayerEventIntent; import intents.chat.ChatRoomUpdateIntent; -import intents.object.ObjectCreateIntent; +import intents.object.ObjectCreatedIntent; import intents.object.ObjectIdRequestIntent; import intents.object.ObjectIdResponseIntent; import network.packets.swg.zone.chat.ChatSystemMessage; @@ -297,7 +297,7 @@ public class GroupService extends Service { groups.put(group.getObjectId(), group); - new ObjectCreateIntent(group).broadcast(); + new ObjectCreatedIntent(group).broadcast(); String galaxy = player.getGalaxyName(); new ChatRoomUpdateIntent(getGroupChatPath(group.getObjectId(), galaxy), String.valueOf(group.getObjectId()), null, diff --git a/src/services/objects/ObjectAwareness.java b/src/services/objects/ObjectAwareness.java index 4e5d2ced5..30e7d5e81 100644 --- a/src/services/objects/ObjectAwareness.java +++ b/src/services/objects/ObjectAwareness.java @@ -30,7 +30,6 @@ package services.objects; import intents.PlayerEventIntent; import intents.RequestZoneInIntent; import intents.network.GalacticPacketIntent; -import intents.object.ObjectCreateIntent; import intents.object.ObjectCreatedIntent; import intents.object.ObjectTeleportIntent; import intents.object.UpdateObjectAwareness; @@ -54,7 +53,7 @@ import resources.control.Service; import resources.objects.SWGObject; import resources.objects.creature.CreatureObject; import resources.objects.quadtree.QuadTree; -import resources.objects.staticobject.StaticObject; +import resources.objects.tangible.TangibleObject; import resources.player.Player; import resources.server_info.Log; @@ -68,7 +67,6 @@ public class ObjectAwareness extends Service { public ObjectAwareness() { quadTree = new HashMap>(); registerForIntent(PlayerEventIntent.TYPE); - registerForIntent(ObjectCreateIntent.TYPE); registerForIntent(ObjectCreatedIntent.TYPE); registerForIntent(ObjectTeleportIntent.TYPE); registerForIntent(GalacticPacketIntent.TYPE); @@ -83,10 +81,6 @@ public class ObjectAwareness extends Service { if (i instanceof PlayerEventIntent) handlePlayerEventIntent((PlayerEventIntent) i); break; - case ObjectCreateIntent.TYPE: - if (i instanceof ObjectCreateIntent) - handleObjectCreateIntent((ObjectCreateIntent) i); - break; case ObjectCreatedIntent.TYPE: if (i instanceof ObjectCreatedIntent) handleObjectCreatedIntent((ObjectCreatedIntent) i); @@ -130,14 +124,6 @@ public class ObjectAwareness extends Service { } } - private void handleObjectCreateIntent(ObjectCreateIntent oci) { - SWGObject object = oci.getObject(); - if (isInAwareness(object)) { - add(object); - update(object); - } - } - private void handleObjectCreatedIntent(ObjectCreatedIntent oci) { SWGObject object = oci.getObject(); if (isInAwareness(object)) { @@ -251,7 +237,7 @@ public class ObjectAwareness extends Service { } private boolean isInAwareness(SWGObject object) { - return object.getParent() == null && !(object instanceof StaticObject); + return object.getParent() == null && object instanceof TangibleObject; } private double invertNormalizedValue(double x) { diff --git a/src/services/objects/ObjectCreator.java b/src/services/objects/ObjectCreator.java index 5ff098f78..acaae9e7b 100644 --- a/src/services/objects/ObjectCreator.java +++ b/src/services/objects/ObjectCreator.java @@ -31,6 +31,7 @@ import java.util.Map.Entry; import resources.client_info.ClientFactory; import resources.client_info.visitors.ObjectData; +import resources.client_info.visitors.ObjectData.ObjectDataAttribute; import resources.client_info.visitors.SlotArrangementData; import resources.client_info.visitors.SlotDescriptorData; import resources.objects.SWGObject; @@ -99,27 +100,31 @@ public final class ObjectCreator { if (attributes == null) return; - for (Entry e : attributes.getAttributes().entrySet()) { - obj.setTemplateAttribute(e.getKey(), e.getValue()); + ObjectDataAttribute key; + Object value; + for (Entry e : attributes.getAttributes().entrySet()) { + key = e.getKey(); + value = e.getValue(); + obj.setTemplateAttribute(key, value); - setObjectAttribute(e.getKey(), e.getValue().toString(), obj); + setObjectAttribute(key, value.toString(), obj); } } - private static void setObjectAttribute(String key, String value, SWGObject object) { - 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.parseInt(value)); break; - case ObjectData.CONTAINER_TYPE: object.setContainerType(Integer.parseInt(value)); break; + private static void setObjectAttribute(ObjectDataAttribute key, String value, SWGObject object) { + switch (key) { + case OBJECT_NAME: object.setStringId(value); break; + case DETAILED_DESCRIPTION: object.setDetailStringId(value); break; + case CONTAINER_VOLUME_LIMIT: object.setVolume(Integer.parseInt(value)); break; + case CONTAINER_TYPE: object.setContainerType(Integer.parseInt(value)); break; default: break; } } private static void createObjectSlots(SWGObject object) { - if (object.getTemplateAttribute(ObjectData.SLOT_DESCRIPTOR) != null) { + if (object.getTemplateAttribute(ObjectDataAttribute.SLOT_DESCRIPTOR_FILENAME) != null) { // These are the slots that the object *HAS* - SlotDescriptorData descriptor = (SlotDescriptorData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.SLOT_DESCRIPTOR), true); + SlotDescriptorData descriptor = (SlotDescriptorData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectDataAttribute.SLOT_DESCRIPTOR_FILENAME), true); if (descriptor == null) return; @@ -128,9 +133,9 @@ public final class ObjectCreator { } } - if (object.getTemplateAttribute(ObjectData.ARRANGEMENT_FILE) != null) { + if (object.getTemplateAttribute(ObjectDataAttribute.ARRANGEMENT_DESCRIPTOR_FILENAME) != null) { // This is what slots the created object is able to go into/use - SlotArrangementData arrangementData = (SlotArrangementData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.ARRANGEMENT_FILE), true); + SlotArrangementData arrangementData = (SlotArrangementData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectDataAttribute.ARRANGEMENT_DESCRIPTOR_FILENAME), true); if (arrangementData == null) return; diff --git a/src/services/objects/ObjectManager.java b/src/services/objects/ObjectManager.java index 667978c3f..af8123075 100644 --- a/src/services/objects/ObjectManager.java +++ b/src/services/objects/ObjectManager.java @@ -36,7 +36,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import intents.object.ObjectCreateIntent; import intents.object.ObjectCreatedIntent; import intents.object.ObjectIdRequestIntent; import intents.object.ObjectIdResponseIntent; @@ -99,7 +98,7 @@ public class ObjectManager extends Manager { registerForIntent(GalacticPacketIntent.TYPE); registerForIntent(ObjectTeleportIntent.TYPE); registerForIntent(ObjectIdRequestIntent.TYPE); - registerForIntent(ObjectCreateIntent.TYPE); + registerForIntent(ObjectCreatedIntent.TYPE); registerForIntent(DeleteCharacterIntent.TYPE); } @@ -197,16 +196,21 @@ public class ObjectManager extends Manager { processGalacticPacketIntent((GalacticPacketIntent) i); } else if (i instanceof ObjectIdRequestIntent) { processObjectIdRequestIntent((ObjectIdRequestIntent) i); - } else if (i instanceof ObjectCreateIntent) { - processObjectCreateIntent((ObjectCreateIntent) i); + } else if (i instanceof ObjectCreatedIntent) { + processObjectCreatedIntent((ObjectCreatedIntent) i); } else if (i instanceof DeleteCharacterIntent) { deleteObject(((DeleteCharacterIntent) i).getCreature().getObjectId()); } } - - private void processObjectCreateIntent(ObjectCreateIntent intent) { + + private void processObjectCreatedIntent(ObjectCreatedIntent intent) { SWGObject object = intent.getObject(); - objectMap.put(object.getObjectId(), object); + synchronized (objectMap) { + if (object.getObjectId() >= maxObjectId) { + maxObjectId = object.getObjectId() + 1; + } + objectMap.put(object.getObjectId(), object); + } } private void processObjectIdRequestIntent(ObjectIdRequestIntent intent) { diff --git a/src/services/spawn/StaticService.java b/src/services/spawn/StaticService.java index 7d813f4d2..0dadcc214 100644 --- a/src/services/spawn/StaticService.java +++ b/src/services/spawn/StaticService.java @@ -105,6 +105,8 @@ public class StaticService extends Service { } private SWGObject createObject(String iff, SWGObject parent, double x, double y, double z, double heading) { + if (parent == null) + return null; Location loc = new Location(x, y, z, parent.getTerrain()); loc.setHeading(heading); return objectManager.createObject(parent, iff, loc, false); diff --git a/test/resources/control/TestIntentQueue.java b/test/resources/control/TestIntentQueue.java index 6571e412a..31afcf1e5 100644 --- a/test/resources/control/TestIntentQueue.java +++ b/test/resources/control/TestIntentQueue.java @@ -4,9 +4,9 @@ import java.util.Arrays; import intents.LoginEventIntent; import intents.PlayerEventIntent; -import intents.object.ObjectCreateIntent; import intents.object.ObjectCreatedIntent; import intents.object.ObjectTeleportIntent; +import intents.object.UpdateObjectAwareness; import org.junit.Assert; import org.junit.Test; @@ -21,7 +21,7 @@ public class TestIntentQueue { Intent [] intents = new Intent[5]; intents[0] = new PlayerEventIntent(null, null); intents[1] = new ObjectTeleportIntent(null, null); - intents[2] = new ObjectCreateIntent(null); + intents[2] = new UpdateObjectAwareness(null, false); intents[3] = new ObjectCreatedIntent(null); intents[4] = new LoginEventIntent(0, null); IntentQueue queue = new IntentQueue();