From 74fe88ae011c430e3b9a65a768d31e101f959346 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 7 Aug 2019 01:28:12 +1000 Subject: [PATCH] merge --- build.gradle | 7 +- settings.gradle | 2 - worldedit-bukkit/build.gradle | 4 +- .../com/boydti/fawe/bukkit/BukkitPlayer.java | 27 +-- .../com/boydti/fawe/bukkit/FaweBukkit.java | 33 ++-- .../boydti/fawe/bukkit/beta/BukkitQueue.java | 31 ++-- .../fawe/bukkit/regions/ASkyBlockHook.java | 18 +- .../fawe/bukkit/regions/FactionsFeature.java | 16 +- .../bukkit/regions/FactionsOneFeature.java | 15 +- .../bukkit/regions/FactionsUUIDFeature.java | 9 +- .../fawe/bukkit/regions/FreeBuildRegion.java | 14 +- .../regions/GriefPreventionFeature.java | 20 +-- .../bukkit/regions/PreciousStonesFeature.java | 17 +- .../fawe/bukkit/regions/ResidenceFeature.java | 6 +- .../fawe/bukkit/regions/TownyFeature.java | 48 +++-- .../fawe/bukkit/regions/Worldguard.java | 34 ++-- .../fawe/bukkit/regions/WorldguardFlag.java | 24 +-- .../bukkit/BukkitBlockCommandSender.java | 168 ++++++++++++++++++ .../worldedit/bukkit/BukkitCommandSender.java | 18 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 11 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 6 + .../worldedit/bukkit/WorldEditPlugin.java | 2 + .../src/main/java/com/boydti/fawe/Fawe.java | 6 +- .../boydti/fawe/beta/ArrayFilterBlock.java | 40 +++-- .../com/boydti/fawe/beta/CharFilterBlock.java | 140 ++++++++------- .../boydti/fawe/beta/ChunkFilterBlock.java | 12 +- .../com/boydti/fawe/beta/ChunkFuture.java | 11 +- .../com/boydti/fawe/beta/DelegateFilter.java | 2 + .../boydti/fawe/beta/DelegateFilterBlock.java | 109 +++++++----- .../com/boydti/fawe/beta/DirectionMask.java | 1 + .../java/com/boydti/fawe/beta/Filter.java | 36 ++-- .../com/boydti/fawe/beta/FilterBlock.java | 36 ++-- .../com/boydti/fawe/beta/FilterBlockMask.java | 5 +- .../main/java/com/boydti/fawe/beta/Flood.java | 20 +-- .../java/com/boydti/fawe/beta/IBlocks.java | 3 +- .../java/com/boydti/fawe/beta/IChunk.java | 30 ++-- .../java/com/boydti/fawe/beta/IChunkGet.java | 3 +- .../java/com/boydti/fawe/beta/IChunkSet.java | 4 +- .../com/boydti/fawe/beta/IDelegateChunk.java | 30 ++-- .../com/boydti/fawe/beta/IDelegateFilter.java | 2 +- .../fawe/beta/IDelegateQueueExtent.java | 18 +- .../com/boydti/fawe/beta/IQueueExtent.java | 42 +++-- .../com/boydti/fawe/beta/NorthVector.java | 19 +- .../boydti/fawe/beta/SimpleFilterBlock.java | 1 + .../boydti/fawe/beta/SingleFilterBlock.java | 39 ++-- .../java/com/boydti/fawe/beta/Trimable.java | 9 +- .../fawe/beta/filters/ArrayImageMask.java | 5 +- .../boydti/fawe/beta/filters/CountFilter.java | 7 +- .../boydti/fawe/beta/filters/DistrFilter.java | 26 ++- .../fawe/beta/filters/ForkedFilter.java | 11 +- .../boydti/fawe/beta/filters/SetFilter.java | 5 +- .../beta/implementation/DelegateChunkSet.java | 7 +- .../beta/implementation/IQueueWrapper.java | 1 + .../implementation/MultiThreadedQueue.java | 90 +++++----- .../beta/implementation/QueueHandler.java | 45 ++--- .../implementation/SimpleCharQueueExtent.java | 2 +- .../worldedit/MissingWorldException.java | 27 +++ .../platform/AbstractNonPlayerActor.java | 51 ++++++ .../extension/platform/Locatable.java | 69 +++++++ 59 files changed, 938 insertions(+), 556 deletions(-) create mode 100644 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Locatable.java diff --git a/build.gradle b/build.gradle index f0b7a714d..a5f7a101c 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ allprojects { def buildNumber = "" def date = "" ext { - git = Grgit.open(dir: '.git') + git = Grgit.open(dir: new File(rootDir.toString()+'/.git')) date = git.head().getDate().format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; @@ -63,6 +63,7 @@ allprojects { version = String.format("%s.%s", rootVersion, buildNumber) } + description = rootProject.name subprojects { @@ -99,7 +100,7 @@ subprojects { } } -configure(['worldedit-core', 'worldedit-bukkit', 'favs'].collect { project("$it") }) { +configure(['worldedit-core', 'worldedit-bukkit'].collect { project("$it") }) { apply plugin: 'java' apply plugin: 'maven' // apply plugin: 'checkstyle' @@ -191,4 +192,4 @@ task aggregatedJavadocs(type: Javadoc, description: 'Generate javadocs from all includes += javadocTask.includes } } -} \ No newline at end of file +} diff --git a/settings.gradle b/settings.gradle index ca59bb4b2..b29efe82f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,5 +7,3 @@ include 'worldedit-libs' include "worldedit-$it" } include "worldedit-libs:core:ap" - -include 'favs' diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 4004e00f1..d825d7e30 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -23,10 +23,10 @@ dependencies { compileOnly 'com.sk89q:dummypermscompat:1.10' testCompile 'org.mockito:mockito-core:1.9.0-rc1' implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1'){transitive = false} - compileOnly 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT' + compileOnly 'com.destroystokyo.paper:paper-api:1.14.4-R0.1-SNAPSHOT' implementation('io.papermc:paperlib:1.0.2'){transitive = false} compileOnly 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT' - compileOnly 'BuildTools:lastSuccessfulBuild:spigot-1.14.3@jar' + compileOnly 'BuildTools:lastSuccessfulBuild:spigot-1.14.4@jar' implementation('com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39'){transitive = false} implementation('com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39'){transitive = false} implementation('com.massivecraft:factions:2.8.0'){transitive = false} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitPlayer.java index 7fe7f7a9e..2c811f70c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitPlayer.java @@ -1,16 +1,13 @@ package com.boydti.fawe.bukkit; -import com.boydti.fawe.Fawe; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FawePlayer; import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; -import java.util.UUID; - public class BukkitPlayer extends FawePlayer { private static ConsoleCommandSender console; @@ -39,26 +36,6 @@ public class BukkitPlayer extends FawePlayer { return parent.isSneaking(); } - @Override - public void setPermission(final String perm, final boolean flag) { - /* - * Permissions are used to managing WorldEdit region restrictions - * - The `/wea` command will give/remove the required bypass permission - */ - if (Fawe.imp().getVault() == null || Fawe.imp().getVault().permission == null) { - this.parent.addAttachment(Fawe.imp().getPlugin()).setPermission(perm, flag); - } else if (flag) { - if (!Fawe.imp().getVault().permission.playerAdd(this.parent, perm)) { - this.parent.addAttachment(Fawe.imp().getPlugin()).setPermission(perm, flag); - } - } else { - if (!Fawe.imp().getVault().permission.playerRemove(this.parent, perm)) { - this.parent.addAttachment(Fawe.imp().getPlugin()).setPermission(perm, flag); - } - } - } - - @Override public void resetTitle() { parent.resetTitle(); @@ -77,7 +54,7 @@ public class BukkitPlayer extends FawePlayer { @Override public void sendMessage(final String message) { - this.parent.sendMessage(BBC.color(message)); + this.parent.sendMessage(message); } @Override public void printError(String msg) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index e37f7b888..061f04902 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -3,11 +3,9 @@ package com.boydti.fawe.bukkit; import com.boydti.fawe.Fawe; import com.boydti.fawe.IFawe; import com.boydti.fawe.beta.implementation.QueueHandler; -import com.boydti.fawe.bukkit.beta.BukkitQueue; import com.boydti.fawe.bukkit.beta.BukkitQueueHandler; import com.boydti.fawe.bukkit.listener.BrushListener; import com.boydti.fawe.bukkit.listener.BukkitImageListener; -import com.boydti.fawe.bukkit.listener.CFIPacketListener; import com.boydti.fawe.bukkit.listener.RenderListener; import com.boydti.fawe.bukkit.regions.*; import com.boydti.fawe.bukkit.util.BukkitReflectionUtils; @@ -21,7 +19,6 @@ import com.boydti.fawe.bukkit.v0.ChunkListener_8; import com.boydti.fawe.bukkit.v0.ChunkListener_9; import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13; import com.boydti.fawe.bukkit.v1_14.BukkitQueue_1_14; -import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FawePlayer; @@ -32,10 +29,10 @@ import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.image.ImageViewer; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.World; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; -import org.bukkit.Chunk; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; @@ -43,11 +40,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileOutputStream; @@ -155,7 +150,7 @@ public class FaweBukkit implements IFawe, Listener { fos.write(jarData); } } - BukkitImageViewer viewer = new BukkitImageViewer((Player) fp.parent); + BukkitImageViewer viewer = new BukkitImageViewer(BukkitAdapter.adapt(fp.toWorldEditPlayer())); if (imageListener == null) { this.imageListener = new BukkitImageListener(plugin); } @@ -184,7 +179,7 @@ public class FaweBukkit implements IFawe, Listener { @Override public void debug(final String message) { ConsoleCommandSender console = Bukkit.getConsoleSender(); - console.sendMessage(BBC.color(message)); + console.sendMessage(message); } @Override @@ -398,19 +393,19 @@ public class FaweBukkit implements IFawe, Listener { final ArrayList managers = new ArrayList<>(); if (worldguardPlugin != null && worldguardPlugin.isEnabled()) { try { - managers.add(new Worldguard(worldguardPlugin, this)); - managers.add(new WorldguardFlag(worldguardPlugin, this)); + managers.add(new Worldguard(worldguardPlugin)); + managers.add(new WorldguardFlag(worldguardPlugin)); Fawe.debug("Plugin 'WorldGuard' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny"); if (townyPlugin != null && townyPlugin.isEnabled()) { try { - managers.add(new TownyFeature(townyPlugin, this)); + managers.add(new TownyFeature(townyPlugin)); Fawe.debug("Plugin 'Towny' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } @@ -419,7 +414,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new FactionsFeature(factionsPlugin)); Fawe.debug("Plugin 'Factions' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { try { managers.add(new FactionsUUIDFeature(factionsPlugin, this)); Fawe.debug("Plugin 'FactionsUUID' found. Using it now."); @@ -439,7 +434,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new ResidenceFeature(residencePlugin, this)); Fawe.debug("Plugin 'Residence' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } @@ -448,7 +443,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new GriefPreventionFeature(griefpreventionPlugin)); Fawe.debug("Plugin 'GriefPrevention' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } @@ -457,7 +452,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new PreciousStonesFeature(preciousStonesPlugin, this)); Fawe.debug("Plugin 'PreciousStones' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } @@ -468,7 +463,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new ASkyBlockHook(aSkyBlock)); Fawe.debug("Plugin 'ASkyBlock' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } @@ -476,7 +471,7 @@ public class FaweBukkit implements IFawe, Listener { try { managers.add(new FreeBuildRegion()); Fawe.debug("Plugin '' found. Using it now."); - } catch (final Throwable e) { + } catch (Throwable e) { e.printStackTrace(); } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java index e23c09c0f..a3530e1df 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java @@ -7,7 +7,7 @@ import com.boydti.fawe.beta.implementation.SimpleCharQueueExtent; import com.boydti.fawe.beta.implementation.WorldChunkCache; import com.boydti.fawe.bukkit.v1_14.adapter.BlockMaterial_1_14; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.jnbt.anvil.BitArray4096; +import com.boydti.fawe.object.collection.BitArray4096; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.bukkit.BukkitWorld; @@ -19,19 +19,15 @@ import net.jpountz.util.UnsafeUtils; import net.minecraft.server.v1_14_R1.Block; import net.minecraft.server.v1_14_R1.Chunk; import net.minecraft.server.v1_14_R1.ChunkCoordIntPair; -import net.minecraft.server.v1_14_R1.ChunkProviderServer; import net.minecraft.server.v1_14_R1.ChunkSection; -import net.minecraft.server.v1_14_R1.ChunkStatus; import net.minecraft.server.v1_14_R1.DataBits; import net.minecraft.server.v1_14_R1.DataPalette; import net.minecraft.server.v1_14_R1.DataPaletteBlock; import net.minecraft.server.v1_14_R1.DataPaletteLinear; import net.minecraft.server.v1_14_R1.GameProfileSerializer; import net.minecraft.server.v1_14_R1.IBlockData; -import net.minecraft.server.v1_14_R1.IChunkAccess; import net.minecraft.server.v1_14_R1.PlayerChunk; import net.minecraft.server.v1_14_R1.PlayerChunkMap; -import net.minecraft.server.v1_14_R1.ProtoChunkExtension; import net.minecraft.server.v1_14_R1.WorldServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; @@ -46,6 +42,10 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.locks.Lock; import java.util.function.Supplier; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull; public class BukkitQueue extends SimpleCharQueueExtent { @@ -53,6 +53,16 @@ public class BukkitQueue extends SimpleCharQueueExtent { private org.bukkit.World bukkitWorld; private WorldServer nmsWorld; + @Override + public void enableQueue() { + + } + + @Override + public void disableQueue() { + + } + @Override public synchronized void init(WorldChunkCache cache) { World world = cache.getWorld(); @@ -88,7 +98,7 @@ public class BukkitQueue extends SimpleCharQueueExtent { // }; @Override - public IChunk create(boolean full) { + public IChunk create(boolean isFull) { // if (full) { // //TODO implement // return FULL_CHUNKS.get(); @@ -234,10 +244,11 @@ public class BukkitQueue extends SimpleCharQueueExtent { return playerChunk; } - public boolean sendChunk(final int X, final int Z, final int mask) { + @Override + public void sendChunk(final int X, final int Z, final int mask) { PlayerChunk playerChunk = getPlayerChunk(X, Z); if (playerChunk == null) { - return false; + return; } // ChunkSection[] sections = nmsChunk.getSections(); // for (int layer = 0; layer < 16; layer++) { @@ -268,9 +279,9 @@ public class BukkitQueue extends SimpleCharQueueExtent { return null; } }); - return true; + return; } - return false; + return; } /* diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ASkyBlockHook.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ASkyBlockHook.java index 2c1a58fcd..664734cd9 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ASkyBlockHook.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ASkyBlockHook.java @@ -3,10 +3,11 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector3; import com.wasteofplastic.askyblock.ASkyBlockAPI; import com.wasteofplastic.askyblock.Island; import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; @@ -24,22 +25,21 @@ public class ASkyBlockHook extends BukkitMaskManager implements Listener { @Override public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Location location = player.getLocation(); Island island = ASkyBlockAPI.getInstance().getIslandAt(location); if (island != null && isAllowed(player, island, type)) { - World world = location.getWorld(); - Location center = island.getCenter(); - Location pos1 = new Location(world, island.getMinProtectedX(), 0, island.getMinProtectedZ()); - Location pos2 = center.add(center.subtract(pos1)); - pos2.setY(255); + Location center1 = island.getCenter(); + MutableBlockVector3 center = MutableBlockVector3.at(center1.getX(), center1.getY(), center1.getZ()); + BlockVector3 pos1 = BlockVector3.at(island.getMinProtectedX(), 0, island.getMinProtectedZ()); + MutableBlockVector3 pos2 = center.add(center.subtract(pos1)).mutY(255); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + return new FaweMask(pos1, pos2) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed((Player) player.parent, island, type); + return isAllowed(BukkitAdapter.adapt(player.toWorldEditPlayer()), island, type); } }; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java index 723a6a838..2b1fa2b62 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.ps.PS; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -21,7 +22,7 @@ public class FactionsFeature extends BukkitMaskManager implements Listener { @Override public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Location loc = player.getLocation(); final PS ps = PS.valueOf(loc); final Faction fac = BoardColl.get().getFactionAt(ps); @@ -30,16 +31,17 @@ public class FactionsFeature extends BukkitMaskManager implements Listener { MPlayer leader = fac.getLeader(); if (leader != null && fp.getUUID().equals(leader.getUuid())) { final Chunk chunk = loc.getChunk(); - final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); - final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); + final BlockVector3 pos1 = BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16); + final BlockVector3 pos2 = BlockVector3 + .at((chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); + return new FaweMask(pos1, pos2); } } else if (fac.getOnlinePlayers().contains(player)) { if (!fac.getComparisonName().equals("wilderness")) { final Chunk chunk = loc.getChunk(); - final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); - final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); + final BlockVector3 pos1 = BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16); + final BlockVector3 pos2 = BlockVector3.at((chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); + return new FaweMask(pos1, pos2); } } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java index e1ec86f25..656ebacf0 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java @@ -6,16 +6,15 @@ import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.util.Permission; import com.massivecraft.factions.FLocation; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import java.lang.reflect.Method; +import java.util.List; import org.bukkit.Chunk; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; -import java.lang.reflect.Method; -import java.util.List; - public class FactionsOneFeature extends BukkitMaskManager implements Listener { private final Method methodGetFactionAt; @@ -28,7 +27,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { @Override public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Chunk chunk = player.getLocation().getChunk(); final boolean perm = Permission .hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); @@ -75,9 +74,9 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { } } - final Location pos1 = new Location(world, locs.minX << 4, 1, locs.minZ << 4); - final Location pos2 = new Location(world, 15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); + final BlockVector3 pos1 = BlockVector3.at(locs.minX << 4, 1, locs.minZ << 4); + final BlockVector3 pos2 = BlockVector3.at(15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); + return new FaweMask(pos1, pos2); } return null; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java index c6f9e3bb2..cccb32804 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.Board; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -26,7 +27,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { @Override public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Chunk chunk = player.getLocation().getChunk(); final boolean perm = Permission .hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); @@ -73,9 +74,9 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { } } - final Location pos1 = new Location(world, locs.minX << 4, 1, locs.minZ << 4); - final Location pos2 = new Location(world, 15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); + final BlockVector3 pos1 = BlockVector3.at(locs.minX << 4, 1, locs.minZ << 4); + final BlockVector3 pos2 = BlockVector3.at(15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); + return new FaweMask(pos1,pos2); } return null; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java index 6e9b47a9d..3a4c1268d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java @@ -10,6 +10,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockTypes; +import jdk.nashorn.internal.ir.Block; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -20,6 +21,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.plugin.RegisteredListener; import java.util.ArrayList; +import org.bukkit.util.BlockVector; public class FreeBuildRegion extends BukkitMaskManager { private final ArrayList listeners; @@ -52,20 +54,20 @@ public class FreeBuildRegion extends BukkitMaskManager { if (currRegList.isEmpty()) return null; RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[0]); - World bukkitWorld = player.parent.getWorld(); + World bukkitWorld = BukkitAdapter.adapt(player.toWorldEditPlayer().getWorld()); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); - Location pos1 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); - Location pos2 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); + BlockVector3 pos1 = BlockVector3.ZERO; + BlockVector3 pos2 = BlockVector3.ZERO; AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0); - BlockBreakEvent event = new BlockBreakEvent(block, player.parent); + BlockBreakEvent event = new BlockBreakEvent(block, BukkitAdapter.adapt(player.toWorldEditPlayer())); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + return new FaweMask(pos1, pos2) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return bukkitWorld == ((FawePlayer)player).parent.getWorld() && type == MaskType.MEMBER; + return bukkitWorld == BukkitAdapter.adapt(player.toWorldEditPlayer().getWorld()) && type == MaskType.MEMBER; } @Override diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java index 6b987df14..15a22d1fe 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java @@ -5,10 +5,10 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.general.RegionFilter; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.GriefPrevention; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -21,24 +21,24 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene } public boolean isAllowed(Player player, Claim claim, MaskType type) { - return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(player.getUniqueId()) || (type == MaskType.MEMBER && (claim.allowBuild(player, Material.AIR) == null))); + return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(player.getUniqueId()) || + type == MaskType.MEMBER && claim.allowBuild(player, Material.AIR) == null); } @Override public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; - final Location location = player.getLocation(); - final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null); + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); + final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(BukkitAdapter.adapt(fp.getLocation()), true, null); if (claim != null) { if (isAllowed(player, claim, type)) { claim.getGreaterBoundaryCorner().getBlockX(); - final Location pos1 = new Location(location.getWorld(), claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ()); - final Location pos2 = new Location(location.getWorld(), claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ()); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + final BlockVector3 pos1 = BlockVector3.at(claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ()); + final BlockVector3 pos2 = BlockVector3.at(claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ()); + return new FaweMask(pos1, pos2) { @Override - public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed((Player) player.parent, claim, type); + public boolean isValid(FawePlayer fp, MaskType type) { + return isAllowed(player, claim, type); } }; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java index d67f9a919..a94b4a7f2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java @@ -3,6 +3,7 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import java.util.List; @@ -15,23 +16,19 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; public class PreciousStonesFeature extends BukkitMaskManager implements Listener { - FaweBukkit plugin; - Plugin preciousstones; - public PreciousStonesFeature(final Plugin preciousstonesPlugin, final FaweBukkit p3) { + public PreciousStonesFeature(Plugin preciousstonesPlugin, FaweBukkit p3) { super(preciousstonesPlugin.getName()); - this.preciousstones = preciousstonesPlugin; - this.plugin = p3; } public boolean isAllowed(Player player, Field field, MaskType type, boolean allowMember) { - return field != null && (field.isOwner(player.getName()) || (type == MaskType.MEMBER && allowMember && field.getAllAllowed().contains(player.getName()))); + return field != null && (field.isOwner(player.getName()) || type == MaskType.MEMBER && allowMember && field.getAllAllowed().contains(player.getName())); } @Override - public FaweMask getMask(final FawePlayer fp, MaskType type) { - final Player player = fp.parent; + public FaweMask getMask(FawePlayer fp, MaskType type) { + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Location location = player.getLocation(); final List fields = PreciousStones.API().getFieldsProtectingArea(FieldFlag.ALL, location); if (fields.isEmpty()) { @@ -39,14 +36,14 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener } String name = player.getName(); boolean member = fp.hasPermission("fawe.preciousstones.member"); - for (final Field myField : fields) { + for (Field myField : fields) { if (isAllowed(player, myField, type, member)) { BlockVector3 pos1 = BlockVector3.at(myField.getMinx(), myField.getMiny(), myField.getMinz()); BlockVector3 pos2 = BlockVector3.at(myField.getMaxx(), myField.getMaxy(), myField.getMaxz()); return new FaweMask(pos1, pos2) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed((Player) player.parent, myField, type, fp.hasPermission("fawe.preciousstones.member")); + return isAllowed((Player) BukkitAdapter.adapt(player.toWorldEditPlayer()), myField, type, fp.hasPermission("fawe.preciousstones.member")); } }; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java index 398be6d63..3217ab4e1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java @@ -29,7 +29,7 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener { @Override public FaweMask getMask(final FawePlayer fp, final MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Location location = player.getLocation(); ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(location); if (residence != null) { @@ -42,10 +42,10 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener { final Location pos1 = area.getLowLoc(); final Location pos2 = area.getHighLoc(); final ClaimedResidence finalResidence = residence; - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + return new FaweMask(BukkitAdapter.asBlockVector(pos1), BukkitAdapter.asBlockVector(pos2)) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed((Player) player.parent, finalResidence, type); + return isAllowed((Player) BukkitAdapter.adapt(player.toWorldEditPlayer()), finalResidence, type); } }; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java index 06a4476d1..f7cc9dc27 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/TownyFeature.java @@ -1,12 +1,17 @@ package com.boydti.fawe.bukkit.regions; -import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.*; +import com.palmergames.bukkit.towny.object.PlayerCache; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownBlock; +import com.palmergames.bukkit.towny.object.TownyUniverse; +import com.palmergames.bukkit.towny.object.WorldCoord; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -14,13 +19,12 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; public class TownyFeature extends BukkitMaskManager implements Listener { - FaweBukkit plugin; - Plugin towny; - public TownyFeature(final Plugin townyPlugin, final FaweBukkit p3) { + private Plugin towny; + + public TownyFeature(Plugin townyPlugin) { super(townyPlugin.getName()); this.towny = townyPlugin; - this.plugin = p3; } public boolean isAllowed(Player player, TownBlock block) { @@ -30,16 +34,19 @@ public class TownyFeature extends BukkitMaskManager implements Listener { Resident resident; try { resident = TownyUniverse.getDataSource().getResident(player.getName()); - try { - if (block.getResident().equals(resident)) { - return true; + try { + if (block.getResident().equals(resident)) { + return true; + } + } catch (NotRegisteredException ignore) { } - } catch (NotRegisteredException ignore) {} Town town = block.getTown(); if (town.isMayor(resident)) { return true; } - if (!town.hasResident(resident)) return false; + if (!town.hasResident(resident)) { + return false; + } if (player.hasPermission("fawe.towny.*")) { return true; } @@ -55,8 +62,8 @@ public class TownyFeature extends BukkitMaskManager implements Listener { } @Override - public FaweMask getMask(final FawePlayer fp) { - final Player player = fp.parent; + public FaweMask getMask(FawePlayer fp) { + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final Location location = player.getLocation(); try { final PlayerCache cache = ((Towny) this.towny).getCache(player); @@ -71,18 +78,23 @@ public class TownyFeature extends BukkitMaskManager implements Listener { boolean isMember = isAllowed(player, myplot); if (isMember) { final Chunk chunk = location.getChunk(); - final Location pos1 = new Location(location.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); - final Location pos2 = new Location(location.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + final BlockVector3 pos1 = BlockVector3 + .at(chunk.getX() * 16, 0, chunk.getZ() * 16); + final BlockVector3 pos2 = BlockVector3.at( + chunk.getX() * 16 + 15, 156, chunk.getZ() * 16 + + 15); + return new FaweMask(pos1, pos2) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed((Player) player.parent, myplot); + return isAllowed(BukkitAdapter.adapt(player.toWorldEditPlayer()), + myplot); } }; } } } - } catch (final Exception e) {} + } catch (Exception ignored) { + } return null; } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java index 887c47a01..f9125bc0e 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java @@ -1,6 +1,5 @@ package com.boydti.fawe.bukkit.regions; -import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.filter.WorldGuardFilter; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; @@ -30,7 +29,6 @@ import org.bukkit.plugin.Plugin; public class Worldguard extends BukkitMaskManager implements Listener { private WorldGuardPlugin worldguard; - FaweBukkit plugin; private WorldGuardPlugin getWorldGuard() { final Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard"); @@ -43,13 +41,12 @@ public class Worldguard extends BukkitMaskManager implements Listener { return (WorldGuardPlugin) plugin; } - public Worldguard(final Plugin p2, final FaweBukkit p3) { + public Worldguard(Plugin p2) { super(p2.getName()); this.worldguard = this.getWorldGuard(); - this.plugin = p3; } - public ProtectedRegion getRegion(final LocalPlayer player, final Location location) { + public ProtectedRegion getRegion(LocalPlayer player, Location location) { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); if (container == null) { System.out.println("Region capability is not enabled for WorldGuard."); @@ -65,7 +62,7 @@ public class Worldguard extends BukkitMaskManager implements Listener { return global; } final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())); - for (final ProtectedRegion region : regions) { + for (ProtectedRegion region : regions) { if (isAllowed(player, region)) { return region; } @@ -86,43 +83,42 @@ public class Worldguard extends BukkitMaskManager implements Listener { if (localplayer.hasPermission("fawe.worldguard.member")) { if (region.isMember(localplayer) || region.isMember(localplayer.getName())) { return true; - } else if (region.isMember("*")) { - return true; - } + } else + return region.isMember("*"); } return false; } @Override public FaweMask getMask(FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final LocalPlayer localplayer = this.worldguard.wrapPlayer(player); final Location location = player.getLocation(); final ProtectedRegion myregion = this.getRegion(localplayer, location); if (myregion != null) { - final Location pos1; - final Location pos2; + final BlockVector3 pos1; + final BlockVector3 pos2; if (myregion.getId().equals("__global__")) { - pos1 = new Location(location.getWorld(), Integer.MIN_VALUE, 0, Integer.MIN_VALUE); - pos2 = new Location(location.getWorld(), Integer.MAX_VALUE, 255, Integer.MAX_VALUE); + pos1 = BlockVector3.at(Integer.MIN_VALUE, 0, Integer.MIN_VALUE); + pos2 = BlockVector3.at(Integer.MAX_VALUE, 255, Integer.MAX_VALUE); } else { if (myregion instanceof ProtectedCuboidRegion) { - pos1 = new Location(location.getWorld(), myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ()); - pos2 = new Location(location.getWorld(), myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ()); + pos1 = BlockVector3.at(myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ()); + pos2 = BlockVector3.at(myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ()); } else { return new FaweMask(adapt(myregion)) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed(worldguard.wrapPlayer((Player) player.parent), myregion); + return isAllowed(worldguard.wrapPlayer(BukkitAdapter.adapt(player.toWorldEditPlayer())), myregion); } }; } } - return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { + return new FaweMask(pos1, pos2) { @Override public boolean isValid(FawePlayer player, MaskType type) { - return isAllowed(worldguard.wrapPlayer((Player) player.parent), myregion); + return isAllowed(worldguard.wrapPlayer(BukkitAdapter.adapt(player.toWorldEditPlayer())), myregion); } }; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java index 4e5d5e7ed..7992f769f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java @@ -1,10 +1,10 @@ package com.boydti.fawe.bukkit.regions; -import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.filter.WorldGuardFilter; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.general.RegionFilter; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldguard.LocalPlayer; @@ -12,29 +12,29 @@ import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.*; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; -import java.util.Map; - public class WorldguardFlag extends BukkitMaskManager implements Listener { - private WorldGuardPlugin worldguard; - private FaweBukkit plugin; - public WorldguardFlag(Plugin p2, FaweBukkit p3) { + private WorldGuardPlugin worldguard; + + public WorldguardFlag(Plugin p2) { super("worldguardflag"); this.worldguard = (WorldGuardPlugin) p2; // this.getWorldGuard(); - this.plugin = p3; } @Override public FaweMask getMask(FawePlayer fp, MaskType type) { - final Player player = fp.parent; + final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer()); final LocalPlayer localplayer = this.worldguard.wrapPlayer(player); - final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + final RegionContainer container = WorldGuard.getInstance().getPlatform() + .getRegionContainer(); final RegionManager manager = container.get(fp.getWorld()); return new FaweMask(new ManagerRegion(manager, localplayer)) { @@ -55,6 +55,7 @@ public class WorldguardFlag extends BukkitMaskManager implements Listener { * ManagerRegion wraps a RegionManager and will provide results based upon the regions enclosed */ private static class ManagerRegion extends AbstractRegion { + private final RegionManager manager; private final LocalPlayer localplayer; @@ -105,7 +106,8 @@ public class WorldguardFlag extends BukkitMaskManager implements Listener { @Override public boolean contains(BlockVector3 position) { // Make sure that all these flags are not denied. Denies override allows. WorldGuardExtraFlags can add Flags.WORLDEDIT - return manager.getApplicableRegions(position).testState(localplayer, Flags.BUILD, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK); + return manager.getApplicableRegions(position) + .testState(localplayer, Flags.BUILD, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java new file mode 100644 index 000000000..21053ba35 --- /dev/null +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -0,0 +1,168 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.bukkit; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; +import com.sk89q.worldedit.extension.platform.Locatable; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.auth.AuthorizationException; +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; +import org.bukkit.Material; +import org.bukkit.command.BlockCommandSender; + +import java.util.UUID; + +import javax.annotation.Nullable; + +public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements Locatable { + + private final BlockCommandSender sender; + private final WorldEditPlugin plugin; + private final Location location; + private final UUID uuid; + + public BukkitBlockCommandSender(WorldEditPlugin plugin, BlockCommandSender sender) { + checkNotNull(plugin); + checkNotNull(sender); + + this.plugin = plugin; + this.sender = sender; + this.location = BukkitAdapter.adapt(sender.getBlock().getLocation()); + this.uuid = new UUID(location.toVector().toBlockPoint().hashCode(), location.getExtent().hashCode()); + } + + @Override + public String getName() { + return sender.getName(); + } + + @Override + public void printRaw(String msg) { + for (String part : msg.split("\n")) { + sender.sendMessage(part); + } + } + + @Override + public void print(String msg) { + for (String part : msg.split("\n")) { + sender.sendMessage("\u00A7d" + part); + } + } + + @Override + public void printDebug(String msg) { + for (String part : msg.split("\n")) { + sender.sendMessage("\u00A77" + part); + } + } + + @Override + public void printError(String msg) { + for (String part : msg.split("\n")) { + sender.sendMessage("\u00A7c" + part); + } + } + + @Override + public void print(Component component) { + TextAdapter.sendComponent(sender, component); + } + + @Override + public Location getLocation() { + return this.location; + } + + @Override + public boolean setLocation(Location location) { + return false; + } + + @Override + public Extent getExtent() { + return this.location.getExtent(); + } + + @Override + public UUID getUniqueId() { + return uuid; + } + + @Override + public String[] getGroups() { + return new String[0]; + } + + @Override + public void checkPermission(String permission) throws AuthorizationException { + if (!hasPermission(permission)) { + throw new AuthorizationException(); + } + } + + @Override + public boolean hasPermission(String permission) { + return sender.hasPermission(permission); + } + + @Override + public boolean togglePermission(String permission) { + return true; + } + + @Override + public void setPermission(String permission, boolean value) { + + } + + @Override + public SessionKey getSessionKey() { + return new SessionKey() { + @Nullable + @Override + public String getName() { + return sender.getName(); + } + + @Override + public boolean isActive() { + return sender.getBlock().getType() == Material.COMMAND_BLOCK + || sender.getBlock().getType() == Material.CHAIN_COMMAND_BLOCK + || sender.getBlock().getType() == Material.REPEATING_COMMAND_BLOCK; + } + + @Override + public boolean isPersistent() { + return false; + } + + @Override + public UUID getUniqueId() { + return uuid; + } + }; + } +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java index 36f7d248d..455fdc47f 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java @@ -22,21 +22,19 @@ package com.sk89q.worldedit.bukkit; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; +import java.io.File; +import java.util.UUID; +import javax.annotation.Nullable; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.io.File; -import java.util.UUID; - -import javax.annotation.Nullable; - -public class BukkitCommandSender implements Actor { +public class BukkitCommandSender extends AbstractNonPlayerActor { /** * One time generated ID. @@ -149,17 +147,17 @@ public class BukkitCommandSender implements Actor { @Nullable @Override public String getName() { - return null; + return sender.getName(); } @Override public boolean isActive() { - return false; + return true; } @Override public boolean isPersistent() { - return false; + return true; } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 3dee53bf9..cfcf9f44f 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -255,14 +255,13 @@ public class BukkitPlayer extends AbstractPlayerActor { } @Override - public void floatAt(int x, int y, int z, boolean alwaysGlass) { - if (alwaysGlass || !player.getAllowFlight()) { - super.floatAt(x, y, z, alwaysGlass); - return; + public boolean isAllowedToFly() { + return player.getAllowFlight(); } - setPosition(Vector3.at(x + 0.5, y, z + 0.5)); - player.setFlying(true); + @Override + public void setFlying(boolean flying) { + player.setFlying(flying); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index b22974a4f..12f922f54 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -45,6 +45,7 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.annotation.Nullable; import org.bukkit.Effect; @@ -156,6 +157,11 @@ public class BukkitWorld extends AbstractWorld { return getWorld().getName(); } + @Override + public String getId() { + return getWorld().getName().replace(" ", "_").toLowerCase(Locale.ROOT); + } + @Override public Path getStoragePath() { return getWorld().getWorldFolder().toPath(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index dcc606800..eb2b96707 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -527,6 +527,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter public Actor wrapCommandSender(CommandSender sender) { if (sender instanceof Player) { return wrapPlayer((Player) sender); + } else if (sender instanceof BlockCommandSender) { + return new BukkitBlockCommandSender(this, (BlockCommandSender) sender); } return new BukkitCommandSender(this, sender); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java index b2a4dd8df..183b07c37 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/Fawe.java @@ -135,7 +135,7 @@ public class Fawe { if (INSTANCE != null) { INSTANCE.IMP.debug(s); } else { - System.out.println(BBC.stripColor(BBC.color(s))); + System.out.println(s); } } @@ -147,10 +147,10 @@ public class Fawe { public static void debug(Object s) { Actor actor = Request.request().getActor(); if (actor != null && actor.isPlayer()) { - actor.print(BBC.color(BBC.PREFIX.original() + " " + s)); + actor.print((String)s); return; } - debugPlain(BBC.PREFIX.original() + " " + s); + debugPlain((String) s); } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/ArrayFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/ArrayFilterBlock.java index 8e29eecd2..8e72068c7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/ArrayFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/ArrayFilterBlock.java @@ -5,18 +5,19 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; - import javax.annotation.Nullable; public class ArrayFilterBlock extends SimpleFilterBlock { + private final char[] blocks; private final byte[] heights; private final int yOffset; + private final int width, length; private int x, z, index; private char ordinal; - private final int width, length; - public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, int yOffset) { + public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, + int yOffset) { super(extent); this.blocks = blocks; this.width = width; @@ -34,43 +35,44 @@ public class ArrayFilterBlock extends SimpleFilterBlock { } } - @Override - public void setOrdinal(int ordinal) { - blocks[index] = (char) ordinal; - } - - @Override - public void setBlock(BlockState state) { - blocks[index] = state.getOrdinalChar(); - } - - @Override - public void setFullBlock(BaseBlock block) { - blocks[index] = block.getOrdinalChar(); - } - @Override public int getOrdinal() { return ordinal; } + @Override + public void setOrdinal(int ordinal) { + blocks[index] = (char) ordinal; + } + @Override public BlockState getBlock() { return BlockTypes.states[ordinal]; } + @Override + public void setBlock(BlockState state) { + blocks[index] = state.getOrdinalChar(); + } + @Override public BaseBlock getFullBlock() { return getBlock().toBaseBlock(); } + @Override + public void setFullBlock(BaseBlock block) { + blocks[index] = block.getOrdinalChar(); + } + @Override public CompoundTag getNbtData() { return null; } @Override - public void setNbtData(@Nullable CompoundTag nbtData) {} + public void setNbtData(@Nullable CompoundTag nbtData) { + } @Override public int getX() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/CharFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/CharFilterBlock.java index ea236d5a4..25a037169 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/CharFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/CharFilterBlock.java @@ -12,39 +12,54 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; import javax.annotation.Nullable; + public class CharFilterBlock extends ChunkFilterBlock { + + private static final SetDelegate FULL = new SetDelegate() { + @Override + public final void set(CharFilterBlock block, char value) { + block.setArr[block.index] = value; + } + }; + private static final SetDelegate NULL = new SetDelegate() { + @Override + public void set(CharFilterBlock block, char value) { + block.initSet().set(block, value); + } + }; private CharGetBlocks get; private IChunkSet set; - private char[] getArr; - private @Nullable char[] setArr; + private @Nullable + char[] setArr; private SetDelegate delegate; - // local - private int layer, index, x, y, z, xx, yy, zz, X, Z; + private int layer, index, x, y, z, xx, yy, zz, chunkX, chunkZ; public CharFilterBlock(IQueueExtent queueExtent) { super(queueExtent); } @Override - public final ChunkFilterBlock init(final int chunkX, final int chunkZ, final IChunkGet chunk) { + public final ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk) { this.get = (CharGetBlocks) chunk; - this.X = chunkX; - this.Z = chunkZ; + this.chunkX = chunkX; + this.chunkZ = chunkZ; this.xx = chunkX << 4; this.zz = chunkZ << 4; return this; } - public void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask) { + @Override + public void flood(IChunkGet iget, IChunkSet iset, int layer, Flood flood, + FilterBlockMask mask) { final int maxDepth = flood.getMaxDepth(); final boolean checkDepth = maxDepth < Character.MAX_VALUE; if (init(iget, iset, layer) != null) { while ((index = flood.poll()) != -1) { x = index & 15; - z = (index >> 4) & 15; - y = (index >> 8) & 15; + z = index >> 4 & 15; + y = index >> 8 & 15; if (mask.applyBlock(this)) { int depth = index >> 12; @@ -60,10 +75,13 @@ public class CharFilterBlock extends ChunkFilterBlock { } @Override - public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) { + public final ChunkFilterBlock init(IChunkGet iget, IChunkSet iset, + int layer) { this.layer = layer; final CharGetBlocks get = (CharGetBlocks) iget; - if (!get.hasSection(layer)) return null; + if (!get.hasSection(layer)) { + return null; + } this.set = iset; getArr = get.sections[layer].get(get, layer); if (set.hasSection(layer)) { @@ -82,13 +100,13 @@ public class CharFilterBlock extends ChunkFilterBlock { this.x = x; this.y = y; this.z = z; - this.index = x | (z << 4) | (y << 8); + this.index = x | z << 4 | y << 8; filter.applyBlock(this); } @Override public void filter(Filter filter, int yStart, int yEnd) { - for (y = yStart, index = (yStart << 8); y < yEnd; y++) { + for (y = yStart, index = yStart << 8; y < yEnd; y++) { for (z = 0; z < 16; z++) { for (x = 0; x < 16; x++, index++) { filter.applyBlock(this); @@ -99,8 +117,8 @@ public class CharFilterBlock extends ChunkFilterBlock { @Override public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { - int yis = (minY << 8); - int zis = (minZ << 4); + int yis = minY << 8; + int zis = minZ << 4; for (y = minY, index = yis; y <= maxY; y++) { for (z = minZ, index += zis; z <= maxZ; z++) { for (x = minX, index += minX; x <= maxX; x++, index++) { @@ -111,7 +129,7 @@ public class CharFilterBlock extends ChunkFilterBlock { } @Override - public final void filter(final Filter filter, final Region region) { + public final void filter(Filter filter, Region region) { for (y = 0, index = 0; y < 16; y++) { int absY = yy + y; for (z = 0; z < 16; z++) { @@ -127,7 +145,7 @@ public class CharFilterBlock extends ChunkFilterBlock { } @Override - public final void filter(final Filter filter) { + public final void filter(Filter filter) { for (y = 0, index = 0; y < 16; y++) { for (z = 0; z < 16; z++) { for (x = 0; x < 16; x++, index++) { @@ -142,25 +160,6 @@ public class CharFilterBlock extends ChunkFilterBlock { set.setBiome(x, y, z, biome); } - @Override - public void setOrdinal(final int ordinal) { - delegate.set(this, (char) ordinal); - } - - @Override - public void setBlock(final BlockState state) { - delegate.set(this, state.getOrdinalChar()); - } - - @Override - public void setFullBlock(final BaseBlock block) { - delegate.set(this, block.getOrdinalChar()); - final CompoundTag nbt = block.getNbtData(); - if (nbt != null) { // TODO optimize check via ImmutableBaseBlock - set.setTile(x, yy + y, z, nbt); - } - } - @Override public final int getX() { return xx + x; @@ -193,12 +192,12 @@ public class CharFilterBlock extends ChunkFilterBlock { @Override public final int getChunkX() { - return X; + return chunkX; } @Override public final int getChunkZ() { - return Z; + return chunkZ; } public final char getOrdinalChar() { @@ -210,12 +209,22 @@ public class CharFilterBlock extends ChunkFilterBlock { return getArr[index]; } + @Override + public void setOrdinal(int ordinal) { + delegate.set(this, (char) ordinal); + } + @Override public final BlockState getBlock() { final int ordinal = getArr[index]; return BlockTypes.states[ordinal]; } + @Override + public void setBlock(BlockState state) { + delegate.set(this, state.getOrdinalChar()); + } + @Override public final BaseBlock getFullBlock() { final BlockState state = getBlock(); @@ -227,10 +236,25 @@ public class CharFilterBlock extends ChunkFilterBlock { return state.toBaseBlock(); } + @Override + public void setFullBlock(BaseBlock block) { + delegate.set(this, block.getOrdinalChar()); + final CompoundTag nbt = block.getNbtData(); + if (nbt != null) { // TODO optimize check via ImmutableBaseBlock + set.setTile(x, yy + y, z, nbt); + } + } + @Override public final CompoundTag getNbtData() { return get.getTag(x, y + (layer << 4), z); } + /* + NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1), + EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2), + SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3), + WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0), + */ @Override public void setNbtData(CompoundTag tag) { @@ -245,19 +269,13 @@ public class CharFilterBlock extends ChunkFilterBlock { final BlockMaterial material = state.getMaterial(); return material.hasContainer(); } - /* - NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1), - EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2), - SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3), - WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0), - */ @Override public final BlockState getBlockNorth() { if (z > 0) { return states[getArr[index - 16]]; } - return getExtent().getBlock(getX(), getY(), getZ() - 1); + return getExtent().getBlock(getX(), getY(), getZ() - 1); } @Override @@ -265,7 +283,7 @@ public class CharFilterBlock extends ChunkFilterBlock { if (x < 15) { return states[getArr[index + 1]]; } - return getExtent().getBlock(getX() + 1, getY(), getZ()); + return getExtent().getBlock(getX() + 1, getY(), getZ()); } @Override @@ -273,7 +291,7 @@ public class CharFilterBlock extends ChunkFilterBlock { if (z < 15) { return states[getArr[index + 16]]; } - return getExtent().getBlock(getX(), getY(), getZ() + 1); + return getExtent().getBlock(getX(), getY(), getZ() + 1); } @Override @@ -281,7 +299,7 @@ public class CharFilterBlock extends ChunkFilterBlock { if (x > 0) { return states[getArr[index - 1]]; } - return getExtent().getBlock(getX() - 1, getY(), getZ()); + return getExtent().getBlock(getX() - 1, getY(), getZ()); } @Override @@ -311,7 +329,7 @@ public class CharFilterBlock extends ChunkFilterBlock { } @Override - public final BlockState getBlockRelativeY(final int y) { + public final BlockState getBlockRelativeY(int y) { final int newY = this.y + y; final int layerAdd = newY >> 4; switch (layerAdd) { @@ -353,14 +371,13 @@ public class CharFilterBlock extends ChunkFilterBlock { case -12: case -13: case -14: - case -15: { + case -15: final int newLayer = layer + layerAdd; if (newLayer >= 0) { final int index = this.index + ((y & 15) << 8); return states[get.sections[newLayer].get(get, newLayer, index)]; } break; - } } return BlockTypes.__RESERVED__.getDefaultState(); } @@ -383,7 +400,7 @@ public class CharFilterBlock extends ChunkFilterBlock { @Override public BiomeType getBiomeType(int x, int z) { - if ((x >> 4) == X && (z >> 4) == Z) { + if (x >> 4 == chunkX && z >> 4 == chunkZ) { return get.getBiomeType(x & 15, z & 15); } return getExtent().getBiomeType(x, z); @@ -391,27 +408,14 @@ public class CharFilterBlock extends ChunkFilterBlock { @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { - if ((x >> 4) == X && (z >> 4) == Z) { + if (x >> 4 == chunkX && z >> 4 == chunkZ) { return set.setBiome(x & 15, y, z & 15, biome); } return getExtent().setBiome(x, y, z, biome); } private interface SetDelegate { + void set(CharFilterBlock block, char value); } - - private static final SetDelegate NULL = new SetDelegate() { - @Override - public void set(final CharFilterBlock block, final char value) { - block.initSet().set(block, value); - } - }; - - private static final SetDelegate FULL = new SetDelegate() { - @Override - public final void set(final CharFilterBlock block, final char value) { - block.setArr[block.index] = value; - } - }; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFilterBlock.java index 2e0de38c4..d87a536f5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFilterBlock.java @@ -4,24 +4,28 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.regions.Region; public abstract class ChunkFilterBlock extends SimpleFilterBlock { + public ChunkFilterBlock(Extent extent) { super(extent); } public abstract ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk); - public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer); + public abstract ChunkFilterBlock init(IChunkGet iget, IChunkSet iset, + int layer); - public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask); + public abstract void flood(IChunkGet iget, IChunkSet iset, int layer, + Flood flood, FilterBlockMask mask); public abstract void filter(Filter filter, int x, int y, int z); - public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ); + public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, + int maxZ); public abstract void filter(Filter filter); public abstract void filter(Filter filter, int yStart, int yEnd); - public abstract void filter(final Filter filter, final Region region); + public abstract void filter(Filter filter, Region region); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFuture.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFuture.java index 264eb4509..38fecb9c9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFuture.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/ChunkFuture.java @@ -6,11 +6,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class ChunkFuture implements Future { + private final IChunk chunk; private volatile boolean cancelled; private volatile boolean done; - public ChunkFuture(final IChunk chunk) { + public ChunkFuture(IChunk chunk) { this.chunk = chunk; } @@ -19,10 +20,9 @@ public class ChunkFuture implements Future { } @Override - public boolean cancel(final boolean mayInterruptIfRunning) { + public boolean cancel(boolean mayInterruptIfRunning) { cancelled = true; - if (done) return false; - return true; + return !done; } @Override @@ -46,7 +46,8 @@ public class ChunkFuture implements Future { } @Override - public Void get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + public Void get(long timeout, TimeUnit unit) + throws InterruptedException, ExecutionException, TimeoutException { synchronized (chunk) { if (!done) { this.wait(unit.toMillis(timeout)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java index bbbe85f61..c71da676a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java @@ -1,11 +1,13 @@ package com.boydti.fawe.beta; public class DelegateFilter implements IDelegateFilter { + private final Filter parent; public DelegateFilter(T parent) { this.parent = parent; } + @Override public T getParent() { return (T) parent; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilterBlock.java index 01c34a309..8aa790db2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilterBlock.java @@ -24,43 +24,35 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; - -import javax.annotation.Nullable; import java.util.Comparator; import java.util.List; +import javax.annotation.Nullable; public class DelegateFilterBlock extends FilterBlock { + private final FilterBlock parent; public DelegateFilterBlock(FilterBlock parent) { this.parent = parent; } + public static BlockVector3 at(double x, double y, double z) { + return BlockVector3.at(x, y, z); + } + + public static BlockVector3 at(int x, int y, int z) { + return BlockVector3.at(x, y, z); + } + + public static Comparator sortByCoordsYzx() { + return BlockVector3.sortByCoordsYzx(); + } + @Override public Extent getExtent() { return parent.getExtent(); } - @Override - public void setOrdinal(int ordinal) { - parent.setOrdinal(ordinal); - } - - @Override - public void setBlock(BlockState state) { - parent.setBlock(state); - } - - @Override - public void setFullBlock(BaseBlock block) { - parent.setFullBlock(block); - } - - @Override - public void setNbtData(@Nullable CompoundTag nbtData) { - parent.setNbtData(nbtData); - } - @Override public boolean hasNbtData() { return parent.hasNbtData(); @@ -76,21 +68,41 @@ public class DelegateFilterBlock extends FilterBlock { return parent.getOrdinal(); } + @Override + public void setOrdinal(int ordinal) { + parent.setOrdinal(ordinal); + } + @Override public BlockState getBlock() { return parent.getBlock(); } + @Override + public void setBlock(BlockState state) { + parent.setBlock(state); + } + @Override public BaseBlock getFullBlock() { return parent.getFullBlock(); } + @Override + public void setFullBlock(BaseBlock block) { + parent.setFullBlock(block); + } + @Override public CompoundTag getNbtData() { return parent.getNbtData(); } + @Override + public void setNbtData(@Nullable CompoundTag nbtData) { + parent.setNbtData(nbtData); + } + @Override public BlockVector3 getMinimumPoint() { return parent.getMinimumPoint(); @@ -241,18 +253,6 @@ public class DelegateFilterBlock extends FilterBlock { return parent.getStateRelativeY(orDefault, y); } - public static BlockVector3 at(double x, double y, double z) { - return BlockVector3.at(x, y, z); - } - - public static BlockVector3 at(int x, int y, int z) { - return BlockVector3.at(x, y, z); - } - - public static Comparator sortByCoordsYzx() { - return BlockVector3.sortByCoordsYzx(); - } - @Override public MutableBlockVector3 setComponents(double x, double y, double z) { return parent.setComponents(x, y, z); @@ -479,7 +479,8 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, + double translateZ) { return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ); } @@ -560,7 +561,8 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) { + public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, + boolean ignoreAir) { return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir); } @@ -570,18 +572,23 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) { + public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, + int failedMax) { return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax); } @Override - public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) { - return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); + public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, + int failedMax, Mask mask) { + return parent + .getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); } @Override - public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) { - return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir); + public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, + int failedMax, boolean ignoreAir) { + return parent + .getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir); } @Override @@ -595,12 +602,14 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public void addSchems(Region region, Mask mask, List clipboards, int rarity, boolean rotate) throws WorldEditException { + public void addSchems(Region region, Mask mask, List clipboards, int rarity, + boolean rotate) throws WorldEditException { parent.addSchems(region, mask, clipboards, rarity, rotate); } @Override - public void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException { + public void spawnResource(Region region, Resource gen, int rarity, int frequency) + throws WorldEditException { parent.spawnResource(region, gen, rarity, frequency); } @@ -610,7 +619,8 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException { + public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, + int rarity, int minY, int maxY) throws WorldEditException { parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY); } @@ -650,6 +660,11 @@ public class DelegateFilterBlock extends FilterBlock { return parent.getBlock(position); } + @Override + public BlockType getBlockType(BlockVector3 position) { + return parent.getBlockType(position); + } + @Override public BaseBlock getFullBlock(BlockVector3 position) { return parent.getFullBlock(position); @@ -666,12 +681,14 @@ public class DelegateFilterBlock extends FilterBlock { } @Override - public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, T block) + throws WorldEditException { return parent.setBlock(position, block); } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return parent.setBlock(x, y, z, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/DirectionMask.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/DirectionMask.java index 4efce15ec..a6ff0e687 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/DirectionMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/DirectionMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.beta; public interface DirectionMask { + boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java index bb4da31f7..a459a751c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java @@ -2,31 +2,33 @@ package com.boydti.fawe.beta; import com.sk89q.worldedit.regions.Region; import javax.annotation.Nullable; +import org.jetbrains.annotations.Range; /** - * A filter is an interface used for setting blocks + * A filter is an interface used for setting blocks. */ -public interface Filter { +public interface Filter { + /** * Checks whether a chunk should be read. * - * @param chunkX - * @param chunkZ + * @param chunkX the x coordinate in the chunk + * @param chunkZ the z coordinate in the chunk * @return */ - default boolean appliesChunk(final int chunkX, final int chunkZ) { + default boolean appliesChunk(@Range(from = 0, to = 15) int chunkX, + @Range(from = 0, to = 15) int chunkZ) { return true; } /** - * Do something with the IChunk
- * - Return null if you don't want to filter blocks
- * - Return the chunk if you do want to filter blocks
+ * Do something with the IChunk
- Return null if you don't want to filter blocks
- + * Return the chunk if you do want to filter blocks
* * @param chunk * @return */ - default IChunk applyChunk(final IChunk chunk, @Nullable Region region) { + default IChunk applyChunk(IChunk chunk, @Nullable Region region) { return chunk; } @@ -35,27 +37,27 @@ public interface Filter { } /** - * Make changes to the block here
- * - e.g. block.setId(...)
- * - Note: Performance is critical here
+ * Make changes to the block here
- e.g. block.setId(...)
- Note: Performance is + * critical here
* * @param block */ - default void applyBlock(final FilterBlock block) { + default void applyBlock(FilterBlock block) { } /** - * Do something with the IChunk after block filtering
+ * Do something with the IChunk after block filtering. * * @param chunk * @return */ - default void finishChunk(final IChunk chunk) { + default void finishChunk(IChunk chunk) { } /** - * Fork this for use by another thread - * - Typically filters are simple and don't need to create another copy to be thread safe here + * Fork this for use by another thread - Typically filters are simple and don't need to create + * another copy to be thread safe here + * * @return this */ default Filter fork() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java index ed2a84be4..f0ed63fd2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java @@ -7,34 +7,35 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; - import javax.annotation.Nullable; -import static com.sk89q.worldedit.world.block.BlockTypes.states; - public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock { + public abstract Extent getExtent(); - public abstract void setOrdinal(int ordinal); - - public abstract void setBlock(BlockState state); - - public abstract void setFullBlock(BaseBlock block); - public void setBiome(BiomeType biome) { setBiome(getX(), getY(), getZ(), biome); } public abstract int getOrdinal(); + public abstract void setOrdinal(int ordinal); + public abstract BlockState getBlock(); + public abstract void setBlock(BlockState state); + public abstract BaseBlock getFullBlock(); + public abstract void setFullBlock(BaseBlock block); + + @Override public abstract CompoundTag getNbtData(); + @Override public abstract void setNbtData(@Nullable CompoundTag nbtData); + @Override public boolean hasNbtData() { return getNbtData() != null; } @@ -83,8 +84,8 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn return getBlock(getX() - 1, getY(), getZ()); } - public BlockState getBlockRelativeY(final int y) { - return getBlock(getX(), getY() + y , getZ()); + public BlockState getBlockRelativeY(int y) { + return getBlock(getX(), getY() + y, getZ()); } @Override @@ -119,51 +120,62 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn /* Extent */ + @Override public boolean setOrdinal(Extent orDefault, int ordinal) { setOrdinal(ordinal); return true; } + @Override public boolean setBlock(Extent orDefault, BlockState state) { setBlock(state); return true; } + @Override public boolean setFullBlock(Extent orDefault, BaseBlock block) { setFullBlock(block); return true; } + @Override public boolean setBiome(Extent orDefault, BiomeType biome) { setBiome(biome); return true; } + @Override public int getOrdinal(Extent orDefault) { return getOrdinal(); } + @Override public BlockState getBlock(Extent orDefault) { return getBlock(); } + @Override public BaseBlock getFullBlock(Extent orDefault) { return getFullBlock(); } + @Override public CompoundTag getNbtData(Extent orDefault) { return getNbtData(); } + @Override public BlockState getOrdinalBelow(Extent orDefault) { return getBlockBelow(); } + @Override public BlockState getStateAbove(Extent orDefault) { return getBlockAbove(); } - public BlockState getStateRelativeY(Extent orDefault, final int y) { + @Override + public BlockState getStateRelativeY(Extent orDefault, int y) { return getBlockRelativeY(y); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlockMask.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlockMask.java index e7728435c..7ad53d554 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlockMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlockMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.beta; public interface FilterBlockMask { - boolean applyBlock(final FilterBlock block); -} \ No newline at end of file + + boolean applyBlock(FilterBlock block); +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java index 377edfa34..961dfba08 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/Flood.java @@ -6,27 +6,23 @@ import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.World; import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; - import java.util.concurrent.ConcurrentLinkedQueue; public class Flood { + private final int maxBranch; private final int maxDepth; private final Direction[] directions; - + private final Long2ObjectLinkedOpenHashMap chunkVisits; + private final Long2ObjectLinkedOpenHashMap chunkQueues; private int[] queue; private long[] visit; - private int[][] queues; private long[][] visits; - private int chunkX; private int chunkYLayer; private int chunkZ; - private ConcurrentLinkedQueue queuePool = new ConcurrentLinkedQueue<>(); - private final Long2ObjectLinkedOpenHashMap chunkVisits; - private final Long2ObjectLinkedOpenHashMap chunkQueues; public Flood(int maxBranch, int maxDepth, Direction[] directions) { this.maxBranch = maxBranch; @@ -68,7 +64,7 @@ public class Flood { long pair = MathMan.pairInt(chunkX, chunkZ); int layer = y >> 4; int[] section = getOrCreateQueue(pair, layer); - int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12); + int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12); push(section, val); } @@ -171,12 +167,12 @@ public class Flood { } public void set(long[] bits, int i) { - bits[i >> 6] |= (1L << (i & 0x3F)); + bits[i >> 6] |= 1L << (i & 0x3F); } public final boolean getAndSet(long[] bits, int i) { int index = i >> 6; - long offset = (1L << (i & 0x3F)); + long offset = 1L << (i & 0x3F); long val = bits[index]; if ((val & offset) != 0) { return true; @@ -186,7 +182,7 @@ public class Flood { } } - public boolean get(long[] bits, final int i) { - return (bits[i >> 6] & (1L << (i & 0x3F))) != 0; + public boolean get(long[] bits, int i) { + return (bits[i >> 6] & 1L << (i & 0x3F)) != 0; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index a66d38157..7dafab979 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -4,7 +4,8 @@ package com.boydti.fawe.beta; * Shared interface for IGetBlocks and ISetBlocks */ public interface IBlocks extends Trimable { + boolean hasSection(int layer); IBlocks reset(); -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java index 2a643d6fe..0d6f4e211 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java @@ -12,12 +12,14 @@ import java.util.concurrent.Future; import javax.annotation.Nullable; /** - * Represents a chunk in the queue {@link IQueueExtent} - * Used for getting and setting blocks / biomes / entities + * Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes + * / entities */ public interface IChunk> extends Trimable, Callable, IChunkGet { + /** * Initialize at the location + * * @param extent * @param x * @param z @@ -31,7 +33,8 @@ public interface IChunk> extends Trimable, Callable, IChu int getZ(); /** - * If the chunk is a delegate, returns it's paren'ts root + * If the chunk is a delegate, returns it's parent's root + * * @return root IChunk */ default IChunk getRoot() { @@ -39,20 +42,25 @@ public interface IChunk> extends Trimable, Callable, IChu } /** + * Checks if there are any queued changes for this chunk. + * * @return true if no changes are queued for this chunk */ boolean isEmpty(); /** - * Apply the queued changes to the world
- * The future returned may return another future
- * To ensure completion keep calling {@link Future#get()} on each result + * Apply the queued changes to the world containing this chunk. + *

The future returned may return another future. To ensure completion keep calling {@link + * Future#get()} on each result.

+ * * @return Futures */ + @Override T call(); /** * Call and join + * * @throws ExecutionException * @throws InterruptedException */ @@ -66,11 +74,10 @@ public interface IChunk> extends Trimable, Callable, IChu /** * Filter + * * @param filter the filter - * @param block The filter block + * @param block The filter block * @param region The region allowed to filter (may be null) - * @param unitialized a mutable block vector (buffer) - * @param unitialized2 a mutable block vector (buffer) */ void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region); @@ -81,13 +88,16 @@ public interface IChunk> extends Trimable, Callable, IChu boolean setBlock(int x, int y, int z, BlockStateHolder block); - /* get - from the world */ + @Override BiomeType getBiomeType(int x, int z); + @Override BlockState getBlock(int x, int y, int z); + @Override BaseBlock getFullBlock(int x, int y, int z); + @Override CompoundTag getTag(int x, int y, int z); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java index a76894912..c59d4d09d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java @@ -7,9 +7,10 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; /** - * Interface for getting blocks + * An interface for getting blocks. */ public interface IChunkGet extends IBlocks, Trimable, InputExtent { + @Override BaseBlock getFullBlock(int x, int y, int z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java index 9e34c4d4d..5513708a5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkSet.java @@ -6,16 +6,16 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - -import javax.annotation.Nullable; import java.util.Map; import java.util.Set; import java.util.UUID; +import javax.annotation.Nullable; /** * Interface for setting blocks */ public interface IChunkSet extends IBlocks, OutputExtent { + @Override boolean setBiome(int x, int y, int z, BiomeType biome); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java index d88896ee8..1750c9e42 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java @@ -6,18 +6,20 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - -import javax.annotation.Nullable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import javax.annotation.Nullable; /** * Delegate for IChunk + * * @param parent class */ public interface IDelegateChunk extends IChunk { + U getParent(); + @Override default IChunk getRoot() { IChunk root = getParent(); while (root instanceof IDelegateChunk) { @@ -48,32 +50,32 @@ public interface IDelegateChunk extends IChunk { } @Override - default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) { + default boolean setBiome(int x, int y, int z, BiomeType biome) { return getParent().setBiome(x, y, z, biome); } @Override - default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) { + default boolean setBlock(int x, int y, int z, BlockStateHolder holder) { return getParent().setBlock(x, y, z, holder); } @Override - default BiomeType getBiomeType(final int x, final int z) { + default BiomeType getBiomeType(int x, int z) { return getParent().getBiomeType(x, z); } @Override - default BlockState getBlock(final int x, final int y, final int z) { + default BlockState getBlock(int x, int y, int z) { return getParent().getBlock(x, y, z); } @Override - default BaseBlock getFullBlock(final int x, final int y, final int z) { + default BaseBlock getFullBlock(int x, int y, int z) { return getParent().getFullBlock(x, y, z); } @Override - default void init(final IQueueExtent extent, final int chunkX, final int chunkZ) { + default void init(IQueueExtent extent, int chunkX, int chunkZ) { getParent().init(extent, chunkX, chunkZ); } @@ -89,7 +91,7 @@ public interface IDelegateChunk extends IChunk { @Override - default boolean trim(final boolean aggressive) { + default boolean trim(boolean aggressive) { return getParent().trim(aggressive); } @@ -113,12 +115,16 @@ public interface IDelegateChunk extends IChunk { return getParent().isEmpty(); } - default T findParent(final Class clazz) { + default T findParent(Class clazz) { IChunk root = getParent(); - if (clazz.isAssignableFrom(root.getClass())) return (T) root; + if (clazz.isAssignableFrom(root.getClass())) { + return (T) root; + } while (root instanceof IDelegateChunk) { root = ((IDelegateChunk) root).getParent(); - if (clazz.isAssignableFrom(root.getClass())) return (T) root; + if (clazz.isAssignableFrom(root.getClass())) { + return (T) root; + } } return null; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java index 5736290e7..a354d7ab7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java @@ -1,10 +1,10 @@ package com.boydti.fawe.beta; import com.sk89q.worldedit.regions.Region; - import javax.annotation.Nullable; public interface IDelegateFilter extends Filter { + Filter getParent(); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java index f05a1b2e5..240ab76b9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java @@ -1,37 +1,37 @@ package com.boydti.fawe.beta; import com.boydti.fawe.beta.implementation.WorldChunkCache; - import java.util.concurrent.Future; /** * Delegate for IQueueExtent */ public interface IDelegateQueueExtent extends IQueueExtent { + IQueueExtent getParent(); @Override - default void init(final WorldChunkCache cache) { + default void init(WorldChunkCache cache) { getParent().init(cache); } @Override - default IChunk getCachedChunk(final int X, final int Z) { - return getParent().getCachedChunk(X, Z); + default IChunk getCachedChunk(int x, int z) { + return getParent().getCachedChunk(x, z); } @Override - default Future submit(final IChunk chunk) { + default Future submit(IChunk chunk) { return getParent().submit(chunk); } @Override - default IChunk create(final boolean full) { - return getParent().create(full); + default IChunk create(boolean isFull) { + return getParent().create(isFull); } @Override - default IChunk wrap(final IChunk root) { + default IChunk wrap(IChunk root) { return getParent().wrap(root); } @@ -41,7 +41,7 @@ public interface IDelegateQueueExtent extends IQueueExtent { } @Override - default boolean trim(final boolean aggressive) { + default boolean trim(boolean aggressive) { return getParent().trim(aggressive); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java index 66d7dcfda..38392ef74 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java @@ -8,14 +8,13 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.io.Flushable; import java.util.concurrent.Future; import java.util.function.Supplier; /** - * TODO: implement Extent (need to refactor Extent first) - * Interface for a queue based extent which uses chunks + * TODO: implement Extent (need to refactor Extent first) Interface for a queue based extent which + * uses chunks */ public interface IQueueExtent extends Flushable, Trimable, Extent { @@ -40,38 +39,42 @@ public interface IQueueExtent extends Flushable, Trimable, Extent { /** * Get the {@link WorldChunkCache} + * * @return */ - IChunkGet getCachedGet(int X, int Z, Supplier supplier); + IChunkGet getCachedGet(int x, int z, Supplier supplier); /** * Get the IChunk at a position (and cache it if it's not already) - * @param X - * @param Z + * + * @param x + * @param z * @return IChunk */ - IChunk getCachedChunk(int X, int Z); + IChunk getCachedChunk(int x, int z); /** * Submit the chunk so that it's changes are applied to the world + * * @param chunk * @return result */ > T submit(IChunk chunk); @Override - default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) { + default boolean setBlock(int x, int y, int z, BlockStateHolder state) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.setBlock(x & 15, y, z & 15, state); } @Override - default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) { + default boolean setBiome(int x, int y, int z, BiomeType biome) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.setBiome(x & 15, y, z & 15, biome); } - default BlockState getBlock(final int x, final int y, final int z) { + @Override + default BlockState getBlock(int x, int y, int z) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.getBlock(x & 15, y, z & 15); } @@ -82,7 +85,7 @@ public interface IQueueExtent extends Flushable, Trimable, Extent { return chunk.getFullBlock(x & 15, y, z & 15); } - default BiomeType getBiome(final int x, final int z) { + default BiomeType getBiome(int x, int z) { final IChunk chunk = getCachedChunk(x >> 4, z >> 4); return chunk.getBiomeType(x & 15, z & 15); } @@ -98,26 +101,27 @@ public interface IQueueExtent extends Flushable, Trimable, Extent { } /** - * Create a new root IChunk object
- * - Full chunks will be reused, so a more optimized chunk can be returned in that case
- * - Don't wrap the chunk, that should be done in {@link #wrap(IChunk)} - * @param full + * Create a new root IChunk object
- Full chunks will be reused, so a more optimized chunk + * can be returned in that case
- Don't wrap the chunk, that should be done in {@link + * #wrap(IChunk)} + * + * @param isFull true if a more optimized chunk should be returned * @return */ - IChunk create(boolean full); + IChunk create(boolean isFull); /** * Wrap the chunk object (i.e. for region restrictions / limits etc.) + * * @param root * @return wrapped chunk */ - default IChunk wrap(final IChunk root) { + default IChunk wrap(IChunk root) { return root; } /** - * Flush all changes to the world - * - Best to call this async so it doesn't hang the server + * Flush all changes to the world - Best to call this async so it doesn't hang the server */ @Override void flush(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/NorthVector.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/NorthVector.java index 94279a6aa..a3ab572a1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/NorthVector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/NorthVector.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; public class NorthVector extends BlockVector3 { + private final BlockVector3 parent; public NorthVector(BlockVector3 parent) { @@ -34,55 +35,67 @@ public class NorthVector extends BlockVector3 { return parent.getZ(); } + @Override public boolean setOrdinal(Extent orDefault, int ordinal) { return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal)); } + @Override public boolean setBlock(Extent orDefault, BlockState state) { return orDefault.setBlock(this, state); } + @Override public boolean setFullBlock(Extent orDefault, BaseBlock block) { - return orDefault.setBlock(this, block); + return orDefault.setBlock(this, block); } + @Override public boolean setBiome(Extent orDefault, BiomeType biome) { return orDefault.setBiome(getX(), getY(), getZ(), biome); } + @Override public int getOrdinal(Extent orDefault) { return getBlock(orDefault).getOrdinal(); } + @Override public char getOrdinalChar(Extent orDefault) { return (char) getOrdinal(orDefault); } + @Override public BlockState getBlock(Extent orDefault) { return orDefault.getBlock(this); } + @Override public BaseBlock getFullBlock(Extent orDefault) { return orDefault.getFullBlock(this); } + @Override public CompoundTag getNbtData(Extent orDefault) { return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); } + @Override public BlockState getOrdinalBelow(Extent orDefault) { return getStateRelative(orDefault, 0, -1, 0); } + @Override public BlockState getStateAbove(Extent orDefault) { return getStateRelative(orDefault, 0, 1, 0); } - public BlockState getStateRelativeY(Extent orDefault, final int y) { + @Override + public BlockState getStateRelativeY(Extent orDefault, int y) { return getStateRelative(orDefault, 0, y, 0); } - public BlockState getStateRelative(Extent orDefault, final int x, final int y, final int z) { + public BlockState getStateRelative(Extent orDefault, int x, int y, int z) { return getFullBlockRelative(orDefault, x, y, z).toBlockState(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/SimpleFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/SimpleFilterBlock.java index b8d865aec..27cc60afd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/SimpleFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/SimpleFilterBlock.java @@ -3,6 +3,7 @@ package com.boydti.fawe.beta; import com.sk89q.worldedit.extent.Extent; public abstract class SimpleFilterBlock extends FilterBlock { + private final Extent extent; public SimpleFilterBlock(Extent extent) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/SingleFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/SingleFilterBlock.java index 39a2c04a0..ec4bf5b73 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/SingleFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/SingleFilterBlock.java @@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; - import javax.annotation.Nullable; public class SingleFilterBlock extends FilterBlock { @@ -26,29 +25,29 @@ public class SingleFilterBlock extends FilterBlock { return this; } + @Override + public int getOrdinal() { + return block.getOrdinal(); + } + @Override public void setOrdinal(int ordinal) { setBlock(BlockState.getFromOrdinal(ordinal)); } + @Override + public BlockState getBlock() { + return block.toBlockState(); + } + @Override public void setBlock(BlockState state) { setFullBlock(state.toBaseBlock(block.getNbtData())); } @Override - public void setFullBlock(BaseBlock block) { - this.block = block; - } - - @Override - public void setNbtData(@Nullable CompoundTag nbtData) { - block = block.toBaseBlock(nbtData); - } - - @Override - public int getOrdinal() { - return block.getOrdinal(); + public BaseBlock getFullBlock() { + return block; } // @Override @@ -57,13 +56,8 @@ public class SingleFilterBlock extends FilterBlock { // } @Override - public BlockState getBlock() { - return block.toBlockState(); - } - - @Override - public BaseBlock getFullBlock() { - return block; + public void setFullBlock(BaseBlock block) { + this.block = block; } @Override @@ -71,6 +65,11 @@ public class SingleFilterBlock extends FilterBlock { return block.getNbtData(); } + @Override + public void setNbtData(@Nullable CompoundTag nbtData) { + block = block.toBaseBlock(nbtData); + } + @Override public int getX() { return x; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/Trimable.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/Trimable.java index 34efe59ae..cfbc8480b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/Trimable.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/Trimable.java @@ -1,13 +1,16 @@ package com.boydti.fawe.beta; /** - * Interface for objects that can be trimmed (memory related)
- * - Trimming will reduce it's memory footprint + * Interface for objects that can be trimmed (memory related)
- Trimming will reduce it's memory + * footprint */ public interface Trimable { + /** * Trim the object, reducing it's memory footprint - * @param aggressive if trimming should be aggressive e.g. Not return early when the first element cannot be trimmed + * + * @param aggressive if trimming should be aggressive e.g. Not return early when the first + * element cannot be trimmed * @return if this object is empty at the end of the trim, and can therefore be deleted */ boolean trim(boolean aggressive); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ArrayImageMask.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ArrayImageMask.java index 26c2e4e98..bc8bb0f46 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ArrayImageMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ArrayImageMask.java @@ -2,11 +2,11 @@ package com.boydti.fawe.beta.filters; import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.beta.FilterBlockMask; - import java.awt.image.BufferedImage; import java.util.concurrent.ThreadLocalRandom; public class ArrayImageMask implements FilterBlockMask { + private final ThreadLocalRandom random; private final boolean white; private final BufferedImage image; @@ -16,9 +16,10 @@ public class ArrayImageMask implements FilterBlockMask { this.white = white; this.random = ThreadLocalRandom.current(); } + @Override public boolean applyBlock(FilterBlock block) { int height = image.getRGB(block.getX(), block.getZ()) & 0xFF; - return ((height == 255 || height > 0 && !white && random.nextInt(256) <= height)); + return height == 255 || height > 0 && !white && random.nextInt(256) <= height; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/CountFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/CountFilter.java index 8dda75900..111502781 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/CountFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/CountFilter.java @@ -3,6 +3,7 @@ package com.boydti.fawe.beta.filters; import com.boydti.fawe.beta.FilterBlock; public class CountFilter extends ForkedFilter { + private int total; public CountFilter() { @@ -23,12 +24,8 @@ public class CountFilter extends ForkedFilter { this.total += filter.getTotal(); } - /* - Implementation - */ - @Override - public final void applyBlock(final FilterBlock block) { + public final void applyBlock(FilterBlock block) { total++; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/DistrFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/DistrFilter.java index bde69e284..91ddf73e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/DistrFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/DistrFilter.java @@ -1,19 +1,19 @@ package com.boydti.fawe.beta.filters; import com.boydti.fawe.beta.FilterBlock; -import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.function.mask.ABlockMask; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; - import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; public class DistrFilter extends ForkedFilter { + private final int[] counter = new int[BlockTypes.states.length]; public DistrFilter() { @@ -36,12 +36,8 @@ public class DistrFilter extends ForkedFilter { } } - /* - Implementation - */ - @Override - public final void applyBlock(final FilterBlock block) { + public final void applyBlock(FilterBlock block) { counter[block.getOrdinal()]++; } @@ -57,9 +53,7 @@ public class DistrFilter extends ForkedFilter { } public int getTotal() { - int total = 0; - for (int value : counter) total += value; - return total; + return Arrays.stream(counter).sum(); } public List> getDistribution() { @@ -94,14 +88,14 @@ public class DistrFilter extends ForkedFilter { return distribution; } - public void print(final Actor actor, final long size) { - for (final Countable c : getDistribution()) { + public void print(Actor actor, long size) { + for (Countable c : getDistribution()) { final String name = c.getID().toString(); final String str = String.format("%-7s (%.3f%%) %s", - String.valueOf(c.getAmount()), - c.getAmount() / (double) size * 100, - name); - actor.print(BBC.getPrefix() + str); + String.valueOf(c.getAmount()), + c.getAmount() / (double) size * 100, + name); + actor.print(str); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ForkedFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ForkedFilter.java index 6118c4dea..64827ffd0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ForkedFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/ForkedFilter.java @@ -1,20 +1,11 @@ package com.boydti.fawe.beta.filters; import com.boydti.fawe.beta.Filter; -import com.boydti.fawe.beta.FilterBlock; -import com.boydti.fawe.config.BBC; -import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.Countable; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public abstract class ForkedFilter> implements Filter { + protected final Map children; public ForkedFilter(T root) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/SetFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/SetFilter.java index 841defd43..0ba970ea5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/SetFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/filters/SetFilter.java @@ -5,14 +5,15 @@ import com.boydti.fawe.beta.FilterBlock; import com.sk89q.worldedit.world.block.BlockState; public class SetFilter implements Filter { + private final BlockState state; - public SetFilter(final BlockState state) { + public SetFilter(BlockState state) { this.state = state; } @Override - public void applyBlock(final FilterBlock block) { + public void applyBlock(FilterBlock block) { block.setBlock(state); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/DelegateChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/DelegateChunkSet.java index 6b224de56..b53e12861 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/DelegateChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/DelegateChunkSet.java @@ -9,13 +9,13 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; - -import javax.annotation.Nullable; import java.util.Map; import java.util.Set; import java.util.UUID; +import javax.annotation.Nullable; public interface DelegateChunkSet extends IChunkSet { + IChunkSet getParent(); @Override @@ -102,7 +102,8 @@ public interface DelegateChunkSet extends IChunkSet { } @Override - default > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { + default > boolean setBlock(BlockVector3 position, T block) + throws WorldEditException { return getParent().setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IQueueWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IQueueWrapper.java index 8c4957ce2..c7b47634d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IQueueWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IQueueWrapper.java @@ -3,6 +3,7 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.beta.IQueueExtent; public interface IQueueWrapper { + default IQueueExtent wrapQueue(IQueueExtent queue) { return queue; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiThreadedQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiThreadedQueue.java index e571306ac..5b64ed33c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiThreadedQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/MultiThreadedQueue.java @@ -19,13 +19,14 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; - import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ForkJoinTask; +import java.util.stream.IntStream; public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper { + private final World world; private final QueueHandler handler; @@ -39,56 +40,53 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue return handler.getQueue(this.world); } - public T apply(final Region region, final T filter) { + public T apply(Region region, T filter) { // The chunks positions to iterate over final Set chunks = region.getChunks(); final Iterator chunksIter = chunks.iterator(); // Get a pool, to operate on the chunks in parallel final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS); - final ForkJoinTask[] tasks = new ForkJoinTask[size]; - for (int i = 0; i < size; i++) { - tasks[i] = handler.submit(new Runnable() { - @Override - public void run() { - final Filter newFilter = filter.fork(); - // Create a chunk that we will reuse/reset for each operation - final IQueueExtent queue = wrapQueue(getQueue()); - synchronized (queue) { - ChunkFilterBlock block = null; + final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> { + final Filter newFilter = filter.fork(); + // Create a chunk that we will reuse/reset for each operation + final IQueueExtent queue = wrapQueue(getQueue()); + synchronized (queue) { + ChunkFilterBlock block = null; - while (true) { - // Get the next chunk posWeakChunk - final int X, Z; - synchronized (chunksIter) { - if (!chunksIter.hasNext()) break; - final BlockVector2 pos = chunksIter.next(); - X = pos.getX(); - Z = pos.getZ(); - } - if (!newFilter.appliesChunk(X, Z)) { - continue; - } - IChunk chunk = queue.getCachedChunk(X, Z); - // Initialize - chunk.init(queue, X, Z); - - IChunk newChunk = newFilter.applyChunk(chunk, region); - if (newChunk != null) { - chunk = newChunk; - if (block == null) block = queue.initFilterBlock(); - chunk.filterBlocks(newFilter, block, region); - } - queue.submit(chunk); + while (true) { + // Get the next chunk posWeakChunk + final int X, Z; + synchronized (chunksIter) { + if (!chunksIter.hasNext()) { + break; } - queue.flush(); + final BlockVector2 pos = chunksIter.next(); + X = pos.getX(); + Z = pos.getZ(); } + if (!newFilter.appliesChunk(X, Z)) { + continue; + } + IChunk chunk = queue.getCachedChunk(X, Z); + // Initialize + chunk.init(queue, X, Z); + + IChunk newChunk = newFilter.applyChunk(chunk, region); + if (newChunk != null) { + chunk = newChunk; + if (block == null) { + block = queue.initFilterBlock(); + } + chunk.filterBlocks(newFilter, block, region); + } + queue.submit(chunk); } - }); - } + queue.flush(); + } + })).toArray(ForkJoinTask[]::new); // Join filters - for (int i = 0; i < tasks.length; i++) { - final ForkJoinTask task = tasks[i]; + for (ForkJoinTask task : tasks) { if (task != null) { task.quietlyJoin(); } @@ -102,17 +100,18 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue } @Override - public int countBlocks(final Region region, final Mask searchMask) { + public int countBlocks(Region region, Mask searchMask) { return - // Apply a filter over a region - apply(region, searchMask + // Apply a filter over a region + apply(region, searchMask .toFilter(new CountFilter())) // Adapt the mask to a filter which counts .getParent() // Get the counter of this mask .getTotal(); // Get the total from the counter } @Override - public > int setBlocks(Region region, B block) throws MaxChangedBlocksException { + public > int setBlocks(Region region, B block) + throws MaxChangedBlocksException { apply(region, block); return getChanges(); } @@ -135,7 +134,8 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue } @Override - public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException { + public int replaceBlocks(Region region, Mask mask, Pattern pattern) + throws MaxChangedBlocksException { apply(region, mask.toFilter(pattern)); return getChanges(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java index 374018e26..b4da68e89 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java @@ -12,7 +12,6 @@ import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.wrappers.WorldWrapper; import com.google.common.util.concurrent.Futures; import com.sk89q.worldedit.world.World; - import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Iterator; @@ -31,6 +30,7 @@ import java.util.function.Supplier; * Class which handles all the queues {@link IQueueExtent} */ public abstract class QueueHandler implements Trimable, Runnable { + private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool(); private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor(); @@ -43,17 +43,16 @@ public abstract class QueueHandler implements Trimable, Runnable { return create(); } }; - - public QueueHandler() { - TaskManager.IMP.repeat(this, 1); - } - /** - * Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the server + * Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the + * server */ private long last; private long allocate = 50; private double targetTPS = 18; + public QueueHandler() { + TaskManager.IMP.repeat(this, 1); + } @Override public void run() { @@ -63,7 +62,7 @@ public abstract class QueueHandler implements Trimable, Runnable { if (!syncTasks.isEmpty()) { long now = System.currentTimeMillis(); targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0); - long diff = (50 + this.last) - (this.last = now); + long diff = 50 + this.last - (this.last = now); long absDiff = Math.abs(diff); if (diff == 0) { allocate = Math.min(50, allocate + 1); @@ -105,7 +104,9 @@ public abstract class QueueHandler implements Trimable, Runnable { } while (!syncTasks.isEmpty()) { final FutureTask task = syncTasks.poll(); - if (task != null) task.run(); + if (task != null) { + task.run(); + } } } @@ -119,23 +120,23 @@ public abstract class QueueHandler implements Trimable, Runnable { } } - public Future async(final Runnable run, final T value) { + public Future async(Runnable run, T value) { return forkJoinPoolSecondary.submit(run, value); } - public Future async(final Runnable run) { + public Future async(Runnable run) { return forkJoinPoolSecondary.submit(run); } - public Future async(final Callable call) { + public Future async(Callable call) { return forkJoinPoolSecondary.submit(call); } - public ForkJoinTask submit(final Runnable call) { + public ForkJoinTask submit(Runnable call) { return forkJoinPoolPrimary.submit(call); } - public Future sync(final Runnable run, final T value) { + public Future sync(Runnable run, T value) { if (Fawe.isMainThread()) { run.run(); return Futures.immediateFuture(value); @@ -146,7 +147,7 @@ public abstract class QueueHandler implements Trimable, Runnable { return result; } - public Future sync(final Runnable run) { + public Future sync(Runnable run) { if (Fawe.isMainThread()) { run.run(); return Futures.immediateCancelledFuture(); @@ -157,7 +158,7 @@ public abstract class QueueHandler implements Trimable, Runnable { return result; } - public Future sync(final Callable call) throws Exception { + public Future sync(Callable call) throws Exception { if (Fawe.isMainThread()) { return Futures.immediateFuture(call.call()); } @@ -167,7 +168,7 @@ public abstract class QueueHandler implements Trimable, Runnable { return result; } - public Future sync(final Supplier call) { + public Future sync(Supplier call) { if (Fawe.isMainThread()) { return Futures.immediateFuture(call.get()); } @@ -183,7 +184,7 @@ public abstract class QueueHandler implements Trimable, Runnable { } } - public > T submit(final IChunk chunk) { + public > T submit(IChunk chunk) { // if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this // return (T) forkJoinPoolSecondary.submit(chunk); // } @@ -192,6 +193,7 @@ public abstract class QueueHandler implements Trimable, Runnable { /** * Get or create the WorldChunkCache for a world + * * @param world * @return */ @@ -218,17 +220,18 @@ public abstract class QueueHandler implements Trimable, Runnable { public abstract void endSet(boolean parallel); - public IQueueExtent getQueue(final World world) { + public IQueueExtent getQueue(World world) { final IQueueExtent queue = queuePool.get(); queue.init(getOrCreate(world)); return queue; } @Override - public boolean trim(final boolean aggressive) { + public boolean trim(boolean aggressive) { boolean result = true; synchronized (chunkCache) { - final Iterator>> iter = chunkCache.entrySet().iterator(); + final Iterator>> iter = chunkCache + .entrySet().iterator(); while (iter.hasNext()) { final Map.Entry> entry = iter.next(); final WeakReference value = entry.getValue(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SimpleCharQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SimpleCharQueueExtent.java index b341c7021..4112521a7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SimpleCharQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/SimpleCharQueueExtent.java @@ -2,9 +2,9 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.beta.CharFilterBlock; import com.boydti.fawe.beta.ChunkFilterBlock; -import com.boydti.fawe.beta.FilterBlock; public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent { + @Override public ChunkFilterBlock initFilterBlock() { return new CharFilterBlock(this); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java new file mode 100644 index 000000000..fe6f6beaf --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java @@ -0,0 +1,27 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit; + +/** + * Raised when a world is missing but is required. + */ +public class MissingWorldException extends WorldEditException { + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java new file mode 100644 index 000000000..8262d0696 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java @@ -0,0 +1,51 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.extension.platform; + +import com.sk89q.worldedit.internal.cui.CUIEvent; + +import java.io.File; + +public abstract class AbstractNonPlayerActor implements Actor { + + @Override + public boolean canDestroyBedrock() { + return true; + } + + @Override + public boolean isPlayer() { + return false; + } + + @Override + public File openFileOpenDialog(String[] extensions) { + return null; + } + + @Override + public File openFileSaveDialog(String[] extensions) { + return null; + } + + @Override + public void dispatchCUIEvent(CUIEvent event) { + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Locatable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Locatable.java new file mode 100644 index 000000000..cc25ab5c7 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Locatable.java @@ -0,0 +1,69 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.extension.platform; + +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.util.Location; + +public interface Locatable { + + /** + * Get the location of this actor. + * + * @return the location of the actor + */ + Location getLocation(); + + /** + * Get the location of this actor in block coordinates. + * + * @return the block location of the actor + */ + default Location getBlockLocation() { + Location location = getLocation(); + return location.setPosition(location.toVector().floor()); + } + + /** + * Sets the location of this actor. + * + * @param location the new location of the actor + * @return if the teleport succeeded + */ + boolean setLocation(Location location); + + /** + * Sets the position of this actor. + * + * @param pos where to move them + */ + default void setPosition(Vector3 pos) { + setLocation(new Location(getExtent(), pos)); + } + + /** + * Get the extent that this actor is in. + * + * @return the extent + */ + Extent getExtent(); + +}