geforkt von Mirrors/Paper
Make /spreadplayers command work. Fixes BUKKIT-4720
By: feildmaster <admin@feildmaster.com>
Dieser Commit ist enthalten in:
Ursprung
f9bec6eadd
Commit
f997cacf92
@ -36,25 +36,28 @@ public class SpreadPlayersCommand extends VanillaCommand {
|
|||||||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double x = getDouble(sender, args[0]);
|
|
||||||
double z = getDouble(sender, args[1]);
|
final double x = getDouble(sender, args[0], -30000000, 30000000);
|
||||||
double distance = getDouble(sender, args[2]);
|
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) {
|
if (distance < 0.0D) {
|
||||||
sender.sendMessage(ChatColor.RED + "Distance is too small.");
|
sender.sendMessage(ChatColor.RED + "Distance is too small.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double range = getDouble(sender, args[3]);
|
|
||||||
if (range < distance + 1.0D) {
|
if (range < distance + 1.0D) {
|
||||||
sender.sendMessage(ChatColor.RED + "Max range is too small.");
|
sender.sendMessage(ChatColor.RED + "Max range is too small.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String respectTeams = args[4];
|
||||||
boolean teams = false;
|
boolean teams = false;
|
||||||
if ("true".equalsIgnoreCase(args[4])) {
|
|
||||||
|
if (respectTeams.equalsIgnoreCase("true")) {
|
||||||
teams = true;
|
teams = true;
|
||||||
} else if (!"false".equalsIgnoreCase(args[4])) {
|
} else if (!respectTeams.equalsIgnoreCase("false")) {
|
||||||
sender.sendMessage(String.format(ChatColor.RED + "'%s' is not true or false", args[4]));
|
sender.sendMessage(String.format(ChatColor.RED + "'%s' is not true or false", args[4]));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -68,7 +71,7 @@ public class SpreadPlayersCommand extends VanillaCommand {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world != null) {
|
if (world == null) {
|
||||||
world = player.getWorld();
|
world = player.getWorld();
|
||||||
}
|
}
|
||||||
players.add(player);
|
players.add(player);
|
||||||
@ -78,14 +81,22 @@ public class SpreadPlayersCommand extends VanillaCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double xRangeMin = x - range;
|
final double xRangeMin = x - range;
|
||||||
double zRangeMin = z - range;
|
final double zRangeMin = z - range;
|
||||||
double xRangeMax = x + range;
|
final double xRangeMax = x + range;
|
||||||
double zRangeMax = z + range;
|
final double zRangeMax = z + range;
|
||||||
|
|
||||||
Location[] locations = getSpreadLocations(world, teams ? getTeams(players) : players.size(), xRangeMin, zRangeMin, xRangeMax, zRangeMax);
|
final int spreadSize = teams ? getTeams(players) : players.size();
|
||||||
int rangeSpread = range(world, distance, xRangeMin, zRangeMin, xRangeMax, zRangeMax, locations);
|
|
||||||
double distanceSpread = spread(world, players, locations, teams);
|
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));
|
sender.sendMessage(String.format("Succesfully spread %d %s around %s,%s", locations.length, teams ? "teams" : "players", x, z));
|
||||||
if (locations.length > 1) {
|
if (locations.length > 1) {
|
||||||
@ -96,7 +107,7 @@ public class SpreadPlayersCommand extends VanillaCommand {
|
|||||||
|
|
||||||
private int range(World world, double distance, double xRangeMin, double zRangeMin, double xRangeMax, double zRangeMax, Location[] locations) {
|
private int range(World world, double distance, double xRangeMin, double zRangeMin, double xRangeMax, double zRangeMax, Location[] locations) {
|
||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
double max = Float.MAX_VALUE;
|
double max;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ public abstract class VanillaCommand extends Command {
|
|||||||
public static double getDouble(CommandSender sender, String input, double min, double max) {
|
public static double getDouble(CommandSender sender, String input, double min, double max) {
|
||||||
double result = getDouble(sender, input);
|
double result = getDouble(sender, input);
|
||||||
|
|
||||||
|
// TODO: This should throw an exception instead.
|
||||||
if (result < min) {
|
if (result < min) {
|
||||||
result = min;
|
result = min;
|
||||||
} else if (result > max) {
|
} else if (result > max) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren