use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class MultithreadedOfflineWorldConverter method stetFourTidbits.
protected void stetFourTidbits(MinecraftWorld mcWorld, WorldImplementation csWorld) {
verbose("Entering step four: tidbits");
int spawnX = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnX")).getData();
int spawnY = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnY")).getData();
int spawnZ = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnZ")).getData();
csWorld.setDefaultSpawnLocation(new Location(csWorld, spawnX, spawnY, spawnZ));
csWorld.saveEverything().traverse();
csWorld.destroy();
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class SpawnEntityCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!(emitter instanceof Player)) {
emitter.sendMessage("You need to be a player to use this command.");
return true;
}
Player player = (Player) emitter;
if (!emitter.hasPermission("world.spawnEntity")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
if (arguments.length == 0) {
emitter.sendMessage("Syntax: /spawnEntity <entityId> [x y z]");
return false;
}
Location loc = player.getLocation();
if (arguments.length >= 4) {
loc = new Location(player.getWorld(), Double.parseDouble(arguments[1]), Double.parseDouble(arguments[2]), Double.parseDouble(arguments[3]));
}
EntityDefinition entityType;
String entityName = arguments[0];
entityType = server.getContent().entities().getEntityDefinition(entityName);
if (entityType == null) {
emitter.sendMessage("Entity type : " + arguments[0] + " not found in loaded content.");
return true;
}
Entity entity = entityType.create(loc);
entity.setLocation(loc);
loc.getWorld().addEntity(entity);
emitter.sendMessage("#00FFD0" + "Spawned " + entity.getClass().getSimpleName() + " at " + (arguments.length >= 4 ? loc.toString() : player.getName()));
return true;
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class SpawnCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!(emitter instanceof Player)) {
emitter.sendMessage("You need to be a player to use this command.");
return true;
}
Player player = (Player) emitter;
if (command.getName().equals("spawn")) {
if (!emitter.hasPermission("world.spawn")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
Location loc = player.getWorld().getDefaultSpawnLocation();
player.setLocation(loc);
emitter.sendMessage("#00FFD0Teleported to spawn");
return true;
} else if (command.getName().equals("setspawn")) {
if (!emitter.hasPermission("world.spawn.set")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
Location loc = player.getLocation();
player.getWorld().setDefaultSpawnLocation(loc);
emitter.sendMessage("#00FFD0Set default spawn to : " + loc);
return true;
}
return false;
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class TpCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!emitter.hasPermission("server.tp")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
if (!(emitter instanceof Player)) {
emitter.sendMessage("You need to be a player to use this command.");
return true;
}
Player who = (Player) emitter;
Location to = null;
if (arguments.length == 1) {
Player otherPlayer = server.getPlayerByName(arguments[0]);
if (otherPlayer != null)
to = otherPlayer.getLocation();
else
emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
} else if (arguments.length == 2) {
who = server.getPlayerByName(arguments[0]);
if (who == null)
emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
Player otherPlayer = server.getPlayerByName(arguments[1]);
if (otherPlayer != null)
to = otherPlayer.getLocation();
else
emitter.sendMessage("#FF8966Player not found : " + arguments[1]);
} else if (arguments.length == 3) {
int x = Integer.parseInt(arguments[0]);
int y = Integer.parseInt(arguments[1]);
int z = Integer.parseInt(arguments[2]);
to = new Location(who.getLocation().getWorld(), x, y, z);
} else if (arguments.length == 4) {
who = server.getPlayerByName(arguments[0]);
if (who == null)
emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
int x = Integer.parseInt(arguments[1]);
int y = Integer.parseInt(arguments[2]);
int z = Integer.parseInt(arguments[3]);
to = new Location(who.getLocation().getWorld(), x, y, z);
}
if (who != null && to != null) {
emitter.sendMessage("#FF8966Teleported to : " + to);
who.setLocation(to);
return true;
}
emitter.sendMessage("#FF8966Usage: /tp [who] (<x> <y> <z>)|(to)");
return true;
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class EntitySerializer method readEntityFromStream.
public static Entity readEntityFromStream(DataInputStream dis, OfflineSerializedData source, World world) {
try {
int entityDataLength = dis.readInt();
if (entityDataLength == -1)
return null;
DataInputStream in = LengthAwareBufferedIOHelper.getLengthAwareInput(entityDataLength, dis);
long entityUUID = in.readLong();
// Obsolete ?
// When we reach id -1 in a stream of entities, it means we reached the end.
// if(entityUUID == -1)
// return null;
short entityTypeID = in.readShort();
/*System.out.println("world"+world);
System.out.println("world.getGameContext()"+world.getGameContext());
System.out.println("world.getGameContext().getContent().entities()"+world.getGameContext().getContent().entities());
System.out.println("world.getGameContext().getContent().entities().getEntityTypeById(entityTypeID)"+world.getGameContext().getContent().entities().getEntityTypeById(entityTypeID));
*/
Entity entity = world.getContentTranslator().getEntityForId(entityTypeID).create(new Location(world, 0d, 0d, 0d));
entity.setUUID(entityUUID);
int componentId = in.readInt();
// Loop throught all components
while (true) {
if (// End of components to read
componentId == 0)
break;
else if (componentId == -1) {
// Read UTF-8 component name
String componentName = in.readUTF();
try {
entity.getComponents().tryPullComponentInStream(componentName, source, in);
} catch (UnknownComponentException e) {
logger().warn("Failure reading component " + componentName + " from " + source);
logger().warn(e.getMessage());
}
} else {
// Read int32 component id
try {
entity.getComponents().tryPullComponentInStream(componentId, source, in);
} catch (UnknownComponentException e) {
logger().warn(e.getMessage());
}
}
componentId = in.readInt();
}
return entity;
} catch (NullPointerException | IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations