Search in sources :

Example 11 with Player

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;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) EntityFeedable(io.xol.chunkstories.api.entity.interfaces.EntityFeedable)

Example 12 with Player

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;
}
Also used : Item(io.xol.chunkstories.api.item.Item) Player(io.xol.chunkstories.api.player.Player) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ServerInterface(io.xol.chunkstories.api.server.ServerInterface) Content(io.xol.chunkstories.api.content.Content) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) ItemDefinition(io.xol.chunkstories.api.item.ItemDefinition) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 13 with Player

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;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Location(io.xol.chunkstories.api.Location)

Example 14 with Player

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;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Location(io.xol.chunkstories.api.Location)

Example 15 with Player

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;
}
Also used : Player(io.xol.chunkstories.api.player.Player)

Aggregations

Player (io.xol.chunkstories.api.player.Player)33 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)9 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)7 ServerPlayer (io.xol.chunkstories.server.player.ServerPlayer)5 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)4 Controller (io.xol.chunkstories.api.entity.Controller)4 World (io.xol.chunkstories.api.world.World)4 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)3 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)3 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)3 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)3 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)3 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)3 ByteBuffer (java.nio.ByteBuffer)3 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)2 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)2 EventItemDroppedToWorld (io.xol.chunkstories.api.events.item.EventItemDroppedToWorld)2 PlayerMoveItemEvent (io.xol.chunkstories.api.events.player.PlayerMoveItemEvent)2