use of io.xol.chunkstories.api.entity.interfaces.EntityNameable 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