use of io.xol.chunkstories.api.player.Player in project chunkstories by Hugobros3.
the class FoodCommand 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("self.setfood")) {
emitter.sendMessage("You don't have the permission.");
return true;
}
if (arguments.length < 1 || !isNumeric(arguments[0])) {
emitter.sendMessage("Syntax: /food <hp>");
return true;
}
float food = Float.parseFloat(arguments[0]);
Entity controlledEntity = player.getControlledEntity();
if (controlledEntity != null && controlledEntity instanceof EntityFeedable) {
((EntityFeedable) controlledEntity).setFoodLevel(food);
player.sendMessage("Food set to: " + food);
return true;
}
emitter.sendMessage("This action doesn't apply to your current entity.");
return true;
}
use of io.xol.chunkstories.api.player.Player in project chunkstories by Hugobros3.
the class GiveCommand method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (!emitter.hasPermission("server.give")) {
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;
}
Content gameContent = server.getContent();
Player player = (Player) emitter;
if (arguments.length == 0) {
player.sendMessage("#FF969BSyntax : /give <item> [amount] [to]");
return true;
}
int amount = 1;
Player to = player;
String itemName = arguments[0];
// Look for the item first
ItemDefinition type = gameContent.items().getItemDefinition(itemName);
// If the type was found we are simply trying to spawn an item
Item item = null;
if (type != null)
item = type.newItem();
else {
String voxelName = itemName;
int voxelMeta = 0;
if (voxelName.contains(":")) {
voxelMeta = Integer.parseInt(voxelName.split(":")[1]);
voxelName = voxelName.split(":")[0];
}
// Try to find a matching voxel
Voxel voxel = gameContent.voxels().getVoxel(itemName);
if (voxel != null) {
// Spawn new itemPile in his inventory
ItemVoxel itemVoxel = (ItemVoxel) gameContent.items().getItemDefinition("item_voxel").newItem();
itemVoxel.voxel = voxel;
itemVoxel.voxelMeta = voxelMeta;
item = itemVoxel;
}
}
if (item == null) {
player.sendMessage("#FF969BItem or voxel \"" + arguments[0] + " can't be found.");
return true;
}
if (arguments.length >= 2) {
amount = Integer.parseInt(arguments[1]);
}
if (arguments.length >= 3) {
if (gameContent instanceof ServerInterface)
to = ((ServerInterface) gameContent).getPlayerByName(arguments[2]);
else {
player.sendMessage("#FF969BThis is a singleplayer world - there are no other players");
return true;
}
}
if (to == null) {
player.sendMessage("#FF969BPlayer \"" + arguments[2] + " can't be found.");
return true;
}
ItemPile itemPile = new ItemPile(item);
itemPile.setAmount(amount);
((EntityWithInventory) to.getControlledEntity()).getInventory().addItemPile(itemPile);
player.sendMessage("#FF969BGave " + (amount > 1 ? amount + "x " : "") + "#4CFF00" + itemPile.getItem().getName() + " #FF969Bto " + to.getDisplayName());
return true;
}
use of io.xol.chunkstories.api.player.Player 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.player.Player 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.player.Player in project chunkstories by Hugobros3.
the class ModerationCommands method handleCommand.
@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
if (command.getName().equals("kick") && emitter.hasPermission("server.admin.kick")) {
if (arguments.length >= 1) {
Player clientByName = server.getPlayerByName(arguments[0]);
String kickReason = "Please refrain from further portrayal of such imbecile attitudes";
// Recreate the argument
if (arguments.length >= 2) {
kickReason = "";
for (int i = 1; i < arguments.length; i++) kickReason += arguments[i] + (i < arguments.length - 1 ? " " : "");
}
if (clientByName != null) {
clientByName.disconnect("Kicked from server. \n" + kickReason);
// server.handler.disconnectClient(tokick);
emitter.sendMessage("Kicked " + clientByName + " for " + kickReason);
} else {
emitter.sendMessage("User '" + clientByName + "' not found.");
}
return true;
} else {
emitter.sendMessage("Syntax: /kick <playerName> [reason]");
return true;
}
}
// TODO ban/unban commands
return false;
}
Aggregations