Search in sources :

Example 51 with Player

use of org.spongepowered.api.entity.living.player.Player in project HuskyCrates-Sponge by codeHusky.

the class Chest method execute.

@Override
public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (commandContext.getOne("type").isPresent()) {
        String type = commandContext.<String>getOne("type").get();
        Optional<Player> player = commandContext.getOne("player");
        VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
        int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
        if (virtualCrate == null) {
            commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
            return CommandResult.empty();
        }
        if (!player.isPresent()) {
            commandSource.sendMessage(Text.of("You need to either specify a player or be in game"));
            return CommandResult.empty();
        }
        ItemStack chestItemStack = virtualCrate.getCrateItem(quantity);
        InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(chestItemStack.copy()).getType();
        if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
            InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(chestItemStack.copy()).getType();
            if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
                commandSource.sendMessage(Text.of("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest"));
                HuskyCrates.instance.logger.info("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest");
            } else {
                if (player.isPresent()) {
                    player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " crate(s), but some have been placed in your Ender Chest."));
                } else {
                    commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " crate(s), but some have been placed in your Ender Chest."));
                }
            }
        }
    } else {
        commandSource.sendMessage(Text.of("Usage: /crate chest <id> [player]"));
    }
    return CommandResult.success();
}
Also used : VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 52 with Player

use of org.spongepowered.api.entity.living.player.Player in project HuskyCrates-Sponge by codeHusky.

the class Key method execute.

@Override
public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (commandContext.getOne("type").isPresent()) {
        String type = commandContext.<String>getOne("type").get();
        Optional<Player> player = commandContext.getOne("player");
        VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
        int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
        if (virtualCrate == null) {
            commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
            return CommandResult.empty();
        }
        if (!player.isPresent()) {
            commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
            return CommandResult.empty();
        }
        ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
        InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(keyItemStack.copy()).getType();
        if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
            InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(keyItemStack.copy()).getType();
            if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
                commandSource.sendMessage(Text.of("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest"));
                HuskyCrates.instance.logger.info("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest");
            } else {
                if (player.isPresent()) {
                    player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
                } else {
                    commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
                }
            }
        }
    } else {
        commandSource.sendMessage(Text.of("Usage: /crate key <id> [player] [count]"));
    }
    return CommandResult.success();
}
Also used : VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 53 with Player

use of org.spongepowered.api.entity.living.player.Player in project ClearMob by axle2005.

the class CommandInfo method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext arguments) throws CommandException {
    String type = arguments.<String>getOne("range/hand").get();
    if (!Util.playerPermCheck(src, "clearmob.admin")) {
        return CommandResult.empty();
    } else if (src instanceof Player) {
        Player player = (Player) src;
        if (type.equalsIgnoreCase("hand")) {
            player.sendMessage(Text.of(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getId()));
            return CommandResult.success();
        } else if (type.equalsIgnoreCase("range")) {
            Integer range = arguments.<Integer>getOne("range").get();
            Collection<Entity> e = player.getNearbyEntities(range);
            for (Entity en : e) {
                plugin.getLogger().info("Entity: " + en.getType().getId());
                plugin.getLogger().info("Name " + en.getType().getName());
                plugin.getLogger().info("DisplayName " + en.getContainers());
                plugin.getLogger().info("Display " + en.getValues());
                if (en.getKeys().contains(Keys.DISPLAY_NAME)) {
                    plugin.getLogger().info("D " + en.get(Keys.DISPLAY_NAME));
                }
            }
            return CommandResult.success();
        } else {
            src.sendMessage(Text.of("clearmob <info><range|hand>"));
            return CommandResult.empty();
        }
    } else {
        src.sendMessage(Text.of("You can not run this command"));
        return CommandResult.empty();
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player)

Example 54 with Player

use of org.spongepowered.api.entity.living.player.Player in project ClearMob by axle2005.

the class CommandSearch method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext arguments) throws CommandException {
    String args = arguments.<String>getOne("tileentity|entity|nearby|all").get();
    if (src instanceof Player && !src.hasPermission("clearmob.dump")) {
        Player player = (Player) src;
        player.sendMessage(Text.of("You do not have permission to use this command!"));
        return CommandResult.empty();
    }
    if (args.equalsIgnoreCase("entity")) {
        // entityDump();
        return CommandResult.success();
    } else {
        src.sendMessage(Text.of("/clearmob <search><entityid>"));
        return CommandResult.empty();
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player)

Example 55 with Player

use of org.spongepowered.api.entity.living.player.Player in project ClearMob by axle2005.

the class ClearEntity method run.

public static void run(ClearMob plugin, EntityType tile, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<Entity> e = new ArrayList<Entity>();
    for (World world : worlds) {
        for (Entity entity : world.getEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (Entity entity : e) {
            if (!(entity instanceof Item) && !(entity instanceof Player) && !(entity instanceof ExperienceOrb)) {
                if ((entity.getType().equals(tile))) {
                    entity.getLocation().removeBlock(Cause.source(Sponge.getPluginManager().fromInstance(plugin).get()).build());
                    removedentities++;
                }
            }
        }
    }
    feedback(plugin, src, removedentities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World)

Aggregations

Player (org.spongepowered.api.entity.living.player.Player)125 Listener (org.spongepowered.api.event.Listener)40 ItemStack (org.spongepowered.api.item.inventory.ItemStack)28 Entity (org.spongepowered.api.entity.Entity)25 World (org.spongepowered.api.world.World)21 Text (org.spongepowered.api.text.Text)17 BigDecimal (java.math.BigDecimal)16 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)12 Vector3d (com.flowpowered.math.vector.Vector3d)10 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)10 List (java.util.List)10 Optional (java.util.Optional)10 ItemStack (net.minecraft.item.ItemStack)10 Living (org.spongepowered.api.entity.living.Living)10 Task (org.spongepowered.api.scheduler.Task)10 Location (org.spongepowered.api.world.Location)10 MarketService (com.skelril.skree.service.MarketService)8 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 TextColors (org.spongepowered.api.text.format.TextColors)8