@Command( aliases = {"gamemode", "gm"}, usage = "[player] <0|1|2|survival|creative|adventure> (0 = SURVIVAL, 1 = CREATIVE, 2 = ADVENTURE)", desc = "Change a player's game mode", min = 1, max = 2) @CommandPermissions("vanilla.command.gamemode") public void gamemode(CommandContext args, CommandSource source) throws CommandException { int index = 0; Player player; if (args.length() == 2) { if (Spout.getEngine() instanceof Client) { throw new CommandException("You cannot search for players unless you are in server mode."); } player = Spout.getEngine().getPlayer(args.getString(index++), true); if (player == null) { throw new CommandException(args.getString(0) + " is not online."); } } else { if (!(source instanceof Player)) { throw new CommandException("You must be a player to toggle your game mode."); } player = (Player) source; } if (!player.has(Human.class)) { throw new CommandException("Invalid player!"); } GameMode mode; try { if (args.isInteger(index)) { mode = GameMode.get(args.getInteger(index)); } else { mode = GameMode.get(args.getString(index)); } } catch (Exception e) { throw new CommandException( "A game mode must be either a number between 0 and 2, 'CREATIVE', 'SURVIVAL' or 'ADVENTURE'"); } player.get(Human.class).setGamemode(mode); if (!player.equals(source)) { source.sendMessage( plugin.getPrefix(), ChatStyle.WHITE, player.getName(), "'s ", ChatStyle.BRIGHT_GREEN, "gamemode has been changed to ", ChatStyle.WHITE, mode.name(), ChatStyle.BRIGHT_GREEN, "."); } }
@Command( aliases = "xp", usage = "[player] <amount>", desc = "Give/take experience from a player", min = 1, max = 2) @CommandPermissions("vanilla.command.xp") public void xp(CommandContext args, CommandSource source) throws CommandException { // If source is player if (args.length() == 1) { if (source instanceof Player) { @SuppressWarnings("unused") Player sender = (Player) source; int amount = args.getInteger(0); source.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "You have been given ", ChatStyle.WHITE, amount, ChatStyle.BRIGHT_GREEN, " xp."); // TODO: Give player 'amount' of xp. } else { throw new CommandException("You must be a player to give yourself xp."); } } else { if (Spout.getEngine() instanceof Client) { throw new CommandException("You cannot search for players unless you are in server mode."); } Player player = ((Server) Spout.getEngine()).getPlayer(args.getString(0), true); if (player != null) { short amount = (short) args.getInteger(1); LevelComponent level = player.get(LevelComponent.class); if (level == null) { return; } if (amount > 0) { level.addExperience(amount); } else { level.removeExperience(amount); } player.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Your experience has been set to ", ChatStyle.WHITE, amount, ChatStyle.BRIGHT_GREEN, "."); } else { throw new CommandException(args.getString(0) + " is not online."); } } }
@Override public void handlePlayer(Player player, Command command, CommandContext args) { game = GameManager.INSTANCE.getRawGame(args.getString(0)); if (game == null) { ChatUtils.error(player, Lang.getNotExist().replace("<item>", args.getString(0))); return; } ChatUtils.send(player, ChatStyle.BRIGHT_GREEN, "Hit a chest to add it to %s.", game.getName()); if (args.getRawArgs().size() == 2) { try { float weight = (float) args.getDouble(1); SessionListener.addSession( SessionType.CHEST_ADDER, player, args.getString(0), "weight", weight); return; } catch (NumberFormatException numberFormatException) { } } SessionListener.addSession(SessionType.CHEST_ADDER, player, args.getString(0)); }
@Command( aliases = {"op"}, usage = "<player>", desc = "Make a player an operator", min = 1, max = 1) @CommandPermissions("vanilla.command.op") public void op(CommandContext args, CommandSource source) throws CommandException { if (Spout.getEngine() instanceof Client) { throw new CommandException("You cannot search for players unless you are in server mode."); } String playerName = args.getString(0); OpConfiguration ops = VanillaConfiguration.OPS; ops.setOp(playerName, true); source.sendMessage(plugin.getPrefix(), ChatStyle.RED, playerName, " is now an operator!"); Player player = Spout.getEngine().getPlayer(playerName, true); if (player != null && !source.equals(player)) { player.sendMessage(plugin.getPrefix(), ChatStyle.YELLOW, "You are now an operator!"); } }
@Command( aliases = {"kill"}, usage = "[player]", desc = "Kill yourself or another player", min = 0, max = 1) @CommandPermissions("vanilla.command.kill") public void kill(CommandContext args, CommandSource source) throws CommandException { if (args.length() == 0) { if (!(source instanceof Player)) { throw new CommandException("Don't be silly...you cannot kill yourself as the console."); } ((Player) source).get(HealthComponent.class).kill(HealthChangeCause.COMMAND); } else { if (Spout.getEngine() instanceof Client) { throw new CommandException("You cannot search for players unless you are in server mode."); } Player victim = ((Server) Spout.getEngine()).getPlayer(args.getString(0), true); if (victim != null) { victim.get(HealthComponent.class).kill(HealthChangeCause.COMMAND); } } }
@Command( aliases = "weather", usage = "<0|1|2> (0 = CLEAR, 1 = RAIN/SNOW, 2 = THUNDERSTORM) [world]", desc = "Changes the weather", min = 1, max = 2) @CommandPermissions("vanilla.command.weather") public void weather(CommandContext args, CommandSource source) throws CommandException { World world; if (source instanceof Player && args.length() == 1) { world = ((Player) source).getWorld(); } else if (args.length() == 2) { world = plugin.getEngine().getWorld(args.getString(1)); if (world == null) { throw new CommandException("Invalid world '" + args.getString(1) + "'."); } } else { throw new CommandException("You need to specify a world."); } Weather weather; try { if (args.isInteger(0)) { weather = Weather.get(args.getInteger(0)); } else { weather = Weather.get(args.getString(0).replace("snow", "rain")); } } catch (Exception e) { throw new CommandException( "Weather must be a mode between 0 and 2, 'CLEAR', 'RAIN', 'SNOW', or 'THUNDERSTORM'"); } VanillaSky sky = VanillaSky.getSky(world); if (sky == null) { throw new CommandException("The sky of world '" + world.getName() + "' is not availible."); } sky.setWeather(weather); ChatArguments message; switch (weather) { case RAIN: message = new ChatArguments( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Weather set to ", ChatStyle.WHITE, "RAIN/SNOW", ChatStyle.BRIGHT_GREEN, "."); break; default: message = new ChatArguments( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Weather set to ", ChatStyle.WHITE, weather.name(), ChatStyle.BRIGHT_GREEN, "."); break; } if (Spout.getEngine() instanceof Client) { source.sendMessage(message); } else { for (Player player : ((Server) Spout.getEngine()).getOnlinePlayers()) { if (player.getWorld().equals(world)) { player.sendMessage(message); } } } }
@Command( aliases = {"time"}, usage = "<add|set> <0-24000|day|night|dawn|dusk> [world]", desc = "Set the time of the server", min = 2, max = 3) @CommandPermissions("vanilla.command.time") public void time(CommandContext args, CommandSource source) throws CommandException { long time = 0; boolean relative = false; if (args.getString(0).equalsIgnoreCase("set")) { if (args.isInteger(1)) { time = args.getInteger(1); } else { try { time = Time.get(args.getString(1)).getTime(); } catch (Exception e) { throw new CommandException("'" + args.getString(1) + "' is not a valid time."); } } } else if (args.getString(0).equalsIgnoreCase("add")) { relative = true; if (args.isInteger(1)) { time = args.getInteger(1); } else { throw new CommandException("Argument to 'add' must be an integer."); } } World world; if (args.length() == 3) { world = plugin.getEngine().getWorld(args.getString(2)); if (world == null) { throw new CommandException("'" + args.getString(2) + "' is not a valid world."); } } else if (source instanceof Player) { Player player = (Player) source; world = player.getWorld(); } else { throw new CommandException("You must specify a world."); } VanillaSky sky = VanillaSky.getSky(world); if (sky == null) { throw new CommandException("The sky for " + world.getName() + " is not available."); } sky.setTime(relative ? (sky.getTime() + time) : time); if (Spout.getEngine() instanceof Client) { source.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "You set ", ChatStyle.WHITE, world.getName(), ChatStyle.BRIGHT_GREEN, " to time: ", ChatStyle.WHITE, sky.getTime()); } else { ((Server) Spout.getEngine()) .broadcastMessage( plugin.getPrefix(), ChatStyle.WHITE, world.getName(), ChatStyle.BRIGHT_GREEN, " set to: ", ChatStyle.WHITE, sky.getTime()); } }
@Command( aliases = {"give"}, usage = "[player] <block> [amount] ", desc = "Lets a player spawn items", min = 1, max = 3) @CommandPermissions("vanilla.command.give") public void give(CommandContext args, CommandSource source) throws CommandException { int index = 0; Player player = null; if (args.length() != 1) { if (Spout.getEngine() instanceof Client) { throw new CommandException("You cannot search for players unless you are in server mode."); } player = Spout.getEngine().getPlayer(args.getString(index++), true); } if (player == null) { switch (args.length()) { case 3: throw new CommandException(args.getString(0) + " is not online."); case 2: index--; case 1: if (!(source instanceof Player)) { throw new CommandException("You must be a player to give yourself materials!"); } player = (Player) source; break; } } Material material; if (args.isInteger(index)) { material = VanillaMaterials.getMaterial((short) args.getInteger(index)); } else { String name = args.getString(index); if (name.contains(":")) { String[] parts = args.getString(index).split(":"); material = VanillaMaterials.getMaterial(Short.parseShort(parts[0]), Short.parseShort(parts[1])); } else { material = Material.get(args.getString(index)); } } if (material == null) { throw new CommandException(args.getString(index) + " is not a block!"); } int count = args.getInteger(++index, 1); player.get(PlayerInventory.class).add(new ItemStack(material, count)); source.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Gave ", ChatStyle.WHITE, player.getName() + " ", count, ChatStyle.BRIGHT_GREEN, " of ", ChatStyle.WHITE, material.getDisplayName()); }