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();
}
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();
}
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();
}
}
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();
}
}
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);
}
Aggregations