@Command( aliases = {"banip", "ipban"}, usage = "<target> [reason...]", desc = "Ban an IP address", flags = "st:", min = 1, max = -1) @CommandPermissions({"commandbook.bans.ban.ip"}) public void banIP(CommandContext args, CommandSender sender) throws CommandException { String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!"; long endDate = args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L; String addr = args.getString(0).replace("\r", "").replace("\n", "").replace("\0", "").replace("\b", ""); // Need to kick + log for (Player player : CommandBook.server().getOnlinePlayers()) { if (player.getAddress().getAddress().getHostAddress().equals(addr)) { player.kickPlayer(message); getBanDatabase().logKick(player, sender, message); } } getBanDatabase().ban(null, addr, sender, message, endDate); sender.sendMessage(ChatColor.YELLOW + addr + " banned."); if (!getBanDatabase().save()) { sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console."); } }
/** Called when a World is loaded. */ @EventHandler public void onWorldLoad(WorldLoadEvent event) { World world = event.getWorld(); Integer lockedTime = getLockedTimes().get(world.getName()); if (lockedTime != null) { world.setTime(lockedTime); lock(world); CommandBook.logger() .info( "Time locked to '" + CommandBookUtil.getTimeString(lockedTime) + "' for world '" + world.getName() + "'"); } }
private void configureWorldLocks() { config = configure(new LocalConfiguration()); if (config.timeLocks != null) { for (Map.Entry<String, Object> entry : config.timeLocks.entrySet()) { int time = 0; try { time = matchTime(String.valueOf(entry.getValue())); } catch (CommandException e) { CommandBook.logger() .warning("Time lock: Failed to parse time '" + entry.getValue() + "'"); continue; } lockedTimes.put(entry.getKey(), time); World world = CommandBook.server().getWorld(entry.getKey()); if (world == null) { CommandBook.logger().info("Could not time-lock unknown world '" + entry.getKey() + "'"); continue; } world.setTime(time); lock(world); CommandBook.logger() .info( "Time locked to '" + CommandBookUtil.getTimeString(time) + "' for world '" + world.getName() + "'"); } } }
@Command( aliases = {"playertime"}, usage = "[filter] <time|\"current\">", desc = "Get/change a player's time", flags = "rsw", min = 0, max = 2) public void playertime(CommandContext args, CommandSender sender) throws CommandException { Iterable<Player> players = null; String timeStr = "current"; boolean included = false; boolean reset = args.hasFlag('r'); if (args.argsLength() < 2) { if (args.argsLength() == 1) { timeStr = args.getString(0); if (reset) { players = PlayerUtil.matchPlayers(sender, timeStr); } } if (players == null) { players = PlayerUtil.matchPlayers(PlayerUtil.checkPlayer(sender)); } } else { players = PlayerUtil.matchPlayers(sender, args.getString(0)); timeStr = args.getString(1); } for (Player player : players) { if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.time.player.other"); break; } else { CommandBook.inst().checkPermission(sender, "commandbook.time.player"); } } if (args.hasFlag('r')) { for (Player player : players) { player.resetPlayerTime(); if (!args.hasFlag('s')) { player.sendMessage(ChatColor.YELLOW + "Your time was reset to world time"); } if (sender instanceof Player && sender.equals(player)) { included = true; } } if (!included) { sender.sendMessage(ChatColor.YELLOW + "Player times reset"); } return; } if (timeStr.equalsIgnoreCase("current") || timeStr.equalsIgnoreCase("cur") || timeStr.equalsIgnoreCase("now")) { CommandBook.inst().checkPermission(sender, "commandbook.time.player.check"); sender.sendMessage( ChatColor.YELLOW + "Player Time: " + CommandBookUtil.getTimeString( PlayerUtil.matchSinglePlayer( sender, args.getString(0, PlayerUtil.checkPlayer(sender).getName())) .getPlayerTime())); return; } for (Player player : players) { if (!player.equals(sender)) { player.sendMessage( ChatColor.YELLOW + "Your time set to " + CommandBookUtil.getTimeString(player.getPlayerTime())); } else { player.sendMessage( ChatColor.YELLOW + "Your time set to " + CommandBookUtil.getTimeString(player.getPlayerTime())); included = true; } player.setPlayerTime( args.hasFlag('w') ? Integer.parseInt(timeStr) : matchTime(timeStr), args.hasFlag('w')); } if (!included) { sender.sendMessage( ChatColor.YELLOW + "Player times set to " + CommandBookUtil.getTimeString(matchTime(timeStr))); } }
@Command( aliases = {"time"}, usage = "[world] <time|\"current\">", desc = "Get/change the world time", flags = "l", min = 0, max = 2) public void time(CommandContext args, CommandSender sender) throws CommandException { World world; String timeStr; boolean onlyLock = false; // Easy way to get the time if (args.argsLength() == 0) { world = PlayerUtil.checkPlayer(sender).getWorld(); timeStr = "current"; // If no world was specified, get the world from the sender, but // fail if the sender isn't player } else if (args.argsLength() == 1) { world = PlayerUtil.checkPlayer(sender).getWorld(); timeStr = args.getString(0); } else { // A world was specified! world = LocationUtil.matchWorld(sender, args.getString(0)); timeStr = args.getString(1); } // Let the player get the time if (timeStr.equalsIgnoreCase("current") || timeStr.equalsIgnoreCase("cur") || timeStr.equalsIgnoreCase("now")) { // We want to lock to the current time if (!args.hasFlag('l')) { CommandBook.inst().checkPermission(sender, "commandbook.time.check"); sender.sendMessage( ChatColor.YELLOW + "Time: " + CommandBookUtil.getTimeString(world.getTime())); return; } onlyLock = true; } CommandBook.inst().checkPermission(sender, "commandbook.time"); if (!onlyLock) { unlock(world); world.setTime(matchTime(timeStr)); } String verb = "set"; // Locking if (args.hasFlag('l')) { CommandBook.inst().checkPermission(sender, "commandbook.time.lock"); lock(world); verb = "locked"; } if (CommandBook.inst().broadcastChanges) { CommandBook.server() .broadcastMessage( ChatColor.YELLOW + PlayerUtil.toName(sender) + " " + verb + " the time of '" + world.getName() + "' to " + CommandBookUtil.getTimeString(world.getTime()) + "."); } else { sender.sendMessage( ChatColor.YELLOW + "Time " + verb + " to " + CommandBookUtil.getTimeString(world.getTime()) + "."); } }
@Command( aliases = {"ban"}, usage = "[-t end ] <target> [reason...]", desc = "Ban a user or IP address (with the -i flag)", flags = "set:o", min = 1, max = -1) @CommandPermissions({"commandbook.bans.ban"}) public void ban(CommandContext args, CommandSender sender) throws CommandException { String banName; String banAddress = null; long endDate = args.hasFlag('t') ? CommandBookUtil.matchFutureDate(args.getFlag('t')) : 0L; String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Banned!"; final boolean hasExemptOverride = args.hasFlag('o') && CommandBook.inst().hasPermission(sender, "commandbook.bans.exempt.override"); // Check if it's a player in the server right now try { Player player; // Exact mode matches names exactly if (args.hasFlag('e')) { player = PlayerUtil.matchPlayerExactly(sender, args.getString(0)); } else { player = PlayerUtil.matchSinglePlayer(sender, args.getString(0)); } if (CommandBook.inst().hasPermission(player, "commandbook.bans.exempt") && !hasExemptOverride) { throw new CommandException( "This player is exempt from being banned! " + "(use -o flag to override if you have commandbook.bans.exempt.override)"); } // Need to kick + log player.kickPlayer(message); getBanDatabase().logKick(player, sender, message); banName = player.getName(); sender.sendMessage( ChatColor.YELLOW + player.getName() + " (" + player.getDisplayName() + ChatColor.YELLOW + ") banned and kicked."); } catch (CommandException e) { banName = args.getString(0) .replace("\r", "") .replace("\n", "") .replace("\0", "") .replace("\b", ""); sender.sendMessage(ChatColor.YELLOW + banName + " banned."); } // Broadcast the Message if (config.broadcastBans && !args.hasFlag('s')) { CommandBook.server() .broadcastMessage( ChatColor.YELLOW + PlayerUtil.toColoredName(sender, ChatColor.YELLOW) + " has banned " + banName + " - " + message); } getBanDatabase().ban(banName, banAddress, sender, message, endDate); if (!getBanDatabase().save()) { sender.sendMessage(ChatColor.RED + "Bans database failed to save. See console."); } }
@Command( aliases = {"more"}, usage = "[player]", desc = "Gets more of an item", flags = "aio", min = 0, max = 1) @CommandPermissions({"commandbook.more"}) public void more(CommandContext args, CommandSender sender) throws CommandException { Iterable<Player> targets = null; boolean moreAll = args.hasFlag('a'); boolean infinite = args.hasFlag('i'); boolean overrideStackSize = args.hasFlag('o'); if (infinite) { CommandBook.inst().hasPermission(sender, "commandbook.more.infinite"); } else if (overrideStackSize) { CommandBook.inst().hasPermission(sender, "commandbook.override.maxstacksize"); } boolean included = false; if (args.argsLength() == 0) { targets = PlayerUtil.matchPlayers(PlayerUtil.checkPlayer(sender)); // A different player } else { targets = PlayerUtil.matchPlayers(sender, args.getString(0)); // Make sure that this player can 'more' other players! CommandBook.inst().checkPermission(sender, "commandbook.more.other"); } for (Player player : targets) { Inventory inventory = player.getInventory(); if (moreAll) { for (int i = 0; i < 39; i++) { CommandBookUtil.expandStack(inventory.getItem(i), infinite, overrideStackSize); } } else { CommandBookUtil.expandStack(player.getItemInHand(), infinite, overrideStackSize); } // Tell the user about the given item if (player.equals(sender)) { player.sendMessage(ChatColor.YELLOW + "Your item(s) has been expanded in stack size."); // Keep track of this included = true; } else { player.sendMessage( ChatColor.YELLOW + "Your item(s) has been expanded in stack size by " + PlayerUtil.toName(sender)); } } // The player didn't receive any items, then we need to send the // user a message so s/he know that something is indeed working if (!included) { sender.sendMessage(ChatColor.YELLOW + "Stack sizes increased."); } }