public SWGObject deleteObject(long objId) { synchronized (objectMap) { SWGObject obj = objectMap.remove(objId); database.remove(objId); if (obj == null) return null; obj.clearAware(); objectAwareness.remove(obj); Log.i("ObjectManager", "Deleted object %d [%s]", obj.getObjectId(), obj.getTemplate()); return obj; } }
private void loadObjects() { long startLoad = System.nanoTime(); Log.i("ObjectManager", "Loading objects from ObjectDatabase..."); System.out.println("ObjectManager: Loading objects from ObjectDatabase..."); database.load(); database.traverse( new Traverser<SWGObject>() { @Override public void process(SWGObject obj) { loadObject(obj); if (obj.getObjectId() >= maxObjectId) { maxObjectId = obj.getObjectId() + 1; } } }); double loadTime = (System.nanoTime() - startLoad) / 1E6; Log.i("ObjectManager", "Finished loading %d objects. Time: %fms", database.size(), loadTime); System.out.printf( "ObjectManager: Finished loading %d objects. Time: %fms%n", database.size(), loadTime); }
private void updateBuildoutParent(SWGObject obj) { if (obj.getParent() != null) { if (obj.getParent().isBuildout()) { long id = obj.getParent().getObjectId(); obj.getParent().removeObject(obj); SWGObject parent = objectMap.get(id); if (parent != null) parent.addObject(obj); else { System.err.println("Parent for " + obj + " is null! ParentID: " + id); Log.e("ObjectManager", "Parent for %s is null! ParentID: %d", obj, id); } } else { updateBuildoutParent(obj.getParent()); } } }
public SWGObject createObject( SWGObject parent, String template, Location l, boolean addToDatabase) { synchronized (objectMap) { long objectId = getNextObjectId(); SWGObject obj = ObjectCreator.createObjectFromTemplate(objectId, template); if (obj == null) { System.err.println("ObjectManager: Unable to create object with template " + template); return null; } obj.setLocation(l); objectMap.put(objectId, obj); if (parent != null) { parent.addObject(obj); } if (addToDatabase) { database.put(objectId, obj); } Log.i("ObjectManager", "Created object %d [%s]", obj.getObjectId(), obj.getTemplate()); new ObjectCreatedIntent(obj).broadcast(); return obj; } }
private void zoneInCharacter( PlayerManager playerManager, String galaxy, long netId, long characterId) { Player player = playerManager.getPlayerFromNetworkId(netId); if (player == null) { Log.e("ObjectManager", "Unable to zone in null player '%d'", netId); return; } SWGObject creatureObj = objectMap.get(characterId); if (creatureObj == null) { System.err.println( "ObjectManager: Failed to start zone - CreatureObject could not be fetched from database [Character: " + characterId + " User: "******"]"); Log.e( "ObjectManager", "Failed to start zone - CreatureObject could not be fetched from database [Character: %d User: %s]", characterId, player.getUsername()); sendClientFatal( player, "Failed to zone", "You were not found in the database\nTry relogging to fix this problem", 10, TimeUnit.SECONDS); return; } if (!(creatureObj instanceof CreatureObject)) { System.err.println( "ObjectManager: Failed to start zone - Object is not a CreatureObject for ID " + characterId); Log.e( "ObjectManager", "Failed to start zone - Object is not a CreatureObject [Character: %d User: %s]", characterId, player.getUsername()); sendClientFatal( player, "Failed to zone", "There has been an internal server error: Not a Creature.\nPlease delete your character and create a new one", 10, TimeUnit.SECONDS); return; } if (((CreatureObject) creatureObj).getPlayerObject() == null) { System.err.println( "ObjectManager: Failed to start zone - " + player.getUsername() + "'s CreatureObject has a null ghost!"); Log.e( "ObjectManager", "Failed to start zone - CreatureObject doesn't have a ghost [Character: %d User: %s", characterId, player.getUsername()); sendClientFatal( player, "Failed to zone", "There has been an internal server error: Null Ghost.\nPlease delete your character and create a new one", 10, TimeUnit.SECONDS); return; } if (creatureObj.getParent() != null) { objectAwareness.update(creatureObj); Log.d( "ObjectManager", "Zoning in to %s/%s - %s", creatureObj.getParent(), creatureObj.getTerrain(), creatureObj.getLocation().getPosition()); } else { objectAwareness.remove(creatureObj); objectAwareness.add(creatureObj); Log.d( "ObjectManager", "Zoning in to %s - %s", creatureObj.getTerrain(), creatureObj.getLocation().getPosition()); } new RequestZoneInIntent(player, (CreatureObject) creatureObj, galaxy).broadcast(); }