@Override public boolean hasPermission(CommandSender player, String perm) { return plugin.hasPermission(player, perm); } };
public void printTopics(CommandSender sender, String prefix) { StringBuilder sb = new StringBuilder(ChatColor.YELLOW.toString()); if (prefix != null && !prefix.isEmpty()) sb.append(prefix).append(" "); sb.append("Available options are: "); boolean first = true; int count = 0; for (String key : messages.keySet()) { if (!CommandBook.inst().hasPermission(sender, "commandbook.help.topic." + key)) { continue; } if (!first) { sb.append(ChatColor.YELLOW).append(", "); } sb.append(ChatColor.LIGHT_PURPLE).append(key); first = false; ++count; } if (count <= 0) { sender.sendMessage(ChatColor.YELLOW + "No available help options!"); } else { sender.sendMessage(sb.toString()); } }
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if (!player.hasPlayedBefore()) { for (Entry<String, Kit> map : kits.getKits().entrySet()) { if (CommandBook.inst().hasPermission(player, "commandbook.kits.onfirstlogin." + map.getKey())) { map.getValue().distribute(player); } } } }
public boolean checkCooldown(CommandSender sender, String command) { CooldownState state = sessions.getSession(CooldownState.class, sender); command = firstWord(command); synchronized (state.cooldownCommands) { Map<String, Integer> storedTimes = config.registeredActions.get(command); if (storedTimes == null) { // Nothing in the config for this command return true; } Integer requiredCooldownTime = storedTimes.get("cooldown"); if (requiredCooldownTime == null) { // No cooldown for this command return true; } Integer passedCooldownTime = state.cooldownCommands.get(command); if (passedCooldownTime == null) { // There isn't an in-progress cooldown for this command passedCooldownTime = 0; state.cooldownCommands.put(command, passedCooldownTime); } if (passedCooldownTime >= requiredCooldownTime || CommandBook.inst().hasPermission(sender, "commandbook.cooldown.override." + command)) { state.cooldownCommands.remove(command); return true; } else { sender.sendMessage(ChatColor.YELLOW + "The command '" + command + "' has a remaining cooldown of " + formatTime(requiredCooldownTime - passedCooldownTime, TimeUnit.SECONDS) + " seconds."); return false; } } }
if (CommandBook.inst().hasPermission(sender, "commandbook.override.any-item")) { return; boolean hasPermissions = CommandBook.inst().hasPermission(sender, "commandbook.items." + id) || CommandBook.inst().hasPermission(sender, "commandbook.items." + id + "." + damage);
@Override public void run() { if (CommandBook.inst().hasPermission(player, "commandbook.flight.onjoin")) { FlightSession session = sessions.getSession(FlightSession.class, player); player.setAllowFlight(session.canFly = true); //noinspection deprecation if (!player.isOnGround()) { player.setFlying(true); } } } }, 1);
private boolean checkAutoEnable(Player player) { if (config.autoEnable && (CommandBook.inst().getPermissionsResolver() .inGroup(player, "cb-invincible") || CommandBook.inst().hasPermission(player, "commandbook.god.auto-invincible"))) { enableGodMode(player); return true; } return false; }
@EventHandler public void playerChangedWorld(PlayerChangedWorldEvent event) { if (!CommandBook.inst().hasPermission(event.getPlayer(), "commandbook.god")) { disableGodMode(event.getPlayer()); } }
public boolean checkWarmup(CommandSender sender, String command) { CooldownState state = sessions.getSession(CooldownState.class, sender); synchronized (state.warmupCommands) { Map<String, Integer> storedTimes = config.registeredActions.get(firstWord(command)); if (storedTimes == null) { // Nothing in the config for this command return true; } Integer requiredWarmupTime = storedTimes.get("warmup"); if (requiredWarmupTime == null || CommandBook.inst().hasPermission(sender, "commandbook.warmup.override." + firstWord(command))) { // No warmup for this command return true; } WarmupInfo warmupInfo = state.warmupCommands.get(firstWord(command)); if (warmupInfo == null) { // There isn't an in-progress warmup for this command warmupInfo = new WarmupInfo(command); state.warmupCommands.put(command, warmupInfo); sender.sendMessage(ChatColor.YELLOW + "Warmup started for command '" + firstWord(command) + "', time remaining: " + formatTime(requiredWarmupTime, TimeUnit.SECONDS) + " seconds"); return false; } if (!command.equals(warmupInfo.fullCommand)) { sender.sendMessage(ChatColor.RED + "You are trying to use the command '" + command + "', which already has a warmup in progress. Type /warmup cancel " + firstWord(command) + " to cancel the existing warmup" ); } return false; } }
@EventHandler public void playerWhois(InfoComponent.PlayerWhoisEvent event) { if (event.getPlayer() instanceof Player) { if (CommandBook.inst().hasPermission(event.getSource(), "commandbook.god.check")) { event.addWhoisInformation(null, "Player " + (hasGodMode((Player) event.getPlayer()) ? "has" : "does not have") + " god mode"); } } }
@EventHandler public void playerWhois(InfoComponent.PlayerWhoisEvent event) { if (CommandBook.inst().hasPermission(event.getSource(), "commandbook.bans.isbanned")) { event.addWhoisInformation(null, "Player " + (getBanDatabase().isBanned(event.getPlayer().getUniqueId()) ? "is" : "is not") + " banned."); } }
@EventHandler public void onPlayerworldChange(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); FlightSession session = sessions.getSession(FlightSession.class, player); if (config.checkWorldChange && player.getGameMode() != GameMode.CREATIVE && !CommandBook.inst().hasPermission(player, "commandbook.flight." + player.getWorld().getName())) { player.setAllowFlight(session.canFly = false); } } }
if (CommandBook.inst().hasPermission(player, permString)) { if (player.getWorld().equals(target.getWorld()) || CommandBook.inst().hasPermission(player, target.getWorld(), permString)) { success = success && vehicle.teleport(player); vehicle.setPassenger(player);
@Command(aliases = {"baninfo", "isbanned"}, usage = "<target>", desc = "Check if a user is banned", min = 1, max = 1) @CommandPermissions({"commandbook.bans.isbanned", "commandbook.bans.baninfo"}) public void banInfo(CommandContext args, CommandSender sender) throws CommandException { String banName = args.getString(0) .replace("\r", "") .replace("\n", "") .replace("\0", "") .replace("\b", ""); UUID ID = CommandBook.server().getOfflinePlayer(banName).getUniqueId(); Ban ban = getBanDatabase().getBanned(ID); if (ban == null) { sender.sendMessage(ChatColor.YELLOW + banName + " is " + ChatColor.RED + "not " + ChatColor.YELLOW + "banned."); } else { String add = ban.getAddress() == null ? "" : " (Address: " + ban.getAddress() + ")"; sender.sendMessage(ChatColor.YELLOW + banName + add + ChatColor.RED + " is" + ChatColor.YELLOW + " banned."); if (!CommandBook.inst().hasPermission(sender, "commandbook.bans.baninfo")) return; sender.sendMessage(ChatColor.YELLOW + "Duration: " + (ban.getEnd() == 0L ? "Indefinite" : "Until " + ChatUtil.getFriendlyTime(ban.getEnd()))); if (ban.getReason() != null) { sender.sendMessage(ChatColor.YELLOW + "Reason: " + ban.getReason()); } } }
for (Iterator<org.bukkit.command.Command> i = serverCommands.iterator(); i.hasNext();) { final String permission = i.next().getPermission(); if (!(permission == null || permission.length() == 0 || CommandBook.inst().hasPermission(sender, permission))) { i.remove();
@Command(aliases = {"mute"}, usage = "<target>", desc = "Mute a player", flags = "o", min = 1, max = 1) @CommandPermissions({"commandbook.mute"}) public void mute(CommandContext args, CommandSender sender) throws CommandException { Player player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (CommandBook.inst().hasPermission(player, "commandbook.mute.exempt") && !(args.hasFlag('o') && CommandBook.inst().hasPermission(sender, "commandbook.mute.exempt.override"))) { throw new CommandException("Player " + ChatUtil.toName(sender) + " is exempt from being muted!"); } if (!sessions.getSession(AdministrativeSession.class, player).setMute(true)) { if (player != sender) { player.sendMessage(ChatColor.YELLOW + "You've been muted by " + ChatUtil.toColoredName(sender, ChatColor.YELLOW)); } sender.sendMessage(ChatColor.YELLOW + "You've muted " + ChatUtil.toColoredName(player, ChatColor.YELLOW)); } else { throw new CommandException("Player " + ChatUtil.toName(player) + " is already muted!"); } }
target = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); } catch (CommandException ex) { if (!CommandBook.inst().hasPermission(sender, "commandbook.teleport.other")) { } else if (!CommandBook.inst().hasPermission(sender, "commandbook.teleport.other")) {
@Command(aliases = {"kick"}, usage = "<target> [reason...]", desc = "Kick a user", flags = "os", min = 1, max = -1) @CommandPermissions({"commandbook.kick"}) public void kick(CommandContext args, CommandSender sender) throws CommandException { Iterable<Player> targets = InputUtil.PlayerParser.matchPlayers(sender, args.getString(0)); String message = args.argsLength() >= 2 ? args.getJoinedStrings(1) : "Kicked!"; String broadcastPlayers = ""; for (Player player : targets) { if (CommandBook.inst().hasPermission(player, "commandbook.kick.exempt") && !(args.hasFlag('o') && CommandBook.inst().hasPermission(sender, "commandbook.kick.exempt.override"))) { sender.sendMessage(ChatColor.RED + "Player " + player.getName() + ChatColor.RED + " is exempt from being kicked!"); continue; } player.kickPlayer(message); broadcastPlayers += ChatUtil.toColoredName(player, ChatColor.YELLOW) + " "; getBanDatabase().logKick(player, sender, message); } if (broadcastPlayers.length() > 0) { sender.sendMessage(ChatColor.YELLOW + "Player(s) kicked."); //Broadcast the Message if (config.broadcastKicks && !args.hasFlag('s')) { BasePlugin.server().broadcastMessage(ChatColor.YELLOW + ChatUtil.toColoredName(sender, ChatColor.YELLOW) + " has kicked " + broadcastPlayers + " - " + message); } } }
@Command(aliases = {"whereami", "getpos", "pos", "where"}, usage = "[player]", desc = "Show your current location", flags = "", min = 0, max = 1) @CommandPermissions({"commandbook.whereami"}) public void whereAmI(CommandContext args, CommandSender sender) throws CommandException { Player player; if (args.argsLength() == 0) { player = PlayerUtil.checkPlayer(sender); } else { player = InputUtil.PlayerParser.matchSinglePlayer(sender, args.getString(0)); if (player != sender) { CommandBook.inst().checkPermission(sender, "commandbook.whereami.other"); } } Location pos = player.getLocation(); sender.sendMessage(ChatColor.YELLOW + "Player: " + player.getName() + (player == sender ? "(That's you!)" : "")); sender.sendMessage(ChatColor.YELLOW + "World: " + player.getWorld().getName()); sender.sendMessage(ChatColor.YELLOW + String.format("Location: (%.4f, %.4f, %.4f)", pos.getX(), pos.getY(), pos.getZ())); sender.sendMessage(ChatColor.YELLOW + "Depth: " + (int) Math.floor(pos.getY())); if (CommandBook.inst().hasPermission(sender, "commandbook.whereami.compass")) { sender.sendMessage(ChatColor.YELLOW + String.format("Direction: %s", getCardinalDirection(player))); } }
if (CommandBook.inst().hasPermission(sender, "commandbook.ip-address")) { event.addWhoisInformation("Address", player.getAddress().toString());