getHelp() {
- return Optional.of("Allows viewing of the war server config or changing various settings.");
- }
-
- /**
- * Get the usage string of this command.
- *
- * A usage string may look like
- * {@code [-w <world>] <var1> <var2>}.
- *
- * @return A usage string
- */
- @Override
- public String getUsage() {
- return "[-p] setting:value...";
- }
-
- /**
- * Get a list of suggestions based on input.
- *
- * If a suggestion is chosen by the user, it will replace the last
- * word.
- *
- * @param source The command source
- * @param arguments The arguments entered up to this point
- * @return A list of suggestions
- * @throws org.spongepowered.api.util.command.CommandException Thrown if there was a parsing error
- */
@Override
public List getSuggestions(CommandSource source, String arguments) throws CommandException {
- ArrayList suggestions = new ArrayList<>();
+ ImmutableList.Builder list = ImmutableList.builder();
for (WarConfig.WarSetting setting : WarConfig.WarSetting.values()) {
if (setting.name().toLowerCase().startsWith(arguments.toLowerCase()))
- suggestions.add(setting.name().toLowerCase() + ":");
+ list.add(setting.name().toLowerCase() + ":");
}
- return suggestions;
+ return list.build();
+ }
+
+ @Override
+ public boolean testPermission(CommandSource source) {
+ try {
+ if (source instanceof Player && plugin.getConfig().getZoneMakers().contains(source)) {
+ return true;
+ }
+ } catch (SQLException e) {
+ plugin.getLogger().error("Loading zone makers for testing permission", e);
+ }
+ if (source.hasPermission("war.config")) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Optional extends Text> getShortDescription(CommandSource source) {
+ return desc;
+ }
+
+ @Override
+ public Optional extends Text> getHelp(CommandSource source) {
+ return help;
+ }
+
+ @Override
+ public Text getUsage(CommandSource source) {
+ return usage;
}
}
diff --git a/sponge/src/main/java/com/tommytony/war/command/WarzoneCommand.java b/sponge/src/main/java/com/tommytony/war/command/WarzoneCommand.java
index a4bbbef..ecfbd2f 100644
--- a/sponge/src/main/java/com/tommytony/war/command/WarzoneCommand.java
+++ b/sponge/src/main/java/com/tommytony/war/command/WarzoneCommand.java
@@ -1,126 +1,82 @@
package com.tommytony.war.command;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.tommytony.war.WarPlugin;
import com.tommytony.war.zone.Warzone;
import org.spongepowered.api.entity.player.Player;
+import org.spongepowered.api.text.Text;
+import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
+import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
-import java.util.ArrayList;
import java.util.List;
/**
* Teleport to warzone.
*/
public class WarzoneCommand implements CommandCallable {
+
+ private final Optional desc = Optional.of((Text) Texts.of("Teleport to a zone"));
+ private final Optional help = Optional.of((Text) Texts.of("Teleport to a warzone, or join automatically."));
+ private final Text usage = (Text) Texts.of("");
+
private WarPlugin plugin;
public WarzoneCommand(WarPlugin plugin) {
this.plugin = plugin;
}
- /**
- * Execute the command based on input arguments.
- *
- * The implementing class must perform the necessary permission
- * checks.
- *
- * @param source The caller of the command
- * @param arguments The raw arguments for this command
- * @param parents A stack of parent commands, where the first entry is
- * the root command
- * @return Whether a command was processed
- * @throws org.spongepowered.api.util.command.CommandException Thrown on a command error
- */
@Override
- public boolean call(CommandSource source, String arguments, List parents) throws CommandException {
- if (!(source instanceof Player)) {
- return false;
+ public CommandResult process(CommandSource commandSource, String s) throws CommandException {
+ if (!(commandSource instanceof Player)) {
+ return CommandResult.empty();
}
- String[] argv = arguments.split(" ");
+ String[] argv = s.split(" ");
if (argv.length < 1) {
- return false;
+ return CommandResult.empty();
}
String zoneName = argv[0];
Optional zone = plugin.getZone(zoneName);
if (!zone.isPresent()) {
- return false;
+ return CommandResult.empty();
}
- Player player = (Player) source;
- player.teleport(zone.get().getTeleport());
+ Player player = (Player) commandSource;
+ player.setLocation(zone.get().getTeleport());
- return true;
+ return CommandResult.success();
}
- /**
- * Test whether this command can probably be executed by the given source.
- *
- * If implementations are unsure if the command can be executed by
- * the source, {@code true} should be returned. Return values of this method
- * may be used to determine whether this command is listed in command
- * listings.
- *
- * @param source The caller of the command
- * @return Whether permission is (probably) granted
- */
@Override
- public boolean testPermission(CommandSource source) {
- return true;
- }
-
- /**
- * Get a short one-line description of this command.
- *
- * @return A description, if available
- */
- @Override
- public Optional getShortDescription() {
- return Optional.of("Teleport to a zone");
- }
-
- /**
- * Get a longer help text about this command.
- *
- * @return A help text, if available
- */
- @Override
- public Optional getHelp() {
- return Optional.of("Use this command to teleport to a zone lobby");
- }
-
- /**
- * Get the usage string of this command.
- *
- * A usage string may look like
- * {@code [-w <world>] <var1> <var2>}.
- *
- * @return A usage string
- */
- @Override
- public String getUsage() {
- return "";
- }
-
- /**
- * Get a list of suggestions based on input.
- *
- * If a suggestion is chosen by the user, it will replace the last
- * word.
- *
- * @param source The command source
- * @param arguments The arguments entered up to this point
- * @return A list of suggestions
- * @throws org.spongepowered.api.util.command.CommandException Thrown if there was a parsing error
- */
- @Override
- public List getSuggestions(CommandSource source, String arguments) throws CommandException {
- ArrayList suggestions = new ArrayList<>();
- for (String zone : plugin.getZones().keySet()) {
- if (zone.toLowerCase().startsWith(arguments.toLowerCase()))
- suggestions.add(zone);
+ public List getSuggestions(CommandSource commandSource, String s) throws CommandException {
+ ImmutableList.Builder list = ImmutableList.builder();
+ for (Warzone zone : plugin.getZones().values()) {
+ if (zone.getName().toLowerCase().startsWith(s.toLowerCase())) {
+ list.add(zone.getName());
+ }
}
- return suggestions;
+ return list.build();
+ }
+
+ @Override
+ public boolean testPermission(CommandSource commandSource) {
+ return commandSource.hasPermission("war.teleport");
+ }
+
+ @Override
+ public Optional extends Text> getShortDescription(CommandSource commandSource) {
+ return desc;
+ }
+
+ @Override
+ public Optional extends Text> getHelp(CommandSource commandSource) {
+ return help;
+ }
+
+ @Override
+ public Text getUsage(CommandSource commandSource) {
+ return usage;
}
}
diff --git a/sponge/src/main/java/com/tommytony/war/struct/Region.java b/sponge/src/main/java/com/tommytony/war/struct/Region.java
deleted file mode 100644
index ecbf06f..0000000
--- a/sponge/src/main/java/com/tommytony/war/struct/Region.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.tommytony.war.struct;
-
-import org.spongepowered.api.block.BlockLoc;
-import org.spongepowered.api.math.Vector3d;
-import org.spongepowered.api.world.Location;
-import org.spongepowered.api.world.extent.BlockVolume;
-
-/**
- * A selection of blocks in the world. Identified by two corners.
- */
-public class Region implements BlockVolume {
- /**
- * One corner of the selection.
- */
- private Location first;
- /**
- * The second corner of the selection.
- */
- private Location second;
-
- public Region(Location first, Location second) {
- this.first = first;
- this.second = second;
- }
-
- /**
- * Calculate the minimum value of the selection.
- *
- * @return the minimum value.
- */
- public Location getMin() {
- return new Location(first.getExtent(), first.getPosition().min(second.getPosition()));
- }
-
- /**
- * Calculate the maximum value of the selection.
- *
- * @return the maximum value.
- */
- public Location getMax() {
- return new Location(first.getExtent(), first.getPosition().max(second.getPosition()));
- }
-
- /**
- * Get the size of the region in the X dimension.
- *
- * @return X dimension length.
- */
- public int getSizeX() {
- return getMax().getBlock().getX() - getMin().getBlock().getX();
- }
-
- /**
- * Get the size of the region in the Y dimension.
- *
- * @return Y dimension length.
- */
- public int getSizeY() {
- return getMax().getBlock().getY() - getMin().getBlock().getY();
- }
-
- /**
- * Get the size of the region in the Z dimension.
- *
- * @return Z dimension length.
- */
- public int getSizeZ() {
- return getMax().getBlock().getZ() - getMin().getBlock().getZ();
- }
-
- /**
- * Get the total area of the region.
- *
- * @return region total area.
- */
- public int getSize() {
- return getSizeX() * getSizeY() * getSizeZ();
- }
-
- /**
- * Get a representation of the block at the given position.
- *
- * @param position The position
- * @return The block
- */
- @Override
- public BlockLoc getBlock(Vector3d position) {
- return first.getExtent().getBlock(position);
- }
-
- /**
- * Get a representation of the block at the given position.
- *
- * @param x The X position
- * @param y The Y position
- * @param z The Z position
- * @return The block
- */
- @Override
- public BlockLoc getBlock(int x, int y, int z) {
- return first.getExtent().getBlock(x, y, z);
- }
-}
diff --git a/sponge/src/main/java/com/tommytony/war/zone/Warzone.java b/sponge/src/main/java/com/tommytony/war/zone/Warzone.java
index 85cab9f..e332d88 100644
--- a/sponge/src/main/java/com/tommytony/war/zone/Warzone.java
+++ b/sponge/src/main/java/com/tommytony/war/zone/Warzone.java
@@ -19,7 +19,7 @@ public class Warzone {
private final String name;
private final ZoneStorage db;
private final ZoneConfig config;
- private Location teleport;
+ private Location teleport;
/**
* Load or create a war zone from the war settings store.
@@ -56,11 +56,11 @@ public class Warzone {
return name;
}
- public Location getTeleport() {
+ public Location getTeleport() {
try {
Optional lobby = db.getPosition("lobby", Optional.absent());
if (lobby.isPresent())
- return lobby.get();
+ return lobby.get();
else throw new RuntimeException("No teleport location found for zone " + name);
} catch (SQLException e) {
plugin.getLogger().error("Retrieving teleport", e);
diff --git a/sponge/src/main/java/com/tommytony/war/zone/ZoneStorage.java b/sponge/src/main/java/com/tommytony/war/zone/ZoneStorage.java
index 028514a..39fc80c 100644
--- a/sponge/src/main/java/com/tommytony/war/zone/ZoneStorage.java
+++ b/sponge/src/main/java/com/tommytony/war/zone/ZoneStorage.java
@@ -2,7 +2,6 @@ package com.tommytony.war.zone;
import com.google.common.base.Optional;
import com.tommytony.war.WarPlugin;
-import org.spongepowered.api.math.Vectors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
@@ -86,10 +85,18 @@ public class ZoneStorage implements AutoCloseable {
try (ResultSet resultSet = stmt.executeQuery()) {
if (resultSet.next()) {
World resultWorld;
- if (world.isPresent()) resultWorld = world.get();
- else resultWorld = plugin.getGame().getWorld(resultSet.getString("world"));
- return Optional.of(new Location(resultWorld, Vectors.create3d(
- resultSet.getDouble("x"), resultSet.getDouble("y"), resultSet.getDouble("z"))));
+ if (world.isPresent()) {
+ resultWorld = world.get();
+ } else {
+ Optional optwld = plugin.getGame().getServer().getWorld(resultSet.getString("world"));
+ if (optwld.isPresent()) {
+ resultWorld = optwld.get();
+ } else {
+ return Optional.absent();
+ }
+ }
+ return Optional.of(new Location(resultWorld,
+ resultSet.getDouble("x"), resultSet.getDouble("y"), resultSet.getDouble("z")));
}
}
}