13
0
geforkt von Mirrors/Paper

Remove Bukkit reimplimentations of Vanilla commands.

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2017-05-14 12:00:00 +10:00
Ursprung b2156bae0d
Commit 975152bbcb
45 geänderte Dateien mit 4 neuen und 3961 gelöschten Zeilen

Datei anzeigen

@ -95,7 +95,7 @@ public class SimpleCommandMap implements CommandMap {
*/ */
private synchronized boolean register(String label, Command command, boolean isAlias, String fallbackPrefix) { private synchronized boolean register(String label, Command command, boolean isAlias, String fallbackPrefix) {
knownCommands.put(fallbackPrefix + ":" + label, command); knownCommands.put(fallbackPrefix + ":" + label, command);
if ((command instanceof VanillaCommand || isAlias) && knownCommands.containsKey(label)) { if (isAlias && knownCommands.containsKey(label)) {
// Request is for an alias/fallback command and it conflicts with // Request is for an alias/fallback command and it conflicts with
// a existing command or previous alias ignore it // a existing command or previous alias ignore it
// Note: This will mean it gets removed from the commands list of active aliases // Note: This will mean it gets removed from the commands list of active aliases

Datei anzeigen

@ -1,188 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
import org.bukkit.Material;
import org.bukkit.Statistic.Type;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerAchievementAwardedEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import com.google.common.collect.ImmutableList;
@Deprecated
public class AchievementCommand extends VanillaCommand {
public AchievementCommand() {
super("achievement");
this.description = "Gives the specified player an achievement or changes a statistic value. Use '*' to give all achievements.";
this.usageMessage = "/achievement give <stat_name> [player]";
this.setPermission("bukkit.command.achievement");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (!args[0].equalsIgnoreCase("give")) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
String statisticString = args[1];
Player player = null;
if (args.length > 2) {
player = Bukkit.getPlayer(args[1]);
} else if (sender instanceof Player) {
player = (Player) sender;
}
if (player == null) {
sender.sendMessage("You must specify which player you wish to perform this action on.");
return true;
}
if (statisticString.equals("*")) {
for (Achievement achievement : Achievement.values()) {
if (player.hasAchievement(achievement)) {
continue;
}
PlayerAchievementAwardedEvent event = new PlayerAchievementAwardedEvent(player, achievement);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.awardAchievement(achievement);
}
}
Command.broadcastCommandMessage(sender, String.format("Successfully given all achievements to %s", player.getName()));
return true;
}
Achievement achievement = Bukkit.getUnsafe().getAchievementFromInternalName(statisticString);
Statistic statistic = Bukkit.getUnsafe().getStatisticFromInternalName(statisticString);
if (achievement != null) {
if (player.hasAchievement(achievement)) {
sender.sendMessage(String.format("%s already has achievement %s", player.getName(), statisticString));
return true;
}
PlayerAchievementAwardedEvent event = new PlayerAchievementAwardedEvent(player, achievement);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
sender.sendMessage(String.format("Unable to award %s the achievement %s", player.getName(), statisticString));
return true;
}
player.awardAchievement(achievement);
Command.broadcastCommandMessage(sender, String.format("Successfully given %s the stat %s", player.getName(), statisticString));
return true;
}
if (statistic == null) {
sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
return true;
}
if (statistic.getType() == Type.UNTYPED) {
PlayerStatisticIncrementEvent event = new PlayerStatisticIncrementEvent(player, statistic, player.getStatistic(statistic), player.getStatistic(statistic) + 1);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
sender.sendMessage(String.format("Unable to increment %s for %s", statisticString, player.getName()));
return true;
}
player.incrementStatistic(statistic);
Command.broadcastCommandMessage(sender, String.format("Successfully given %s the stat %s", player.getName(), statisticString));
return true;
}
if (statistic.getType() == Type.ENTITY) {
EntityType entityType = EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1));
if (entityType == null) {
sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
return true;
}
PlayerStatisticIncrementEvent event = new PlayerStatisticIncrementEvent(player, statistic, player.getStatistic(statistic), player.getStatistic(statistic) + 1, entityType);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
sender.sendMessage(String.format("Unable to increment %s for %s", statisticString, player.getName()));
return true;
}
try {
player.incrementStatistic(statistic, entityType);
} catch (IllegalArgumentException e) {
sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
return true;
}
} else {
int id;
try {
id = getInteger(sender, statisticString.substring(statisticString.lastIndexOf(".") + 1), 0, Integer.MAX_VALUE, true);
} catch (NumberFormatException e) {
sender.sendMessage(e.getMessage());
return true;
}
Material material = Material.getMaterial(id);
if (material == null) {
sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
return true;
}
PlayerStatisticIncrementEvent event = new PlayerStatisticIncrementEvent(player, statistic, player.getStatistic(statistic), player.getStatistic(statistic) + 1, material);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
sender.sendMessage(String.format("Unable to increment %s for %s", statisticString, player.getName()));
return true;
}
try {
player.incrementStatistic(statistic, material);
} catch (IllegalArgumentException e) {
sender.sendMessage(String.format("Unknown achievement or statistic '%s'", statisticString));
return true;
}
}
Command.broadcastCommandMessage(sender, String.format("Successfully given %s the stat %s", player.getName(), statisticString));
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return Arrays.asList("give");
}
if (args.length == 2) {
return Bukkit.getUnsafe().tabCompleteInternalStatisticOrAchievementName(args[1], new ArrayList<String>());
}
if (args.length == 3) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,56 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class BanCommand extends VanillaCommand {
public BanCommand() {
super("ban");
this.description = "Prevents the specified player from using this server";
this.usageMessage = "/ban <player> [reason ...]";
this.setPermission("bukkit.command.ban.player");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
String reason = args.length > 0 ? StringUtils.join(args, ' ', 1, args.length) : null;
Bukkit.getBanList(BanList.Type.NAME).addBan(args[0], reason, null, sender.getName());
Player player = Bukkit.getPlayer(args[0]);
if (player != null) {
player.kickPlayer("Banned by admin.");
}
Command.broadcastCommandMessage(sender, "Banned player " + args[0]);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length >= 1) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,78 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class BanIpCommand extends VanillaCommand {
public static final Pattern ipValidity = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
public BanIpCommand() {
super("ban-ip");
this.description = "Prevents the specified IP address from using this server";
this.usageMessage = "/ban-ip <address|player> [reason ...]";
this.setPermission("bukkit.command.ban.ip");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
String reason = args.length > 0 ? StringUtils.join(args, ' ', 1, args.length) : null;
if (ipValidity.matcher(args[0]).matches()) {
processIPBan(args[0], sender, reason);
} else {
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
processIPBan(player.getAddress().getAddress().getHostAddress(), sender, reason);
}
return true;
}
private void processIPBan(String ip, CommandSender sender, String reason) {
Bukkit.getBanList(BanList.Type.IP).addBan(ip, reason, null, sender.getName());
// Find all matching players and kick
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getAddress().getAddress().getHostAddress().equals(ip)) {
player.kickPlayer("You have been IP banned.");
}
}
Command.broadcastCommandMessage(sender, "Banned IP Address " + ip);
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,74 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang.Validate;
import org.bukkit.BanEntry;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class BanListCommand extends VanillaCommand {
private static final List<String> BANLIST_TYPES = ImmutableList.of("ips", "players");
public BanListCommand() {
super("banlist");
this.description = "View all players banned from this server";
this.usageMessage = "/banlist [ips|players]";
this.setPermission("bukkit.command.ban.list");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
BanList.Type banType = BanList.Type.NAME;
if (args.length > 0) {
if (args[0].equalsIgnoreCase("ips")) {
banType = BanList.Type.IP;
} else if (!args[0].equalsIgnoreCase("players")) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
}
StringBuilder message = new StringBuilder();
BanEntry[] banlist = Bukkit.getBanList(banType).getBanEntries().toArray(new BanEntry[0]);
for (int x = 0; x < banlist.length; x++) {
if (x != 0) {
if (x == banlist.length - 1) {
message.append(" and ");
} else {
message.append(", ");
}
}
message.append(banlist[x].getTarget());
}
sender.sendMessage("There are " + banlist.length + " total banned players:");
sender.sendMessage(message.toString());
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], BANLIST_TYPES, new ArrayList<String>(BANLIST_TYPES.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,115 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Deprecated
public class ClearCommand extends VanillaCommand {
private static List<String> materials;
static {
ArrayList<String> materialList = new ArrayList<String>();
for (Material material : Material.values()) {
materialList.add(material.name());
}
Collections.sort(materialList);
materials = ImmutableList.copyOf(materialList);
}
public ClearCommand() {
super("clear");
this.description = "Clears the player's inventory. Can specify item and data filters too.";
this.usageMessage = "/clear <player> [item] [data]";
this.setPermission("bukkit.command.clear");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Player player = null;
if (args.length > 0) {
player = Bukkit.getPlayer(args[0]);
} else if (sender instanceof Player) {
player = (Player) sender;
}
if (player != null) {
int id;
if (args.length > 1 && !(args[1].equals("-1"))) {
Material material = Material.matchMaterial(args[1]);
if (material == null) {
sender.sendMessage(ChatColor.RED + "There's no item called " + args[1]);
return false;
}
id = material.getId();
} else {
id = -1;
}
int data = args.length >= 3 ? getInteger(sender, args[2], 0) : -1;
int count = player.getInventory().clear(id, data);
Command.broadcastCommandMessage(sender, "Cleared the inventory of " + player.getDisplayName() + ", removing " + count + " items");
} else if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Please provide a player!");
} else {
sender.sendMessage(ChatColor.RED + "Can't find player " + args[0]);
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return super.tabComplete(sender, alias, args);
}
if (args.length == 2) {
final String arg = args[1];
final List<String> materials = ClearCommand.materials;
List<String> completion = null;
final int size = materials.size();
int i = Collections.binarySearch(materials, arg, String.CASE_INSENSITIVE_ORDER);
if (i < 0) {
// Insertion (start) index
i = -1 - i;
}
for ( ; i < size; i++) {
String material = materials.get(i);
if (StringUtil.startsWithIgnoreCase(material, arg)) {
if (completion == null) {
completion = new ArrayList<String>();
}
completion.add(material);
} else {
break;
}
}
if (completion != null) {
return completion;
}
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,71 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class DefaultGameModeCommand extends VanillaCommand {
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival");
public DefaultGameModeCommand() {
super("defaultgamemode");
this.description = "Set the default gamemode";
this.usageMessage = "/defaultgamemode <mode>";
this.setPermission("bukkit.command.defaultgamemode");
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage("Usage: " + usageMessage);
return false;
}
String modeArg = args[0];
int value = -1;
try {
value = Integer.parseInt(modeArg);
} catch (NumberFormatException ex) {}
GameMode mode = GameMode.getByValue(value);
if (mode == null) {
if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
mode = GameMode.CREATIVE;
} else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
mode = GameMode.ADVENTURE;
} else {
mode = GameMode.SURVIVAL;
}
}
Bukkit.getServer().setDefaultGameMode(mode);
Command.broadcastCommandMessage(sender, "Default game mode set to " + mode.toString().toLowerCase());
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<String>(GAMEMODE_NAMES.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,63 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class DeopCommand extends VanillaCommand {
public DeopCommand() {
super("deop");
this.description = "Takes the specified player's operator status";
this.usageMessage = "/deop <player>";
this.setPermission("bukkit.command.op.take");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
player.setOp(false);
if (player instanceof Player) {
((Player) player).sendMessage(ChatColor.YELLOW + "You are no longer op!");
}
Command.broadcastCommandMessage(sender, "De-opped " + args[0]);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getOperators()) {
String playerName = player.getName();
if (StringUtil.startsWithIgnoreCase(playerName, args[0])) {
completions.add(playerName);
}
}
return completions;
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,82 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import org.bukkit.Difficulty;
import java.util.ArrayList;
import java.util.List;
@Deprecated
public class DifficultyCommand extends VanillaCommand {
private static final List<String> DIFFICULTY_NAMES = ImmutableList.of("peaceful", "easy", "normal", "hard");
public DifficultyCommand() {
super("difficulty");
this.description = "Sets the game difficulty";
this.usageMessage = "/difficulty <new difficulty> ";
this.setPermission("bukkit.command.difficulty");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Difficulty difficulty = Difficulty.getByValue(getDifficultyForString(sender, args[0]));
if (Bukkit.isHardcore()) {
difficulty = Difficulty.HARD;
}
Bukkit.getWorlds().get(0).setDifficulty(difficulty);
int levelCount = 1;
if (Bukkit.getAllowNether()) {
Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
levelCount++;
}
if (Bukkit.getAllowEnd()) {
Bukkit.getWorlds().get(levelCount).setDifficulty(difficulty);
}
Command.broadcastCommandMessage(sender, "Set difficulty to " + difficulty.toString());
return true;
}
protected int getDifficultyForString(CommandSender sender, String name) {
if (name.equalsIgnoreCase("peaceful") || name.equalsIgnoreCase("p")) {
return 0;
} else if (name.equalsIgnoreCase("easy") || name.equalsIgnoreCase("e")) {
return 1;
} else if (name.equalsIgnoreCase("normal") || name.equalsIgnoreCase("n")) {
return 2;
} else if (name.equalsIgnoreCase("hard") || name.equalsIgnoreCase("h")) {
return 3;
} else {
return getInteger(sender, name, 0, 3);
}
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], DIFFICULTY_NAMES, new ArrayList<String>(DIFFICULTY_NAMES.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,120 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.StringUtil;
@Deprecated
public class EffectCommand extends VanillaCommand {
private static final List<String> effects;
public EffectCommand() {
super("effect");
this.description = "Adds/Removes effects on players";
this.usageMessage = "/effect <player> <effect|clear> [seconds] [amplifier]";
this.setPermission("bukkit.command.effect");
}
static {
ImmutableList.Builder<String> builder = ImmutableList.<String>builder();
for (PotionEffectType type : PotionEffectType.values()) {
if (type != null) {
builder.add(type.getName());
}
}
effects = builder.build();
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(getUsage());
return true;
}
final Player player = sender.getServer().getPlayer(args[0]);
if (player == null) {
sender.sendMessage(ChatColor.RED + String.format("Player, %s, not found", args[0]));
return true;
}
if ("clear".equalsIgnoreCase(args[1])) {
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
sender.sendMessage(String.format("Took all effects from %s", args[0]));
return true;
}
PotionEffectType effect = PotionEffectType.getByName(args[1]);
if (effect == null) {
effect = PotionEffectType.getById(getInteger(sender, args[1], 0));
}
if (effect == null) {
sender.sendMessage(ChatColor.RED + String.format("Effect, %s, not found", args[1]));
return true;
}
int duration = 600;
int duration_temp = 30;
int amplification = 0;
if (args.length >= 3) {
duration_temp = getInteger(sender, args[2], 0, 1000000);
if (effect.isInstant()) {
duration = duration_temp;
} else {
duration = duration_temp * 20;
}
} else if (effect.isInstant()) {
duration = 1;
}
if (args.length >= 4) {
amplification = getInteger(sender, args[3], 0, 255);
}
if (duration_temp == 0) {
if (!player.hasPotionEffect(effect)) {
sender.sendMessage(String.format("Couldn't take %s from %s as they do not have the effect", effect.getName(), args[0]));
return true;
}
player.removePotionEffect(effect);
broadcastCommandMessage(sender, String.format("Took %s from %s", effect.getName(), args[0]));
} else {
final PotionEffect applyEffect = new PotionEffect(effect, duration, amplification);
player.addPotionEffect(applyEffect, true);
broadcastCommandMessage(sender, String.format("Given %s (ID %d) * %d to %s for %d seconds", effect.getName(), effect.getId(), amplification, args[0], duration_temp));
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String commandLabel, String[] args) {
if (args.length == 1) {
return super.tabComplete(sender, commandLabel, args);
} else if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], effects, new ArrayList<String>(effects.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,170 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.WordUtils;
import com.google.common.collect.ImmutableList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
@Deprecated
public class EnchantCommand extends VanillaCommand {
private static final List<String> ENCHANTMENT_NAMES = new ArrayList<String>();
public EnchantCommand() {
super("enchant");
this.description = "Adds enchantments to the item the player is currently holding. Specify 0 for the level to remove an enchantment. Specify force to ignore normal enchantment restrictions";
this.usageMessage = "/enchant <player> <enchantment> [level|max|0] [force]";
this.setPermission("bukkit.command.enchant");
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
boolean force = false;
if (args.length > 2) {
force = args[args.length > 3 ? 3 : 2].equalsIgnoreCase("force");
}
Player player = Bukkit.getPlayerExact(args[0]);
if (player == null) {
sender.sendMessage("Can't find player " + args[0]);
} else {
ItemStack item = player.getItemInHand();
if (item.getType() == Material.AIR) {
sender.sendMessage("The player isn't holding an item");
} else {
String itemName = item.getType().toString().replaceAll("_", " ");
itemName = WordUtils.capitalizeFully(itemName);
Enchantment enchantment = getEnchantment(args[1].toUpperCase(java.util.Locale.ENGLISH));
if (enchantment == null) {
sender.sendMessage(String.format("Enchantment does not exist: %s", args[1]));
} else {
String enchantmentName = enchantment.getName().replaceAll("_", " ");
enchantmentName = WordUtils.capitalizeFully(enchantmentName);
if (!force && !enchantment.canEnchantItem(item)) {
sender.sendMessage(String.format("%s cannot be applied to %s", enchantmentName, itemName));
} else {
int level = 1;
if (args.length > 2) {
Integer integer = getInteger(args[2]);
int minLevel = enchantment.getStartLevel();
int maxLevel = force ? Short.MAX_VALUE : enchantment.getMaxLevel();
if (integer != null) {
if (integer == 0) {
item.removeEnchantment(enchantment);
Command.broadcastCommandMessage(sender, String.format("Removed %s on %s's %s", enchantmentName, player.getName(), itemName));
return true;
}
if (integer < minLevel || integer > maxLevel) {
sender.sendMessage(String.format("Level for enchantment %s must be between %d and %d", enchantmentName, minLevel, maxLevel));
sender.sendMessage("Specify 0 for level to remove an enchantment");
return true;
}
level = integer;
}
if ("max".equals(args[2])) {
level = maxLevel;
}
}
Map<Enchantment, Integer> enchantments = item.getEnchantments();
boolean conflicts = false;
if (!force && !enchantments.isEmpty()) { // TODO: Improve this to use a "hasEnchantments" call
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
Enchantment enchant = entry.getKey();
if (enchant.equals(enchantment)) continue;
if (enchant.conflictsWith(enchantment)) {
sender.sendMessage(String.format("Can't apply the enchantment %s on an item with the enchantment %s", enchantmentName, WordUtils.capitalizeFully(enchant.getName().replaceAll("_", " "))));
conflicts = true;
break;
}
}
}
if (!conflicts) {
item.addUnsafeEnchantment(enchantment, level);
Command.broadcastCommandMessage(sender, String.format("Applied %s (Lvl %d) on %s's %s", enchantmentName, level, player.getName(), itemName), false);
sender.sendMessage(String.format("Enchanting succeeded, applied %s (Lvl %d) onto your %s", enchantmentName, level, itemName));
}
}
}
}
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return super.tabComplete(sender, alias, args);
}
if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], ENCHANTMENT_NAMES, new ArrayList<String>(ENCHANTMENT_NAMES.size()));
}
if (args.length == 3 || args.length == 4) {
if (!args[args.length - 2].equalsIgnoreCase("force")) {
return ImmutableList.of("force");
}
}
return ImmutableList.of();
}
private Enchantment getEnchantment(String lookup) {
Enchantment enchantment = Enchantment.getByName(lookup);
if (enchantment == null) {
Integer id = getInteger(lookup);
if (id != null) {
enchantment = Enchantment.getById(id);
}
}
return enchantment;
}
public static void buildEnchantments() {
if (!ENCHANTMENT_NAMES.isEmpty()) {
throw new IllegalStateException("Enchantments have already been built!");
}
for (Enchantment enchantment : Enchantment.values()) {
ENCHANTMENT_NAMES.add(enchantment.getName());
}
Collections.sort(ENCHANTMENT_NAMES);
}
}

Datei anzeigen

@ -1,90 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class ExpCommand extends VanillaCommand {
public ExpCommand() {
super("xp");
this.description = "Gives the specified player a certain amount of experience. Specify <amount>L to give levels instead, with a negative amount resulting in taking levels.";
this.usageMessage = "/xp <amount> [player] OR /xp <amount>L [player]";
this.setPermission("bukkit.command.xp");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length > 0) {
String inputAmount = args[0];
Player player = null;
boolean isLevel = inputAmount.endsWith("l") || inputAmount.endsWith("L");
if (isLevel && inputAmount.length() > 1) {
inputAmount = inputAmount.substring(0, inputAmount.length() - 1);
}
int amount = getInteger(sender, inputAmount, Integer.MIN_VALUE, Integer.MAX_VALUE);
boolean isTaking = amount < 0;
if (isTaking) {
amount *= -1;
}
if (args.length > 1) {
player = Bukkit.getPlayer(args[1]);
} else if (sender instanceof Player) {
player = (Player) sender;
}
if (player != null) {
if (isLevel) {
if (isTaking) {
player.giveExpLevels(-amount);
Command.broadcastCommandMessage(sender, "Taken " + amount + " level(s) from " + player.getName());
} else {
player.giveExpLevels(amount);
Command.broadcastCommandMessage(sender, "Given " + amount + " level(s) to " + player.getName());
}
} else {
if (isTaking) {
sender.sendMessage(ChatColor.RED + "Taking experience can only be done by levels, cannot give players negative experience points");
return false;
} else {
player.giveExp(amount);
Command.broadcastCommandMessage(sender, "Given " + amount + " experience to " + player.getName());
}
}
} else {
sender.sendMessage("Can't find player, was one provided?\n" + ChatColor.RED + "Usage: " + usageMessage);
return false;
}
return true;
}
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 2) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,101 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class GameModeCommand extends VanillaCommand {
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival", "spectator");
public GameModeCommand() {
super("gamemode");
this.description = "Changes the player to a specific game mode";
this.usageMessage = "/gamemode <mode> [player]";
this.setPermission("bukkit.command.gamemode");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
String modeArg = args[0];
String playerArg = sender.getName();
if (args.length == 2) {
playerArg = args[1];
}
Player player = Bukkit.getPlayerExact(playerArg);
if (player != null) {
int value = -1;
try {
value = Integer.parseInt(modeArg);
} catch (NumberFormatException ex) {}
GameMode mode = GameMode.getByValue(value);
if (mode == null) {
if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
mode = GameMode.CREATIVE;
} else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
mode = GameMode.ADVENTURE;
} else if (modeArg.equalsIgnoreCase("spectator") || modeArg.equalsIgnoreCase("sp")) {
mode = GameMode.SPECTATOR;
} else {
mode = GameMode.SURVIVAL;
}
}
if (mode != player.getGameMode()) {
player.setGameMode(mode);
if (mode != player.getGameMode()) {
sender.sendMessage("Game mode change for " + player.getName() + " failed!");
} else {
if (player == sender) {
Command.broadcastCommandMessage(sender, "Set own game mode to " + mode.toString() + " mode");
} else {
Command.broadcastCommandMessage(sender, "Set " + player.getName() + "'s game mode to " + mode.toString() + " mode");
}
}
} else {
sender.sendMessage(player.getName() + " already has game mode " + mode.getValue());
}
} else {
sender.sendMessage("Can't find player " + playerArg);
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES, new ArrayList<String>(GAMEMODE_NAMES.size()));
} else if (args.length == 2) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,89 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.HumanEntity;
@Deprecated
public class GameRuleCommand extends VanillaCommand {
private static final List<String> GAMERULE_STATES = ImmutableList.of("true", "false");
public GameRuleCommand() {
super("gamerule");
this.description = "Sets a server's game rules";
this.usageMessage = "/gamerule <rule name> <value> OR /gamerule <rule name>";
this.setPermission("bukkit.command.gamerule");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length > 0) {
String rule = args[0];
World world = getGameWorld(sender);
if (world.isGameRule(rule)) {
if (args.length > 1) {
String value = args[1];
world.setGameRuleValue(rule, value);
Command.broadcastCommandMessage(sender, "Game rule " + rule + " has been set to: " + value);
} else {
String value = world.getGameRuleValue(rule);
sender.sendMessage(rule + " = " + value);
}
} else {
sender.sendMessage(ChatColor.RED + "No game rule called " + rule + " is available");
}
return true;
} else {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
sender.sendMessage("Rules: " + this.createString(getGameWorld(sender).getGameRules(), 0, ", "));
return true;
}
}
private World getGameWorld(CommandSender sender) {
if (sender instanceof HumanEntity) {
World world = ((HumanEntity) sender).getWorld();
if (world != null) {
return world;
}
} else if (sender instanceof BlockCommandSender) {
return ((BlockCommandSender) sender).getBlock().getWorld();
}
return Bukkit.getWorlds().get(0);
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], Arrays.asList(getGameWorld(sender).getGameRules()), new ArrayList<String>());
}
if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], GAMERULE_STATES, new ArrayList<String>(GAMERULE_STATES.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,130 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@Deprecated
public class GiveCommand extends VanillaCommand {
private static List<String> materials;
static {
ArrayList<String> materialList = new ArrayList<String>();
for (Material material : Material.values()) {
materialList.add(material.name());
}
Collections.sort(materialList);
materials = ImmutableList.copyOf(materialList);
}
public GiveCommand() {
super("give");
this.description = "Gives the specified player a certain amount of items";
this.usageMessage = "/give <player> <item> [amount [data]]";
this.setPermission("bukkit.command.give");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if ((args.length < 2)) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player = Bukkit.getPlayerExact(args[0]);
if (player != null) {
Material material = Material.matchMaterial(args[1]);
if (material == null) {
material = Bukkit.getUnsafe().getMaterialFromInternalName(args[1]);
}
if (material != null) {
int amount = 1;
short data = 0;
if (args.length >= 3) {
amount = this.getInteger(sender, args[2], 1, 64);
if (args.length >= 4) {
try {
data = Short.parseShort(args[3]);
} catch (NumberFormatException ex) {}
}
}
ItemStack stack = new ItemStack(material, amount, data);
if (args.length >= 5) {
try {
stack = Bukkit.getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(args).subList(4, args.length)));
} catch (Throwable t) {
player.sendMessage("Not a valid tag");
return true;
}
}
player.getInventory().addItem(stack);
Command.broadcastCommandMessage(sender, "Gave " + player.getName() + " some " + material.getId() + " (" + material + ")");
} else {
sender.sendMessage("There's no item called " + args[1]);
}
} else {
sender.sendMessage("Can't find player " + args[0]);
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return super.tabComplete(sender, alias, args);
}
if (args.length == 2) {
final String arg = args[1];
final List<String> materials = GiveCommand.materials;
List<String> completion = new ArrayList<String>();
final int size = materials.size();
int i = Collections.binarySearch(materials, arg, String.CASE_INSENSITIVE_ORDER);
if (i < 0) {
// Insertion (start) index
i = -1 - i;
}
for ( ; i < size; i++) {
String material = materials.get(i);
if (StringUtil.startsWithIgnoreCase(material, arg)) {
completion.add(material);
} else {
break;
}
}
return Bukkit.getUnsafe().tabCompleteInternalMaterialName(arg, completion);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -24,7 +24,7 @@ import org.bukkit.util.ChatPaginator;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public class HelpCommand extends VanillaCommand { public class HelpCommand extends BukkitCommand {
public HelpCommand() { public HelpCommand() {
super("help"); super("help");
this.description = "Shows the help menu"; this.description = "Shows the help menu";

Datei anzeigen

@ -1,60 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class KickCommand extends VanillaCommand {
public KickCommand() {
super("kick");
this.description = "Removes the specified player from the server";
this.usageMessage = "/kick <player> [reason ...]";
this.setPermission("bukkit.command.kick");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player = Bukkit.getPlayerExact(args[0]);
if (player != null) {
String reason = "Kicked by an operator.";
if (args.length > 1) {
reason = createString(args, 1);
}
player.kickPlayer(reason);
Command.broadcastCommandMessage(sender, "Kicked player " + player.getName() + ". With reason:\n" + reason);
} else {
sender.sendMessage( args[0] + " not found.");
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length >= 1) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,51 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.google.common.collect.ImmutableList;
@Deprecated
public class KillCommand extends VanillaCommand {
public KillCommand() {
super("kill");
this.description = "Commits suicide, only usable as a player";
this.usageMessage = "/kill";
this.setPermission("bukkit.command.kill");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (sender instanceof Player) {
Player player = (Player) sender;
EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
Bukkit.getPluginManager().callEvent(ede);
if (ede.isCancelled()) return true;
ede.getEntity().setLastDamageCause(ede);
player.setHealth(0);
sender.sendMessage("Ouch. That look like it hurt.");
} else {
sender.sendMessage("You can only perform this command as a player");
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,55 +0,0 @@
package org.bukkit.command.defaults;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class ListCommand extends VanillaCommand {
public ListCommand() {
super("list");
this.description = "Lists all online players";
this.usageMessage = "/list";
this.setPermission("bukkit.command.list");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
StringBuilder online = new StringBuilder();
final Collection<? extends Player> players = Bukkit.getOnlinePlayers();
for (Player player : players) {
// If a player is hidden from the sender don't show them in the list
if (sender instanceof Player && !((Player) sender).canSee(player))
continue;
if (online.length() > 0) {
online.append(", ");
}
online.append(player.getDisplayName());
}
sender.sendMessage("There are " + players.size() + "/" + Bukkit.getMaxPlayers() + " players online:\n" + online.toString());
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,36 +0,0 @@
package org.bukkit.command.defaults;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@Deprecated
public class MeCommand extends VanillaCommand {
public MeCommand() {
super("me");
this.description = "Performs the specified action in chat";
this.usageMessage = "/me <action>";
this.setPermission("bukkit.command.me");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
StringBuilder message = new StringBuilder();
message.append(sender.getName());
for (String arg : args) {
message.append(" ");
message.append(arg);
}
Bukkit.broadcastMessage("* " + message.toString());
return true;
}
}

Datei anzeigen

@ -1,76 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class OpCommand extends VanillaCommand {
public OpCommand() {
super("op");
this.description = "Gives the specified player operator status";
this.usageMessage = "/op <player>";
this.setPermission("bukkit.command.op.give");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
player.setOp(true);
Command.broadcastCommandMessage(sender, "Opped " + args[0]);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
if (!(sender instanceof Player)) {
return ImmutableList.of();
}
String lastWord = args[0];
if (lastWord.length() == 0) {
return ImmutableList.of();
}
Player senderPlayer = (Player) sender;
ArrayList<String> matchedPlayers = new ArrayList<String>();
for (Player player : sender.getServer().getOnlinePlayers()) {
String name = player.getName();
if (!senderPlayer.canSee(player) || player.isOp()) {
continue;
}
if (StringUtil.startsWithIgnoreCase(name, lastWord)) {
matchedPlayers.add(name);
}
}
Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
return matchedPlayers;
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,57 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class PardonCommand extends VanillaCommand {
public PardonCommand() {
super("pardon");
this.description = "Allows the specified player to use this server";
this.usageMessage = "/pardon <player>";
this.setPermission("bukkit.command.unban.player");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Bukkit.getBanList(BanList.Type.NAME).pardon(args[0]);
Command.broadcastCommandMessage(sender, "Pardoned " + args[0]);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[0])) {
completions.add(name);
}
}
return completions;
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,53 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class PardonIpCommand extends VanillaCommand {
public PardonIpCommand() {
super("pardon-ip");
this.description = "Allows the specified IP address to use this server";
this.usageMessage = "/pardon-ip <address>";
this.setPermission("bukkit.command.unban.ip");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (BanIpCommand.ipValidity.matcher(args[0]).matches()) {
Bukkit.unbanIP(args[0]);
Command.broadcastCommandMessage(sender, "Pardoned ip " + args[0]);
} else {
sender.sendMessage("Invalid ip");
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], Bukkit.getIPBans(), new ArrayList<String>());
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,88 +0,0 @@
package org.bukkit.command.defaults;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Deprecated
public class PlaySoundCommand extends VanillaCommand {
public PlaySoundCommand() {
super("playsound");
this.description = "Plays a sound to a given player";
this.usageMessage = "/playsound <sound> <player> [x] [y] [z] [volume] [pitch] [minimumVolume]";
this.setPermission("bukkit.command.playsound");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
final String soundArg = args[0];
final String playerArg = args[1];
final Player player = Bukkit.getPlayerExact(playerArg);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Can't find player " + playerArg);
return false;
}
final Location location = player.getLocation();
double x = Math.floor(location.getX());
double y = Math.floor(location.getY() + 0.5D);
double z = Math.floor(location.getZ());
double volume = 1.0D;
double pitch = 1.0D;
double minimumVolume = 0.0D;
switch (args.length) {
default:
case 8:
minimumVolume = getDouble(sender, args[7], 0.0D, 1.0D);
case 7:
pitch = getDouble(sender, args[6], 0.0D, 2.0D);
case 6:
volume = getDouble(sender, args[5], 0.0D, Float.MAX_VALUE);
case 5:
z = getRelativeDouble(z, sender, args[4]);
case 4:
y = getRelativeDouble(y, sender, args[3]);
case 3:
x = getRelativeDouble(x, sender, args[2]);
case 2:
// Noop
}
final double fixedVolume = volume > 1.0D ? volume * 16.0D : 16.0D;
final Location soundLocation = new Location(player.getWorld(), x, y, z);
if (location.distanceSquared(soundLocation) > fixedVolume * fixedVolume) {
if (minimumVolume <= 0.0D) {
sender.sendMessage(ChatColor.RED + playerArg + " is too far away to hear the sound");
return false;
}
final double deltaX = x - location.getX();
final double deltaY = y - location.getY();
final double deltaZ = z - location.getZ();
final double delta = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / 2.0D;
if (delta > 0.0D) {
location.add(deltaX / delta, deltaY / delta, deltaZ / delta);
}
player.playSound(location, soundArg, (float) minimumVolume, (float) pitch);
} else {
player.playSound(soundLocation, soundArg, (float) volume, (float) pitch);
}
sender.sendMessage(String.format("Played '%s' to %s", soundArg, playerArg));
return true;
}
}

Datei anzeigen

@ -1,47 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.google.common.collect.ImmutableList;
@Deprecated
public class SaveCommand extends VanillaCommand {
public SaveCommand() {
super("save-all");
this.description = "Saves the server to disk";
this.usageMessage = "/save-all";
this.setPermission("bukkit.command.save.perform");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Command.broadcastCommandMessage(sender, "Forcing save..");
Bukkit.savePlayers();
for (World world : Bukkit.getWorlds()) {
world.save();
}
Command.broadcastCommandMessage(sender, "Save complete.");
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,42 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.google.common.collect.ImmutableList;
@Deprecated
public class SaveOffCommand extends VanillaCommand {
public SaveOffCommand() {
super("save-off");
this.description = "Disables server autosaving";
this.usageMessage = "/save-off";
this.setPermission("bukkit.command.save.disable");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
for (World world : Bukkit.getWorlds()) {
world.setAutoSave(false);
}
Command.broadcastCommandMessage(sender, "Disabled level saving..");
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,42 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.google.common.collect.ImmutableList;
@Deprecated
public class SaveOnCommand extends VanillaCommand {
public SaveOnCommand() {
super("save-on");
this.description = "Enables server autosaving";
this.usageMessage = "/save-on";
this.setPermission("bukkit.command.save.enable");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
for (World world : Bukkit.getWorlds()) {
world.setAutoSave(true);
}
Command.broadcastCommandMessage(sender, "Enabled level saving..");
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,63 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class SayCommand extends VanillaCommand {
public SayCommand() {
super("say");
this.description = "Broadcasts the given message as the sender";
this.usageMessage = "/say <message ...>";
this.setPermission("bukkit.command.say");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
StringBuilder message = new StringBuilder();
message.append(ChatColor.LIGHT_PURPLE).append("[");
if (sender instanceof ConsoleCommandSender) {
message.append("Server");
} else if (sender instanceof Player) {
message.append(((Player) sender).getDisplayName());
} else {
message.append(sender.getName());
}
message.append(ChatColor.LIGHT_PURPLE).append("] ");
if (args.length > 0) {
message.append(args[0]);
for (int i = 1; i < args.length; i++) {
message.append(" ").append(args[i]);
}
}
Bukkit.broadcastMessage(message.toString());
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
if (args.length >= 1) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,618 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@Deprecated
public class ScoreboardCommand extends VanillaCommand {
private static final List<String> MAIN_CHOICES = ImmutableList.of("objectives", "players", "teams");
private static final List<String> OBJECTIVES_CHOICES = ImmutableList.of("list", "add", "remove", "setdisplay");
private static final List<String> OBJECTIVES_CRITERIA = ImmutableList.of("health", "playerKillCount", "totalKillCount", "deathCount", "dummy");
private static final List<String> PLAYERS_CHOICES = ImmutableList.of("set", "add", "remove", "reset", "list");
private static final List<String> TEAMS_CHOICES = ImmutableList.of("add", "remove", "join", "leave", "empty", "list", "option");
private static final List<String> TEAMS_OPTION_CHOICES = ImmutableList.of("color", "friendlyfire", "seeFriendlyInvisibles");
private static final Map<String, DisplaySlot> OBJECTIVES_DISPLAYSLOT = ImmutableMap.of("belowName", DisplaySlot.BELOW_NAME, "list", DisplaySlot.PLAYER_LIST, "sidebar", DisplaySlot.SIDEBAR);
private static final Map<String, ChatColor> TEAMS_OPTION_COLOR = ImmutableMap.<String, ChatColor>builder()
.put("aqua", ChatColor.AQUA)
.put("black", ChatColor.BLACK)
.put("blue", ChatColor.BLUE)
.put("bold", ChatColor.BOLD)
.put("dark_aqua", ChatColor.DARK_AQUA)
.put("dark_blue", ChatColor.DARK_BLUE)
.put("dark_gray", ChatColor.DARK_GRAY)
.put("dark_green", ChatColor.DARK_GREEN)
.put("dark_purple", ChatColor.DARK_PURPLE)
.put("dark_red", ChatColor.DARK_RED)
.put("gold", ChatColor.GOLD)
.put("gray", ChatColor.GRAY)
.put("green", ChatColor.GREEN)
.put("italic", ChatColor.ITALIC)
.put("light_purple", ChatColor.LIGHT_PURPLE)
.put("obfuscated", ChatColor.MAGIC) // This is the important line
.put("red", ChatColor.RED)
.put("reset", ChatColor.RESET)
.put("strikethrough", ChatColor.STRIKETHROUGH)
.put("underline", ChatColor.UNDERLINE)
.put("white", ChatColor.WHITE)
.put("yellow", ChatColor.YELLOW)
.build();
private static final List<String> BOOLEAN = ImmutableList.of("true", "false");
public ScoreboardCommand() {
super("scoreboard");
this.description = "Scoreboard control";
this.usageMessage = "/scoreboard";
this.setPermission("bukkit.command.scoreboard");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender))
return true;
if (args.length < 1 || args[0].length() == 0) {
sender.sendMessage(ChatColor.RED + "Usage: /scoreboard <objectives|players|teams>");
return false;
}
final Scoreboard mainScoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
if (args[0].equalsIgnoreCase("objectives")) {
if (args.length == 1) {
sender.sendMessage(ChatColor.RED + "Usage: /scoreboard objectives <list|add|remove|setdisplay>");
return false;
}
if (args[1].equalsIgnoreCase("list")) {
Set<Objective> objectives = mainScoreboard.getObjectives();
if (objectives.isEmpty()) {
sender.sendMessage(ChatColor.RED + "There are no objectives on the scoreboard");
return false;
}
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + objectives.size() + " objective(s) on scoreboard");
for (Objective objective : objectives) {
sender.sendMessage("- " + objective.getName() + ": displays as '" + objective.getDisplayName() + "' and is type '" + objective.getCriteria() + "'");
}
} else if (args[1].equalsIgnoreCase("add")) {
if (args.length < 4) {
sender.sendMessage(ChatColor.RED + "/scoreboard objectives add <name> <criteriaType> [display name ...]");
return false;
}
String name = args[2];
String criteria = args[3];
if (criteria == null) {
sender.sendMessage(ChatColor.RED + "Invalid objective criteria type. Valid types are: " + stringCollectionToString(OBJECTIVES_CRITERIA));
} else if (name.length() > 16) {
sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for an objective, it can be at most 16 characters long");
} else if (mainScoreboard.getObjective(name) != null) {
sender.sendMessage(ChatColor.RED + "An objective with the name '" + name + "' already exists");
} else {
String displayName = null;
if (args.length > 4) {
displayName = StringUtils.join(ArrayUtils.subarray(args, 4, args.length), ' ');
if (displayName.length() > 32) {
sender.sendMessage(ChatColor.RED + "The name '" + displayName + "' is too long for an objective, it can be at most 32 characters long");
return false;
}
}
Objective objective = mainScoreboard.registerNewObjective(name, criteria);
if (displayName != null && displayName.length() > 0) {
objective.setDisplayName(displayName);
}
sender.sendMessage("Added new objective '" + name + "' successfully");
}
} else if (args[1].equalsIgnoreCase("remove")) {
if (args.length != 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard objectives remove <name>");
return false;
}
String name = args[2];
Objective objective = mainScoreboard.getObjective(name);
if (objective == null) {
sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + name + "'");
} else {
objective.unregister();
sender.sendMessage("Removed objective '" + name + "' successfully");
}
} else if (args[1].equalsIgnoreCase("setdisplay")) {
if (args.length != 3 && args.length != 4) {
sender.sendMessage(ChatColor.RED + "/scoreboard objectives setdisplay <slot> [objective]");
return false;
}
String slotName = args[2];
DisplaySlot slot = OBJECTIVES_DISPLAYSLOT.get(slotName);
if (slot == null) {
sender.sendMessage(ChatColor.RED + "No such display slot '" + slotName + "'");
} else {
if (args.length == 4) {
String objectiveName = args[3];
Objective objective = mainScoreboard.getObjective(objectiveName);
if (objective == null) {
sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
return false;
}
objective.setDisplaySlot(slot);
sender.sendMessage("Set the display objective in slot '" + slotName + "' to '" + objective.getName() + "'");
} else {
Objective objective = mainScoreboard.getObjective(slot);
if (objective != null) {
objective.setDisplaySlot(null);
}
sender.sendMessage("Cleared objective display slot '" + slotName + "'");
}
}
}
} else if (args[0].equalsIgnoreCase("players")) {
if (args.length == 1) {
sender.sendMessage(ChatColor.RED + "/scoreboard players <set|add|remove|reset|list>");
return false;
}
if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
if (args.length != 5) {
if (args[1].equalsIgnoreCase("set")) {
sender.sendMessage(ChatColor.RED + "/scoreboard players set <player> <objective> <score>");
} else if (args[1].equalsIgnoreCase("add")) {
sender.sendMessage(ChatColor.RED + "/scoreboard players add <player> <objective> <count>");
} else {
sender.sendMessage(ChatColor.RED + "/scoreboard players remove <player> <objective> <count>");
}
return false;
}
String objectiveName = args[3];
Objective objective = mainScoreboard.getObjective(objectiveName);
if (objective == null) {
sender.sendMessage(ChatColor.RED + "No objective was found by the name '" + objectiveName + "'");
return false;
} else if (!objective.isModifiable()) {
sender.sendMessage(ChatColor.RED + "The objective '" + objectiveName + "' is read-only and cannot be set");
return false;
}
String valueString = args[4];
int value;
try {
value = Integer.parseInt(valueString);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "'" + valueString + "' is not a valid number");
return false;
}
if (value < 1 && !args[1].equalsIgnoreCase("set")) {
sender.sendMessage(ChatColor.RED + "The number you have entered (" + value + ") is too small, it must be at least 1");
return false;
}
String playerName = args[2];
if (playerName.length() > 16) {
sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false;
}
Score score = objective.getScore(playerName);
int newScore;
if (args[1].equalsIgnoreCase("set")) {
newScore = value;
} else if (args[1].equalsIgnoreCase("add")) {
newScore = score.getScore() + value;
} else {
newScore = score.getScore() - value;
}
score.setScore(newScore);
sender.sendMessage("Set score of " + objectiveName + " for player " + playerName + " to " + newScore);
} else if (args[1].equalsIgnoreCase("reset")) {
if (args.length != 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard players reset <player>");
return false;
}
String playerName = args[2];
if (playerName.length() > 16) {
sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false;
}
mainScoreboard.resetScores(playerName);
sender.sendMessage("Reset all scores of player " + playerName);
} else if (args[1].equalsIgnoreCase("list")) {
if (args.length > 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard players list <player>");
return false;
}
if (args.length == 2) {
Set<String> entries = mainScoreboard.getEntries();
if (entries.isEmpty()) {
sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard");
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + entries.size() + " tracked players on the scoreboard");
sender.sendMessage(stringCollectionToString(entries));
}
} else {
String playerName = args[2];
if (playerName.length() > 16) {
sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false;
}
Set<Score> scores = mainScoreboard.getScores(playerName);
if (scores.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded");
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + scores.size() + " tracked objective(s) for " + playerName);
for (Score score : scores) {
sender.sendMessage("- " + score.getObjective().getDisplayName() + ": " + score.getScore() + " (" + score.getObjective().getName() + ")");
}
}
}
}
} else if (args[0].equalsIgnoreCase("teams")) {
if (args.length == 1) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams <list|add|remove|empty|join|leave|option>");
return false;
}
if (args[1].equalsIgnoreCase("list")) {
if (args.length == 2) {
Set<Team> teams = mainScoreboard.getTeams();
if (teams.isEmpty()) {
sender.sendMessage(ChatColor.RED + "There are no teams registered on the scoreboard");
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + teams.size() + " teams on the scoreboard");
for (Team team : teams) {
sender.sendMessage("- " + team.getName() + ": '" + team.getDisplayName() + "' has " + team.getSize() + " players");
}
}
} else if (args.length == 3) {
String teamName = args[2];
Team team = mainScoreboard.getTeam(teamName);
if (team == null) {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
} else {
Set<OfflinePlayer> players = team.getPlayers();
if (players.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " has no players");
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " player(s) in team " + team.getName());
sender.sendMessage(offlinePlayerSetToString(players));
}
}
} else {
sender.sendMessage(ChatColor.RED + "/scoreboard teams list [name]");
return false;
}
} else if (args[1].equalsIgnoreCase("add")) {
if (args.length < 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams add <name> [display name ...]");
return false;
}
String name = args[2];
if (name.length() > 16) {
sender.sendMessage(ChatColor.RED + "The name '" + name + "' is too long for a team, it can be at most 16 characters long");
} else if (mainScoreboard.getTeam(name) != null) {
sender.sendMessage(ChatColor.RED + "A team with the name '" + name + "' already exists");
} else {
String displayName = null;
if (args.length > 3) {
displayName = StringUtils.join(ArrayUtils.subarray(args, 3, args.length), ' ');
if (displayName.length() > 32) {
sender.sendMessage(ChatColor.RED + "The display name '" + displayName + "' is too long for a team, it can be at most 32 characters long");
return false;
}
}
Team team = mainScoreboard.registerNewTeam(name);
if (displayName != null && displayName.length() > 0) {
team.setDisplayName(displayName);
}
sender.sendMessage("Added new team '" + team.getName() + "' successfully");
}
} else if (args[1].equalsIgnoreCase("remove")) {
if (args.length != 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams remove <name>");
return false;
}
String name = args[2];
Team team = mainScoreboard.getTeam(name);
if (team == null) {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
} else {
team.unregister();
sender.sendMessage("Removed team " + name);
}
} else if (args[1].equalsIgnoreCase("empty")) {
if (args.length != 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams clear <name>");
return false;
}
String name = args[2];
Team team = mainScoreboard.getTeam(name);
if (team == null) {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + name + "'");
} else {
Set<OfflinePlayer> players = team.getPlayers();
if (players.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Team " + team.getName() + " is already empty, cannot remove nonexistant players");
} else {
for (OfflinePlayer player : players) {
team.removePlayer(player);
}
sender.sendMessage("Removed all " + players.size() + " player(s) from team " + team.getName());
}
}
} else if (args[1].equalsIgnoreCase("join")) {
if ((sender instanceof Player) ? args.length < 3 : args.length < 4) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams join <team> [player...]");
return false;
}
String teamName = args[2];
Team team = mainScoreboard.getTeam(teamName);
if (team == null) {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
} else {
Set<String> addedPlayers = new HashSet<String>();
if ((sender instanceof Player) && args.length == 3) {
team.addPlayer((Player) sender);
addedPlayers.add(sender.getName());
} else {
for (int i = 3; i < args.length; i++) {
String playerName = args[i];
OfflinePlayer offlinePlayer;
Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
offlinePlayer = player;
} else {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
team.addPlayer(offlinePlayer);
addedPlayers.add(offlinePlayer.getName());
}
}
sender.sendMessage("Added " + addedPlayers.size() + " player(s) to team " + team.getName() + ": " + stringCollectionToString(addedPlayers));
}
} else if (args[1].equalsIgnoreCase("leave")) {
if (!(sender instanceof Player) && args.length < 3) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams leave [player...]");
return false;
}
Set<String> left = new HashSet<String>();
Set<String> noTeam = new HashSet<String>();
if ((sender instanceof Player) && args.length == 2) {
Team team = mainScoreboard.getPlayerTeam((Player) sender);
if (team != null) {
team.removePlayer((Player) sender);
left.add(sender.getName());
} else {
noTeam.add(sender.getName());
}
} else {
for (int i = 2; i < args.length; i++) {
String playerName = args[i];
OfflinePlayer offlinePlayer;
Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
offlinePlayer = player;
} else {
offlinePlayer = Bukkit.getOfflinePlayer(playerName);
}
Team team = mainScoreboard.getPlayerTeam(offlinePlayer);
if (team != null) {
team.removePlayer(offlinePlayer);
left.add(offlinePlayer.getName());
} else {
noTeam.add(offlinePlayer.getName());
}
}
}
if (!left.isEmpty()) {
sender.sendMessage("Removed " + left.size() + " player(s) from their teams: " + stringCollectionToString(left));
}
if (!noTeam.isEmpty()) {
sender.sendMessage("Could not remove " + noTeam.size() + " player(s) from their teams: " + stringCollectionToString(noTeam));
}
} else if (args[1].equalsIgnoreCase("option")) {
if (args.length != 4 && args.length != 5) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
return false;
}
String teamName = args[2];
Team team = mainScoreboard.getTeam(teamName);
if (team == null) {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
return false;
}
String option = args[3].toLowerCase(java.util.Locale.ENGLISH);
if (!option.equals("friendlyfire") && !option.equals("color") && !option.equals("seefriendlyinvisibles")) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
return false;
}
if (args.length == 4) {
if (option.equals("color")) {
sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
} else {
sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
}
} else {
String value = args[4].toLowerCase(java.util.Locale.ENGLISH);
if (option.equals("color")) {
ChatColor color = TEAMS_OPTION_COLOR.get(value);
if (color == null) {
sender.sendMessage(ChatColor.RED + "Valid values for option color are: " + stringCollectionToString(TEAMS_OPTION_COLOR.keySet()));
return false;
}
team.setPrefix(color.toString());
team.setSuffix(ChatColor.RESET.toString());
} else {
if (!value.equals("true") && !value.equals("false")) {
sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
return false;
}
if (option.equals("friendlyfire")) {
team.setAllowFriendlyFire(value.equals("true"));
} else {
team.setCanSeeFriendlyInvisibles(value.equals("true"));
}
}
sender.sendMessage("Set option " + option + " for team " + team.getName() + " to " + value);
}
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: /scoreboard <objectives|players|teams>");
return false;
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], MAIN_CHOICES, new ArrayList<String>());
}
if (args.length > 1) {
if (args[0].equalsIgnoreCase("objectives")) {
if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], OBJECTIVES_CHOICES, new ArrayList<String>());
}
if (args[1].equalsIgnoreCase("add")) {
if (args.length == 4) {
return StringUtil.copyPartialMatches(args[3], OBJECTIVES_CRITERIA, new ArrayList<String>());
}
} else if (args[1].equalsIgnoreCase("remove")) {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], this.getCurrentObjectives(), new ArrayList<String>());
}
} else if (args[1].equalsIgnoreCase("setdisplay")) {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], OBJECTIVES_DISPLAYSLOT.keySet(), new ArrayList<String>());
}
if (args.length == 4) {
return StringUtil.copyPartialMatches(args[3], this.getCurrentObjectives(), new ArrayList<String>());
}
}
} else if (args[0].equalsIgnoreCase("players")) {
if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], PLAYERS_CHOICES, new ArrayList<String>());
}
if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
if (args.length == 3) {
return super.tabComplete(sender, alias, args);
}
if (args.length == 4) {
return StringUtil.copyPartialMatches(args[3], this.getCurrentObjectives(), new ArrayList<String>());
}
} else {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], this.getCurrentEntries(), new ArrayList<String>());
}
}
} else if (args[0].equalsIgnoreCase("teams")) {
if (args.length == 2) {
return StringUtil.copyPartialMatches(args[1], TEAMS_CHOICES, new ArrayList<String>());
}
if (args[1].equalsIgnoreCase("join")) {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], this.getCurrentTeams(), new ArrayList<String>());
}
if (args.length >= 4) {
return super.tabComplete(sender, alias, args);
}
} else if (args[1].equalsIgnoreCase("leave")) {
return super.tabComplete(sender, alias, args);
} else if (args[1].equalsIgnoreCase("option")) {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], this.getCurrentTeams(), new ArrayList<String>());
}
if (args.length == 4) {
return StringUtil.copyPartialMatches(args[3], TEAMS_OPTION_CHOICES, new ArrayList<String>());
}
if (args.length == 5) {
if (args[3].equalsIgnoreCase("color")) {
return StringUtil.copyPartialMatches(args[4], TEAMS_OPTION_COLOR.keySet(), new ArrayList<String>());
} else {
return StringUtil.copyPartialMatches(args[4], BOOLEAN, new ArrayList<String>());
}
}
} else {
if (args.length == 3) {
return StringUtil.copyPartialMatches(args[2], this.getCurrentTeams(), new ArrayList<String>());
}
}
}
}
return ImmutableList.of();
}
private static String offlinePlayerSetToString(Set<OfflinePlayer> set) {
StringBuilder string = new StringBuilder();
String lastValue = null;
for (OfflinePlayer value : set) {
string.append(lastValue = value.getName()).append(", ");
}
string.delete(string.length() - 2, Integer.MAX_VALUE);
if (string.length() != lastValue.length()) {
string.insert(string.length() - lastValue.length(), "and ");
}
return string.toString();
}
private static String stringCollectionToString(Collection<String> set) {
StringBuilder string = new StringBuilder();
String lastValue = null;
for (String value : set) {
string.append(lastValue = value).append(", ");
}
string.delete(string.length() - 2, Integer.MAX_VALUE);
if (string.length() != lastValue.length()) {
string.insert(string.length() - lastValue.length(), "and ");
}
return string.toString();
}
private List<String> getCurrentObjectives() {
List<String> list = new ArrayList<String>();
for (Objective objective : Bukkit.getScoreboardManager().getMainScoreboard().getObjectives()) {
list.add(objective.getName());
}
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
}
private List<String> getCurrentEntries() {
List<String> list = new ArrayList<String>();
for (String entry : Bukkit.getScoreboardManager().getMainScoreboard().getEntries()) {
list.add(entry);
}
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
}
private List<String> getCurrentTeams() {
List<String> list = new ArrayList<String>();
for (Team team : Bukkit.getScoreboardManager().getMainScoreboard().getTeams()) {
list.add(team.getName());
}
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
}
}

Datei anzeigen

@ -1,42 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class SeedCommand extends VanillaCommand {
public SeedCommand() {
super("seed");
this.description = "Shows the world seed";
this.usageMessage = "/seed";
this.setPermission("bukkit.command.seed");
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) return true;
long seed;
if (sender instanceof Player) {
seed = ((Player) sender).getWorld().getSeed();
} else {
seed = Bukkit.getWorlds().get(0).getSeed();
}
sender.sendMessage("Seed: " + seed);
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,54 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.util.List;
@Deprecated
public class SetIdleTimeoutCommand extends VanillaCommand {
public SetIdleTimeoutCommand() {
super("setidletimeout");
this.description = "Sets the server's idle timeout";
this.usageMessage = "/setidletimeout <Minutes until kick>";
this.setPermission("bukkit.command.setidletimeout");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 1) {
int minutes;
try {
minutes = getInteger(sender, args[0], 0, Integer.MAX_VALUE, true);
} catch (NumberFormatException ex) {
sender.sendMessage(ex.getMessage());
return true;
}
Bukkit.getServer().setIdleTimeout(minutes);
Command.broadcastCommandMessage(sender, "Successfully set the idle timeout to " + minutes + " minutes.");
return true;
}
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,80 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@Deprecated
public class SetWorldSpawnCommand extends VanillaCommand {
public SetWorldSpawnCommand() {
super("setworldspawn");
this.description = "Sets a worlds's spawn point. If no coordinates are specified, the player's coordinates will be used.";
this.usageMessage = "/setworldspawn OR /setworldspawn <x> <y> <z>";
this.setPermission("bukkit.command.setworldspawn");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Player player = null;
World world;
if (sender instanceof Player) {
player = (Player) sender;
world = player.getWorld();
} else {
world = Bukkit.getWorlds().get(0);
}
final int x, y, z;
if (args.length == 0) {
if (player == null) {
sender.sendMessage("You can only perform this command as a player");
return true;
}
Location location = player.getLocation();
x = location.getBlockX();
y = location.getBlockY();
z = location.getBlockZ();
} else if (args.length == 3) {
try {
x = getInteger(sender, args[0], MIN_COORD, MAX_COORD, true);
y = getInteger(sender, args[1], 0, world.getMaxHeight(), true);
z = getInteger(sender, args[2], MIN_COORD, MAX_COORD, true);
} catch (NumberFormatException ex) {
sender.sendMessage(ex.getMessage());
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
world.setSpawnLocation(x, y, z);
Command.broadcastCommandMessage(sender, "Set world " + world.getName() + "'s spawnpoint to (" + x + ", " + y + ", " + z + ")");
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,88 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
@Deprecated
public class SpawnpointCommand extends VanillaCommand {
public SpawnpointCommand() {
super("spawnpoint");
this.description = "Sets a player's spawn point";
this.usageMessage = "/spawnpoint OR /spawnpoint <player> OR /spawnpoint <player> <x> <y> <z>";
this.setPermission("bukkit.command.spawnpoint");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Player player;
if (args.length == 0) {
if (sender instanceof Player) {
player = (Player) sender;
} else {
sender.sendMessage("Please provide a player!");
return true;
}
} else {
player = Bukkit.getPlayerExact(args[0]);
if (player == null) {
sender.sendMessage("Can't find player " + args[0]);
return true;
}
}
World world = player.getWorld();
if (args.length == 4) {
if (world != null) {
int pos = 1;
final int x, y, z;
try {
x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD, true);
y = getInteger(sender, args[pos++], 0, world.getMaxHeight());
z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD, true);
} catch(NumberFormatException ex) {
sender.sendMessage(ex.getMessage());
return true;
}
player.setBedSpawnLocation(new Location(world, x, y, z), true);
Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z);
}
} else if (args.length <= 1) {
Location location = player.getLocation();
player.setBedSpawnLocation(location, true);
Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + location.getX() + ", " + location.getY() + ", " + location.getZ());
} else {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,266 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
@Deprecated
public class SpreadPlayersCommand extends VanillaCommand {
private static final Random random = new Random();
public SpreadPlayersCommand() {
super("spreadplayers");
this.description = "Spreads players around a point";
this.usageMessage = "/spreadplayers <x> <z> <spreadDistance> <maxRange> <respectTeams true|false> <player ...>";
this.setPermission("bukkit.command.spreadplayers");
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) {
return true;
}
if (args.length < 6) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
final double x = getDouble(sender, args[0], -30000000, 30000000);
final double z = getDouble(sender, args[1], -30000000, 30000000);
final double distance = getDouble(sender, args[2]);
final double range = getDouble(sender, args[3]);
if (distance < 0.0D) {
sender.sendMessage(ChatColor.RED + "Distance is too small.");
return false;
}
if (range < distance + 1.0D) {
sender.sendMessage(ChatColor.RED + "Max range is too small.");
return false;
}
final String respectTeams = args[4];
boolean teams = false;
if (respectTeams.equalsIgnoreCase("true")) {
teams = true;
} else if (!respectTeams.equalsIgnoreCase("false")) {
sender.sendMessage(String.format(ChatColor.RED + "'%s' is not true or false", args[4]));
return false;
}
List<Player> players = Lists.newArrayList();
World world = null;
for (int i = 5; i < args.length; i++) {
Player player = Bukkit.getPlayerExact(args[i]);
if (player == null) {
continue;
}
if (world == null) {
world = player.getWorld();
}
players.add(player);
}
if (world == null) {
return true;
}
final double xRangeMin = x - range;
final double zRangeMin = z - range;
final double xRangeMax = x + range;
final double zRangeMax = z + range;
final int spreadSize = teams ? getTeams(players) : players.size();
final Location[] locations = getSpreadLocations(world, spreadSize, xRangeMin, zRangeMin, xRangeMax, zRangeMax);
final int rangeSpread = range(world, distance, xRangeMin, zRangeMin, xRangeMax, zRangeMax, locations);
if (rangeSpread == -1) {
sender.sendMessage(String.format("Could not spread %d %s around %s,%s (too many players for space - try using spread of at most %s)", spreadSize, teams ? "teams" : "players", x, z));
return false;
}
final double distanceSpread = spread(world, players, locations, teams);
sender.sendMessage(String.format("Succesfully spread %d %s around %s,%s", locations.length, teams ? "teams" : "players", x, z));
if (locations.length > 1) {
sender.sendMessage(String.format("(Average distance between %s is %s blocks apart after %s iterations)", teams ? "teams" : "players", String.format("%.2f", distanceSpread), rangeSpread));
}
return true;
}
private int range(World world, double distance, double xRangeMin, double zRangeMin, double xRangeMax, double zRangeMax, Location[] locations) {
boolean flag = true;
double max;
int i;
for (i = 0; i < 10000 && flag; ++i) {
flag = false;
max = Float.MAX_VALUE;
Location loc1;
int j;
for (int k = 0; k < locations.length; ++k) {
Location loc2 = locations[k];
j = 0;
loc1 = new Location(world, 0, 0, 0);
for (int l = 0; l < locations.length; ++l) {
if (k != l) {
Location loc3 = locations[l];
double dis = loc2.distanceSquared(loc3);
max = Math.min(dis, max);
if (dis < distance) {
++j;
loc1.add(loc3.getX() - loc2.getX(), 0, 0);
loc1.add(loc3.getZ() - loc2.getZ(), 0, 0);
}
}
}
if (j > 0) {
loc2.setX(loc2.getX() / j);
loc2.setZ(loc2.getZ() / j);
double d7 = Math.sqrt(loc1.getX() * loc1.getX() + loc1.getZ() * loc1.getZ());
if (d7 > 0.0D) {
loc1.setX(loc1.getX() / d7);
loc2.add(-loc1.getX(), 0, -loc1.getZ());
} else {
double x = xRangeMin >= xRangeMax ? xRangeMin : random.nextDouble() * (xRangeMax - xRangeMin) + xRangeMin;
double z = zRangeMin >= zRangeMax ? zRangeMin : random.nextDouble() * (zRangeMax - zRangeMin) + zRangeMin;
loc2.setX(x);
loc2.setZ(z);
}
flag = true;
}
boolean swap = false;
if (loc2.getX() < xRangeMin) {
loc2.setX(xRangeMin);
swap = true;
} else if (loc2.getX() > xRangeMax) {
loc2.setX(xRangeMax);
swap = true;
}
if (loc2.getZ() < zRangeMin) {
loc2.setZ(zRangeMin);
swap = true;
} else if (loc2.getZ() > zRangeMax) {
loc2.setZ(zRangeMax);
swap = true;
}
if (swap) {
flag = true;
}
}
if (!flag) {
Location[] locs = locations;
int i1 = locations.length;
for (j = 0; j < i1; ++j) {
loc1 = locs[j];
if (world.getHighestBlockYAt(loc1) == 0) {
double x = xRangeMin >= xRangeMax ? xRangeMin : random.nextDouble() * (xRangeMax - xRangeMin) + xRangeMin;
double z = zRangeMin >= zRangeMax ? zRangeMin : random.nextDouble() * (zRangeMax - zRangeMin) + zRangeMin;
locations[i] = (new Location(world, x, 0, z));
loc1.setX(x);
loc1.setZ(z);
flag = true;
}
}
}
}
if (i >= 10000) {
return -1;
} else {
return i;
}
}
private double spread(World world, List<Player> list, Location[] locations, boolean teams) {
double distance = 0.0D;
int i = 0;
Map<Team, Location> hashmap = Maps.newHashMap();
for (int j = 0; j < list.size(); ++j) {
Player player = list.get(j);
Location location;
if (teams) {
Team team = player.getScoreboard().getPlayerTeam(player);
if (!hashmap.containsKey(team)) {
hashmap.put(team, locations[i++]);
}
location = hashmap.get(team);
} else {
location = locations[i++];
}
player.teleport(new Location(world, Math.floor(location.getX()) + 0.5D, world.getHighestBlockYAt((int) location.getX(), (int) location.getZ()), Math.floor(location.getZ()) + 0.5D));
double value = Double.MAX_VALUE;
for (int k = 0; k < locations.length; ++k) {
if (location != locations[k]) {
double d = location.distanceSquared(locations[k]);
value = Math.min(d, value);
}
}
distance += value;
}
distance /= list.size();
return distance;
}
private int getTeams(List<Player> players) {
Set<Team> teams = Sets.newHashSet();
for (Player player : players) {
teams.add(player.getScoreboard().getPlayerTeam(player));
}
return teams.size();
}
private Location[] getSpreadLocations(World world, int size, double xRangeMin, double zRangeMin, double xRangeMax, double zRangeMax) {
Location[] locations = new Location[size];
for (int i = 0; i < size; ++i) {
double x = xRangeMin >= xRangeMax ? xRangeMin : random.nextDouble() * (xRangeMax - xRangeMin) + xRangeMin;
double z = zRangeMin >= zRangeMax ? zRangeMin : random.nextDouble() * (zRangeMax - zRangeMin) + zRangeMin;
locations[i] = (new Location(world, x, 0, z));
}
return locations;
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class StopCommand extends VanillaCommand {
public StopCommand() {
super("stop");
this.description = "Stops the server with optional reason";
this.usageMessage = "/stop [reason]";
this.setPermission("bukkit.command.stop");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
Command.broadcastCommandMessage(sender, "Stopping the server..");
Bukkit.shutdown();
String reason = this.createString(args, 0);
if (StringUtils.isNotEmpty(reason)) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer(reason);
}
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,125 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.google.common.collect.ImmutableList;
@Deprecated
public class TeleportCommand extends VanillaCommand {
public TeleportCommand() {
super("tp");
this.description = "Teleports the given player (or yourself) to another player or coordinates";
this.usageMessage = "/tp [player] <target> and/or <x> <y> <z>";
this.setPermission("bukkit.command.teleport");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 1 || args.length > 4) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player;
if (args.length == 1 || args.length == 3) {
if (sender instanceof Player) {
player = (Player) sender;
} else {
sender.sendMessage("Please provide a player!");
return true;
}
} else {
player = Bukkit.getPlayerExact(args[0]);
}
if (player == null) {
sender.sendMessage("Player not found: " + args[0]);
return true;
}
if (args.length < 3) {
Player target = Bukkit.getPlayerExact(args[args.length - 1]);
if (target == null) {
sender.sendMessage("Can't find player " + args[args.length - 1] + ". No tp.");
return true;
}
player.teleport(target, TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender, "Teleported " + player.getDisplayName() + " to " + target.getDisplayName());
} else if (player.getWorld() != null) {
Location playerLocation = player.getLocation();
double x = getCoordinate(sender, playerLocation.getX(), args[args.length - 3]);
double y = getCoordinate(sender, playerLocation.getY(), args[args.length - 2], 0, 0);
double z = getCoordinate(sender, playerLocation.getZ(), args[args.length - 1]);
if (x == MIN_COORD_MINUS_ONE || y == MIN_COORD_MINUS_ONE || z == MIN_COORD_MINUS_ONE) {
sender.sendMessage("Please provide a valid location!");
return true;
}
playerLocation.setX(x);
playerLocation.setY(y);
playerLocation.setZ(z);
player.teleport(playerLocation, TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender, String.format("Teleported %s to %.2f, %.2f, %.2f", player.getDisplayName(), x, y, z));
}
return true;
}
private double getCoordinate(CommandSender sender, double current, String input) {
return getCoordinate(sender, current, input, MIN_COORD, MAX_COORD);
}
private double getCoordinate(CommandSender sender, double current, String input, int min, int max) {
boolean relative = input.startsWith("~");
double result = relative ? current : 0;
if (!relative || input.length() > 1) {
boolean exact = input.contains(".");
if (relative) input = input.substring(1);
double testResult = getDouble(sender, input);
if (testResult == MIN_COORD_MINUS_ONE) {
return MIN_COORD_MINUS_ONE;
}
result += testResult;
if (!exact && !relative) result += 0.5f;
}
if (min != 0 || max != 0) {
if (result < min) {
result = MIN_COORD_MINUS_ONE;
}
if (result > max) {
result = MIN_COORD_MINUS_ONE;
}
}
return result;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1 || args.length == 2) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,49 +0,0 @@
package org.bukkit.command.defaults;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Deprecated
public class TellCommand extends VanillaCommand {
public TellCommand() {
super("tell");
this.description = "Sends a private message to the given player";
this.usageMessage = "/tell <player> <message>";
this.setAliases(Arrays.asList(new String[] { "w", "msg" }));
this.setPermission("bukkit.command.tell");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player = Bukkit.getPlayerExact(args[0]);
// If a player is hidden from the sender pretend they are offline
if (player == null || (sender instanceof Player && !((Player) sender).canSee(player))) {
sender.sendMessage("There's no player by that name online.");
} else {
StringBuilder message = new StringBuilder();
for (int i = 1; i < args.length; i++) {
if (i > 1) message.append(" ");
message.append(args[i]);
}
String result = ChatColor.GRAY + sender.getName() + " whispers " + message;
sender.sendMessage("[" + sender.getName() + "->" + player.getName() + "] " + message);
player.sendMessage(result);
}
return true;
}
}

Datei anzeigen

@ -1,27 +0,0 @@
package org.bukkit.command.defaults;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@Deprecated
public class TestForCommand extends VanillaCommand {
public TestForCommand() {
super("testfor");
this.description = "Tests whether a specifed player is online";
this.usageMessage = "/testfor <player>";
this.setPermission("bukkit.command.testfor");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length < 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
sender.sendMessage(ChatColor.RED + "/testfor is only usable by commandblocks with analog output.");
return true;
}
}

Datei anzeigen

@ -1,89 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class TimeCommand extends VanillaCommand {
private static final List<String> TABCOMPLETE_ADD_SET = ImmutableList.of("add", "set");
private static final List<String> TABCOMPLETE_DAY_NIGHT = ImmutableList.of("day", "night");
public TimeCommand() {
super("time");
this.description = "Changes the time on each world";
this.usageMessage = "/time set <value>\n/time add <value>";
this.setPermission("bukkit.command.time.add;bukkit.command.time.set");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Incorrect usage. Correct usage:\n" + usageMessage);
return false;
}
int value;
if (args[0].equals("set")) {
if (!sender.hasPermission("bukkit.command.time.set")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to set the time");
return true;
}
if (args[1].equals("day")) {
value = 0;
} else if (args[1].equals("night")) {
value = 12500;
} else {
value = getInteger(sender, args[1], 0);
}
for (World world : Bukkit.getWorlds()) {
world.setTime(value);
}
Command.broadcastCommandMessage(sender, "Set time to " + value);
} else if (args[0].equals("add")) {
if (!sender.hasPermission("bukkit.command.time.add")) {
sender.sendMessage(ChatColor.RED + "You don't have permission to set the time");
return true;
}
value = getInteger(sender, args[1], 0);
for (World world : Bukkit.getWorlds()) {
world.setFullTime(world.getFullTime() + value);
}
Command.broadcastCommandMessage(sender, "Added " + value + " to time");
} else {
sender.sendMessage("Unknown method. Usage: " + usageMessage);
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], TABCOMPLETE_ADD_SET, new ArrayList<String>(TABCOMPLETE_ADD_SET.size()));
} else if (args.length == 2 && args[0].equalsIgnoreCase("set")) {
return StringUtil.copyPartialMatches(args[1], TABCOMPLETE_DAY_NIGHT, new ArrayList<String>(TABCOMPLETE_DAY_NIGHT.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,57 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableList;
@Deprecated
public class ToggleDownfallCommand extends VanillaCommand {
public ToggleDownfallCommand() {
super("toggledownfall");
this.description = "Toggles rain on/off on a given world";
this.usageMessage = "/toggledownfall";
this.setPermission("bukkit.command.toggledownfall");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
World world = null;
if (args.length == 1) {
world = Bukkit.getWorld(args[0]);
if (world == null) {
sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'");
return true;
}
} else if (sender instanceof Player) {
world = ((Player) sender).getWorld();
} else {
world = Bukkit.getWorlds().get(0);
}
Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'");
world.setStorm(!world.hasStorm());
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,111 +0,0 @@
package org.bukkit.command.defaults;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@Deprecated
public abstract class VanillaCommand extends Command {
static final int MAX_COORD = 30000000;
static final int MIN_COORD_MINUS_ONE = -30000001;
static final int MIN_COORD = -30000000;
protected VanillaCommand(String name) {
super(name);
}
protected VanillaCommand(String name, String description, String usageMessage, List<String> aliases) {
super(name, description, usageMessage, aliases);
}
public boolean matches(String input) {
return input.equalsIgnoreCase(this.getName());
}
protected int getInteger(CommandSender sender, String value, int min) {
return getInteger(sender, value, min, Integer.MAX_VALUE);
}
int getInteger(CommandSender sender, String value, int min, int max) {
return getInteger(sender, value, min, max, false);
}
int getInteger(CommandSender sender, String value, int min, int max, boolean Throws) {
int i = min;
try {
i = Integer.valueOf(value);
} catch (NumberFormatException ex) {
if (Throws) {
throw new NumberFormatException(String.format("%s is not a valid number", value));
}
}
if (i < min) {
i = min;
} else if (i > max) {
i = max;
}
return i;
}
Integer getInteger(String value) {
try {
return Integer.valueOf(value);
} catch (NumberFormatException ex) {
return null;
}
}
public static double getRelativeDouble(double original, CommandSender sender, String input) {
if (input.startsWith("~")) {
double value = getDouble(sender, input.substring(1));
if (value == MIN_COORD_MINUS_ONE) {
return MIN_COORD_MINUS_ONE;
}
return original + value;
} else {
return getDouble(sender, input);
}
}
public static double getDouble(CommandSender sender, String input) {
try {
return Double.parseDouble(input);
} catch (NumberFormatException ex) {
return MIN_COORD_MINUS_ONE;
}
}
public static double getDouble(CommandSender sender, String input, double min, double max) {
double result = getDouble(sender, input);
// TODO: This should throw an exception instead.
if (result < min) {
result = min;
} else if (result > max) {
result = max;
}
return result;
}
String createString(String[] args, int start) {
return createString(args, start, " ");
}
String createString(String[] args, int start, String glue) {
StringBuilder string = new StringBuilder();
for (int x = start; x < args.length; x++) {
string.append(args[x]);
if (x != args.length - 1) {
string.append(glue);
}
}
return string.toString();
}
}

Datei anzeigen

@ -1,74 +0,0 @@
package org.bukkit.command.defaults;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Deprecated
public class WeatherCommand extends VanillaCommand {
private static final List<String> WEATHER_TYPES = ImmutableList.of("clear", "rain", "thunder");
public WeatherCommand() {
super("weather");
this.description = "Changes the weather";
this.usageMessage = "/weather <clear/rain/thunder> [duration in seconds]";
this.setPermission("bukkit.command.weather");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
int duration = (300 + new Random().nextInt(600)) * 20;
if (args.length >= 2) {
duration = getInteger(sender, args[1], 1, 1000000) * 20;
}
World world = Bukkit.getWorlds().get(0);
world.setWeatherDuration(duration);
world.setThunderDuration(duration);
if ("clear".equalsIgnoreCase(args[0])) {
world.setStorm(false);
world.setThundering(false);
Command.broadcastCommandMessage(sender, "Changed weather to clear for " + (duration / 20) + " seconds.");
} else if ("rain".equalsIgnoreCase(args[0])) {
world.setStorm(true);
world.setThundering(false);
Command.broadcastCommandMessage(sender, "Changed weather to rainy for " + (duration / 20) + " seconds.");
} else if ("thunder".equalsIgnoreCase(args[0])) {
world.setStorm(true);
world.setThundering(true);
Command.broadcastCommandMessage(sender, "Changed weather to thundering " + (duration / 20) + " seconds.");
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], WEATHER_TYPES, new ArrayList<String>(WEATHER_TYPES.size()));
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -1,128 +0,0 @@
package org.bukkit.command.defaults;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
@Deprecated
public class WhitelistCommand extends VanillaCommand {
private static final List<String> WHITELIST_SUBCOMMANDS = ImmutableList.of("add", "remove", "on", "off", "list", "reload");
public WhitelistCommand() {
super("whitelist");
this.description = "Manages the list of players allowed to use this server";
this.usageMessage = "/whitelist (add|remove) <player>\n/whitelist (on|off|list|reload)";
this.setPermission("bukkit.command.whitelist.reload;bukkit.command.whitelist.enable;bukkit.command.whitelist.disable;bukkit.command.whitelist.list;bukkit.command.whitelist.add;bukkit.command.whitelist.remove");
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (badPerm(sender, "reload")) return true;
Bukkit.reloadWhitelist();
Command.broadcastCommandMessage(sender, "Reloaded white-list from file");
return true;
} else if (args[0].equalsIgnoreCase("on")) {
if (badPerm(sender, "enable")) return true;
Bukkit.setWhitelist(true);
Command.broadcastCommandMessage(sender, "Turned on white-listing");
return true;
} else if (args[0].equalsIgnoreCase("off")) {
if (badPerm(sender, "disable")) return true;
Bukkit.setWhitelist(false);
Command.broadcastCommandMessage(sender, "Turned off white-listing");
return true;
} else if (args[0].equalsIgnoreCase("list")) {
if (badPerm(sender, "list")) return true;
StringBuilder result = new StringBuilder();
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
if (result.length() > 0) {
result.append(", ");
}
result.append(player.getName());
}
sender.sendMessage("White-listed players: " + result.toString());
return true;
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("add")) {
if (badPerm(sender, "add")) return true;
Bukkit.getOfflinePlayer(args[1]).setWhitelisted(true);
Command.broadcastCommandMessage(sender, "Added " + args[1] + " to white-list");
return true;
} else if (args[0].equalsIgnoreCase("remove")) {
if (badPerm(sender, "remove")) return true;
Bukkit.getOfflinePlayer(args[1]).setWhitelisted(false);
Command.broadcastCommandMessage(sender, "Removed " + args[1] + " from white-list");
return true;
}
}
sender.sendMessage(ChatColor.RED + "Correct command usage:\n" + usageMessage);
return false;
}
private boolean badPerm(CommandSender sender, String perm) {
if (!sender.hasPermission("bukkit.command.whitelist." + perm)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to perform this action.");
return true;
}
return false;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], WHITELIST_SUBCOMMANDS, new ArrayList<String>(WHITELIST_SUBCOMMANDS.size()));
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("add")) {
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[1]) && !player.isWhitelisted()) {
completions.add(name);
}
}
return completions;
} else if (args[0].equalsIgnoreCase("remove")) {
List<String> completions = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
String name = player.getName();
if (StringUtil.startsWithIgnoreCase(name, args[1])) {
completions.add(name);
}
}
return completions;
}
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -3,7 +3,6 @@ package org.bukkit.enchantments;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.command.defaults.EnchantCommand;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
@ -305,7 +304,6 @@ public abstract class Enchantment {
*/ */
public static void stopAcceptingRegistrations() { public static void stopAcceptingRegistrations() {
acceptingNew = false; acceptingNew = false;
EnchantCommand.buildEnchantments();
} }
/** /**

Datei anzeigen

@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.command.defaults.VanillaCommand;
import org.bukkit.help.HelpTopic; import org.bukkit.help.HelpTopic;
/** /**
@ -62,8 +61,8 @@ public class GenericCommandHelpTopic extends HelpTopic {
} }
public boolean canSee(CommandSender sender) { public boolean canSee(CommandSender sender) {
if (!command.isRegistered() && !(command instanceof VanillaCommand)) { if (!command.isRegistered()) {
// Unregistered commands should not show up in the help (ignore VanillaCommands) // Unregistered commands should not show up in the help
return false; return false;
} }