diff --git a/labyrinth-common/pom.xml b/labyrinth-common/pom.xml
index 72664daa..5e389a2d 100644
--- a/labyrinth-common/pom.xml
+++ b/labyrinth-common/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-gui/pom.xml b/labyrinth-gui/pom.xml
index 8d03a8f9..ff2bb315 100644
--- a/labyrinth-gui/pom.xml
+++ b/labyrinth-gui/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-loci/pom.xml b/labyrinth-loci/pom.xml
index 00cfed59..5a2b1bd9 100644
--- a/labyrinth-loci/pom.xml
+++ b/labyrinth-loci/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-perms/pom.xml b/labyrinth-perms/pom.xml
index 1cb326f1..95b945b4 100644
--- a/labyrinth-perms/pom.xml
+++ b/labyrinth-perms/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-plugin/pom.xml b/labyrinth-plugin/pom.xml
index 3c274de4..43858385 100644
--- a/labyrinth-plugin/pom.xml
+++ b/labyrinth-plugin/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-plugin/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManagerImpl.java b/labyrinth-plugin/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManagerImpl.java
index f8cb6d43..c0fa1afb 100644
--- a/labyrinth-plugin/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManagerImpl.java
+++ b/labyrinth-plugin/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManagerImpl.java
@@ -2,6 +2,7 @@
import com.github.sanctum.labyrinth.Labyrinth;
import com.github.sanctum.labyrinth.LabyrinthProvider;
+import com.github.sanctum.labyrinth.data.container.Region;
import com.github.sanctum.labyrinth.event.CuboidSelectEvent;
import com.github.sanctum.labyrinth.event.LabyrinthVentCall;
import com.github.sanctum.labyrinth.event.RegionBuildEvent;
@@ -9,7 +10,6 @@
import com.github.sanctum.labyrinth.event.RegionInteractionEvent;
import com.github.sanctum.labyrinth.event.RegionPVPEvent;
import com.github.sanctum.labyrinth.event.DefaultEvent;
-import com.github.sanctum.labyrinth.library.Cuboid;
import com.github.sanctum.labyrinth.library.Items;
import com.github.sanctum.labyrinth.task.TaskScheduler;
import com.github.sanctum.panther.container.ImmutablePantherCollection;
@@ -25,6 +25,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
+import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.ServicePriority;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +35,8 @@
public final class RegionServicesManagerImpl extends RegionServicesManager {
final PantherCollection cache = new PantherList<>();
- final Cuboid.FlagManager flagManager = new Cuboid.FlagManager(this);
+ final FlagManager flagManager = new FlagManager(this);
+ private ItemStack wand = new ItemStack(Material.STICK);
public static void initialize(Labyrinth instance) {
@@ -102,7 +104,7 @@ public static void initialize(Labyrinth instance) {
if (!e.getPlayer().hasPermission("labyrinth.selection"))
return;
- Cuboid.Selection selection = Cuboid.Selection.source(e.getPlayer());
+ CuboidSelection selection = CuboidSelection.get(e.getPlayer());
if (e.getItem().getType() == selection.getWand().getType()) {
if (e.getResult() != Event.Result.DENY) {
@@ -144,7 +146,7 @@ public static void initialize(Labyrinth instance) {
}
if (e.getItem().getType() == mat) {
- Cuboid.Selection selection = Cuboid.Selection.source(e.getPlayer());
+ CuboidSelection selection = CuboidSelection.get(e.getPlayer());
if (e.getResult() != Event.Result.DENY) {
e.setResult(Event.Result.DENY);
}
@@ -213,17 +215,17 @@ public Region get(@NotNull String name) {
@Override
public Region get(@NotNull Location location, boolean passthrough) {
- return cache.stream().filter(region -> region.contains(location) && region.isPassthrough() == passthrough).findFirst().orElse(null);
+ return cache.stream().filter(region -> region.contains(location) && region.isDominant() == passthrough).findFirst().orElse(null);
}
@Override
public Region get(@NotNull Player player, boolean passthrough) {
- return cache.stream().filter(region -> region.contains(player) && region.isPassthrough() == passthrough).findFirst().orElse(null);
+ return cache.stream().filter(region -> region.contains(player) && region.isDominant() == passthrough).findFirst().orElse(null);
}
@Override
public Region get(@NotNull String name, boolean passthrough) {
- return cache.stream().filter(region -> region.getName().equals(name) && region.isPassthrough() == passthrough).findFirst().orElse(null);
+ return cache.stream().filter(region -> region.getName().equals(name) && region.isDominant() == passthrough).findFirst().orElse(null);
}
@Override
@@ -239,7 +241,17 @@ public boolean unload(@NotNull Region region) {
}
@Override
- public Cuboid.FlagManager getFlagManager() {
+ public FlagManager getFlagManager() {
return flagManager;
}
+
+ @Override
+ public ItemStack getWand() {
+ return wand;
+ }
+
+ @Override
+ public void setWand(@NotNull ItemStack itemStack) {
+ this.wand = itemStack;
+ }
}
diff --git a/labyrinth-plugin/src/main/resources/lib/1_20_R1.jar b/labyrinth-plugin/src/main/resources/lib/1_20_R1.jar
new file mode 100644
index 00000000..b19667d1
Binary files /dev/null and b/labyrinth-plugin/src/main/resources/lib/1_20_R1.jar differ
diff --git a/labyrinth-regions/pom.xml b/labyrinth-regions/pom.xml
index 62244fea..cc5d28f7 100644
--- a/labyrinth-regions/pom.xml
+++ b/labyrinth-regions/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidAxis.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidAxis.java
new file mode 100644
index 00000000..293fab6d
--- /dev/null
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidAxis.java
@@ -0,0 +1,69 @@
+package com.github.sanctum.labyrinth.data;
+
+public class CuboidAxis {
+
+ private final int xMin;
+ private final int xMax;
+ private final int yMin;
+ private final int yMax;
+ private final int zMin;
+ private final int zMax;
+ private final int height;
+ private final int zWidth;
+ private final int xWidth;
+ private final int totalSize;
+
+ public CuboidAxis(int x1, int x2, int y1, int y2, int z1, int z2) {
+ this.xMin = Math.min(x1, x2);
+ this.xMax = Math.max(x1, x2);
+ this.yMin = Math.min(y1, y2);
+ this.yMax = Math.max(y1, y2);
+ this.zMin = Math.min(z1, z2);
+ this.zMax = Math.max(z1, z2);
+ this.height = this.yMax - this.yMin + 1;
+ this.xWidth = this.xMax - this.xMin + 1;
+ this.zWidth = this.zMax - this.zMin + 1;
+ this.totalSize = height * xWidth * zWidth;
+ }
+
+ public int getTotalSize() {
+ return totalSize;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public int getxWidth() {
+ return xWidth;
+ }
+
+ public int getzWidth() {
+ return zWidth;
+ }
+
+ public int getxMax() {
+ return xMax;
+ }
+
+ public int getxMin() {
+ return xMin;
+ }
+
+ public int getyMax() {
+ return yMax;
+ }
+
+ public int getyMin() {
+ return yMin;
+ }
+
+ public int getzMax() {
+ return zMax;
+ }
+
+ public int getzMin() {
+ return zMin;
+ }
+
+}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidLocation.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidLocation.java
new file mode 100644
index 00000000..2bc6ec84
--- /dev/null
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidLocation.java
@@ -0,0 +1,34 @@
+package com.github.sanctum.labyrinth.data;
+
+import java.util.Random;
+import org.bukkit.Location;
+import org.bukkit.World;
+
+public class CuboidLocation {
+
+ private final World world;
+ private final CuboidAxis axis;
+ private final Location center;
+
+ public CuboidLocation(CuboidAxis axis, World world) {
+ this.world = world;
+ this.axis = axis;
+ this.center = new Location(getWorld(), (double) (this.axis.getxMax() - this.axis.getxMin()) / 2 + this.axis.getxMin(), (double) (this.axis.getyMax() - this.axis.getyMin()) / 2 + this.axis.getyMin(), (double) (this.axis.getzMax() - this.axis.getzMin()) / 2 + this.axis.getzMin());
+ }
+
+ public Location getCenter() {
+ return center;
+ }
+
+ public Location getRandom() {
+ Random r = new Random();
+ int x = r.nextInt(Math.abs(this.axis.getxMax() - this.axis.getxMin()) + 1) + this.axis.getxMin();
+ int y = r.nextInt(Math.abs(this.axis.getyMax() - this.axis.getyMin()) + 1) + this.axis.getyMin();
+ int z = r.nextInt(Math.abs(this.axis.getzMax() - this.axis.getzMin()) + 1) + this.axis.getzMin();
+ return new Location(getWorld(), x, y, z);
+ }
+
+ public World getWorld() {
+ return world;
+ }
+}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidSelection.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidSelection.java
new file mode 100644
index 00000000..d298e7b4
--- /dev/null
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/CuboidSelection.java
@@ -0,0 +1,152 @@
+package com.github.sanctum.labyrinth.data;
+
+import com.github.sanctum.labyrinth.data.container.Cuboid;
+import java.util.HashSet;
+import java.util.Set;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+/**
+ * Represents that of a cuboid selection in emphasis. It contains area data for easy manipulation with regions.
+ */
+public class CuboidSelection {
+
+ private static final Set cache = new HashSet<>();
+
+ private final Player wizard;
+ private ItemStack wand;
+ private Location pos1;
+ private Location pos2;
+
+ protected CuboidSelection(Player wizard) {
+ this.wizard = wizard;
+ this.wand = RegionServicesManager.getInstance().getWand();
+ }
+
+ public Player getPlayer() {
+ return wizard;
+ }
+
+ public ItemStack getWand() {
+ return wand;
+ }
+
+ public boolean isEmpty() {
+ return getPos1() == null || getPos2() == null;
+ }
+
+ public void setWand(ItemStack wand) {
+ this.wand = wand;
+ }
+
+ public Location getPos1() {
+ return pos1;
+ }
+
+ public Location getPos2() {
+ return pos2;
+ }
+
+ public Location getHighest() {
+ return getPos1().getBlockY() > getPos2().getBlockY() ? getPos1() : getPos2();
+ }
+
+ public Location getLowest() {
+ return getPos2().getBlockY() < getPos1().getBlockY() ? getPos2() : getPos1();
+ }
+
+ public Location expand(BlockFace direction) {
+ Location update;
+ switch (direction) {
+ case UP:
+ update = getHighest().getBlock().getRelative(BlockFace.UP).getLocation();
+ setPos1(update);
+ return update;
+ case DOWN:
+ update = getHighest().getBlock().getRelative(BlockFace.DOWN).getLocation();
+ setPos2(update);
+ return update;
+ case EAST:
+ update = getHighest().getBlock().getRelative(BlockFace.EAST).getLocation();
+ setPos1(update);
+ return update;
+ case WEST:
+ update = getHighest().getBlock().getRelative(BlockFace.WEST).getLocation();
+ setPos2(update);
+ return update;
+ case NORTH:
+ update = getHighest().getBlock().getRelative(BlockFace.NORTH).getLocation();
+ setPos1(update);
+ return update;
+ case SOUTH:
+ update = getHighest().getBlock().getRelative(BlockFace.SOUTH).getLocation();
+ setPos2(update);
+ return update;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ public Location expand(BlockFace direction, int distance) {
+ Location update;
+ switch (direction) {
+ case UP:
+ update = getHighest().getBlock().getRelative(BlockFace.UP, distance).getLocation();
+ setPos1(update);
+ return update;
+ case DOWN:
+ update = getHighest().getBlock().getRelative(BlockFace.DOWN, distance).getLocation();
+ setPos2(update);
+ return update;
+ case EAST:
+ update = getHighest().getBlock().getRelative(BlockFace.EAST, distance).getLocation();
+ setPos1(update);
+ return update;
+ case WEST:
+ update = getHighest().getBlock().getRelative(BlockFace.WEST, distance).getLocation();
+ setPos2(update);
+ return update;
+ case NORTH:
+ update = getHighest().getBlock().getRelative(BlockFace.NORTH, distance).getLocation();
+ setPos1(update);
+ return update;
+ case SOUTH:
+ update = getHighest().getBlock().getRelative(BlockFace.SOUTH, distance).getLocation();
+ setPos2(update);
+ return update;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ public void setPos1(Location pos1) {
+ this.pos1 = pos1;
+ }
+
+ public void setPos2(Location pos2) {
+ this.pos2 = pos2;
+ }
+
+ public Cuboid toCuboid() {
+ return Cuboid.fromPoints(getPos1(), getPos2());
+ }
+
+ public static boolean has(Player p) {
+ return cache.stream().anyMatch(s -> s.getPlayer().equals(p));
+ }
+
+ public static CuboidSelection get(Player p) {
+ for (CuboidSelection r : cache) {
+ if (r.getPlayer().equals(p)) {
+ return r;
+ }
+ }
+ CuboidSelection r = new CuboidSelection(p);
+ cache.add(r);
+ return r;
+ }
+
+}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultCuboid.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultCuboid.java
new file mode 100644
index 00000000..8f624c52
--- /dev/null
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultCuboid.java
@@ -0,0 +1,40 @@
+package com.github.sanctum.labyrinth.data;
+
+import com.github.sanctum.labyrinth.data.container.Cuboid;
+import com.github.sanctum.panther.util.Check;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+public class DefaultCuboid implements Cuboid {
+
+ private final CuboidAxis axis;
+ private final CuboidLocation location;
+
+ public DefaultCuboid(Location start, Location end) throws NullPointerException {
+ Check.forNull(start, "Starting point cannot be null!");
+ Check.forNull(end, "End point cannot be null!");
+ Check.argument(start.getWorld().getName().equals(end.getWorld().getName()), "The locations must both be from the same realm!");
+ this.axis = new CuboidAxis(start.getBlockX(), end.getBlockX(), start.getBlockY(), end.getBlockY(), start.getBlockZ(), end.getBlockZ());
+ this.location = new CuboidLocation(axis, start.getWorld());
+ }
+
+ @Override
+ public VisualBoundary getBoundary(Player target) {
+ return new VisualBoundary(axis.getxMax(), axis.getxMin(), axis.getyMax(), axis.getyMin(), axis.getzMax(), axis.getzMin()).setViewer(target);
+ }
+
+ @Override
+ public int getTotalBlocks() {
+ return axis.getTotalSize();
+ }
+
+ @Override
+ public CuboidAxis getAxis() {
+ return axis;
+ }
+
+ @Override
+ public CuboidLocation getLocation() {
+ return location;
+ }
+}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionFlag.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultFlag.java
similarity index 77%
rename from labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionFlag.java
rename to labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultFlag.java
index 4f4f0ce7..36e00c9c 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionFlag.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/DefaultFlag.java
@@ -1,17 +1,16 @@
package com.github.sanctum.labyrinth.data;
import com.github.sanctum.labyrinth.LabyrinthProvider;
-import com.github.sanctum.labyrinth.library.Cuboid;
+import com.github.sanctum.labyrinth.data.container.Cuboid;
import com.github.sanctum.panther.event.Vent;
-public class RegionFlag extends Cuboid.Flag {
+public class DefaultFlag extends Cuboid.Flag {
public static class Builder {
private Vent.Subscription> subscription;
private String id;
protected Builder() {
-
}
public static Builder initialize() {
@@ -32,17 +31,17 @@ public Cuboid.Flag finish() {
if (this.subscription != null) {
LabyrinthProvider.getInstance().getEventMap().subscribe(subscription);
}
- return new RegionFlag(this.id);
+ return new DefaultFlag(this.id);
}
}
- public RegionFlag(Cuboid.Flag flag) {
+ public DefaultFlag(Cuboid.Flag flag) {
super(flag);
}
- public RegionFlag(String id) {
+ public DefaultFlag(String id) {
super(id);
}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/FlagManager.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/FlagManager.java
new file mode 100644
index 00000000..1c0d1944
--- /dev/null
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/FlagManager.java
@@ -0,0 +1,85 @@
+package com.github.sanctum.labyrinth.data;
+
+import com.github.sanctum.labyrinth.LabyrinthProvider;
+import com.github.sanctum.labyrinth.data.container.Cuboid;
+import com.github.sanctum.labyrinth.data.container.Region;
+import com.github.sanctum.labyrinth.task.TaskScheduler;
+import com.github.sanctum.panther.event.Vent;
+import com.github.sanctum.panther.event.VentMap;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.bukkit.plugin.Plugin;
+
+public class FlagManager {
+
+ private final Plugin plugin = LabyrinthProvider.getInstance().getPluginInstance();
+ private final Set CACHE = new HashSet<>();
+ private final RegionServicesManager regionServices;
+
+
+ public FlagManager(RegionServicesManager manager) {
+ this.regionServices = manager;
+ Cuboid.Flag BREAK = DefaultFlag.Builder
+ .initialize()
+ .label("break")
+ .finish();
+
+ Cuboid.Flag BUILD = DefaultFlag.Builder
+ .initialize()
+ .label("build")
+ .finish();
+
+ Cuboid.Flag PVP = DefaultFlag.Builder
+ .initialize()
+ .label("pvp")
+ .finish();
+
+ register(PVP);
+ register(BREAK);
+ register(BUILD);
+
+ }
+
+ public Optional getFlag(String id) {
+ return CACHE.stream().filter(f -> f.getId().equals(id)).findFirst();
+ }
+
+ public Set getFlags() {
+ return Collections.unmodifiableSet(CACHE);
+ }
+
+ public boolean isRegistered(Cuboid.Flag flag) {
+ return CACHE.stream().anyMatch(f -> f.getId().equals(flag.getId()));
+ }
+
+ public boolean unregister(Cuboid.Flag flag) {
+ for (Region r : regionServices.getAll()) {
+ r.getFlags().forEach(f -> {
+ if (f.getId().equals(flag.getId())) {
+ TaskScheduler.of(() -> r.removeFlag(f)).schedule();
+ }
+ });
+ }
+ return CACHE.removeIf(f -> f.getId().equals(flag.getId()));
+ }
+
+ public boolean register(Cuboid.Flag flag) {
+ if (!getFlag(flag.getId()).isPresent()) {
+ regionServices.getAll().forEach(region -> region.addFlag(flag));
+ return CACHE.add(flag);
+ }
+ return false;
+ }
+
+ public boolean registerControlling(Cuboid.Flag flag) {
+ if (!getFlag(flag.getId()).isPresent()) {
+ VentMap.getInstance().subscribe((Vent.Host) plugin, flag);
+ regionServices.getAll().forEach(region -> region.addFlag(flag));
+ return CACHE.add(flag);
+ }
+ return false;
+ }
+
+}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManager.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManager.java
index 4aee60a7..3a3b9e27 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManager.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/RegionServicesManager.java
@@ -1,10 +1,11 @@
package com.github.sanctum.labyrinth.data;
-import com.github.sanctum.labyrinth.library.Cuboid;
+import com.github.sanctum.labyrinth.data.container.Region;
import com.github.sanctum.panther.container.PantherCollection;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
@@ -12,15 +13,6 @@
*/
public abstract class RegionServicesManager {
- /**
- * Get the main region service manager instance.
- *
- * @return the region services manager
- */
- public static RegionServicesManager getInstance() {
- return Bukkit.getServicesManager().load(RegionServicesManager.class);
- }
-
public abstract PantherCollection getAll();
public abstract Region get(@NotNull Location location);
@@ -44,6 +36,19 @@ public static RegionServicesManager getInstance() {
*
* @return this manager's flag manager
*/
- public abstract Cuboid.FlagManager getFlagManager();
+ public abstract FlagManager getFlagManager();
+
+ public abstract ItemStack getWand();
+
+ public abstract void setWand(@NotNull ItemStack itemStack);
+
+ /**
+ * Get the main region service manager instance.
+ *
+ * @return the region services manager
+ */
+ public static RegionServicesManager getInstance() {
+ return Bukkit.getServicesManager().load(RegionServicesManager.class);
+ }
}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/library/Cuboid.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Cuboid.java
similarity index 50%
rename from labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/library/Cuboid.java
rename to labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Cuboid.java
index 3e262003..990f4da6 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/library/Cuboid.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Cuboid.java
@@ -1,299 +1,50 @@
-package com.github.sanctum.labyrinth.library;
+package com.github.sanctum.labyrinth.data.container;
-import com.github.sanctum.labyrinth.LabyrinthProvider;
-import com.github.sanctum.labyrinth.api.Service;
-import com.github.sanctum.labyrinth.data.Region;
-import com.github.sanctum.labyrinth.data.RegionFlag;
+import com.github.sanctum.labyrinth.data.CuboidAxis;
+import com.github.sanctum.labyrinth.data.CuboidLocation;
+import com.github.sanctum.labyrinth.data.DefaultCuboid;
+import com.github.sanctum.labyrinth.data.DefaultFlag;
import com.github.sanctum.labyrinth.data.RegionServicesManager;
import com.github.sanctum.labyrinth.data.SimpleKeyedValue;
+import com.github.sanctum.labyrinth.library.StringUtils;
import com.github.sanctum.labyrinth.task.TaskScheduler;
-import com.github.sanctum.panther.event.Vent;
-import com.github.sanctum.panther.event.VentMap;
-import com.github.sanctum.panther.util.Check;
import com.github.sanctum.panther.util.HUID;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
import java.util.function.Function;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
-import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
-import java.util.Optional;
import java.util.Random;
/**
+ * An interface for capturing cubic or rectangular areas.
+ *
* @author Hempfest
*/
public interface Cuboid {
static Cuboid fromPoints(Location start, Location end) {
- Check.forNull(start, "Starting point cannot be null!");
- Check.forNull(end, "End point cannot be null!");
- return new Cuboid() {
-
- private final int xMin;
- private final int xMax;
- private final int yMin;
- private final int yMax;
- private final int zMin;
- private final int zMax;
- private final int height;
- private final int zWidth;
- private final int xWidth;
- private final int totalSize;
- private final World world;
-
- {
- this.xMin = Math.min(start.getBlockX(), end.getBlockX());
- this.xMax = Math.max(start.getBlockX(), end.getBlockX());
- this.yMin = Math.min(start.getBlockY(), end.getBlockY());
- this.yMax = Math.max(start.getBlockY(), end.getBlockY());
- this.zMin = Math.min(start.getBlockZ(), end.getBlockZ());
- this.zMax = Math.max(start.getBlockZ(), end.getBlockZ());
- this.world = start.getWorld();
- this.height = this.yMax - this.yMin + 1;
- this.xWidth = this.xMax - this.xMin + 1;
- this.zWidth = this.zMax - this.zMin + 1;
- this.totalSize = height * xWidth * zWidth;
- }
-
- @Override
- public Boundary getBoundary(Player target) {
- return new Boundary(xMax, xMin, yMax, yMin, zMax, zMin).target(target);
- }
-
- @Override
- public World getWorld() {
- return world;
- }
-
- @Override
- public int getTotalBlocks() {
- return totalSize;
- }
-
- @Override
- public int getXWidth() {
- return xWidth;
- }
-
- @Override
- public int getZWidth() {
- return zWidth;
- }
-
- @Override
- public int getHeight() {
- return height;
- }
-
- @Override
- public int xMax() {
- return xMax;
- }
-
- @Override
- public int xMin() {
- return xMin;
- }
-
- @Override
- public int yMax() {
- return yMax;
- }
-
- @Override
- public int yMin() {
- return yMin;
- }
-
- @Override
- public int zMax() {
- return zMax;
- }
-
- @Override
- public int zMin() {
- return zMin;
- }
- };
+ return new DefaultCuboid(start, end);
}
- Boundary getBoundary(Player target);
-
- World getWorld();
+ VisualBoundary getBoundary(Player target);
int getTotalBlocks();
- int getXWidth();
+ CuboidAxis getAxis();
- int getZWidth();
-
- int getHeight();
-
- int xMax();
-
- int xMin();
-
- int yMax();
-
- int yMin();
-
- int zMax();
-
- int zMin();
+ CuboidLocation getLocation();
default Region toRegion() {
- return new Region(getWorld(), xMin(), xMax(), yMin(), yMax(), zMin(), zMax(), HUID.randomID()){};
+ return new Region(getLocation().getWorld(), getAxis().getxMin(), getAxis().getxMax(), getAxis().getyMin(), getAxis().getyMax(), getAxis().getzMin(), getAxis().getzMax(), HUID.randomID()){};
}
default R toRegion(Function>, R> function) {
- return function.apply(SimpleKeyedValue.of(this, SimpleKeyedValue.of(new Location(getWorld(), xMin(), yMin(), zMin()), new Location(getWorld(), xMax(), yMax(), this.zMax()))));
- }
-
- class Selection {
-
- private static final Set cache = new HashSet<>();
-
- private final Player wizard;
-
- private ItemStack wand = new ItemStack(Material.WOODEN_AXE);
-
- private Location pos1;
-
- private Location pos2;
-
- protected Selection(Player wizard) {
- this.wizard = wizard;
- }
-
- public static boolean contains(Player p) {
- return cache.stream().anyMatch(s -> s.getPlayer().equals(p));
- }
-
- public static Selection source(Player p) {
- for (Selection r : cache) {
- if (r.getPlayer().equals(p)) {
- return r;
- }
- }
- Selection r = new Selection(p);
- cache.add(r);
- return r;
- }
-
- public Player getPlayer() {
- return wizard;
- }
-
- public ItemStack getWand() {
- return wand;
- }
-
- public void setWand(ItemStack wand) {
- this.wand = wand;
- }
-
- public Location getPos1() {
- return pos1;
- }
-
- public Location getPos2() {
- return pos2;
- }
-
- public Location getHighest() {
- return getPos1().getBlockY() > getPos2().getBlockY() ? getPos1() : getPos2();
- }
-
- public Location getLowest() {
- return getPos2().getBlockY() < getPos1().getBlockY() ? getPos2() : getPos1();
- }
-
- public Location expand(BlockFace direction) {
- Location update;
- switch (direction) {
- case UP:
- update = getHighest().getBlock().getRelative(BlockFace.UP).getLocation();
- setPos1(update);
- return update;
- case DOWN:
- update = getHighest().getBlock().getRelative(BlockFace.DOWN).getLocation();
- setPos2(update);
- return update;
- case EAST:
- update = getHighest().getBlock().getRelative(BlockFace.EAST).getLocation();
- setPos1(update);
- return update;
- case WEST:
- update = getHighest().getBlock().getRelative(BlockFace.WEST).getLocation();
- setPos2(update);
- return update;
- case NORTH:
- update = getHighest().getBlock().getRelative(BlockFace.NORTH).getLocation();
- setPos1(update);
- return update;
- case SOUTH:
- update = getHighest().getBlock().getRelative(BlockFace.SOUTH).getLocation();
- setPos2(update);
- return update;
- default:
- throw new IllegalStateException();
- }
- }
-
- public Location expand(BlockFace direction, int distance) {
- Location update;
- switch (direction) {
- case UP:
- update = getHighest().getBlock().getRelative(BlockFace.UP, distance).getLocation();
- setPos1(update);
- return update;
- case DOWN:
- update = getHighest().getBlock().getRelative(BlockFace.DOWN, distance).getLocation();
- setPos2(update);
- return update;
- case EAST:
- update = getHighest().getBlock().getRelative(BlockFace.EAST, distance).getLocation();
- setPos1(update);
- return update;
- case WEST:
- update = getHighest().getBlock().getRelative(BlockFace.WEST, distance).getLocation();
- setPos2(update);
- return update;
- case NORTH:
- update = getHighest().getBlock().getRelative(BlockFace.NORTH, distance).getLocation();
- setPos1(update);
- return update;
- case SOUTH:
- update = getHighest().getBlock().getRelative(BlockFace.SOUTH, distance).getLocation();
- setPos2(update);
- return update;
- default:
- throw new IllegalStateException();
- }
- }
-
- public void setPos1(Location pos1) {
- this.pos1 = pos1;
- }
-
- public void setPos2(Location pos2) {
- this.pos2 = pos2;
- }
-
- public Cuboid toCuboid() {
- return fromPoints(getPos1(), getPos2());
- }
-
+ return function.apply(SimpleKeyedValue.of(this, SimpleKeyedValue.of(new Location(getLocation().getWorld(), getAxis().getxMin(), getAxis().getyMin(), getAxis().getzMin()), new Location(getLocation().getWorld(), getAxis().getxMax(), getAxis().getyMax(), getAxis().getzMax()))));
}
abstract class Flag implements Listener {
@@ -312,7 +63,7 @@ public Flag(String id) {
}
public Flag clone() {
- return new RegionFlag(this);
+ return new DefaultFlag(this);
}
public final void setEnabled(boolean allowed) {
@@ -337,79 +88,7 @@ public String getId() {
}
- class FlagManager {
-
- private final Plugin plugin = LabyrinthProvider.getInstance().getPluginInstance();
- private final Set CACHE = new HashSet<>();
- private final RegionServicesManager regionServices;
-
- @SuppressWarnings("OptionalGetWithoutIsPresent") // TODO: Refactor to avoid unchecked #get/safely operate on Optionals
- public FlagManager(RegionServicesManager manager) {
- this.regionServices = manager;
- Flag BREAK = RegionFlag.Builder
- .initialize()
- .label("break")
- .finish();
-
- Flag BUILD = RegionFlag.Builder
- .initialize()
- .label("build")
- .finish();
-
- Flag PVP = RegionFlag.Builder
- .initialize()
- .label("pvp")
- .finish();
-
- register(PVP);
- register(BREAK);
- register(BUILD);
-
- }
-
- public Optional getFlag(String id) {
- return CACHE.stream().filter(f -> f.getId().equals(id)).findFirst();
- }
-
- public Set getFlags() {
- return Collections.unmodifiableSet(CACHE);
- }
-
- public boolean isRegistered(Cuboid.Flag flag) {
- return CACHE.stream().anyMatch(f -> f.getId().equals(flag.getId()));
- }
-
- public boolean unregister(Cuboid.Flag flag) {
- for (Region r : regionServices.getAll()) {
- r.getFlags().forEach(f -> {
- if (f.getId().equals(flag.getId())) {
- TaskScheduler.of(() -> r.removeFlag(f)).schedule();
- }
- });
- }
- return CACHE.removeIf(f -> f.getId().equals(flag.getId()));
- }
-
- public boolean register(Cuboid.Flag flag) {
- if (!getFlag(flag.getId()).isPresent()) {
- regionServices.getAll().forEach(region -> region.addFlag(flag));
- return CACHE.add(flag);
- }
- return false;
- }
-
- public boolean registerControlling(Cuboid.Flag flag) {
- if (!getFlag(flag.getId()).isPresent()) {
- VentMap.getInstance().subscribe((Vent.Host) plugin, flag);
- regionServices.getAll().forEach(region -> region.addFlag(flag));
- return CACHE.add(flag);
- }
- return false;
- }
-
- }
-
- class Boundary {
+ class VisualBoundary {
private final double xMax;
private final double xMin;
@@ -420,7 +99,7 @@ class Boundary {
private Player p;
- public Boundary(double xMax, double xMin, double yMax, double yMin, double zMax, double zMin) {
+ public VisualBoundary(double xMax, double xMin, double yMax, double yMin, double zMax, double zMin) {
this.xMax = xMax;
this.zMax = zMax;
this.yMax = yMax;
@@ -429,7 +108,7 @@ public Boundary(double xMax, double xMin, double yMax, double yMin, double zMax,
this.yMin = yMin;
}
- public Boundary target(Player target) {
+ public VisualBoundary setViewer(Player target) {
this.p = target;
return this;
}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/Region.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Region.java
similarity index 61%
rename from labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/Region.java
rename to labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Region.java
index 61d3a4c5..0a79f33a 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/Region.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/data/container/Region.java
@@ -1,16 +1,20 @@
-package com.github.sanctum.labyrinth.data;
+package com.github.sanctum.labyrinth.data.container;
import com.github.sanctum.labyrinth.LabyrinthProvider;
+import com.github.sanctum.labyrinth.data.CuboidAxis;
+import com.github.sanctum.labyrinth.data.CuboidLocation;
+import com.github.sanctum.labyrinth.data.RegionServicesManager;
import com.github.sanctum.labyrinth.formatting.UniformedComponents;
import com.github.sanctum.labyrinth.interfacing.Catchable;
import com.github.sanctum.labyrinth.interfacing.Snapshot;
-import com.github.sanctum.labyrinth.library.Cuboid;
+import com.github.sanctum.panther.container.ImmutablePantherCollection;
+import com.github.sanctum.panther.container.PantherCollection;
+import com.github.sanctum.panther.container.PantherList;
import com.github.sanctum.panther.util.HUID;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@@ -25,60 +29,67 @@
public abstract class Region implements Cuboid, Snapshot, Catchable {
private Region parent;
- private final int xMin;
- private final int xMax;
- private final int yMin;
- private final int yMax;
- private final int zMin;
- private final int zMax;
- private final int totalSize;
private final double distanceBetweenPoints;
- private final World world;
private final Location point1;
private final Location point2;
+ private final CuboidAxis axis;
+ private final CuboidLocation location;
private final HUID id;
- private final int height;
- private final int xWidth;
- private final int zWidth;
private UUID owner;
private String name;
- private boolean passthrough;
+ private boolean dominant;
private final Plugin plugin;
protected final List FLAGS;
private final List MEMBERS;
- private final List list;
+ private final PantherList list;
+
+ protected Region(Cuboid cuboid) {
+ if (cuboid instanceof Region) {
+ this.parent = ((Region) cuboid);
+ this.axis = ((Region) cuboid).axis;
+ this.id = ((Region) cuboid).id;
+ this.FLAGS = ((Region) cuboid).FLAGS;
+ this.MEMBERS = ((Region) cuboid).MEMBERS;
+ this.plugin = ((Region) cuboid).plugin;
+ this.list = ((Region) cuboid).list;
+ this.owner = ((Region) cuboid).owner;
+ this.name = ((Region) cuboid).name;
+ this.dominant = ((Region) cuboid).dominant;
+ this.point1 = ((Region) cuboid).point1;
+ this.point2 = ((Region) cuboid).point2;
+ this.distanceBetweenPoints = ((Region) cuboid).distanceBetweenPoints;
+ this.location = ((Region) cuboid).location;
+ } else {
+ this.axis = cuboid.getAxis();
+ this.location = cuboid.getLocation();
+ this.id = HUID.randomID();
+ this.FLAGS = new ArrayList<>();
+ this.MEMBERS = new ArrayList<>();
+ this.plugin = LabyrinthProvider.getInstance().getPluginInstance();
+ this.list = new PantherList<>(axis.getTotalSize());
+ for (int x = axis.getxMin(); x <= axis.getxMax(); x++) {
+ for (int y = axis.getyMin(); y <= axis.getyMax(); y++) {
+ for (int z = axis.getzMin(); z <= axis.getzMax(); z++) {
+ Block b = location.getWorld().getBlockAt(x, y, z);
+ list.add(b);
+ }
+ }
+ }
+ this.point1 = new Location(location.getWorld(), axis.getxMin(), axis.getyMin(), axis.getzMin());
+ this.point2 = new Location(location.getWorld(), axis.getxMax(), axis.getyMax(), axis.getzMax());
+ this.distanceBetweenPoints = this.getStartingPoint().distance(this.getEndingPoint());
+ for (Flag registered : RegionServicesManager.getInstance().getFlagManager().getFlags()) {
+ addFlag(registered);
+ }
+ }
+
+ }
protected Region(Region cuboid, Region parent) {
this(cuboid);
this.parent = parent;
}
- protected Region(Region cuboid) {
- this.parent = cuboid.parent;
- this.xMin = cuboid.xMin;
- this.xMax = cuboid.xMax;
- this.yMin = cuboid.yMin;
- this.yMax = cuboid.yMax;
- this.zMin = cuboid.zMin;
- this.zMax = cuboid.zMax;
- this.height = this.yMax - this.yMin + 1;
- this.xWidth = this.xMax - this.xMin + 1;
- this.zWidth = this.zMax - this.zMin + 1;
- this.totalSize = this.getHeight() * this.getXWidth() * this.getZWidth();
- this.world = cuboid.world;
- this.id = cuboid.id;
- this.FLAGS = cuboid.FLAGS;
- this.MEMBERS = cuboid.MEMBERS;
- this.plugin = cuboid.plugin;
- this.list = cuboid.list;
- this.owner = cuboid.owner;
- this.name = cuboid.name;
- this.passthrough = cuboid.passthrough;
- this.point1 = new Location(this.world, this.xMin, this.yMin, this.zMin);
- this.point2 = new Location(this.world, this.xMax, this.yMax, this.zMax);
- this.distanceBetweenPoints = this.getStartingPoint().distance(this.getEndingPoint());
- }
-
protected Region(final Location point1, final Location point2) {
this(point1, point2, HUID.randomID());
}
@@ -100,32 +111,23 @@ protected Region(World world, int xMin, int xMax, int yMin, int yMax, int zMin,
}
protected Region(World world, int xMin, int xMax, int yMin, int yMax, int zMin, int zMax, Plugin plugin, HUID id) {
- this.xMin = xMin;
- this.xMax = xMax;
- this.yMin = yMin;
- this.yMax = yMax;
- this.zMin = zMin;
- this.zMax = zMax;
- this.height = this.yMax - this.yMin + 1;
- this.xWidth = this.xMax - this.xMin + 1;
- this.zWidth = this.zMax - this.zMin + 1;
- this.totalSize = this.getHeight() * this.getXWidth() * this.getZWidth();
- this.world = world;
+ this.axis = new CuboidAxis(xMax, xMin, yMax, yMin, zMax, zMin);
+ this.location = new CuboidLocation(axis, world);
this.id = id;
this.FLAGS = new ArrayList<>();
this.MEMBERS = new ArrayList<>();
this.plugin = plugin;
- this.list = new ArrayList<>(this.getTotalBlocks());
- for (int x = this.xMin; x <= this.xMax; x++) {
- for (int y = this.yMin; y <= this.yMax; y++) {
- for (int z = this.zMin; z <= this.zMax; z++) {
- Block b = this.world.getBlockAt(x, y, z);
+ this.list = new PantherList<>(axis.getTotalSize());
+ for (int x = axis.getxMin(); x <= axis.getxMax(); x++) {
+ for (int y = axis.getyMin(); y <= axis.getyMax(); y++) {
+ for (int z = axis.getzMin(); z <= axis.getzMax(); z++) {
+ Block b = location.getWorld().getBlockAt(x, y, z);
list.add(b);
}
}
}
- this.point1 = new Location(this.world, this.xMin, this.yMin, this.zMin);
- this.point2 = new Location(this.world, this.xMax, this.yMax, this.zMax);
+ this.point1 = new Location(location.getWorld(), axis.getxMin(), axis.getyMin(), axis.getzMin());
+ this.point2 = new Location(location.getWorld(), axis.getxMax(), axis.getyMax(), axis.getzMax());
this.distanceBetweenPoints = this.getStartingPoint().distance(this.getEndingPoint());
for (Flag registered : RegionServicesManager.getInstance().getFlagManager().getFlags()) {
addFlag(registered);
@@ -172,22 +174,20 @@ public HUID getId() {
return this.id;
}
- public List getBlocks() {
- return Collections.unmodifiableList(list);
+ public PantherCollection getBlocks() {
+ return ImmutablePantherCollection.of(list);
}
public List getLaced() {
- return CompletableFuture.supplyAsync(() -> {
- List list = new ArrayList<>();
- RegionServicesManager.getInstance().getAll().forEach(c -> {
- for (Block b : this.list) {
- if (c.contains(b.getLocation()) && !c.getId().equals(getId())) {
- list.add(c);
- }
+ List list = new ArrayList<>();
+ RegionServicesManager.getInstance().getAll().forEach(c -> {
+ for (Block b : this.list) {
+ if (c.contains(b.getLocation()) && !c.getId().equals(getId())) {
+ list.add(c);
}
- });
- return list;
- }).join();
+ }
+ });
+ return list;
}
public Location getHighpoint() {
@@ -198,10 +198,6 @@ public Location getLowpoint() {
return getEndingPoint().getBlockY() < getStartingPoint().getBlockY() ? getEndingPoint() : getStartingPoint();
}
- public Location getCenter() {
- return new Location(this.world, (double) (this.xMax - this.xMin) / 2 + this.xMin, (double) (this.yMax - this.yMin) / 2 + this.yMin, (double) (this.zMax - this.zMin) / 2 + this.zMin);
- }
-
public double getDistanceBetweenPoints() {
return this.distanceBetweenPoints;
}
@@ -214,14 +210,6 @@ public Location getEndingPoint() {
return point2;
}
- public Location getRandomWithin() {
- Random r = new Random();
- int x = r.nextInt(Math.abs(this.xMax - this.xMin) + 1) + this.xMin;
- int y = r.nextInt(Math.abs(this.yMax - this.yMin) + 1) + this.yMin;
- int z = r.nextInt(Math.abs(this.zMax - this.zMin) + 1) + this.zMin;
- return new Location(this.world, x, y, z);
- }
-
public void setName(String name) {
this.name = name;
}
@@ -231,63 +219,23 @@ public String getName() {
}
@Override
- public Boundary getBoundary(Player target) {
- return new Boundary(xMax + 0.5, xMin + 0.5, yMax + 0.5, yMin + 0.5, zMax + 0.5, zMin + 0.5).target(target);
+ public VisualBoundary getBoundary(Player target) {
+ return new VisualBoundary(this.axis.getxMax() + 0.5, this.axis.getxMin() + 0.5, this.axis.getyMax() + 0.5, this.axis.getyMin() + 0.5, this.axis.getzMax() + 0.5, this.axis.getzMin() + 0.5).setViewer(target);
}
@Override
- public World getWorld() {
- return this.world;
+ public CuboidAxis getAxis() {
+ return this.axis;
}
@Override
- public int getHeight() {
- return height;
+ public CuboidLocation getLocation() {
+ return this.location;
}
@Override
public int getTotalBlocks() {
- return totalSize;
- }
-
- @Override
- public int getXWidth() {
- return xWidth;
- }
-
- @Override
- public int getZWidth() {
- return zWidth;
- }
-
- @Override
- public int xMax() {
- return xMax;
- }
-
- @Override
- public int xMin() {
- return xMin;
- }
-
- @Override
- public int yMax() {
- return yMax;
- }
-
- @Override
- public int yMin() {
- return yMin;
- }
-
- @Override
- public int zMax() {
- return zMax;
- }
-
- @Override
- public int zMin() {
- return zMin;
+ return this.axis.getTotalSize();
}
public OfflinePlayer getOwner() {
@@ -329,12 +277,12 @@ public boolean addFlag(Flag flag) {
return false;
}
- public boolean isPassthrough() {
- return passthrough;
+ public boolean isDominant() {
+ return this.dominant;
}
- public void setPassthrough(boolean passthrough) {
- this.passthrough = passthrough;
+ public void setDominant(boolean dominant) {
+ this.dominant = dominant;
}
public boolean addFlag(Flag... flag) {
@@ -387,18 +335,31 @@ public boolean removeMember(OfflinePlayer... p) {
return true;
}
- public boolean contains(final Location loc) {
- return loc.getWorld() == this.world && loc.getBlockX() >= this.xMin && loc.getBlockX() <= this.xMax && loc.getBlockY() >= this.yMin && loc.getBlockY() <= this.yMax && loc
- .getBlockZ() >= this.zMin && loc.getBlockZ() <= this.zMax;
+ public boolean contains(Block block) {
+ return block.getWorld() == this.location.getWorld() && block.getX() >= this.axis.getxMin() && block.getX() <= this.axis.getxMax() && block.getY() >= this.axis.getyMin() && block.getY() <= this.axis.getyMax() && block
+ .getZ() >= this.axis.getzMin() && block.getZ() <= this.axis.getzMax();
}
- public boolean contains(final Player player) {
+ public boolean contains(Location loc) {
+ return loc.getWorld() == this.location.getWorld() && loc.getBlockX() >= this.axis.getxMin() && loc.getBlockX() <= this.axis.getxMax() && loc.getBlockY() >= this.axis.getyMin() && loc.getBlockY() <= this.axis.getyMax() && loc
+ .getBlockZ() >= this.axis.getzMin() && loc.getBlockZ() <= this.axis.getzMax();
+ }
+
+ public boolean contains(Player player) {
return this.contains(player.getLocation());
}
- public boolean contains(final Location loc, double precision) {
- return loc.getWorld() == this.world && loc.getX() >= (xMin() + 0.5) - precision && loc.getX() <= (xMax() + 0.5) + precision && loc.getY() >= (yMin() + 0.5) - precision && loc
- .getY() <= (yMax() + 0.5) + precision && loc.getZ() >= (zMin() + 0.5) - precision && loc.getZ() <= (zMax() + 0.5) + precision;
+ public boolean contains(Block b, double precision) {
+ return contains(b.getLocation(), precision);
+ }
+
+ public boolean contains(Player p, double precision) {
+ return contains(p.getLocation(), precision);
+ }
+
+ public boolean contains(Location loc, double precision) {
+ return loc.getWorld() == this.location.getWorld() && loc.getX() >= (axis.getxMin() + 0.5) - precision && loc.getX() <= (axis.getxMax() + 0.5) + precision && loc.getY() >= (axis.getyMin() + 0.5) - precision && loc
+ .getY() <= (axis.getyMax() + 0.5) + precision && loc.getZ() >= (axis.getzMin() + 0.5) - precision && loc.getZ() <= (axis.getzMax() + 0.5) + precision;
}
public final boolean remove() {
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/CuboidSelectEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/CuboidSelectEvent.java
index f889e410..01ac294a 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/CuboidSelectEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/CuboidSelectEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.library.Cuboid;
+import com.github.sanctum.labyrinth.data.CuboidSelection;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
@@ -9,9 +9,9 @@
public abstract class CuboidSelectEvent extends DefaultEvent.Player {
- private final Cuboid.Selection selection;
+ private final CuboidSelection selection;
- public CuboidSelectEvent(Cuboid.Selection selection) {
+ public CuboidSelectEvent(CuboidSelection selection) {
super(selection.getPlayer(), false);
this.selection = selection;
}
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionBuildEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionBuildEvent.java
index 0ae2be78..975b1c2f 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionBuildEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionBuildEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
import org.bukkit.block.Block;
public class RegionBuildEvent extends RegionInteractEvent {
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionDestroyEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionDestroyEvent.java
index 12087bac..ec179266 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionDestroyEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionDestroyEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
import org.bukkit.block.Block;
public class RegionDestroyEvent extends RegionInteractEvent {
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractEvent.java
index b93a15ac..01d8245c 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
public abstract class RegionInteractEvent extends DefaultEvent.Player {
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractionEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractionEvent.java
index ebaa33e1..3da06194 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractionEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionInteractionEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
import org.bukkit.block.Block;
public class RegionInteractionEvent extends RegionInteractEvent {
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionPVPEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionPVPEvent.java
index 16811c2f..61fb73c8 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionPVPEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionPVPEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
diff --git a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionTraverseEvent.java b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionTraverseEvent.java
index 06c0158c..29e7ca2e 100644
--- a/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionTraverseEvent.java
+++ b/labyrinth-regions/src/main/java/com/github/sanctum/labyrinth/event/RegionTraverseEvent.java
@@ -1,6 +1,6 @@
package com.github.sanctum.labyrinth.event;
-import com.github.sanctum.labyrinth.data.Region;
+import com.github.sanctum.labyrinth.data.container.Region;
public class RegionTraverseEvent extends DefaultEvent {
diff --git a/labyrinth-skulls/pom.xml b/labyrinth-skulls/pom.xml
index 75eec371..ea745c4e 100644
--- a/labyrinth-skulls/pom.xml
+++ b/labyrinth-skulls/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.1
+ 1.9.2
4.0.0
diff --git a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHead.java b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHead.java
index 1e94897f..e4ec6a16 100644
--- a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHead.java
+++ b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHead.java
@@ -120,17 +120,17 @@ static List loadOffline() {
if (players.length >= 500) {
Counter count = Counter.newInstance();
CollectionTask cache = CollectionTask.process(players, "USER-CACHE", 20, player -> {
- OnlineHeadSearch search = new OnlineHeadSearch(player.getUniqueId());
+ HeadLookup search = new HeadLookup(player.getUniqueId());
if (search.getResult() != null) {
if (player.getName() != null) {
- list.add(new LabyrinthHeadImpl(player.getName(), "Human", search.getResult(), player.getUniqueId()));
+ list.add(new DefaultHead(player.getName(), "Human", search.getResult(), player.getUniqueId()));
}
} else {
count.add();
- OnlineHeadSearch search2 = new OnlineHeadSearch(player.getName());
+ HeadLookup search2 = new HeadLookup(player.getName());
if (search2.getResult() != null) {
if (player.getName() != null) {
- list.add(new LabyrinthHeadImpl(player.getName(), "Deceased", search2.getResult()));
+ list.add(new DefaultHead(player.getName(), "Deceased", search2.getResult()));
}
}
}
@@ -152,17 +152,17 @@ static List loadOffline() {
TaskScheduler.of(() -> {
int count = 0;
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
- OnlineHeadSearch search = new OnlineHeadSearch(player.getUniqueId());
+ HeadLookup search = new HeadLookup(player.getUniqueId());
if (search.getResult() != null) {
if (player.getName() != null) {
- list.add(new LabyrinthHeadImpl(player.getName(), "Human", search.getResult(), player.getUniqueId()));
+ list.add(new DefaultHead(player.getName(), "Human", search.getResult(), player.getUniqueId()));
}
} else {
count++;
- OnlineHeadSearch search2 = new OnlineHeadSearch(player.getName());
+ HeadLookup search2 = new HeadLookup(player.getName());
if (search2.getResult() != null) {
if (player.getName() != null) {
- list.add(new LabyrinthHeadImpl(player.getName(), "Deceased", search2.getResult()));
+ list.add(new DefaultHead(player.getName(), "Deceased", search2.getResult()));
}
}
}
@@ -184,11 +184,11 @@ static List loadOffline() {
*/
public static void load(CustomHeadLoader loader) {
if (loader.isLoaded()) {
- for (Map.Entry entry : loader.getHeads().entrySet()) {
+ for (Map.Entry entry : loader.getHeads().entrySet()) {
load(entry.getKey().getName(), entry.getKey().getCategory(), entry.getValue());
}
} else {
- for (Map.Entry entry : loader.load().getHeads().entrySet()) {
+ for (Map.Entry entry : loader.load().getHeads().entrySet()) {
load(entry.getKey().getName(), entry.getKey().getCategory(), entry.getValue());
}
}
@@ -205,9 +205,9 @@ public static void load(CustomHeadLoader loader) {
public static @Nullable ItemStack get(OfflinePlayer player) {
return HEADS.stream().filter(h -> h.id().isPresent() && h.id().get().equals(player.getUniqueId())).map(CustomHead::get).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(player.getUniqueId());
+ HeadLookup search = new HeadLookup(player.getUniqueId());
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(player.getName(), "Human", search.getResult(), player.getUniqueId());
+ CustomHead head = new DefaultHead(player.getName(), "Human", search.getResult(), player.getUniqueId());
HEADS.add(head);
return head.get();
}
@@ -226,9 +226,9 @@ public static void load(CustomHeadLoader loader) {
public static @Nullable ItemStack get(UUID id) {
return HEADS.stream().filter(h -> h.id().isPresent() && h.id().get().equals(id)).map(CustomHead::get).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(id);
+ HeadLookup search = new HeadLookup(id);
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(Bukkit.getOfflinePlayer(id).getName(), "Human", search.getResult(), id);
+ CustomHead head = new DefaultHead(Bukkit.getOfflinePlayer(id).getName(), "Human", search.getResult(), id);
HEADS.add(head);
return head.get();
}
@@ -248,9 +248,9 @@ public static void load(CustomHeadLoader loader) {
return HEADS.stream().filter(h -> h.name().equals(name)).map(CustomHead::get).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(name);
+ HeadLookup search = new HeadLookup(name);
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(name, "Human", search.getResult());
+ CustomHead head = new DefaultHead(name, "Human", search.getResult());
HEADS.add(head);
return head.get();
}
@@ -269,9 +269,9 @@ public static void load(CustomHeadLoader loader) {
public static @Nullable CustomHead pick(String name) {
return HEADS.stream().filter(h -> h.name().equals(name)).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(name);
+ HeadLookup search = new HeadLookup(name);
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(name, "Human", search.getResult());
+ CustomHead head = new DefaultHead(name, "Human", search.getResult());
HEADS.add(head);
return head;
}
@@ -290,9 +290,9 @@ public static void load(CustomHeadLoader loader) {
public static @Nullable CustomHead pick(UUID id) {
return HEADS.stream().filter(h -> h.id().isPresent() && h.id().get().equals(id)).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(id);
+ HeadLookup search = new HeadLookup(id);
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(Bukkit.getOfflinePlayer(id).getName(), "Human", search.getResult(), id);
+ CustomHead head = new DefaultHead(Bukkit.getOfflinePlayer(id).getName(), "Human", search.getResult(), id);
HEADS.add(head);
return head;
}
@@ -311,9 +311,9 @@ public static void load(CustomHeadLoader loader) {
public static @Nullable CustomHead pick(OfflinePlayer player) {
return HEADS.stream().filter(h -> h.id().isPresent() && h.id().get().equals(player.getUniqueId())).findFirst().orElseGet(() -> {
- OnlineHeadSearch search = new OnlineHeadSearch(player.getUniqueId());
+ HeadLookup search = new HeadLookup(player.getUniqueId());
if (search.getResult() != null) {
- CustomHead head = new LabyrinthHeadImpl(player.getName(), "Human", search.getResult(), player.getUniqueId());
+ CustomHead head = new DefaultHead(player.getName(), "Human", search.getResult(), player.getUniqueId());
HEADS.add(head);
return head;
}
@@ -392,7 +392,7 @@ protected static void load(String name, String category, ItemStack item) {
if (item.getType() != type)
throw new IllegalStateException(item.getType().name() + " is not a direct representation of " + type.name());
- load(new LabyrinthHeadImpl(name, category, item));
+ load(new DefaultHead(name, category, item));
}
/**
diff --git a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHeadLoader.java b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHeadLoader.java
index 45afa11c..541d4025 100644
--- a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHeadLoader.java
+++ b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/CustomHeadLoader.java
@@ -24,18 +24,18 @@ public final class CustomHeadLoader {
private final MemorySpace memory;
private boolean loaded;
- private final Map que;
- private final Map additions;
+ private final Map queue;
+ private final Map additions;
- protected CustomHeadLoader(MemorySpace memory) {
+ public CustomHeadLoader(MemorySpace memory) {
this.memory = memory;
- this.que = new HashMap<>();
+ this.queue = new HashMap<>();
this.additions = new HashMap<>();
}
- protected CustomHeadLoader(Plugin plugin, String fileName, String directory) {
+ public CustomHeadLoader(Plugin plugin, String fileName, String directory) {
this.memory = FileList.search(plugin).get(fileName, directory).getRoot();
- this.que = new HashMap<>();
+ this.queue = new HashMap<>();
this.additions = new HashMap<>();
}
@@ -64,7 +64,7 @@ public CustomHeadLoader look(String section) {
}
if (value != null) {
- additions.put(new HeadText(name, category), provide(value));
+ additions.put(new HeadContext(name, category), provide(value));
} else {
LabyrinthProvider.getInstance().getLogger().severe("- Custom head #" + id + " has no value to use.");
}
@@ -77,9 +77,9 @@ public CustomHeadLoader look(String section) {
boolean isID = user != null && user.contains("-");
if (isID) {
- que.put(new HeadText(name, category), new OnlineHeadSearch(UUID.fromString(user)));
+ queue.put(new HeadContext(name, category), new HeadLookup(UUID.fromString(user)));
} else {
- que.put(new HeadText(name, category), new OnlineHeadSearch(user));
+ queue.put(new HeadContext(name, category), new HeadLookup(user));
}
}
}
@@ -92,7 +92,7 @@ public CustomHeadLoader look(String section) {
*/
public CustomHeadLoader load() {
this.loaded = true;
- for (Map.Entry entry : this.que.entrySet()) {
+ for (Map.Entry entry : this.queue.entrySet()) {
ItemStack result = entry.getValue().getResult();
if (result != null) {
this.additions.put(entry.getKey(), result);
@@ -114,7 +114,7 @@ public void complete() {
}
}
- Map getHeads() {
+ Map getHeads() {
return this.additions;
}
diff --git a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/LabyrinthHeadImpl.java b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/DefaultHead.java
similarity index 71%
rename from labyrinth-skulls/src/main/java/com/github/sanctum/skulls/LabyrinthHeadImpl.java
rename to labyrinth-skulls/src/main/java/com/github/sanctum/skulls/DefaultHead.java
index 42bc09fe..561390f4 100644
--- a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/LabyrinthHeadImpl.java
+++ b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/DefaultHead.java
@@ -5,7 +5,7 @@
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("SameParameterValue")
-final class LabyrinthHeadImpl extends CustomHead {
+final class DefaultHead extends CustomHead {
private final String name;
@@ -13,13 +13,13 @@ final class LabyrinthHeadImpl extends CustomHead {
private final ItemStack item;
- LabyrinthHeadImpl(@NotNull String name, @NotNull String category, @NotNull ItemStack item) {
+ DefaultHead(@NotNull String name, @NotNull String category, @NotNull ItemStack item) {
this.name = name;
this.category = category;
this.item = item;
}
- LabyrinthHeadImpl(@NotNull String name,@NotNull String category, @NotNull ItemStack item, @NotNull UUID owner) {
+ DefaultHead(@NotNull String name, @NotNull String category, @NotNull ItemStack item, @NotNull UUID owner) {
super(owner);
this.category = category;
this.name = name;
diff --git a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadText.java b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadContext.java
similarity index 78%
rename from labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadText.java
rename to labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadContext.java
index d0c058a3..3dfad6de 100644
--- a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadText.java
+++ b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadContext.java
@@ -1,12 +1,12 @@
package com.github.sanctum.skulls;
-final class HeadText {
+final class HeadContext {
private final String name;
private final String category;
- HeadText(String name, String category) {
+ HeadContext(String name, String category) {
this.name = name;
this.category = category;
}
diff --git a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/OnlineHeadSearch.java b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadLookup.java
similarity index 97%
rename from labyrinth-skulls/src/main/java/com/github/sanctum/skulls/OnlineHeadSearch.java
rename to labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadLookup.java
index aae37220..f37b7430 100644
--- a/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/OnlineHeadSearch.java
+++ b/labyrinth-skulls/src/main/java/com/github/sanctum/skulls/HeadLookup.java
@@ -15,14 +15,14 @@
/**
* Encapsulate player data and search online for skin results.
*/
-public class OnlineHeadSearch {
+public class HeadLookup {
protected String name = null;
protected String id = null;
protected String value = null;
// TODO: throw to prevent invalid object state and allow field finality
- public OnlineHeadSearch(String name) {
+ public HeadLookup(String name) {
this.name = name;
try {
Gson g = new Gson();
@@ -42,7 +42,7 @@ public OnlineHeadSearch(String name) {
}
// TODO: throw to prevent invalid object state and allow field finality
- public OnlineHeadSearch(UUID id) {
+ public HeadLookup(UUID id) {
try {
Gson g = new Gson();
String signature = getSessionContent(id.toString());
diff --git a/pom.xml b/pom.xml
index d6847a5f..09e4c5ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.the-h-team
labyrinth
- 1.9.1
+ 1.9.2
labyrinth-common
labyrinth-gui