use of cn.nukkit.level.Position in project Nukkit by Nukkit.
the class ProjectileDispenseBehavior method dispense.
@Override
public void dispense(BlockDispenser source, Item item) {
Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel());
CompoundTag nbt = Entity.getDefaultNBT(dispensePos);
this.correctNBT(nbt);
BlockFace face = source.getFacing();
Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt);
if (projectile == null) {
return;
}
projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6));
projectile.spawnToAll();
}
use of cn.nukkit.level.Position in project Nukkit by Nukkit.
the class Server method getOfflinePlayerData.
public CompoundTag getOfflinePlayerData(String name) {
name = name.toLowerCase();
String path = this.getDataPath() + "players/";
File file = new File(path + name + ".dat");
if (this.shouldSavePlayerData() && file.exists()) {
try {
return NBTIO.readCompressed(new FileInputStream(file));
} catch (Exception e) {
file.renameTo(new File(path + name + ".dat.bak"));
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerCorrupted", name));
}
} else {
this.logger.notice(this.getLanguage().translateString("nukkit.data.playerNotFound", name));
}
Position spawn = this.getDefaultLevel().getSafeSpawn();
CompoundTag nbt = new CompoundTag().putLong("firstPlayed", System.currentTimeMillis() / 1000).putLong("lastPlayed", System.currentTimeMillis() / 1000).putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("0", spawn.x)).add(new DoubleTag("1", spawn.y)).add(new DoubleTag("2", spawn.z))).putString("Level", this.getDefaultLevel().getName()).putList(new ListTag<>("Inventory")).putCompound("Achievements", new CompoundTag()).putInt("playerGameType", this.getGamemode()).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("0", 0)).add(new DoubleTag("1", 0)).add(new DoubleTag("2", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("0", 0)).add(new FloatTag("1", 0))).putFloat("FallDistance", 0).putShort("Fire", 0).putShort("Air", 300).putBoolean("OnGround", true).putBoolean("Invulnerable", false).putString("NameTag", name);
this.saveOfflinePlayerData(name, nbt);
return nbt;
}
use of cn.nukkit.level.Position in project Nukkit by Nukkit.
the class SpawnpointCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
Player target;
if (args.length == 0) {
if (sender instanceof Player) {
target = (Player) sender;
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
} else {
target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
}
Level level = target.getLevel();
DecimalFormat round2 = new DecimalFormat("##0.00");
if (args.length == 4) {
if (level != null) {
int x;
int y;
int z;
try {
x = Integer.parseInt(args[1]);
y = Integer.parseInt(args[2]);
z = Integer.parseInt(args[3]);
} catch (NumberFormatException e1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if (y < 0)
y = 0;
if (y > 256)
y = 256;
target.setSpawn(new Position(x, y, z, level));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.spawnpoint.success", new String[] { target.getName(), round2.format(x), round2.format(y), round2.format(z) }));
return true;
}
} else if (args.length <= 1) {
if (sender instanceof Player) {
Position pos = (Position) sender;
target.setSpawn(pos);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.spawnpoint.success", new String[] { target.getName(), round2.format(pos.x), round2.format(pos.y), round2.format(pos.z) }));
return true;
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
}
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
Aggregations