diff --git a/FoxCore b/FoxCore index 80356a4..fa2c35b 160000 --- a/FoxCore +++ b/FoxCore @@ -1 +1 @@ -Subproject commit 80356a4d2f12843a60319f889c843c3eb7a0dbd7 +Subproject commit fa2c35bb47d31163437901e93cc7aa8e4356f9bd diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FGManager.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FGManager.java index ac1e924..e46fa3a 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FGManager.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/FGManager.java @@ -46,6 +46,7 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.util.GuavaCollectors; import org.spongepowered.api.util.Tristate; +import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.util.*; @@ -92,6 +93,17 @@ public static FGManager getInstance() { return instance; } + public static boolean isNameValid(String name) { + if (name.matches("^.*[ :.=;\"\'\\\\/{}()\\[\\]<>#@|?*].*$")) return false; + for (String s : FGStorageManager.FS_ILLEGAL_NAMES) { + if (name.equalsIgnoreCase(s)) return false; + } + for (String s : ILLEGAL_NAMES) { + if (name.equalsIgnoreCase(s)) return false; + } + return true; + } + public boolean isRegistered(IHandler handler) { return handlers.contains(handler); } @@ -236,24 +248,30 @@ public Set getRegionsAtPos(World world, Vector3d position, boolean incl .collect(Collectors.toSet()); } - public Set getRegionsAtMultiPosI(World world, Iterable positions) { - return getRegionsAtMultiPosI(world, positions, false); + public Set getRegionsAtMultiLocI(Iterable> locations) { + return getRegionsAtMultiLocI(locations, false); } - public Set getRegionsAtMultiPosI(World world, Iterable positions, boolean includeDisabled) { + public Set getRegionsAtMultiLocI(Iterable> locations, boolean includeDisabled) { Set set = new HashSet<>(); - SetMultimap chunkPosMap = HashMultimap.create(); - for (Vector3i pos : positions) { + SetMultimap chunkPosMap = HashMultimap.create(); + for (Location loc : locations) { + Vector3i pos = loc.getBlockPosition(); chunkPosMap.put( - new Vector3i( - pos.getX() >> 4, - pos.getY() >> 4, - pos.getZ() >> 4 - ), pos + new Chunk( + new Vector3i( + pos.getX() >> 4, + pos.getY() >> 4, + pos.getZ() >> 4 + ), + loc.getExtent() + ), + loc.getBlockPosition() ); } - for (Map.Entry> entry : chunkPosMap.asMap().entrySet()) { - RegionCache.ChunkData data = this.regionCache.getData(world, entry.getKey()); + for (Map.Entry> entry : chunkPosMap.asMap().entrySet()) { + Chunk chunk = entry.getKey(); + RegionCache.ChunkData data = this.regionCache.getData(chunk.world, chunk.chunk); Set candidates = new HashSet<>(data.getRegions(includeDisabled)); candidates.removeAll(set); for (Vector3i pos : entry.getValue()) { @@ -261,7 +279,7 @@ public Set getRegionsAtMultiPosI(World world, Iterable positi Iterator regionIterator = candidates.iterator(); do { IRegion region = regionIterator.next(); - if (region.contains(pos, world)) { + if (region.contains(pos, chunk.world)) { set.add(region); regionIterator.remove(); } @@ -272,24 +290,30 @@ public Set getRegionsAtMultiPosI(World world, Iterable positi return set; } - public Set getRegionsAtMultiPosD(World world, Iterable positions) { - return getRegionsAtMultiPosD(world, positions, false); + public Set getRegionsAtMultiLocD(Iterable> locations) { + return getRegionsAtMultiLocD(locations, false); } - public Set getRegionsAtMultiPosD(World world, Iterable positions, boolean includeDisabled) { + public Set getRegionsAtMultiLocD(Iterable> locations, boolean includeDisabled) { Set set = new HashSet<>(); - SetMultimap chunkPosMap = HashMultimap.create(); - for (Vector3d pos : positions) { + SetMultimap chunkPosMap = HashMultimap.create(); + for (Location loc : locations) { + Vector3i pos = loc.getBlockPosition(); chunkPosMap.put( - new Vector3i( - GenericMath.floor(pos.getX()) >> 4, - GenericMath.floor(pos.getY()) >> 4, - GenericMath.floor(pos.getZ()) >> 4) - , pos + new Chunk( + new Vector3i( + pos.getX() >> 4, + pos.getY() >> 4, + pos.getZ() >> 4 + ), + loc.getExtent() + ), + loc.getPosition() ); } - for (Map.Entry> entry : chunkPosMap.asMap().entrySet()) { - RegionCache.ChunkData data = this.regionCache.getData(world, entry.getKey()); + for (Map.Entry> entry : chunkPosMap.asMap().entrySet()) { + Chunk chunk = entry.getKey(); + RegionCache.ChunkData data = this.regionCache.getData(chunk.world, chunk.chunk); Set candidates = new HashSet<>(data.getRegions(includeDisabled)); candidates.removeAll(set); for (Vector3d pos : entry.getValue()) { @@ -297,7 +321,7 @@ public Set getRegionsAtMultiPosD(World world, Iterable positi Iterator regionIterator = candidates.iterator(); do { IRegion region = regionIterator.next(); - if (region.contains(pos, world)) { + if (region.contains(pos, chunk.world)) { set.add(region); regionIterator.remove(); } @@ -477,17 +501,6 @@ public GlobalHandler getGlobalHandler() { return globalHandler; } - public static boolean isNameValid(String name) { - if (name.matches("^.*[ :.=;\"\'\\\\/{}()\\[\\]<>#@|?*].*$")) return false; - for (String s : FGStorageManager.FS_ILLEGAL_NAMES) { - if (name.equalsIgnoreCase(s)) return false; - } - for (String s : ILLEGAL_NAMES) { - if (name.equalsIgnoreCase(s)) return false; - } - return true; - } - public void markDirty(IRegion region, RegionCache.DirtyType type) { regionCache.markDirty(region, type); } @@ -495,4 +508,31 @@ public void markDirty(IRegion region, RegionCache.DirtyType type) { public void clearRegionCache() { this.regionCache.clearCaches(); } + + private static class Chunk { + Vector3i chunk; + World world; + + public Chunk(Vector3i chunk, World world) { + this.chunk = chunk; + this.world = world; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Chunk chunk1 = (Chunk) o; + + return chunk.equals(chunk1.chunk) && world.equals(chunk1.world); + } + + @Override + public int hashCode() { + int result = chunk.hashCode(); + result = 31 * result + world.hashCode(); + return result; + } + } } diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java index 5701dff..50ee921 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/BlockChangeListener.java @@ -43,6 +43,7 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.util.Tristate; +import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.util.*; @@ -94,22 +95,23 @@ public void handle(ChangeBlockEvent event) throws Exception { //FoxGuardMain.instance().getLogger().info(player.getName()); List handlerList; - World world = event.getTargetWorld(); List> transactions = event.getTransactions(); Set handlerSet = new HashSet<>(); if (transactions.size() == 1) { - Vector3i pos = transactions.get(0).getOriginal().getLocation().get().getBlockPosition(); + Location loc = transactions.get(0).getOriginal().getLocation().get(); + Vector3i pos = loc.getBlockPosition(); + World world = loc.getExtent(); + FGManager.getInstance().getRegionsInChunkAtPos(world, pos).stream() .filter(region -> region.contains(pos, world)) .forEach(region -> region.getHandlers().stream() .filter(IFGObject::isEnabled) .forEach(handlerSet::add)); } else { - FGManager.getInstance().getRegionsAtMultiPosI( - world, + FGManager.getInstance().getRegionsAtMultiLocI( transactions.stream() - .map(trans -> trans.getOriginal().getLocation().get().getBlockPosition()) + .map(trans -> trans.getOriginal().getLocation().get()) .collect(Collectors.toList()) ).forEach(region -> region.getHandlers().stream() .filter(IFGObject::isEnabled) diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/ExplosionListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/ExplosionListener.java index 0b3dcf4..d38a965 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/ExplosionListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/ExplosionListener.java @@ -81,7 +81,6 @@ public void handle(ExplosionEvent event) throws Exception { } else user = null; } - World world = event.getTargetWorld(); FlagBitSet flags = FLAG_SET.clone(); Set handlerSet = new HashSet<>(); @@ -91,10 +90,9 @@ public void handle(ExplosionEvent event) throws Exception { flags.set(CHANGE); ExplosionEvent.Post postEvent = (ExplosionEvent.Post) event; - FGManager.getInstance().getRegionsAtMultiPosI( - world, + FGManager.getInstance().getRegionsAtMultiLocI( postEvent.getTransactions().stream() - .map(trans -> trans.getOriginal().getLocation().get().getBlockPosition()) + .map(trans -> trans.getOriginal().getLocation().get()) .collect(Collectors.toList()) ).forEach(region -> region.getHandlers().stream() .filter(IFGObject::isEnabled) @@ -103,18 +101,15 @@ public void handle(ExplosionEvent event) throws Exception { flags.set(DETONATE); ExplosionEvent.Detonate detonateEvent = ((ExplosionEvent.Detonate) event); - FGManager.getInstance().getRegionsAtMultiPosI( - world, - detonateEvent.getAffectedLocations().stream() - .map(Location::getBlockPosition) - .collect(Collectors.toList()) - ).forEach(region -> region.getHandlers().stream() - .filter(IFGObject::isEnabled) - .forEach(handlerSet::add)); + FGManager.getInstance().getRegionsAtMultiLocI(detonateEvent.getAffectedLocations()) + .forEach(region -> region.getHandlers().stream() + .filter(IFGObject::isEnabled) + .forEach(handlerSet::add)); } else if (event instanceof ExplosionEvent.Pre) { flags.set(PRE); - - Vector3d pos = event.getExplosion().getLocation().getPosition(); + Location loc = event.getExplosion().getLocation(); + Vector3d pos = loc.getPosition(); + World world = loc.getExtent(); FGManager.getInstance().getRegionsInChunkAtPos(world, pos).stream() .filter(region -> region.contains(pos, world)) .forEach(region -> region.getHandlers().stream() diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java index 088e1e4..253c8a0 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/listener/SpawnEntityListener.java @@ -44,6 +44,7 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.util.Tristate; +import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.util.ArrayList; @@ -107,10 +108,11 @@ public void handle(SpawnEntityEvent event) throws Exception { } List handlerList = new ArrayList<>(); - World world = event.getTargetWorld(); for (Entity entity : event.getEntities()) { - Vector3d pos = entity.getLocation().getPosition(); + Location loc = entity.getLocation(); + Vector3d pos = loc.getPosition(); + World world = loc.getExtent(); FGManager.getInstance().getRegionsInChunkAtPos(world, pos).stream() .filter(region -> region.contains(pos, world)) .forEach(region -> region.getHandlers().stream() diff --git a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/region/world/IWorldRegion.java b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/region/world/IWorldRegion.java index e7013c6..e622df1 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/region/world/IWorldRegion.java +++ b/src/main/java/net/foxdenstudio/sponge/foxguard/plugin/region/world/IWorldRegion.java @@ -25,29 +25,14 @@ package net.foxdenstudio.sponge.foxguard.plugin.region.world; -import com.flowpowered.math.vector.Vector3i; import net.foxdenstudio.sponge.foxcore.plugin.util.IWorldBounded; import net.foxdenstudio.sponge.foxguard.plugin.region.IRegion; import org.spongepowered.api.world.World; public interface IWorldRegion extends IRegion, IWorldBounded { + @Override World getWorld(); void setWorld(World world); - - @Override - default boolean contains(int x, int y, int z, World world) { - return world == getWorld() && contains(x, y, z); - } - - @Override - default boolean contains(double x, double y, double z, World world) { - return world == getWorld() && contains(x, y, z); - } - - @Override - default boolean isInChunk(Vector3i chunk, World world) { - return world == getWorld() && isInChunk(chunk); - } }