@Command(aliases = "clear", usage = "[player]", desc = "Clears your inventory", min = 0, max = 1) @CommandPermissions("vanilla.command.clear") public void clear(CommandContext args, CommandSource source) throws CommandException { if (args.length() == 0) { if (!(source instanceof Player)) { throw new CommandException("You must be a player to clear your own inventory."); } PlayerInventory inv = ((Player) source).get(PlayerInventory.class); if (inv == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "You have no inventory!"); return; } inv.clear(); } if (args.length() == 1) { Player player = args.getPlayer(0, false); if (player == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player is not online!"); return; } PlayerInventory inv = player.get(PlayerInventory.class); if (inv == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player has no inventory!"); return; } player.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Your inventory has been cleared."); if (source instanceof Player && source.equals(player)) { return; } } source.sendMessage(plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Inventory cleared."); }
@Command( aliases = {"tps"}, usage = "", desc = "Print out the current engine ticks per second", min = 0, max = 0) @CommandPermissions("vanilla.command.tps") public void getTPS(CommandContext args, CommandSource source) throws CommandException { source.sendMessage("TPS: " + tpsMonitor.getTPS()); source.sendMessage("Average TPS: " + tpsMonitor.getAvgTPS()); }
@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 = {"biome"}, usage = "", desc = "Print out the name of the biome at the current location", min = 0, max = 0) @CommandPermissions("vanilla.command.biome") public void getBiomeName(CommandContext args, CommandSource source) throws CommandException { if (!(source instanceof Player)) { throw new CommandException("Only a player may call this command."); } Player player = (Player) source; if (!(player.getTransform().getPosition().getWorld().getGenerator() instanceof BiomeGenerator)) { throw new CommandException("This map does not appear to have any biome data."); } Point pos = player.getTransform().getPosition(); Biome biome = pos.getWorld().getBiome(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); source.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Current biome: ", ChatStyle.WHITE, (biome != null ? biome.getName() : "none")); }
@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."); } } }
@Command( aliases = {"version", "vr"}, usage = "", desc = "Print out the version information for Vanilla", min = 0, max = 0) @CommandPermissions("vanilla.command.version") public void getVersion(CommandContext args, CommandSource source) { source.sendMessage( "Vanilla ", plugin.getDescription().getVersion(), " (Implementing Minecraft protocol v", plugin.getDescription().getData("protocol"), ")"); source.sendMessage( "Powered by Spout " + Spout.getEngine().getVersion(), " (Implementing SpoutAPI ", Spout.getAPIVersion(), ")"); }
@Command( aliases = {"remove", "rm"}, desc = "Removes an existing waypoint", min = 1, max = 1) @Permissible("plugintest.waypoint.remove") public void remove(CommandSource source, CommandArguments args) throws CommandException { String name = args.getString(0); if (this.waypoints.containsKey(name)) { throw new CommandException("The \"" + name + "\" waypoint does not exist."); } this.waypoints.remove(name); source.sendMessage("Waypoint \"" + name + "\" has been removed."); }
@Override public void broadcast(String source, CommandSource[] receivers, String clazz, Object[] args) { int key = getKey(source, clazz); for (CommandSource receiver : receivers) { String use = source; LanguageDictionary dict = getDictionary(receiver.getPreferredLocale()); if (dict != null) { String translation = dict.getTranslation(key); if (translation != null) { use = translation; } } receiver.sendMessage(use); } }
@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 = {"list", "ls"}, desc = "Lists the existing waypoints", min = 0, max = 0) @Permissible("plugintest.waypoint.list") public void list(CommandSource source, CommandArguments args) throws CommandException { for (Map.Entry<String, Point> entry : this.waypoints.entrySet()) { Point p = entry.getValue(); source.sendMessage( entry.getKey() + " -> (" + p.getWorld().getName() + ":" + p.getX() + "," + p.getY() + "," + p.getZ() + ")"); } }
@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()); }