use of io.xol.chunkstories.entity.SerializedEntityFile in project chunkstories by Hugobros3.
the class Ingame method destroy.
@Override
public void destroy() {
// Logout sequence: Save the player entity
if (world instanceof WorldMaster) {
Player player = getPlayer();
PlayerLogoutEvent playerDisconnectionEvent = new PlayerLogoutEvent(player);
world.getPluginManager().fireEvent(playerDisconnectionEvent);
if (this.playerEntity != null) {
SerializedEntityFile playerEntityFile = new SerializedEntityFile(world.getFolderPath() + "/players/" + getPlayer().getName().toLowerCase() + ".csf");
playerEntityFile.write(this.playerEntity);
}
}
// Stop the game logic and save
if (world instanceof WorldMaster) {
// TODO: Stop simulation
Fence fence = ((WorldMaster) world).stopLogic();
// exitButton.text = "#{world.saving}";
fence.traverse();
fence = world.saveEverything();
// exitButton.text = "#{world.saving}";
fence.traverse();
}
// Disables plugins
world.getPluginManager().disablePlugins();
this.world.getWorldRenderer().destroy();
}
use of io.xol.chunkstories.entity.SerializedEntityFile in project chunkstories by Hugobros3.
the class ServerPlayer method save.
/**
* Serializes the stuff describing this player
*/
public void save() {
long lastTime = playerDataFile.getLong("timeplayed", 0);
long lastLogin = playerDataFile.getLong("lastlogin", 0);
if (controlledEntity != null) {
// Useless, kept for admin easyness, scripts, whatnot
Location controlledEntityLocation = controlledEntity.getLocation();
// Safely assumes as a SERVER the world will be master ;)
WorldMaster world = (WorldMaster) controlledEntityLocation.getWorld();
playerDataFile.setDouble("posX", controlledEntityLocation.x());
playerDataFile.setDouble("posY", controlledEntityLocation.y());
playerDataFile.setDouble("posZ", controlledEntityLocation.z());
playerDataFile.setString("world", world.getWorldInfo().getInternalName());
// Serializes the whole player entity !!!
SerializedEntityFile playerEntityFile = new SerializedEntityFile(world.getFolderPath() + "/players/" + this.getName().toLowerCase() + ".csf");
playerEntityFile.write(controlledEntity);
}
// Telemetry (EVIL)
playerDataFile.setString("timeplayed", "" + (lastTime + (System.currentTimeMillis() - lastLogin)));
playerDataFile.save();
System.out.println("Player profile " + name + " saved.");
}
use of io.xol.chunkstories.entity.SerializedEntityFile in project chunkstories by Hugobros3.
the class WorldImplementation method spawnPlayer.
public void spawnPlayer(Player player) {
if (!(this instanceof WorldMaster))
throw new UnsupportedOperationException("Only Master Worlds can do this");
Entity savedEntity = null;
SerializedEntityFile playerEntityFile = new SerializedEntityFile(this.getFolderPath() + "/players/" + player.getName().toLowerCase() + ".csf");
if (playerEntityFile.exists())
savedEntity = playerEntityFile.read(this);
Location previousLocation = null;
if (savedEntity != null)
previousLocation = savedEntity.getLocation();
PlayerSpawnEvent playerSpawnEvent = new PlayerSpawnEvent(player, (WorldMaster) this, savedEntity, previousLocation);
getGameContext().getPluginManager().fireEvent(playerSpawnEvent);
if (!playerSpawnEvent.isCancelled()) {
Entity entity = playerSpawnEvent.getEntity();
Location actualSpawnLocation = playerSpawnEvent.getSpawnLocation();
if (actualSpawnLocation == null)
actualSpawnLocation = this.getDefaultSpawnLocation();
// TODO EntitySimplePlayer ?
if (entity == null || ((entity instanceof EntityLiving) && (((EntityLiving) entity).isDead())))
entity = this.gameContext.getContent().entities().getEntityDefinition("player").create(actualSpawnLocation);
else
// entity = new EntityPlayer(this, 0d, 0d, 0d, player.getName()); //Default entity
entity.setUUID(-1);
// Name your player !
if (entity instanceof EntityNameable)
((EntityNameable) entity).getNameComponent().setName(player.getName());
entity.setLocation(actualSpawnLocation);
addEntity(entity);
if (entity instanceof EntityControllable)
player.setControlledEntity((EntityControllable) entity);
else
System.out.println("Error : entity is not controllable");
}
}
Aggregations