getPermissions() {
+ return ImmutableList.of("war.admin", "war.admin.config");
+ }
+ };
+ }
+
+ /**
+ * 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) {
+ if (source instanceof Player) {
+ try {
+ if (plugin.getConfig().getZoneMakers().contains(source)) {
+ source.sendMessage("You are a zone maker.");
+ return true;
+ }
+ } catch (SQLException e) {
+ plugin.getLogger().error("Loading zone makers for testing permission", e);
+ }
+ }
+ if (source instanceof Subject && ((Subject) source).isPermitted("war.admin.config")) {
+ source.sendMessage("You are a war admin.");
+ return true;
+ }
+ if (!(source instanceof Player) && !(source instanceof Subject)) {
+ source.sendMessage("You are console or something.");
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 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 (WarConfig.WarSetting setting : WarConfig.WarSetting.values()) {
+ if (setting.name().toLowerCase().startsWith(arguments.toLowerCase()))
+ suggestions.add(setting.name().toLowerCase() + ":");
+ }
+ return suggestions;
+ }
+}
diff --git a/sponge/src/main/java/com/tommytony/war/struct/Region.java b/sponge/src/main/java/com/tommytony/war/struct/Region.java
new file mode 100644
index 0000000..3575d65
--- /dev/null
+++ b/sponge/src/main/java/com/tommytony/war/struct/Region.java
@@ -0,0 +1,103 @@
+package com.tommytony.war.struct;
+
+import org.spongepowered.api.block.Block;
+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 Block 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 Block getBlock(int x, int y, int z) {
+ return first.getExtent().getBlock(x, y, z);
+ }
+}