3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 20:10:06 +01:00
Dieser Commit ist enthalten in:
Jesse Boyd 2019-08-07 01:28:12 +10:00
Ursprung b6bc09226c
Commit 74fe88ae01
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
59 geänderte Dateien mit 938 neuen und 556 gelöschten Zeilen

Datei anzeigen

@ -46,7 +46,7 @@ allprojects {
def buildNumber = "" def buildNumber = ""
def date = "" def date = ""
ext { ext {
git = Grgit.open(dir: '.git') git = Grgit.open(dir: new File(rootDir.toString()+'/.git'))
date = git.head().getDate().format("yy.MM.dd") date = git.head().getDate().format("yy.MM.dd")
revision = "-${git.head().abbreviatedId}" revision = "-${git.head().abbreviatedId}"
parents = git.head().parentIds; parents = git.head().parentIds;
@ -63,6 +63,7 @@ allprojects {
version = String.format("%s.%s", rootVersion, buildNumber) version = String.format("%s.%s", rootVersion, buildNumber)
} }
description = rootProject.name description = rootProject.name
subprojects { 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: 'java'
apply plugin: 'maven' apply plugin: 'maven'
// apply plugin: 'checkstyle' // apply plugin: 'checkstyle'

Datei anzeigen

@ -7,5 +7,3 @@ include 'worldedit-libs'
include "worldedit-$it" include "worldedit-$it"
} }
include "worldedit-libs:core:ap" include "worldedit-libs:core:ap"
include 'favs'

Datei anzeigen

@ -23,10 +23,10 @@ dependencies {
compileOnly 'com.sk89q:dummypermscompat:1.10' compileOnly 'com.sk89q:dummypermscompat:1.10'
testCompile 'org.mockito:mockito-core:1.9.0-rc1' testCompile 'org.mockito:mockito-core:1.9.0-rc1'
implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1'){transitive = false} 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} implementation('io.papermc:paperlib:1.0.2'){transitive = false}
compileOnly 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT' 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-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.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39'){transitive = false}
implementation('com.massivecraft:factions:2.8.0'){transitive = false} implementation('com.massivecraft:factions:2.8.0'){transitive = false}

Datei anzeigen

@ -1,16 +1,13 @@
package com.boydti.fawe.bukkit; package com.boydti.fawe.bukkit;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID;
public class BukkitPlayer extends FawePlayer<Player> { public class BukkitPlayer extends FawePlayer<Player> {
private static ConsoleCommandSender console; private static ConsoleCommandSender console;
@ -39,26 +36,6 @@ public class BukkitPlayer extends FawePlayer<Player> {
return parent.isSneaking(); 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.<FaweBukkit>imp().getVault() == null || Fawe.<FaweBukkit>imp().getVault().permission == null) {
this.parent.addAttachment(Fawe.<FaweBukkit>imp().getPlugin()).setPermission(perm, flag);
} else if (flag) {
if (!Fawe.<FaweBukkit>imp().getVault().permission.playerAdd(this.parent, perm)) {
this.parent.addAttachment(Fawe.<FaweBukkit>imp().getPlugin()).setPermission(perm, flag);
}
} else {
if (!Fawe.<FaweBukkit>imp().getVault().permission.playerRemove(this.parent, perm)) {
this.parent.addAttachment(Fawe.<FaweBukkit>imp().getPlugin()).setPermission(perm, flag);
}
}
}
@Override @Override
public void resetTitle() { public void resetTitle() {
parent.resetTitle(); parent.resetTitle();
@ -77,7 +54,7 @@ public class BukkitPlayer extends FawePlayer<Player> {
@Override @Override
public void sendMessage(final String message) { public void sendMessage(final String message) {
this.parent.sendMessage(BBC.color(message)); this.parent.sendMessage(message);
} }
@Override public void printError(String msg) { @Override public void printError(String msg) {

Datei anzeigen

@ -3,11 +3,9 @@ package com.boydti.fawe.bukkit;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.IFawe; import com.boydti.fawe.IFawe;
import com.boydti.fawe.beta.implementation.QueueHandler; 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.beta.BukkitQueueHandler;
import com.boydti.fawe.bukkit.listener.BrushListener; import com.boydti.fawe.bukkit.listener.BrushListener;
import com.boydti.fawe.bukkit.listener.BukkitImageListener; 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.listener.RenderListener;
import com.boydti.fawe.bukkit.regions.*; import com.boydti.fawe.bukkit.regions.*;
import com.boydti.fawe.bukkit.util.BukkitReflectionUtils; 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.v0.ChunkListener_9;
import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13; import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13;
import com.boydti.fawe.bukkit.v1_14.BukkitQueue_1_14; 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.config.Settings;
import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer; 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.TaskManager;
import com.boydti.fawe.util.image.ImageViewer; import com.boydti.fawe.util.image.ImageViewer;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.bstats.bukkit.MetricsLite; import org.bstats.bukkit.MetricsLite;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -43,11 +40,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -155,7 +150,7 @@ public class FaweBukkit implements IFawe, Listener {
fos.write(jarData); fos.write(jarData);
} }
} }
BukkitImageViewer viewer = new BukkitImageViewer((Player) fp.parent); BukkitImageViewer viewer = new BukkitImageViewer(BukkitAdapter.adapt(fp.toWorldEditPlayer()));
if (imageListener == null) { if (imageListener == null) {
this.imageListener = new BukkitImageListener(plugin); this.imageListener = new BukkitImageListener(plugin);
} }
@ -184,7 +179,7 @@ public class FaweBukkit implements IFawe, Listener {
@Override @Override
public void debug(final String message) { public void debug(final String message) {
ConsoleCommandSender console = Bukkit.getConsoleSender(); ConsoleCommandSender console = Bukkit.getConsoleSender();
console.sendMessage(BBC.color(message)); console.sendMessage(message);
} }
@Override @Override
@ -398,19 +393,19 @@ public class FaweBukkit implements IFawe, Listener {
final ArrayList<FaweMaskManager> managers = new ArrayList<>(); final ArrayList<FaweMaskManager> managers = new ArrayList<>();
if (worldguardPlugin != null && worldguardPlugin.isEnabled()) { if (worldguardPlugin != null && worldguardPlugin.isEnabled()) {
try { try {
managers.add(new Worldguard(worldguardPlugin, this)); managers.add(new Worldguard(worldguardPlugin));
managers.add(new WorldguardFlag(worldguardPlugin, this)); managers.add(new WorldguardFlag(worldguardPlugin));
Fawe.debug("Plugin 'WorldGuard' found. Using it now."); Fawe.debug("Plugin 'WorldGuard' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny"); final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny");
if (townyPlugin != null && townyPlugin.isEnabled()) { if (townyPlugin != null && townyPlugin.isEnabled()) {
try { try {
managers.add(new TownyFeature(townyPlugin, this)); managers.add(new TownyFeature(townyPlugin));
Fawe.debug("Plugin 'Towny' found. Using it now."); Fawe.debug("Plugin 'Towny' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -419,7 +414,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new FactionsFeature(factionsPlugin)); managers.add(new FactionsFeature(factionsPlugin));
Fawe.debug("Plugin 'Factions' found. Using it now."); Fawe.debug("Plugin 'Factions' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
try { try {
managers.add(new FactionsUUIDFeature(factionsPlugin, this)); managers.add(new FactionsUUIDFeature(factionsPlugin, this));
Fawe.debug("Plugin 'FactionsUUID' found. Using it now."); Fawe.debug("Plugin 'FactionsUUID' found. Using it now.");
@ -439,7 +434,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new ResidenceFeature(residencePlugin, this)); managers.add(new ResidenceFeature(residencePlugin, this));
Fawe.debug("Plugin 'Residence' found. Using it now."); Fawe.debug("Plugin 'Residence' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -448,7 +443,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new GriefPreventionFeature(griefpreventionPlugin)); managers.add(new GriefPreventionFeature(griefpreventionPlugin));
Fawe.debug("Plugin 'GriefPrevention' found. Using it now."); Fawe.debug("Plugin 'GriefPrevention' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -457,7 +452,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new PreciousStonesFeature(preciousStonesPlugin, this)); managers.add(new PreciousStonesFeature(preciousStonesPlugin, this));
Fawe.debug("Plugin 'PreciousStones' found. Using it now."); Fawe.debug("Plugin 'PreciousStones' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -468,7 +463,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new ASkyBlockHook(aSkyBlock)); managers.add(new ASkyBlockHook(aSkyBlock));
Fawe.debug("Plugin 'ASkyBlock' found. Using it now."); Fawe.debug("Plugin 'ASkyBlock' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -476,7 +471,7 @@ public class FaweBukkit implements IFawe, Listener {
try { try {
managers.add(new FreeBuildRegion()); managers.add(new FreeBuildRegion());
Fawe.debug("Plugin '<internal.freebuild>' found. Using it now."); Fawe.debug("Plugin '<internal.freebuild>' found. Using it now.");
} catch (final Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

Datei anzeigen

@ -7,7 +7,7 @@ import com.boydti.fawe.beta.implementation.SimpleCharQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache; import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.bukkit.v1_14.adapter.BlockMaterial_1_14; import com.boydti.fawe.bukkit.v1_14.adapter.BlockMaterial_1_14;
import com.boydti.fawe.config.Settings; 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.MathMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.bukkit.BukkitWorld; 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.Block;
import net.minecraft.server.v1_14_R1.Chunk; import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair; 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.ChunkSection;
import net.minecraft.server.v1_14_R1.ChunkStatus;
import net.minecraft.server.v1_14_R1.DataBits; import net.minecraft.server.v1_14_R1.DataBits;
import net.minecraft.server.v1_14_R1.DataPalette; import net.minecraft.server.v1_14_R1.DataPalette;
import net.minecraft.server.v1_14_R1.DataPaletteBlock; import net.minecraft.server.v1_14_R1.DataPaletteBlock;
import net.minecraft.server.v1_14_R1.DataPaletteLinear; import net.minecraft.server.v1_14_R1.DataPaletteLinear;
import net.minecraft.server.v1_14_R1.GameProfileSerializer; import net.minecraft.server.v1_14_R1.GameProfileSerializer;
import net.minecraft.server.v1_14_R1.IBlockData; 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.PlayerChunk;
import net.minecraft.server.v1_14_R1.PlayerChunkMap; 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 net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; 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.concurrent.locks.Lock;
import java.util.function.Supplier; 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; import static com.google.common.base.Preconditions.checkNotNull;
public class BukkitQueue extends SimpleCharQueueExtent { public class BukkitQueue extends SimpleCharQueueExtent {
@ -53,6 +53,16 @@ public class BukkitQueue extends SimpleCharQueueExtent {
private org.bukkit.World bukkitWorld; private org.bukkit.World bukkitWorld;
private WorldServer nmsWorld; private WorldServer nmsWorld;
@Override
public void enableQueue() {
}
@Override
public void disableQueue() {
}
@Override @Override
public synchronized void init(WorldChunkCache cache) { public synchronized void init(WorldChunkCache cache) {
World world = cache.getWorld(); World world = cache.getWorld();
@ -88,7 +98,7 @@ public class BukkitQueue extends SimpleCharQueueExtent {
// }; // };
@Override @Override
public IChunk create(boolean full) { public IChunk create(boolean isFull) {
// if (full) { // if (full) {
// //TODO implement // //TODO implement
// return FULL_CHUNKS.get(); // return FULL_CHUNKS.get();
@ -234,10 +244,11 @@ public class BukkitQueue extends SimpleCharQueueExtent {
return playerChunk; 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); PlayerChunk playerChunk = getPlayerChunk(X, Z);
if (playerChunk == null) { if (playerChunk == null) {
return false; return;
} }
// ChunkSection[] sections = nmsChunk.getSections(); // ChunkSection[] sections = nmsChunk.getSections();
// for (int layer = 0; layer < 16; layer++) { // for (int layer = 0; layer < 16; layer++) {
@ -268,9 +279,9 @@ public class BukkitQueue extends SimpleCharQueueExtent {
return null; return null;
} }
}); });
return true; return;
} }
return false; return;
} }
/* /*

Datei anzeigen

@ -3,10 +3,11 @@ package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMask;
import com.sk89q.worldedit.bukkit.BukkitAdapter; 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.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island; import com.wasteofplastic.askyblock.Island;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -24,22 +25,21 @@ public class ASkyBlockHook extends BukkitMaskManager implements Listener {
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location location = player.getLocation(); final Location location = player.getLocation();
Island island = ASkyBlockAPI.getInstance().getIslandAt(location); Island island = ASkyBlockAPI.getInstance().getIslandAt(location);
if (island != null && isAllowed(player, island, type)) { if (island != null && isAllowed(player, island, type)) {
World world = location.getWorld(); Location center1 = island.getCenter();
Location center = island.getCenter(); MutableBlockVector3 center = MutableBlockVector3.at(center1.getX(), center1.getY(), center1.getZ());
Location pos1 = new Location(world, island.getMinProtectedX(), 0, island.getMinProtectedZ()); BlockVector3 pos1 = BlockVector3.at(island.getMinProtectedX(), 0, island.getMinProtectedZ());
Location pos2 = center.add(center.subtract(pos1)); MutableBlockVector3 pos2 = center.add(center.subtract(pos1)).mutY(255);
pos2.setY(255);
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { return new FaweMask(pos1, pos2) {
@Override @Override
public boolean isValid(FawePlayer player, MaskType type) { public boolean isValid(FawePlayer player, MaskType type) {
return isAllowed((Player) player.parent, island, type); return isAllowed(BukkitAdapter.adapt(player.toWorldEditPlayer()), island, type);
} }
}; };
} }

Datei anzeigen

@ -7,6 +7,7 @@ import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,7 +22,7 @@ public class FactionsFeature extends BukkitMaskManager implements Listener {
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location loc = player.getLocation(); final Location loc = player.getLocation();
final PS ps = PS.valueOf(loc); final PS ps = PS.valueOf(loc);
final Faction fac = BoardColl.get().getFactionAt(ps); final Faction fac = BoardColl.get().getFactionAt(ps);
@ -30,16 +31,17 @@ public class FactionsFeature extends BukkitMaskManager implements Listener {
MPlayer leader = fac.getLeader(); MPlayer leader = fac.getLeader();
if (leader != null && fp.getUUID().equals(leader.getUuid())) { if (leader != null && fp.getUUID().equals(leader.getUuid())) {
final Chunk chunk = loc.getChunk(); final Chunk chunk = loc.getChunk();
final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); final BlockVector3 pos1 = BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16);
final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); final BlockVector3 pos2 = BlockVector3
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); .at((chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15);
return new FaweMask(pos1, pos2);
} }
} else if (fac.getOnlinePlayers().contains(player)) { } else if (fac.getOnlinePlayers().contains(player)) {
if (!fac.getComparisonName().equals("wilderness")) { if (!fac.getComparisonName().equals("wilderness")) {
final Chunk chunk = loc.getChunk(); final Chunk chunk = loc.getChunk();
final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); final BlockVector3 pos1 = BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16);
final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); final BlockVector3 pos2 = BlockVector3.at((chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15);
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); return new FaweMask(pos1, pos2);
} }
} }
} }

Datei anzeigen

@ -6,16 +6,15 @@ import com.boydti.fawe.regions.FaweMask;
import com.boydti.fawe.util.Permission; import com.boydti.fawe.util.Permission;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.sk89q.worldedit.bukkit.BukkitAdapter; 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.Chunk;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.lang.reflect.Method;
import java.util.List;
public class FactionsOneFeature extends BukkitMaskManager implements Listener { public class FactionsOneFeature extends BukkitMaskManager implements Listener {
private final Method methodGetFactionAt; private final Method methodGetFactionAt;
@ -28,7 +27,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener {
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Chunk chunk = player.getLocation().getChunk(); final Chunk chunk = player.getLocation().getChunk();
final boolean perm = Permission final boolean perm = Permission
.hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); .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 BlockVector3 pos1 = BlockVector3.at(locs.minX << 4, 1, locs.minZ << 4);
final Location pos2 = new Location(world, 15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); final BlockVector3 pos2 = BlockVector3.at(15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4));
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); return new FaweMask(pos1, pos2);
} }
return null; return null;
} }

Datei anzeigen

@ -9,6 +9,7 @@ import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -26,7 +27,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener {
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Chunk chunk = player.getLocation().getChunk(); final Chunk chunk = player.getLocation().getChunk();
final boolean perm = Permission final boolean perm = Permission
.hasPermission(fp.toWorldEditPlayer(), "fawe.factions.wilderness"); .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 BlockVector3 pos1 = BlockVector3.at(locs.minX << 4, 1, locs.minZ << 4);
final Location pos2 = new Location(world, 15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4)); final BlockVector3 pos2 = BlockVector3.at(15 + (locs.maxX << 4), 256, 15 + (locs.maxZ << 4));
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()); return new FaweMask(pos1,pos2);
} }
return null; return null;
} }

Datei anzeigen

@ -10,6 +10,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import jdk.nashorn.internal.ir.Block;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -20,6 +21,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.RegisteredListener;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.util.BlockVector;
public class FreeBuildRegion extends BukkitMaskManager { public class FreeBuildRegion extends BukkitMaskManager {
private final ArrayList<RegisteredListener> listeners; private final ArrayList<RegisteredListener> listeners;
@ -52,20 +54,20 @@ public class FreeBuildRegion extends BukkitMaskManager {
if (currRegList.isEmpty()) return null; if (currRegList.isEmpty()) return null;
RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[0]); RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[0]);
World bukkitWorld = player.parent.getWorld(); World bukkitWorld = BukkitAdapter.adapt(player.toWorldEditPlayer().getWorld());
AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
Location pos1 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); BlockVector3 pos1 = BlockVector3.ZERO;
Location pos2 = BukkitAdapter.adapt(bukkitWorld, BlockVector3.ZERO); BlockVector3 pos2 = BlockVector3.ZERO;
AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0); 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 @Override
public boolean isValid(FawePlayer player, MaskType type) { public boolean isValid(FawePlayer player, MaskType type) {
return bukkitWorld == ((FawePlayer<Player>)player).parent.getWorld() && type == MaskType.MEMBER; return bukkitWorld == BukkitAdapter.adapt(player.toWorldEditPlayer().getWorld()) && type == MaskType.MEMBER;
} }
@Override @Override

Datei anzeigen

@ -5,10 +5,10 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMask;
import com.boydti.fawe.regions.general.RegionFilter; import com.boydti.fawe.regions.general.RegionFilter;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention; import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; 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) { 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 @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location location = player.getLocation(); final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(BukkitAdapter.adapt(fp.getLocation()), true, null);
final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null);
if (claim != null) { if (claim != null) {
if (isAllowed(player, claim, type)) { if (isAllowed(player, claim, type)) {
claim.getGreaterBoundaryCorner().getBlockX(); claim.getGreaterBoundaryCorner().getBlockX();
final Location pos1 = new Location(location.getWorld(), claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ()); final BlockVector3 pos1 = BlockVector3.at(claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ());
final Location pos2 = new Location(location.getWorld(), claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ()); final BlockVector3 pos2 = BlockVector3.at(claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ());
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { return new FaweMask(pos1, pos2) {
@Override @Override
public boolean isValid(FawePlayer player, MaskType type) { public boolean isValid(FawePlayer fp, MaskType type) {
return isAllowed((Player) player.parent, claim, type); return isAllowed(player, claim, type);
} }
}; };
} }

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMask;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import java.util.List; import java.util.List;
@ -15,23 +16,19 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class PreciousStonesFeature extends BukkitMaskManager implements Listener { 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()); super(preciousstonesPlugin.getName());
this.preciousstones = preciousstonesPlugin;
this.plugin = p3;
} }
public boolean isAllowed(Player player, Field field, MaskType type, boolean allowMember) { 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 @Override
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location location = player.getLocation(); final Location location = player.getLocation();
final List<Field> fields = PreciousStones.API().getFieldsProtectingArea(FieldFlag.ALL, location); final List<Field> fields = PreciousStones.API().getFieldsProtectingArea(FieldFlag.ALL, location);
if (fields.isEmpty()) { if (fields.isEmpty()) {
@ -39,14 +36,14 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener
} }
String name = player.getName(); String name = player.getName();
boolean member = fp.hasPermission("fawe.preciousstones.member"); boolean member = fp.hasPermission("fawe.preciousstones.member");
for (final Field myField : fields) { for (Field myField : fields) {
if (isAllowed(player, myField, type, member)) { if (isAllowed(player, myField, type, member)) {
BlockVector3 pos1 = BlockVector3.at(myField.getMinx(), myField.getMiny(), myField.getMinz()); BlockVector3 pos1 = BlockVector3.at(myField.getMinx(), myField.getMiny(), myField.getMinz());
BlockVector3 pos2 = BlockVector3.at(myField.getMaxx(), myField.getMaxy(), myField.getMaxz()); BlockVector3 pos2 = BlockVector3.at(myField.getMaxx(), myField.getMaxy(), myField.getMaxz());
return new FaweMask(pos1, pos2) { return new FaweMask(pos1, pos2) {
@Override @Override
public boolean isValid(FawePlayer player, MaskType type) { 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"));
} }
}; };
} }

Datei anzeigen

@ -29,7 +29,7 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener {
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp, final MaskType type) { public FaweMask getMask(final FawePlayer<Player> fp, final MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location location = player.getLocation(); final Location location = player.getLocation();
ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(location); ClaimedResidence residence = Residence.getInstance().getResidenceManager().getByLoc(location);
if (residence != null) { if (residence != null) {
@ -42,10 +42,10 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener {
final Location pos1 = area.getLowLoc(); final Location pos1 = area.getLowLoc();
final Location pos2 = area.getHighLoc(); final Location pos2 = area.getHighLoc();
final ClaimedResidence finalResidence = residence; 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 @Override
public boolean isValid(FawePlayer player, MaskType type) { public boolean isValid(FawePlayer player, MaskType type) {
return isAllowed((Player) player.parent, finalResidence, type); return isAllowed((Player) BukkitAdapter.adapt(player.toWorldEditPlayer()), finalResidence, type);
} }
}; };
} }

Datei anzeigen

@ -1,12 +1,17 @@
package com.boydti.fawe.bukkit.regions; package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMask;
import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; 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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,13 +19,12 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class TownyFeature extends BukkitMaskManager implements Listener { 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()); super(townyPlugin.getName());
this.towny = townyPlugin; this.towny = townyPlugin;
this.plugin = p3;
} }
public boolean isAllowed(Player player, TownBlock block) { public boolean isAllowed(Player player, TownBlock block) {
@ -30,16 +34,19 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
Resident resident; Resident resident;
try { try {
resident = TownyUniverse.getDataSource().getResident(player.getName()); resident = TownyUniverse.getDataSource().getResident(player.getName());
try { try {
if (block.getResident().equals(resident)) { if (block.getResident().equals(resident)) {
return true; return true;
}
} catch (NotRegisteredException ignore) {
} }
} catch (NotRegisteredException ignore) {}
Town town = block.getTown(); Town town = block.getTown();
if (town.isMayor(resident)) { if (town.isMayor(resident)) {
return true; return true;
} }
if (!town.hasResident(resident)) return false; if (!town.hasResident(resident)) {
return false;
}
if (player.hasPermission("fawe.towny.*")) { if (player.hasPermission("fawe.towny.*")) {
return true; return true;
} }
@ -55,8 +62,8 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
} }
@Override @Override
public FaweMask getMask(final FawePlayer<Player> fp) { public FaweMask getMask(FawePlayer<Player> fp) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final Location location = player.getLocation(); final Location location = player.getLocation();
try { try {
final PlayerCache cache = ((Towny) this.towny).getCache(player); final PlayerCache cache = ((Towny) this.towny).getCache(player);
@ -71,18 +78,23 @@ public class TownyFeature extends BukkitMaskManager implements Listener {
boolean isMember = isAllowed(player, myplot); boolean isMember = isAllowed(player, myplot);
if (isMember) { if (isMember) {
final Chunk chunk = location.getChunk(); final Chunk chunk = location.getChunk();
final Location pos1 = new Location(location.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); final BlockVector3 pos1 = BlockVector3
final Location pos2 = new Location(location.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); .at(chunk.getX() * 16, 0, chunk.getZ() * 16);
return new FaweMask(BukkitAdapter.adapt(pos1).toBlockPoint(), BukkitAdapter.adapt(pos2).toBlockPoint()) { final BlockVector3 pos2 = BlockVector3.at(
chunk.getX() * 16 + 15, 156, chunk.getZ() * 16
+ 15);
return new FaweMask(pos1, pos2) {
@Override @Override
public boolean isValid(FawePlayer player, MaskType type) { 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; return null;
} }
} }

Datei anzeigen

@ -1,6 +1,5 @@
package com.boydti.fawe.bukkit.regions; package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.bukkit.filter.WorldGuardFilter; import com.boydti.fawe.bukkit.filter.WorldGuardFilter;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RegionWrapper;
@ -30,7 +29,6 @@ import org.bukkit.plugin.Plugin;
public class Worldguard extends BukkitMaskManager implements Listener { public class Worldguard extends BukkitMaskManager implements Listener {
private WorldGuardPlugin worldguard; private WorldGuardPlugin worldguard;
FaweBukkit plugin;
private WorldGuardPlugin getWorldGuard() { private WorldGuardPlugin getWorldGuard() {
final Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard"); final Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard");
@ -43,13 +41,12 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return (WorldGuardPlugin) plugin; return (WorldGuardPlugin) plugin;
} }
public Worldguard(final Plugin p2, final FaweBukkit p3) { public Worldguard(Plugin p2) {
super(p2.getName()); super(p2.getName());
this.worldguard = this.getWorldGuard(); 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(); RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
if (container == null) { if (container == null) {
System.out.println("Region capability is not enabled for WorldGuard."); System.out.println("Region capability is not enabled for WorldGuard.");
@ -65,7 +62,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return global; return global;
} }
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())); 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)) { if (isAllowed(player, region)) {
return region; return region;
} }
@ -86,43 +83,42 @@ public class Worldguard extends BukkitMaskManager implements Listener {
if (localplayer.hasPermission("fawe.worldguard.member")) { if (localplayer.hasPermission("fawe.worldguard.member")) {
if (region.isMember(localplayer) || region.isMember(localplayer.getName())) { if (region.isMember(localplayer) || region.isMember(localplayer.getName())) {
return true; return true;
} else if (region.isMember("*")) { } else
return true; return region.isMember("*");
}
} }
return false; return false;
} }
@Override @Override
public FaweMask getMask(FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final LocalPlayer localplayer = this.worldguard.wrapPlayer(player); final LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
final Location location = player.getLocation(); final Location location = player.getLocation();
final ProtectedRegion myregion = this.getRegion(localplayer, location); final ProtectedRegion myregion = this.getRegion(localplayer, location);
if (myregion != null) { if (myregion != null) {
final Location pos1; final BlockVector3 pos1;
final Location pos2; final BlockVector3 pos2;
if (myregion.getId().equals("__global__")) { if (myregion.getId().equals("__global__")) {
pos1 = new Location(location.getWorld(), Integer.MIN_VALUE, 0, Integer.MIN_VALUE); pos1 = BlockVector3.at(Integer.MIN_VALUE, 0, Integer.MIN_VALUE);
pos2 = new Location(location.getWorld(), Integer.MAX_VALUE, 255, Integer.MAX_VALUE); pos2 = BlockVector3.at(Integer.MAX_VALUE, 255, Integer.MAX_VALUE);
} else { } else {
if (myregion instanceof ProtectedCuboidRegion) { if (myregion instanceof ProtectedCuboidRegion) {
pos1 = new Location(location.getWorld(), myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ()); pos1 = BlockVector3.at(myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ());
pos2 = new Location(location.getWorld(), myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ()); pos2 = BlockVector3.at(myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ());
} else { } else {
return new FaweMask(adapt(myregion)) { return new FaweMask(adapt(myregion)) {
@Override @Override
public boolean isValid(FawePlayer player, MaskType type) { 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 @Override
public boolean isValid(FawePlayer player, MaskType type) { public boolean isValid(FawePlayer player, MaskType type) {
return isAllowed(worldguard.wrapPlayer((Player) player.parent), myregion); return isAllowed(worldguard.wrapPlayer(BukkitAdapter.adapt(player.toWorldEditPlayer())), myregion);
} }
}; };
} }

Datei anzeigen

@ -1,10 +1,10 @@
package com.boydti.fawe.bukkit.regions; package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.bukkit.filter.WorldGuardFilter; import com.boydti.fawe.bukkit.filter.WorldGuardFilter;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMask;
import com.boydti.fawe.regions.general.RegionFilter; import com.boydti.fawe.regions.general.RegionFilter;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
@ -12,29 +12,29 @@ import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager; 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.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.Map;
public class WorldguardFlag extends BukkitMaskManager implements Listener { 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"); super("worldguardflag");
this.worldguard = (WorldGuardPlugin) p2; // this.getWorldGuard(); this.worldguard = (WorldGuardPlugin) p2; // this.getWorldGuard();
this.plugin = p3;
} }
@Override @Override
public FaweMask getMask(FawePlayer<Player> fp, MaskType type) { public FaweMask getMask(FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent; final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
final LocalPlayer localplayer = this.worldguard.wrapPlayer(player); 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()); final RegionManager manager = container.get(fp.getWorld());
return new FaweMask(new ManagerRegion(manager, localplayer)) { 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 * ManagerRegion wraps a RegionManager and will provide results based upon the regions enclosed
*/ */
private static class ManagerRegion extends AbstractRegion { private static class ManagerRegion extends AbstractRegion {
private final RegionManager manager; private final RegionManager manager;
private final LocalPlayer localplayer; private final LocalPlayer localplayer;
@ -105,7 +106,8 @@ public class WorldguardFlag extends BukkitMaskManager implements Listener {
@Override @Override
public boolean contains(BlockVector3 position) { public boolean contains(BlockVector3 position) {
// Make sure that all these flags are not denied. Denies override allows. WorldGuardExtraFlags can add Flags.WORLDEDIT // 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);
} }
} }

Datei anzeigen

@ -0,0 +1,168 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
};
}
}

Datei anzeigen

@ -22,21 +22,19 @@ package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; 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.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; public class BukkitCommandSender extends AbstractNonPlayerActor {
import java.util.UUID;
import javax.annotation.Nullable;
public class BukkitCommandSender implements Actor {
/** /**
* One time generated ID. * One time generated ID.
@ -149,17 +147,17 @@ public class BukkitCommandSender implements Actor {
@Nullable @Nullable
@Override @Override
public String getName() { public String getName() {
return null; return sender.getName();
} }
@Override @Override
public boolean isActive() { public boolean isActive() {
return false; return true;
} }
@Override @Override
public boolean isPersistent() { public boolean isPersistent() {
return false; return true;
} }
@Override @Override

Datei anzeigen

@ -255,14 +255,13 @@ public class BukkitPlayer extends AbstractPlayerActor {
} }
@Override @Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) { public boolean isAllowedToFly() {
if (alwaysGlass || !player.getAllowFlight()) { return player.getAllowFlight();
super.floatAt(x, y, z, alwaysGlass);
return;
} }
setPosition(Vector3.at(x + 0.5, y, z + 0.5)); @Override
player.setFlying(true); public void setFlying(boolean flying) {
player.setFlying(flying);
} }
@Override @Override

Datei anzeigen

@ -45,6 +45,7 @@ import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.bukkit.Effect; import org.bukkit.Effect;
@ -156,6 +157,11 @@ public class BukkitWorld extends AbstractWorld {
return getWorld().getName(); return getWorld().getName();
} }
@Override
public String getId() {
return getWorld().getName().replace(" ", "_").toLowerCase(Locale.ROOT);
}
@Override @Override
public Path getStoragePath() { public Path getStoragePath() {
return getWorld().getWorldFolder().toPath(); return getWorld().getWorldFolder().toPath();

Datei anzeigen

@ -527,6 +527,8 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
public Actor wrapCommandSender(CommandSender sender) { public Actor wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
return wrapPlayer((Player) sender); return wrapPlayer((Player) sender);
} else if (sender instanceof BlockCommandSender) {
return new BukkitBlockCommandSender(this, (BlockCommandSender) sender);
} }
return new BukkitCommandSender(this, sender); return new BukkitCommandSender(this, sender);

Datei anzeigen

@ -135,7 +135,7 @@ public class Fawe {
if (INSTANCE != null) { if (INSTANCE != null) {
INSTANCE.IMP.debug(s); INSTANCE.IMP.debug(s);
} else { } 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) { public static void debug(Object s) {
Actor actor = Request.request().getActor(); Actor actor = Request.request().getActor();
if (actor != null && actor.isPlayer()) { if (actor != null && actor.isPlayer()) {
actor.print(BBC.color(BBC.PREFIX.original() + " " + s)); actor.print((String)s);
return; return;
} }
debugPlain(BBC.PREFIX.original() + " " + s); debugPlain((String) s);
} }
/** /**

Datei anzeigen

@ -5,18 +5,19 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ArrayFilterBlock extends SimpleFilterBlock { public class ArrayFilterBlock extends SimpleFilterBlock {
private final char[] blocks; private final char[] blocks;
private final byte[] heights; private final byte[] heights;
private final int yOffset; private final int yOffset;
private final int width, length;
private int x, z, index; private int x, z, index;
private char ordinal; 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); super(extent);
this.blocks = blocks; this.blocks = blocks;
this.width = width; 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 @Override
public int getOrdinal() { public int getOrdinal() {
return ordinal; return ordinal;
} }
@Override
public void setOrdinal(int ordinal) {
blocks[index] = (char) ordinal;
}
@Override @Override
public BlockState getBlock() { public BlockState getBlock() {
return BlockTypes.states[ordinal]; return BlockTypes.states[ordinal];
} }
@Override
public void setBlock(BlockState state) {
blocks[index] = state.getOrdinalChar();
}
@Override @Override
public BaseBlock getFullBlock() { public BaseBlock getFullBlock() {
return getBlock().toBaseBlock(); return getBlock().toBaseBlock();
} }
@Override
public void setFullBlock(BaseBlock block) {
blocks[index] = block.getOrdinalChar();
}
@Override @Override
public CompoundTag getNbtData() { public CompoundTag getNbtData() {
return null; return null;
} }
@Override @Override
public void setNbtData(@Nullable CompoundTag nbtData) {} public void setNbtData(@Nullable CompoundTag nbtData) {
}
@Override @Override
public int getX() { public int getX() {

Datei anzeigen

@ -12,39 +12,54 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class CharFilterBlock extends ChunkFilterBlock { 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 CharGetBlocks get;
private IChunkSet set; private IChunkSet set;
private char[] getArr; private char[] getArr;
private @Nullable char[] setArr; private @Nullable
char[] setArr;
private SetDelegate delegate; private SetDelegate delegate;
// local // 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) { public CharFilterBlock(IQueueExtent queueExtent) {
super(queueExtent); super(queueExtent);
} }
@Override @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.get = (CharGetBlocks) chunk;
this.X = chunkX; this.chunkX = chunkX;
this.Z = chunkZ; this.chunkZ = chunkZ;
this.xx = chunkX << 4; this.xx = chunkX << 4;
this.zz = chunkZ << 4; this.zz = chunkZ << 4;
return this; 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 int maxDepth = flood.getMaxDepth();
final boolean checkDepth = maxDepth < Character.MAX_VALUE; final boolean checkDepth = maxDepth < Character.MAX_VALUE;
if (init(iget, iset, layer) != null) { if (init(iget, iset, layer) != null) {
while ((index = flood.poll()) != -1) { while ((index = flood.poll()) != -1) {
x = index & 15; x = index & 15;
z = (index >> 4) & 15; z = index >> 4 & 15;
y = (index >> 8) & 15; y = index >> 8 & 15;
if (mask.applyBlock(this)) { if (mask.applyBlock(this)) {
int depth = index >> 12; int depth = index >> 12;
@ -60,10 +75,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
@Override @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; this.layer = layer;
final CharGetBlocks get = (CharGetBlocks) iget; final CharGetBlocks get = (CharGetBlocks) iget;
if (!get.hasSection(layer)) return null; if (!get.hasSection(layer)) {
return null;
}
this.set = iset; this.set = iset;
getArr = get.sections[layer].get(get, layer); getArr = get.sections[layer].get(get, layer);
if (set.hasSection(layer)) { if (set.hasSection(layer)) {
@ -82,13 +100,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.index = x | (z << 4) | (y << 8); this.index = x | z << 4 | y << 8;
filter.applyBlock(this); filter.applyBlock(this);
} }
@Override @Override
public void filter(Filter filter, int yStart, int yEnd) { 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 (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) { for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this); filter.applyBlock(this);
@ -99,8 +117,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
int yis = (minY << 8); int yis = minY << 8;
int zis = (minZ << 4); int zis = minZ << 4;
for (y = minY, index = yis; y <= maxY; y++) { for (y = minY, index = yis; y <= maxY; y++) {
for (z = minZ, index += zis; z <= maxZ; z++) { for (z = minZ, index += zis; z <= maxZ; z++) {
for (x = minX, index += minX; x <= maxX; x++, index++) { for (x = minX, index += minX; x <= maxX; x++, index++) {
@ -111,7 +129,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
@Override @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++) { for (y = 0, index = 0; y < 16; y++) {
int absY = yy + y; int absY = yy + y;
for (z = 0; z < 16; z++) { for (z = 0; z < 16; z++) {
@ -127,7 +145,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
@Override @Override
public final void filter(final Filter filter) { public final void filter(Filter filter) {
for (y = 0, index = 0; y < 16; y++) { for (y = 0, index = 0; y < 16; y++) {
for (z = 0; z < 16; z++) { for (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) { for (x = 0; x < 16; x++, index++) {
@ -142,25 +160,6 @@ public class CharFilterBlock extends ChunkFilterBlock {
set.setBiome(x, y, z, biome); 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 @Override
public final int getX() { public final int getX() {
return xx + x; return xx + x;
@ -193,12 +192,12 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public final int getChunkX() { public final int getChunkX() {
return X; return chunkX;
} }
@Override @Override
public final int getChunkZ() { public final int getChunkZ() {
return Z; return chunkZ;
} }
public final char getOrdinalChar() { public final char getOrdinalChar() {
@ -210,12 +209,22 @@ public class CharFilterBlock extends ChunkFilterBlock {
return getArr[index]; return getArr[index];
} }
@Override
public void setOrdinal(int ordinal) {
delegate.set(this, (char) ordinal);
}
@Override @Override
public final BlockState getBlock() { public final BlockState getBlock() {
final int ordinal = getArr[index]; final int ordinal = getArr[index];
return BlockTypes.states[ordinal]; return BlockTypes.states[ordinal];
} }
@Override
public void setBlock(BlockState state) {
delegate.set(this, state.getOrdinalChar());
}
@Override @Override
public final BaseBlock getFullBlock() { public final BaseBlock getFullBlock() {
final BlockState state = getBlock(); final BlockState state = getBlock();
@ -227,10 +236,25 @@ public class CharFilterBlock extends ChunkFilterBlock {
return state.toBaseBlock(); 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 @Override
public final CompoundTag getNbtData() { public final CompoundTag getNbtData() {
return get.getTag(x, y + (layer << 4), z); 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 @Override
public void setNbtData(CompoundTag tag) { public void setNbtData(CompoundTag tag) {
@ -245,19 +269,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
final BlockMaterial material = state.getMaterial(); final BlockMaterial material = state.getMaterial();
return material.hasContainer(); 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 @Override
public final BlockState getBlockNorth() { public final BlockState getBlockNorth() {
if (z > 0) { if (z > 0) {
return states[getArr[index - 16]]; return states[getArr[index - 16]];
} }
return getExtent().getBlock(getX(), getY(), getZ() - 1); return getExtent().getBlock(getX(), getY(), getZ() - 1);
} }
@Override @Override
@ -265,7 +283,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (x < 15) { if (x < 15) {
return states[getArr[index + 1]]; return states[getArr[index + 1]];
} }
return getExtent().getBlock(getX() + 1, getY(), getZ()); return getExtent().getBlock(getX() + 1, getY(), getZ());
} }
@Override @Override
@ -273,7 +291,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (z < 15) { if (z < 15) {
return states[getArr[index + 16]]; return states[getArr[index + 16]];
} }
return getExtent().getBlock(getX(), getY(), getZ() + 1); return getExtent().getBlock(getX(), getY(), getZ() + 1);
} }
@Override @Override
@ -281,7 +299,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (x > 0) { if (x > 0) {
return states[getArr[index - 1]]; return states[getArr[index - 1]];
} }
return getExtent().getBlock(getX() - 1, getY(), getZ()); return getExtent().getBlock(getX() - 1, getY(), getZ());
} }
@Override @Override
@ -311,7 +329,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
} }
@Override @Override
public final BlockState getBlockRelativeY(final int y) { public final BlockState getBlockRelativeY(int y) {
final int newY = this.y + y; final int newY = this.y + y;
final int layerAdd = newY >> 4; final int layerAdd = newY >> 4;
switch (layerAdd) { switch (layerAdd) {
@ -353,14 +371,13 @@ public class CharFilterBlock extends ChunkFilterBlock {
case -12: case -12:
case -13: case -13:
case -14: case -14:
case -15: { case -15:
final int newLayer = layer + layerAdd; final int newLayer = layer + layerAdd;
if (newLayer >= 0) { if (newLayer >= 0) {
final int index = this.index + ((y & 15) << 8); final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)]; return states[get.sections[newLayer].get(get, newLayer, index)];
} }
break; break;
}
} }
return BlockTypes.__RESERVED__.getDefaultState(); return BlockTypes.__RESERVED__.getDefaultState();
} }
@ -383,7 +400,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public BiomeType getBiomeType(int x, int z) { 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 get.getBiomeType(x & 15, z & 15);
} }
return getExtent().getBiomeType(x, z); return getExtent().getBiomeType(x, z);
@ -391,27 +408,14 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { 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 set.setBiome(x & 15, y, z & 15, biome);
} }
return getExtent().setBiome(x, y, z, biome); return getExtent().setBiome(x, y, z, biome);
} }
private interface SetDelegate { private interface SetDelegate {
void set(CharFilterBlock block, char value); 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;
}
};
} }

Datei anzeigen

@ -4,24 +4,28 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
public abstract class ChunkFilterBlock extends SimpleFilterBlock { public abstract class ChunkFilterBlock extends SimpleFilterBlock {
public ChunkFilterBlock(Extent extent) { public ChunkFilterBlock(Extent extent) {
super(extent); super(extent);
} }
public abstract ChunkFilterBlock init(int chunkX, int chunkZ, IChunkGet chunk); 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 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);
public abstract void filter(Filter filter, int yStart, int yEnd); 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);
} }

Datei anzeigen

@ -6,11 +6,12 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
public class ChunkFuture implements Future<Void> { public class ChunkFuture implements Future<Void> {
private final IChunk chunk; private final IChunk chunk;
private volatile boolean cancelled; private volatile boolean cancelled;
private volatile boolean done; private volatile boolean done;
public ChunkFuture(final IChunk chunk) { public ChunkFuture(IChunk chunk) {
this.chunk = chunk; this.chunk = chunk;
} }
@ -19,10 +20,9 @@ public class ChunkFuture implements Future<Void> {
} }
@Override @Override
public boolean cancel(final boolean mayInterruptIfRunning) { public boolean cancel(boolean mayInterruptIfRunning) {
cancelled = true; cancelled = true;
if (done) return false; return !done;
return true;
} }
@Override @Override
@ -46,7 +46,8 @@ public class ChunkFuture implements Future<Void> {
} }
@Override @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) { synchronized (chunk) {
if (!done) { if (!done) {
this.wait(unit.toMillis(timeout)); this.wait(unit.toMillis(timeout));

Datei anzeigen

@ -1,11 +1,13 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
public class DelegateFilter<T extends Filter> implements IDelegateFilter { public class DelegateFilter<T extends Filter> implements IDelegateFilter {
private final Filter parent; private final Filter parent;
public DelegateFilter(T parent) { public DelegateFilter(T parent) {
this.parent = parent; this.parent = parent;
} }
@Override @Override
public T getParent() { public T getParent() {
return (T) parent; return (T) parent;

Datei anzeigen

@ -24,43 +24,35 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import javax.annotation.Nullable;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
public class DelegateFilterBlock extends FilterBlock { public class DelegateFilterBlock extends FilterBlock {
private final FilterBlock parent; private final FilterBlock parent;
public DelegateFilterBlock(FilterBlock parent) { public DelegateFilterBlock(FilterBlock parent) {
this.parent = 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<BlockVector3> sortByCoordsYzx() {
return BlockVector3.sortByCoordsYzx();
}
@Override @Override
public Extent getExtent() { public Extent getExtent() {
return parent.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 @Override
public boolean hasNbtData() { public boolean hasNbtData() {
return parent.hasNbtData(); return parent.hasNbtData();
@ -76,21 +68,41 @@ public class DelegateFilterBlock extends FilterBlock {
return parent.getOrdinal(); return parent.getOrdinal();
} }
@Override
public void setOrdinal(int ordinal) {
parent.setOrdinal(ordinal);
}
@Override @Override
public BlockState getBlock() { public BlockState getBlock() {
return parent.getBlock(); return parent.getBlock();
} }
@Override
public void setBlock(BlockState state) {
parent.setBlock(state);
}
@Override @Override
public BaseBlock getFullBlock() { public BaseBlock getFullBlock() {
return parent.getFullBlock(); return parent.getFullBlock();
} }
@Override
public void setFullBlock(BaseBlock block) {
parent.setFullBlock(block);
}
@Override @Override
public CompoundTag getNbtData() { public CompoundTag getNbtData() {
return parent.getNbtData(); return parent.getNbtData();
} }
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
parent.setNbtData(nbtData);
}
@Override @Override
public BlockVector3 getMinimumPoint() { public BlockVector3 getMinimumPoint() {
return parent.getMinimumPoint(); return parent.getMinimumPoint();
@ -241,18 +253,6 @@ public class DelegateFilterBlock extends FilterBlock {
return parent.getStateRelativeY(orDefault, y); 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<BlockVector3> sortByCoordsYzx() {
return BlockVector3.sortByCoordsYzx();
}
@Override @Override
public MutableBlockVector3 setComponents(double x, double y, double z) { public MutableBlockVector3 setComponents(double x, double y, double z) {
return parent.setComponents(x, y, z); return parent.setComponents(x, y, z);
@ -479,7 +479,8 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @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); return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
} }
@ -560,7 +561,8 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @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); return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
} }
@ -570,18 +572,23 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @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); return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
} }
@Override @Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) { public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask); int failedMax, Mask mask) {
return parent
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
} }
@Override @Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) { public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin,
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir); int failedMax, boolean ignoreAir) {
return parent
.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
} }
@Override @Override
@ -595,12 +602,14 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @Override
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException { public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity,
boolean rotate) throws WorldEditException {
parent.addSchems(region, mask, clipboards, rarity, rotate); parent.addSchems(region, mask, clipboards, rarity, rotate);
} }
@Override @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); parent.spawnResource(region, gen, rarity, frequency);
} }
@ -610,7 +619,8 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @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); parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY);
} }
@ -650,6 +660,11 @@ public class DelegateFilterBlock extends FilterBlock {
return parent.getBlock(position); return parent.getBlock(position);
} }
@Override
public BlockType getBlockType(BlockVector3 position) {
return parent.getBlockType(position);
}
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return parent.getFullBlock(position); return parent.getFullBlock(position);
@ -666,12 +681,14 @@ public class DelegateFilterBlock extends FilterBlock {
} }
@Override @Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException { public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
throws WorldEditException {
return parent.setBlock(position, block); return parent.setBlock(position, block);
} }
@Override @Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException { public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException {
return parent.setBlock(x, y, z, block); return parent.setBlock(x, y, z, block);
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
public interface DirectionMask { public interface DirectionMask {
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ); boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
} }

Datei anzeigen

@ -2,31 +2,33 @@ package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable; 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. * Checks whether a chunk should be read.
* *
* @param chunkX * @param chunkX the x coordinate in the chunk
* @param chunkZ * @param chunkZ the z coordinate in the chunk
* @return * @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; return true;
} }
/** /**
* Do something with the IChunk<br> * Do something with the IChunk<br> - Return null if you don't want to filter blocks<br> -
* - Return null if you don't want to filter blocks<br> * Return the chunk if you do want to filter blocks<br>
* - Return the chunk if you do want to filter blocks<br>
* *
* @param chunk * @param chunk
* @return * @return
*/ */
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) { default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
return chunk; return chunk;
} }
@ -35,27 +37,27 @@ public interface Filter {
} }
/** /**
* Make changes to the block here<br> * Make changes to the block here<br> - e.g. block.setId(...)<br> - Note: Performance is
* - e.g. block.setId(...)<br> * critical here<br>
* - Note: Performance is critical here<br>
* *
* @param block * @param block
*/ */
default void applyBlock(final FilterBlock block) { default void applyBlock(FilterBlock block) {
} }
/** /**
* Do something with the IChunk after block filtering<br> * Do something with the IChunk after block filtering.
* *
* @param chunk * @param chunk
* @return * @return
*/ */
default void finishChunk(final IChunk chunk) { default void finishChunk(IChunk chunk) {
} }
/** /**
* Fork this for use by another thread * Fork this for use by another thread - Typically filters are simple and don't need to create
* - Typically filters are simple and don't need to create another copy to be thread safe here * another copy to be thread safe here
*
* @return this * @return this
*/ */
default Filter fork() { default Filter fork() {

Datei anzeigen

@ -7,34 +7,35 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static com.sk89q.worldedit.world.block.BlockTypes.states;
public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock { public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock {
public abstract Extent getExtent(); 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) { public void setBiome(BiomeType biome) {
setBiome(getX(), getY(), getZ(), biome); setBiome(getX(), getY(), getZ(), biome);
} }
public abstract int getOrdinal(); public abstract int getOrdinal();
public abstract void setOrdinal(int ordinal);
public abstract BlockState getBlock(); public abstract BlockState getBlock();
public abstract void setBlock(BlockState state);
public abstract BaseBlock getFullBlock(); public abstract BaseBlock getFullBlock();
public abstract void setFullBlock(BaseBlock block);
@Override
public abstract CompoundTag getNbtData(); public abstract CompoundTag getNbtData();
@Override
public abstract void setNbtData(@Nullable CompoundTag nbtData); public abstract void setNbtData(@Nullable CompoundTag nbtData);
@Override
public boolean hasNbtData() { public boolean hasNbtData() {
return getNbtData() != null; return getNbtData() != null;
} }
@ -83,8 +84,8 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
return getBlock(getX() - 1, getY(), getZ()); return getBlock(getX() - 1, getY(), getZ());
} }
public BlockState getBlockRelativeY(final int y) { public BlockState getBlockRelativeY(int y) {
return getBlock(getX(), getY() + y , getZ()); return getBlock(getX(), getY() + y, getZ());
} }
@Override @Override
@ -119,51 +120,62 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
/* /*
Extent Extent
*/ */
@Override
public boolean setOrdinal(Extent orDefault, int ordinal) { public boolean setOrdinal(Extent orDefault, int ordinal) {
setOrdinal(ordinal); setOrdinal(ordinal);
return true; return true;
} }
@Override
public boolean setBlock(Extent orDefault, BlockState state) { public boolean setBlock(Extent orDefault, BlockState state) {
setBlock(state); setBlock(state);
return true; return true;
} }
@Override
public boolean setFullBlock(Extent orDefault, BaseBlock block) { public boolean setFullBlock(Extent orDefault, BaseBlock block) {
setFullBlock(block); setFullBlock(block);
return true; return true;
} }
@Override
public boolean setBiome(Extent orDefault, BiomeType biome) { public boolean setBiome(Extent orDefault, BiomeType biome) {
setBiome(biome); setBiome(biome);
return true; return true;
} }
@Override
public int getOrdinal(Extent orDefault) { public int getOrdinal(Extent orDefault) {
return getOrdinal(); return getOrdinal();
} }
@Override
public BlockState getBlock(Extent orDefault) { public BlockState getBlock(Extent orDefault) {
return getBlock(); return getBlock();
} }
@Override
public BaseBlock getFullBlock(Extent orDefault) { public BaseBlock getFullBlock(Extent orDefault) {
return getFullBlock(); return getFullBlock();
} }
@Override
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return getNbtData(); return getNbtData();
} }
@Override
public BlockState getOrdinalBelow(Extent orDefault) { public BlockState getOrdinalBelow(Extent orDefault) {
return getBlockBelow(); return getBlockBelow();
} }
@Override
public BlockState getStateAbove(Extent orDefault) { public BlockState getStateAbove(Extent orDefault) {
return getBlockAbove(); return getBlockAbove();
} }
public BlockState getStateRelativeY(Extent orDefault, final int y) { @Override
public BlockState getStateRelativeY(Extent orDefault, int y) {
return getBlockRelativeY(y); return getBlockRelativeY(y);
} }
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
public interface FilterBlockMask { public interface FilterBlockMask {
boolean applyBlock(final FilterBlock block);
boolean applyBlock(FilterBlock block);
} }

Datei anzeigen

@ -6,27 +6,23 @@ import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
public class Flood { public class Flood {
private final int maxBranch; private final int maxBranch;
private final int maxDepth; private final int maxDepth;
private final Direction[] directions; private final Direction[] directions;
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
private int[] queue; private int[] queue;
private long[] visit; private long[] visit;
private int[][] queues; private int[][] queues;
private long[][] visits; private long[][] visits;
private int chunkX; private int chunkX;
private int chunkYLayer; private int chunkYLayer;
private int chunkZ; private int chunkZ;
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
public Flood(int maxBranch, int maxDepth, Direction[] directions) { public Flood(int maxBranch, int maxDepth, Direction[] directions) {
this.maxBranch = maxBranch; this.maxBranch = maxBranch;
@ -68,7 +64,7 @@ public class Flood {
long pair = MathMan.pairInt(chunkX, chunkZ); long pair = MathMan.pairInt(chunkX, chunkZ);
int layer = y >> 4; int layer = y >> 4;
int[] section = getOrCreateQueue(pair, layer); 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); push(section, val);
} }
@ -171,12 +167,12 @@ public class Flood {
} }
public void set(long[] bits, int i) { 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) { public final boolean getAndSet(long[] bits, int i) {
int index = i >> 6; int index = i >> 6;
long offset = (1L << (i & 0x3F)); long offset = 1L << (i & 0x3F);
long val = bits[index]; long val = bits[index];
if ((val & offset) != 0) { if ((val & offset) != 0) {
return true; return true;
@ -186,7 +182,7 @@ public class Flood {
} }
} }
public boolean get(long[] bits, final int i) { public boolean get(long[] bits, int i) {
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0; return (bits[i >> 6] & 1L << (i & 0x3F)) != 0;
} }
} }

Datei anzeigen

@ -4,6 +4,7 @@ package com.boydti.fawe.beta;
* Shared interface for IGetBlocks and ISetBlocks * Shared interface for IGetBlocks and ISetBlocks
*/ */
public interface IBlocks extends Trimable { public interface IBlocks extends Trimable {
boolean hasSection(int layer); boolean hasSection(int layer);
IBlocks reset(); IBlocks reset();

Datei anzeigen

@ -12,12 +12,14 @@ import java.util.concurrent.Future;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
* Represents a chunk in the queue {@link IQueueExtent} * Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes
* Used for getting and setting blocks / biomes / entities * / entities
*/ */
public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChunkGet { public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChunkGet {
/** /**
* Initialize at the location * Initialize at the location
*
* @param extent * @param extent
* @param x * @param x
* @param z * @param z
@ -31,7 +33,8 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
int getZ(); 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 * @return root IChunk
*/ */
default IChunk getRoot() { default IChunk getRoot() {
@ -39,20 +42,25 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
} }
/** /**
* Checks if there are any queued changes for this chunk.
*
* @return true if no changes are queued for this chunk * @return true if no changes are queued for this chunk
*/ */
boolean isEmpty(); boolean isEmpty();
/** /**
* Apply the queued changes to the world<br> * Apply the queued changes to the world containing this chunk.
* The future returned may return another future<br> * <p>The future returned may return another future. To ensure completion keep calling {@link
* To ensure completion keep calling {@link Future#get()} on each result * Future#get()} on each result.</p>
*
* @return Futures * @return Futures
*/ */
@Override
T call(); T call();
/** /**
* Call and join * Call and join
*
* @throws ExecutionException * @throws ExecutionException
* @throws InterruptedException * @throws InterruptedException
*/ */
@ -66,11 +74,10 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
/** /**
* Filter * Filter
*
* @param filter the 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 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); void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
@ -81,13 +88,16 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T>, IChu
boolean setBlock(int x, int y, int z, BlockStateHolder block); boolean setBlock(int x, int y, int z, BlockStateHolder block);
/* get - from the world */ @Override
BiomeType getBiomeType(int x, int z); BiomeType getBiomeType(int x, int z);
@Override
BlockState getBlock(int x, int y, int z); BlockState getBlock(int x, int y, int z);
@Override
BaseBlock getFullBlock(int x, int y, int z); BaseBlock getFullBlock(int x, int y, int z);
@Override
CompoundTag getTag(int x, int y, int z); CompoundTag getTag(int x, int y, int z);
@Override @Override

Datei anzeigen

@ -7,9 +7,10 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
/** /**
* Interface for getting blocks * An interface for getting blocks.
*/ */
public interface IChunkGet extends IBlocks, Trimable, InputExtent { public interface IChunkGet extends IBlocks, Trimable, InputExtent {
@Override @Override
BaseBlock getFullBlock(int x, int y, int z); BaseBlock getFullBlock(int x, int y, int z);

Datei anzeigen

@ -6,16 +6,16 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
/** /**
* Interface for setting blocks * Interface for setting blocks
*/ */
public interface IChunkSet extends IBlocks, OutputExtent { public interface IChunkSet extends IBlocks, OutputExtent {
@Override @Override
boolean setBiome(int x, int y, int z, BiomeType biome); boolean setBiome(int x, int y, int z, BiomeType biome);

Datei anzeigen

@ -6,18 +6,20 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Nullable;
/** /**
* Delegate for IChunk * Delegate for IChunk
*
* @param <U> parent class * @param <U> parent class
*/ */
public interface IDelegateChunk<U extends IChunk> extends IChunk { public interface IDelegateChunk<U extends IChunk> extends IChunk {
U getParent(); U getParent();
@Override
default IChunk getRoot() { default IChunk getRoot() {
IChunk root = getParent(); IChunk root = getParent();
while (root instanceof IDelegateChunk) { while (root instanceof IDelegateChunk) {
@ -48,32 +50,32 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
} }
@Override @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); return getParent().setBiome(x, y, z, biome);
} }
@Override @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); return getParent().setBlock(x, y, z, holder);
} }
@Override @Override
default BiomeType getBiomeType(final int x, final int z) { default BiomeType getBiomeType(int x, int z) {
return getParent().getBiomeType(x, z); return getParent().getBiomeType(x, z);
} }
@Override @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); return getParent().getBlock(x, y, z);
} }
@Override @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); return getParent().getFullBlock(x, y, z);
} }
@Override @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); getParent().init(extent, chunkX, chunkZ);
} }
@ -89,7 +91,7 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
@Override @Override
default boolean trim(final boolean aggressive) { default boolean trim(boolean aggressive) {
return getParent().trim(aggressive); return getParent().trim(aggressive);
} }
@ -113,12 +115,16 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
return getParent().isEmpty(); return getParent().isEmpty();
} }
default <T extends IChunk> T findParent(final Class<T> clazz) { default <T extends IChunk> T findParent(Class<T> clazz) {
IChunk root = getParent(); IChunk root = getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root; if (clazz.isAssignableFrom(root.getClass())) {
return (T) root;
}
while (root instanceof IDelegateChunk) { while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent(); root = ((IDelegateChunk) root).getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root; if (clazz.isAssignableFrom(root.getClass())) {
return (T) root;
}
} }
return null; return null;
} }

Datei anzeigen

@ -1,10 +1,10 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public interface IDelegateFilter extends Filter { public interface IDelegateFilter extends Filter {
Filter getParent(); Filter getParent();
@Override @Override

Datei anzeigen

@ -1,37 +1,37 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.WorldChunkCache; import com.boydti.fawe.beta.implementation.WorldChunkCache;
import java.util.concurrent.Future; import java.util.concurrent.Future;
/** /**
* Delegate for IQueueExtent * Delegate for IQueueExtent
*/ */
public interface IDelegateQueueExtent extends IQueueExtent { public interface IDelegateQueueExtent extends IQueueExtent {
IQueueExtent getParent(); IQueueExtent getParent();
@Override @Override
default void init(final WorldChunkCache cache) { default void init(WorldChunkCache cache) {
getParent().init(cache); getParent().init(cache);
} }
@Override @Override
default IChunk getCachedChunk(final int X, final int Z) { default IChunk getCachedChunk(int x, int z) {
return getParent().getCachedChunk(X, Z); return getParent().getCachedChunk(x, z);
} }
@Override @Override
default Future<?> submit(final IChunk chunk) { default Future<?> submit(IChunk chunk) {
return getParent().submit(chunk); return getParent().submit(chunk);
} }
@Override @Override
default IChunk create(final boolean full) { default IChunk create(boolean isFull) {
return getParent().create(full); return getParent().create(isFull);
} }
@Override @Override
default IChunk wrap(final IChunk root) { default IChunk wrap(IChunk root) {
return getParent().wrap(root); return getParent().wrap(root);
} }
@ -41,7 +41,7 @@ public interface IDelegateQueueExtent extends IQueueExtent {
} }
@Override @Override
default boolean trim(final boolean aggressive) { default boolean trim(boolean aggressive) {
return getParent().trim(aggressive); return getParent().trim(aggressive);
} }
} }

Datei anzeigen

@ -8,14 +8,13 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.Flushable; import java.io.Flushable;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
* TODO: implement Extent (need to refactor Extent first) * TODO: implement Extent (need to refactor Extent first) Interface for a queue based extent which
* Interface for a queue based extent which uses chunks * uses chunks
*/ */
public interface IQueueExtent extends Flushable, Trimable, Extent { public interface IQueueExtent extends Flushable, Trimable, Extent {
@ -40,38 +39,42 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
/** /**
* Get the {@link WorldChunkCache} * Get the {@link WorldChunkCache}
*
* @return * @return
*/ */
IChunkGet getCachedGet(int X, int Z, Supplier<IChunkGet> supplier); IChunkGet getCachedGet(int x, int z, Supplier<IChunkGet> supplier);
/** /**
* Get the IChunk at a position (and cache it if it's not already) * Get the IChunk at a position (and cache it if it's not already)
* @param X *
* @param Z * @param x
* @param z
* @return IChunk * @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 * Submit the chunk so that it's changes are applied to the world
*
* @param chunk * @param chunk
* @return result * @return result
*/ */
<T extends Future<T>> T submit(IChunk<T> chunk); <T extends Future<T>> T submit(IChunk<T> chunk);
@Override @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); final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBlock(x & 15, y, z & 15, state); return chunk.setBlock(x & 15, y, z & 15, state);
} }
@Override @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); final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBiome(x & 15, y, z & 15, biome); 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); final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBlock(x & 15, y, z & 15); 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); 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); final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBiomeType(x & 15, z & 15); return chunk.getBiomeType(x & 15, z & 15);
} }
@ -98,26 +101,27 @@ public interface IQueueExtent extends Flushable, Trimable, Extent {
} }
/** /**
* Create a new root IChunk object<br> * Create a new root IChunk object<br> - Full chunks will be reused, so a more optimized chunk
* - Full chunks will be reused, so a more optimized chunk can be returned in that case<br> * can be returned in that case<br> - Don't wrap the chunk, that should be done in {@link
* - Don't wrap the chunk, that should be done in {@link #wrap(IChunk)} * #wrap(IChunk)}
* @param full *
* @param isFull true if a more optimized chunk should be returned
* @return * @return
*/ */
IChunk create(boolean full); IChunk create(boolean isFull);
/** /**
* Wrap the chunk object (i.e. for region restrictions / limits etc.) * Wrap the chunk object (i.e. for region restrictions / limits etc.)
*
* @param root * @param root
* @return wrapped chunk * @return wrapped chunk
*/ */
default IChunk wrap(final IChunk root) { default IChunk wrap(IChunk root) {
return root; return root;
} }
/** /**
* Flush all changes to the world * Flush all changes to the world - Best to call this async so it doesn't hang the server
* - Best to call this async so it doesn't hang the server
*/ */
@Override @Override
void flush(); void flush();

Datei anzeigen

@ -8,6 +8,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
public class NorthVector extends BlockVector3 { public class NorthVector extends BlockVector3 {
private final BlockVector3 parent; private final BlockVector3 parent;
public NorthVector(BlockVector3 parent) { public NorthVector(BlockVector3 parent) {
@ -34,55 +35,67 @@ public class NorthVector extends BlockVector3 {
return parent.getZ(); return parent.getZ();
} }
@Override
public boolean setOrdinal(Extent orDefault, int ordinal) { public boolean setOrdinal(Extent orDefault, int ordinal) {
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal)); return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
} }
@Override
public boolean setBlock(Extent orDefault, BlockState state) { public boolean setBlock(Extent orDefault, BlockState state) {
return orDefault.setBlock(this, state); return orDefault.setBlock(this, state);
} }
@Override
public boolean setFullBlock(Extent orDefault, BaseBlock block) { 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) { public boolean setBiome(Extent orDefault, BiomeType biome) {
return orDefault.setBiome(getX(), getY(), getZ(), biome); return orDefault.setBiome(getX(), getY(), getZ(), biome);
} }
@Override
public int getOrdinal(Extent orDefault) { public int getOrdinal(Extent orDefault) {
return getBlock(orDefault).getOrdinal(); return getBlock(orDefault).getOrdinal();
} }
@Override
public char getOrdinalChar(Extent orDefault) { public char getOrdinalChar(Extent orDefault) {
return (char) getOrdinal(orDefault); return (char) getOrdinal(orDefault);
} }
@Override
public BlockState getBlock(Extent orDefault) { public BlockState getBlock(Extent orDefault) {
return orDefault.getBlock(this); return orDefault.getBlock(this);
} }
@Override
public BaseBlock getFullBlock(Extent orDefault) { public BaseBlock getFullBlock(Extent orDefault) {
return orDefault.getFullBlock(this); return orDefault.getFullBlock(this);
} }
@Override
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
} }
@Override
public BlockState getOrdinalBelow(Extent orDefault) { public BlockState getOrdinalBelow(Extent orDefault) {
return getStateRelative(orDefault, 0, -1, 0); return getStateRelative(orDefault, 0, -1, 0);
} }
@Override
public BlockState getStateAbove(Extent orDefault) { public BlockState getStateAbove(Extent orDefault) {
return getStateRelative(orDefault, 0, 1, 0); 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); 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(); return getFullBlockRelative(orDefault, x, y, z).toBlockState();
} }

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.beta;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
public abstract class SimpleFilterBlock extends FilterBlock { public abstract class SimpleFilterBlock extends FilterBlock {
private final Extent extent; private final Extent extent;
public SimpleFilterBlock(Extent extent) { public SimpleFilterBlock(Extent extent) {

Datei anzeigen

@ -5,7 +5,6 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class SingleFilterBlock extends FilterBlock { public class SingleFilterBlock extends FilterBlock {
@ -26,29 +25,29 @@ public class SingleFilterBlock extends FilterBlock {
return this; return this;
} }
@Override
public int getOrdinal() {
return block.getOrdinal();
}
@Override @Override
public void setOrdinal(int ordinal) { public void setOrdinal(int ordinal) {
setBlock(BlockState.getFromOrdinal(ordinal)); setBlock(BlockState.getFromOrdinal(ordinal));
} }
@Override
public BlockState getBlock() {
return block.toBlockState();
}
@Override @Override
public void setBlock(BlockState state) { public void setBlock(BlockState state) {
setFullBlock(state.toBaseBlock(block.getNbtData())); setFullBlock(state.toBaseBlock(block.getNbtData()));
} }
@Override @Override
public void setFullBlock(BaseBlock block) { public BaseBlock getFullBlock() {
this.block = block; return block;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
block = block.toBaseBlock(nbtData);
}
@Override
public int getOrdinal() {
return block.getOrdinal();
} }
// @Override // @Override
@ -57,13 +56,8 @@ public class SingleFilterBlock extends FilterBlock {
// } // }
@Override @Override
public BlockState getBlock() { public void setFullBlock(BaseBlock block) {
return block.toBlockState(); this.block = block;
}
@Override
public BaseBlock getFullBlock() {
return block;
} }
@Override @Override
@ -71,6 +65,11 @@ public class SingleFilterBlock extends FilterBlock {
return block.getNbtData(); return block.getNbtData();
} }
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
block = block.toBaseBlock(nbtData);
}
@Override @Override
public int getX() { public int getX() {
return x; return x;

Datei anzeigen

@ -1,13 +1,16 @@
package com.boydti.fawe.beta; package com.boydti.fawe.beta;
/** /**
* Interface for objects that can be trimmed (memory related)<br> * Interface for objects that can be trimmed (memory related)<br> - Trimming will reduce it's memory
* - Trimming will reduce it's memory footprint * footprint
*/ */
public interface Trimable { public interface Trimable {
/** /**
* Trim the object, reducing it's memory footprint * 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 * @return if this object is empty at the end of the trim, and can therefore be deleted
*/ */
boolean trim(boolean aggressive); boolean trim(boolean aggressive);

Datei anzeigen

@ -2,11 +2,11 @@ package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask; import com.boydti.fawe.beta.FilterBlockMask;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class ArrayImageMask implements FilterBlockMask { public class ArrayImageMask implements FilterBlockMask {
private final ThreadLocalRandom random; private final ThreadLocalRandom random;
private final boolean white; private final boolean white;
private final BufferedImage image; private final BufferedImage image;
@ -16,9 +16,10 @@ public class ArrayImageMask implements FilterBlockMask {
this.white = white; this.white = white;
this.random = ThreadLocalRandom.current(); this.random = ThreadLocalRandom.current();
} }
@Override @Override
public boolean applyBlock(FilterBlock block) { public boolean applyBlock(FilterBlock block) {
int height = image.getRGB(block.getX(), block.getZ()) & 0xFF; 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;
} }
} }

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.beta.FilterBlock;
public class CountFilter extends ForkedFilter<CountFilter> { public class CountFilter extends ForkedFilter<CountFilter> {
private int total; private int total;
public CountFilter() { public CountFilter() {
@ -23,12 +24,8 @@ public class CountFilter extends ForkedFilter<CountFilter> {
this.total += filter.getTotal(); this.total += filter.getTotal();
} }
/*
Implementation
*/
@Override @Override
public final void applyBlock(final FilterBlock block) { public final void applyBlock(FilterBlock block) {
total++; total++;
} }

Datei anzeigen

@ -1,19 +1,19 @@
package com.boydti.fawe.beta.filters; package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.FilterBlock; import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.config.BBC;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.ABlockMask; import com.sk89q.worldedit.function.mask.ABlockMask;
import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class DistrFilter extends ForkedFilter<DistrFilter> { public class DistrFilter extends ForkedFilter<DistrFilter> {
private final int[] counter = new int[BlockTypes.states.length]; private final int[] counter = new int[BlockTypes.states.length];
public DistrFilter() { public DistrFilter() {
@ -36,12 +36,8 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
} }
} }
/*
Implementation
*/
@Override @Override
public final void applyBlock(final FilterBlock block) { public final void applyBlock(FilterBlock block) {
counter[block.getOrdinal()]++; counter[block.getOrdinal()]++;
} }
@ -57,9 +53,7 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
} }
public int getTotal() { public int getTotal() {
int total = 0; return Arrays.stream(counter).sum();
for (int value : counter) total += value;
return total;
} }
public List<Countable<BlockState>> getDistribution() { public List<Countable<BlockState>> getDistribution() {
@ -94,14 +88,14 @@ public class DistrFilter extends ForkedFilter<DistrFilter> {
return distribution; return distribution;
} }
public void print(final Actor actor, final long size) { public void print(Actor actor, long size) {
for (final Countable c : getDistribution()) { for (Countable c : getDistribution()) {
final String name = c.getID().toString(); final String name = c.getID().toString();
final String str = String.format("%-7s (%.3f%%) %s", final String str = String.format("%-7s (%.3f%%) %s",
String.valueOf(c.getAmount()), String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100, c.getAmount() / (double) size * 100,
name); name);
actor.print(BBC.getPrefix() + str); actor.print(str);
} }
} }
} }

Datei anzeigen

@ -1,20 +1,11 @@
package com.boydti.fawe.beta.filters; package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.Filter; 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.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter { public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter {
protected final Map<Thread, T> children; protected final Map<Thread, T> children;
public ForkedFilter(T root) { public ForkedFilter(T root) {

Datei anzeigen

@ -5,14 +5,15 @@ import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
public class SetFilter implements Filter { public class SetFilter implements Filter {
private final BlockState state; private final BlockState state;
public SetFilter(final BlockState state) { public SetFilter(BlockState state) {
this.state = state; this.state = state;
} }
@Override @Override
public void applyBlock(final FilterBlock block) { public void applyBlock(FilterBlock block) {
block.setBlock(state); block.setBlock(state);
} }
} }

Datei anzeigen

@ -9,13 +9,13 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
public interface DelegateChunkSet extends IChunkSet { public interface DelegateChunkSet extends IChunkSet {
IChunkSet getParent(); IChunkSet getParent();
@Override @Override
@ -102,7 +102,8 @@ public interface DelegateChunkSet extends IChunkSet {
} }
@Override @Override
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException { default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block)
throws WorldEditException {
return getParent().setBlock(position, block); return getParent().setBlock(position, block);
} }

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.IQueueExtent;
public interface IQueueWrapper { public interface IQueueWrapper {
default IQueueExtent wrapQueue(IQueueExtent queue) { default IQueueExtent wrapQueue(IQueueExtent queue) {
return queue; return queue;
} }

Datei anzeigen

@ -19,13 +19,14 @@ import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ForkJoinTask; import java.util.concurrent.ForkJoinTask;
import java.util.stream.IntStream;
public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper { public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueueWrapper {
private final World world; private final World world;
private final QueueHandler handler; private final QueueHandler handler;
@ -39,56 +40,53 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
return handler.getQueue(this.world); return handler.getQueue(this.world);
} }
public <T extends Filter> T apply(final Region region, final T filter) { public <T extends Filter> T apply(Region region, T filter) {
// The chunks positions to iterate over // The chunks positions to iterate over
final Set<BlockVector2> chunks = region.getChunks(); final Set<BlockVector2> chunks = region.getChunks();
final Iterator<BlockVector2> chunksIter = chunks.iterator(); final Iterator<BlockVector2> chunksIter = chunks.iterator();
// Get a pool, to operate on the chunks in parallel // Get a pool, to operate on the chunks in parallel
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS); final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
final ForkJoinTask[] tasks = new ForkJoinTask[size]; final ForkJoinTask[] tasks = IntStream.range(0, size).mapToObj(i -> handler.submit(() -> {
for (int i = 0; i < size; i++) { final Filter newFilter = filter.fork();
tasks[i] = handler.submit(new Runnable() { // Create a chunk that we will reuse/reset for each operation
@Override final IQueueExtent queue = wrapQueue(getQueue());
public void run() { synchronized (queue) {
final Filter newFilter = filter.fork(); ChunkFilterBlock block = null;
// Create a chunk that we will reuse/reset for each operation
final IQueueExtent queue = wrapQueue(getQueue());
synchronized (queue) {
ChunkFilterBlock block = null;
while (true) { while (true) {
// Get the next chunk posWeakChunk // Get the next chunk posWeakChunk
final int X, Z; final int X, Z;
synchronized (chunksIter) { synchronized (chunksIter) {
if (!chunksIter.hasNext()) break; if (!chunksIter.hasNext()) {
final BlockVector2 pos = chunksIter.next(); break;
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(); 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 // Join filters
for (int i = 0; i < tasks.length; i++) { for (ForkJoinTask task : tasks) {
final ForkJoinTask task = tasks[i];
if (task != null) { if (task != null) {
task.quietlyJoin(); task.quietlyJoin();
} }
@ -102,17 +100,18 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
} }
@Override @Override
public int countBlocks(final Region region, final Mask searchMask) { public int countBlocks(Region region, Mask searchMask) {
return return
// Apply a filter over a region // Apply a filter over a region
apply(region, searchMask apply(region, searchMask
.toFilter(new CountFilter())) // Adapt the mask to a filter which counts .toFilter(new CountFilter())) // Adapt the mask to a filter which counts
.getParent() // Get the counter of this mask .getParent() // Get the counter of this mask
.getTotal(); // Get the total from the counter .getTotal(); // Get the total from the counter
} }
@Override @Override
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block)
throws MaxChangedBlocksException {
apply(region, block); apply(region, block);
return getChanges(); return getChanges();
} }
@ -135,7 +134,8 @@ public class MultiThreadedQueue extends AbstractDelegateExtent implements IQueue
} }
@Override @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)); apply(region, mask.toFilter(pattern));
return getChanges(); return getChanges();
} }

Datei anzeigen

@ -12,7 +12,6 @@ import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.WorldWrapper; import com.boydti.fawe.wrappers.WorldWrapper;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -31,6 +30,7 @@ import java.util.function.Supplier;
* Class which handles all the queues {@link IQueueExtent} * Class which handles all the queues {@link IQueueExtent}
*/ */
public abstract class QueueHandler implements Trimable, Runnable { public abstract class QueueHandler implements Trimable, Runnable {
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool(); private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool(); private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor(); private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
@ -43,17 +43,16 @@ public abstract class QueueHandler implements Trimable, Runnable {
return create(); 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 last;
private long allocate = 50; private long allocate = 50;
private double targetTPS = 18; private double targetTPS = 18;
public QueueHandler() {
TaskManager.IMP.repeat(this, 1);
}
@Override @Override
public void run() { public void run() {
@ -63,7 +62,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
if (!syncTasks.isEmpty()) { if (!syncTasks.isEmpty()) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
targetTPS = 18 - Math.max(Settings.IMP.QUEUE.EXTRA_TIME_MS * 0.05, 0); 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); long absDiff = Math.abs(diff);
if (diff == 0) { if (diff == 0) {
allocate = Math.min(50, allocate + 1); allocate = Math.min(50, allocate + 1);
@ -105,7 +104,9 @@ public abstract class QueueHandler implements Trimable, Runnable {
} }
while (!syncTasks.isEmpty()) { while (!syncTasks.isEmpty()) {
final FutureTask task = syncTasks.poll(); 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 <T> Future<T> async(final Runnable run, final T value) { public <T> Future<T> async(Runnable run, T value) {
return forkJoinPoolSecondary.submit(run, value); return forkJoinPoolSecondary.submit(run, value);
} }
public Future<?> async(final Runnable run) { public Future<?> async(Runnable run) {
return forkJoinPoolSecondary.submit(run); return forkJoinPoolSecondary.submit(run);
} }
public <T> Future<T> async(final Callable<T> call) { public <T> Future<T> async(Callable<T> call) {
return forkJoinPoolSecondary.submit(call); return forkJoinPoolSecondary.submit(call);
} }
public ForkJoinTask submit(final Runnable call) { public ForkJoinTask submit(Runnable call) {
return forkJoinPoolPrimary.submit(call); return forkJoinPoolPrimary.submit(call);
} }
public <T> Future<T> sync(final Runnable run, final T value) { public <T> Future<T> sync(Runnable run, T value) {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
run.run(); run.run();
return Futures.immediateFuture(value); return Futures.immediateFuture(value);
@ -146,7 +147,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
return result; return result;
} }
public <T> Future<T> sync(final Runnable run) { public <T> Future<T> sync(Runnable run) {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
run.run(); run.run();
return Futures.immediateCancelledFuture(); return Futures.immediateCancelledFuture();
@ -157,7 +158,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
return result; return result;
} }
public <T> Future<T> sync(final Callable<T> call) throws Exception { public <T> Future<T> sync(Callable<T> call) throws Exception {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
return Futures.immediateFuture(call.call()); return Futures.immediateFuture(call.call());
} }
@ -167,7 +168,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
return result; return result;
} }
public <T> Future<T> sync(final Supplier<T> call) { public <T> Future<T> sync(Supplier<T> call) {
if (Fawe.isMainThread()) { if (Fawe.isMainThread()) {
return Futures.immediateFuture(call.get()); return Futures.immediateFuture(call.get());
} }
@ -183,7 +184,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
} }
} }
public <T extends Future<T>> T submit(final IChunk<T> chunk) { public <T extends Future<T>> T submit(IChunk<T> chunk) {
// if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this // if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this
// return (T) forkJoinPoolSecondary.submit(chunk); // return (T) forkJoinPoolSecondary.submit(chunk);
// } // }
@ -192,6 +193,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
/** /**
* Get or create the WorldChunkCache for a world * Get or create the WorldChunkCache for a world
*
* @param world * @param world
* @return * @return
*/ */
@ -218,17 +220,18 @@ public abstract class QueueHandler implements Trimable, Runnable {
public abstract void endSet(boolean parallel); public abstract void endSet(boolean parallel);
public IQueueExtent getQueue(final World world) { public IQueueExtent getQueue(World world) {
final IQueueExtent queue = queuePool.get(); final IQueueExtent queue = queuePool.get();
queue.init(getOrCreate(world)); queue.init(getOrCreate(world));
return queue; return queue;
} }
@Override @Override
public boolean trim(final boolean aggressive) { public boolean trim(boolean aggressive) {
boolean result = true; boolean result = true;
synchronized (chunkCache) { synchronized (chunkCache) {
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache.entrySet().iterator(); final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache
.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next(); final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next();
final WeakReference<WorldChunkCache> value = entry.getValue(); final WeakReference<WorldChunkCache> value = entry.getValue();

Datei anzeigen

@ -2,9 +2,9 @@ package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.CharFilterBlock; import com.boydti.fawe.beta.CharFilterBlock;
import com.boydti.fawe.beta.ChunkFilterBlock; import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.FilterBlock;
public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent { public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent {
@Override @Override
public ChunkFilterBlock initFilterBlock() { public ChunkFilterBlock initFilterBlock() {
return new CharFilterBlock(this); return new CharFilterBlock(this);

Datei anzeigen

@ -0,0 +1,27 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
/**
* Raised when a world is missing but is required.
*/
public class MissingWorldException extends WorldEditException {
}

Datei anzeigen

@ -0,0 +1,51 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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) {
}
}

Datei anzeigen

@ -0,0 +1,69 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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();
}