forked from SteamWar/SteamWar
Fix SelectAdjacent but make it a touch slower
This commit is contained in:
+23
-10
@@ -29,7 +29,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -37,6 +36,7 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -47,13 +47,26 @@ import java.util.Set;
|
|||||||
@MinVersion(20)
|
@MinVersion(20)
|
||||||
public class SelectAdjacent implements Listener {
|
public class SelectAdjacent implements Listener {
|
||||||
|
|
||||||
private BlockFace[] FACES = {
|
private Vector[] FACES = {
|
||||||
BlockFace.NORTH,
|
new Vector(1, 0, 0),
|
||||||
BlockFace.EAST,
|
new Vector(-1, 0, 0),
|
||||||
BlockFace.SOUTH,
|
new Vector(0, 1, 0),
|
||||||
BlockFace.WEST,
|
new Vector(0, -1, 0),
|
||||||
BlockFace.UP,
|
new Vector(0, 0, 1),
|
||||||
BlockFace.DOWN
|
new Vector(0, 0, -1),
|
||||||
|
|
||||||
|
new Vector(1, 1, 0),
|
||||||
|
new Vector(1, -1, 0),
|
||||||
|
new Vector(1, 0, 1),
|
||||||
|
new Vector(1, 0, -1),
|
||||||
|
new Vector(-1, 1, 0),
|
||||||
|
new Vector(-1, -1, 0),
|
||||||
|
new Vector(-1, 0, 1),
|
||||||
|
new Vector(-1, 0, -1),
|
||||||
|
new Vector(0, 1, 1),
|
||||||
|
new Vector(0, 1, -1),
|
||||||
|
new Vector(0, -1, 1),
|
||||||
|
new Vector(0, -1, -1),
|
||||||
};
|
};
|
||||||
|
|
||||||
private Map<Player, Selector> selectors = new HashMap<>();
|
private Map<Player, Selector> selectors = new HashMap<>();
|
||||||
@@ -144,8 +157,8 @@ public class SelectAdjacent implements Listener {
|
|||||||
minZ = Math.min(minZ, location.getBlockZ());
|
minZ = Math.min(minZ, location.getBlockZ());
|
||||||
maxZ = Math.max(maxZ, location.getBlockZ());
|
maxZ = Math.max(maxZ, location.getBlockZ());
|
||||||
|
|
||||||
for (BlockFace face : FACES) {
|
for (Vector face : FACES) {
|
||||||
Block next = block.getRelative(face);
|
Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ());
|
||||||
if (next.isEmpty() || next.isLiquid()) continue;
|
if (next.isEmpty() || next.isLiquid()) continue;
|
||||||
Location loc = next.getLocation();
|
Location loc = next.getLocation();
|
||||||
if (seen.contains(loc)) continue;
|
if (seen.contains(loc)) continue;
|
||||||
|
|||||||
@@ -38,18 +38,32 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SelectAdjacent implements Listener {
|
public class SelectAdjacent implements Listener {
|
||||||
|
|
||||||
private BlockFace[] FACES = {
|
private Vector[] FACES = {
|
||||||
BlockFace.NORTH,
|
new Vector(1, 0, 0),
|
||||||
BlockFace.EAST,
|
new Vector(-1, 0, 0),
|
||||||
BlockFace.SOUTH,
|
new Vector(0, 1, 0),
|
||||||
BlockFace.WEST,
|
new Vector(0, -1, 0),
|
||||||
BlockFace.UP,
|
new Vector(0, 0, 1),
|
||||||
BlockFace.DOWN
|
new Vector(0, 0, -1),
|
||||||
|
|
||||||
|
new Vector(1, 1, 0),
|
||||||
|
new Vector(1, -1, 0),
|
||||||
|
new Vector(1, 0, 1),
|
||||||
|
new Vector(1, 0, -1),
|
||||||
|
new Vector(-1, 1, 0),
|
||||||
|
new Vector(-1, -1, 0),
|
||||||
|
new Vector(-1, 0, 1),
|
||||||
|
new Vector(-1, 0, -1),
|
||||||
|
new Vector(0, 1, 1),
|
||||||
|
new Vector(0, 1, -1),
|
||||||
|
new Vector(0, -1, 1),
|
||||||
|
new Vector(0, -1, -1),
|
||||||
};
|
};
|
||||||
|
|
||||||
private Map<Player, Selector> selectors = new HashMap<>();
|
private Map<Player, Selector> selectors = new HashMap<>();
|
||||||
@@ -140,8 +154,8 @@ public class SelectAdjacent implements Listener {
|
|||||||
minZ = Math.min(minZ, location.getBlockZ());
|
minZ = Math.min(minZ, location.getBlockZ());
|
||||||
maxZ = Math.max(maxZ, location.getBlockZ());
|
maxZ = Math.max(maxZ, location.getBlockZ());
|
||||||
|
|
||||||
for (BlockFace face : FACES) {
|
for (Vector face : FACES) {
|
||||||
Block next = block.getRelative(face);
|
Block next = block.getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ());
|
||||||
if (next.isEmpty() || next.isLiquid()) continue;
|
if (next.isEmpty() || next.isLiquid()) continue;
|
||||||
Location loc = next.getLocation();
|
Location loc = next.getLocation();
|
||||||
if (seen.contains(loc)) continue;
|
if (seen.contains(loc)) continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user