mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
parent
e0bb1ce853
commit
8e97b3b4b1
@ -7,6 +7,7 @@ import com.boydti.fawe.object.RegionWrapper;
|
|||||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||||
import com.boydti.fawe.object.changeset.SimpleChangeSetSummary;
|
import com.boydti.fawe.object.changeset.SimpleChangeSetSummary;
|
||||||
import com.boydti.fawe.object.exception.FaweException;
|
import com.boydti.fawe.object.exception.FaweException;
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.boydti.fawe.regions.FaweMaskManager;
|
import com.boydti.fawe.regions.FaweMaskManager;
|
||||||
import com.boydti.fawe.util.EditSessionBuilder;
|
import com.boydti.fawe.util.EditSessionBuilder;
|
||||||
import com.boydti.fawe.util.MainUtil;
|
import com.boydti.fawe.util.MainUtil;
|
||||||
@ -113,6 +114,27 @@ public class FaweAPI {
|
|||||||
// return parser != null;
|
// return parser != null;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public static <T> T getParser(Class<T> parserClass) {
|
||||||
|
try {
|
||||||
|
Field field = AbstractFactory.class.getDeclaredField("parsers");
|
||||||
|
field.setAccessible(true);
|
||||||
|
ArrayList<InputParser> parsers = new ArrayList<>();
|
||||||
|
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getMaskFactory()));
|
||||||
|
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getBlockFactory()));
|
||||||
|
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getItemFactory()));
|
||||||
|
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getPatternFactory()));
|
||||||
|
for (InputParser parser : parsers) {
|
||||||
|
if (parserClass.isAssignableFrom(parser.getClass())) {
|
||||||
|
return (T) parser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can either use a IQueueExtent or an EditSession to change blocks<br>
|
* You can either use a IQueueExtent or an EditSession to change blocks<br>
|
||||||
* - The IQueueExtent skips a bit of overhead so it's marginally faster<br>
|
* - The IQueueExtent skips a bit of overhead so it's marginally faster<br>
|
||||||
@ -377,30 +399,30 @@ public class FaweAPI {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int fixLighting(World world, Region selection, @Nullable IQueueExtent queue) {
|
public static int fixLighting(World world, Region selection, @Nullable IQueueExtent queue) {
|
||||||
// final BlockVector3 bot = selection.getMinimumPoint();
|
final BlockVector3 bot = selection.getMinimumPoint();
|
||||||
// final BlockVector3 top = selection.getMaximumPoint();
|
final BlockVector3 top = selection.getMaximumPoint();
|
||||||
//
|
|
||||||
// final int minX = bot.getBlockX() >> 4;
|
final int minX = bot.getBlockX() >> 4;
|
||||||
// final int minZ = bot.getBlockZ() >> 4;
|
final int minZ = bot.getBlockZ() >> 4;
|
||||||
//
|
|
||||||
// final int maxX = top.getBlockX() >> 4;
|
final int maxX = top.getBlockX() >> 4;
|
||||||
// final int maxZ = top.getBlockZ() >> 4;
|
final int maxZ = top.getBlockZ() >> 4;
|
||||||
//
|
|
||||||
// int count = 0;
|
int count = 0;
|
||||||
// if (queue == null) queue = createQueue(world, false);
|
if (queue == null) queue = createQueue(world, false);
|
||||||
// // Remove existing lighting first
|
// Remove existing lighting first
|
||||||
// if (queue instanceof LightingExtent) {
|
if (queue instanceof LightingExtent) {
|
||||||
// LightingExtent relighter = (LightingExtent) queue;
|
LightingExtent relighter = (LightingExtent) queue;
|
||||||
// for (int x = minX; x <= maxX; x++) {
|
for (int x = minX; x <= maxX; x++) {
|
||||||
// for (int z = minZ; z <= maxZ; z++) {
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
// relighter.relightChunk(x, z);
|
relighter.relightChunk(x, z);
|
||||||
// count++;
|
count++;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// throw new UnsupportedOperationException("Queue is not " + LightingExtent.class);
|
throw new UnsupportedOperationException("Queue is not " + LightingExtent.class);
|
||||||
// }
|
}
|
||||||
return 0;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,25 +1,48 @@
|
|||||||
package com.boydti.fawe.database
|
package com.boydti.fawe.database;
|
||||||
|
|
||||||
import com.boydti.fawe.config.Config
|
import com.boydti.fawe.config.Config;
|
||||||
import com.sk89q.worldedit.world.World
|
import com.sk89q.worldedit.world.World;
|
||||||
import org.slf4j.LoggerFactory
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
object DBHandler {
|
public class DBHandler {
|
||||||
private val log = LoggerFactory.getLogger(Config::class.java)
|
|
||||||
private val databases: MutableMap<String, RollbackDatabase> = ConcurrentHashMap(8, 0.9f, 1)
|
private final Logger log = LoggerFactory.getLogger(Config.class);
|
||||||
fun getDatabase(world: World): RollbackDatabase? {
|
|
||||||
val worldName = world.name
|
public final static DBHandler IMP = new DBHandler();
|
||||||
var database = databases[worldName]
|
|
||||||
return database
|
private Map<String, RollbackDatabase> databases = new ConcurrentHashMap<>(8, 0.9f, 1);
|
||||||
?: try {
|
|
||||||
database = RollbackDatabase(world)
|
public RollbackDatabase getDatabase(World world) {
|
||||||
databases[worldName] = database
|
String worldName = world.getName();
|
||||||
database
|
RollbackDatabase database = databases.get(worldName);
|
||||||
} catch (e: Throwable) {
|
if (database != null) {
|
||||||
log.error("No JDBC driver found!\n TODO: Bundle driver with FAWE (or disable database)", e)
|
return database;
|
||||||
null
|
}
|
||||||
}
|
try {
|
||||||
|
database = new RollbackDatabase(world);
|
||||||
|
databases.put(worldName, database);
|
||||||
|
return database;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("No JDBC driver found!\n TODO: Bundle driver with FAWE (or disable database)", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RollbackDatabase getDatabase(String world) {
|
||||||
|
RollbackDatabase database = databases.get(world);
|
||||||
|
if (database != null) {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
database = new RollbackDatabase(world);
|
||||||
|
databases.put(world, database);
|
||||||
|
return database;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.boydti.fawe.database;
|
package com.boydti.fawe.database;
|
||||||
|
|
||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
|
import com.boydti.fawe.FaweAPI;
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
||||||
import com.boydti.fawe.object.collection.YieldIterable;
|
import com.boydti.fawe.object.collection.YieldIterable;
|
||||||
@ -39,22 +40,26 @@ public class RollbackDatabase extends AsyncNotifyQueue {
|
|||||||
private final World world;
|
private final World world;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
private @Language("SQLite") String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `{0}edits` (`player` BLOB(16) NOT NULL,`id` INT NOT NULL, `time` INT NOT NULL,`x1` INT NOT NULL,`x2` INT NOT NULL,`z1` INT NOT NULL,`z2` INT NOT NULL,`y1` INT NOT NULL, `y2` INT NOT NULL, `size` INT NOT NULL, `command` VARCHAR, PRIMARY KEY (player, id))";
|
private @Language("sql") String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `{0}edits` (`player` BLOB(16) NOT NULL,`id` INT NOT NULL, `time` INT NOT NULL,`x1` INT NOT NULL,`x2` INT NOT NULL,`z1` INT NOT NULL,`z2` INT NOT NULL,`y1` INT NOT NULL, `y2` INT NOT NULL, `size` INT NOT NULL, `command` VARCHAR, PRIMARY KEY (player, id))";
|
||||||
private @Language("SQLite") String UPDATE_TABLE1 = "ALTER TABLE `{0}edits` ADD COLUMN `command` VARCHAR";
|
private @Language("sql") String UPDATE_TABLE1 = "ALTER TABLE `{0}edits` ADD COLUMN `command` VARCHAR";
|
||||||
private @Language("SQLite") String UPDATE_TABLE2 = "alter table `{0}edits` add size int default 0 not null";
|
private @Language("sql") String UPDATE_TABLE2 = "alter table `{0}edits` add size int default 0 not null";
|
||||||
private @Language("SQLite") String INSERT_EDIT = "INSERT OR REPLACE INTO `{0}edits` (`player`,`id`,`time`,`x1`,`x2`,`z1`,`z2`,`y1`,`y2`,`command`,`size`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
private @Language("sql") String INSERT_EDIT = "INSERT OR REPLACE INTO `{0}edits` (`player`,`id`,`time`,`x1`,`x2`,`z1`,`z2`,`y1`,`y2`,`command`,`size`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||||
private @Language("SQLite") String PURGE = "DELETE FROM `{0}edits` WHERE `time`<?";
|
private @Language("sql") String PURGE = "DELETE FROM `{0}edits` WHERE `time`<?";
|
||||||
private @Language("SQLite") String GET_EDITS_USER = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC";
|
private @Language("sql") String GET_EDITS_USER = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC";
|
||||||
private @Language("SQLite") String GET_EDITS_USER_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC";
|
private @Language("sql") String GET_EDITS_USER_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC";
|
||||||
private @Language("SQLite") String GET_EDITS = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` DESC, `id` DESC";
|
private @Language("sql") String GET_EDITS = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` DESC, `id` DESC";
|
||||||
private @Language("SQLite") String GET_EDITS_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` , `id` ";
|
private @Language("sql") String GET_EDITS_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` , `id` ";
|
||||||
private @Language("SQLite") String GET_EDIT_USER = "SELECT * FROM `{0}edits` WHERE `player`=? AND `id`=?";
|
private @Language("sql") String GET_EDIT_USER = "SELECT * FROM `{0}edits` WHERE `player`=? AND `id`=?";
|
||||||
|
|
||||||
private @Language("SQLite") String DELETE_EDITS_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?";
|
private @Language("sql") String DELETE_EDITS_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?";
|
||||||
private @Language("SQLite") String DELETE_EDIT_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `id`=?";
|
private @Language("sql") String DELETE_EDIT_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `id`=?";
|
||||||
|
|
||||||
private ConcurrentLinkedQueue<RollbackOptimizedHistory> historyChanges = new ConcurrentLinkedQueue<>();
|
private ConcurrentLinkedQueue<RollbackOptimizedHistory> historyChanges = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
|
public RollbackDatabase(String world) throws SQLException, ClassNotFoundException {
|
||||||
|
this(FaweAPI.getWorld(world));
|
||||||
|
}
|
||||||
|
|
||||||
public RollbackDatabase(World world) throws SQLException, ClassNotFoundException {
|
public RollbackDatabase(World world) throws SQLException, ClassNotFoundException {
|
||||||
super((t, e) -> e.printStackTrace());
|
super((t, e) -> e.printStackTrace());
|
||||||
this.prefix = "";
|
this.prefix = "";
|
||||||
|
@ -96,7 +96,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
|
|||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
super.close();
|
super.close();
|
||||||
// Save to DB
|
// Save to DB
|
||||||
RollbackDatabase db = DBHandler.INSTANCE.getDatabase(getWorld());
|
RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld());
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
db.logEdit(this);
|
db.logEdit(this);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
|
|||||||
final int y = target.getBlockY();
|
final int y = target.getBlockY();
|
||||||
final int z = target.getBlockZ();
|
final int z = target.getBlockZ();
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
RollbackDatabase db = DBHandler.INSTANCE.getDatabase(world);
|
RollbackDatabase db = DBHandler.IMP.getDatabase(world);
|
||||||
System.out.println("World " + world.getName());
|
System.out.println("World " + world.getName());
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
|
for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
|
||||||
|
@ -121,9 +121,10 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
// Fawe.debug("Deleting history: " + getWorld().getName() + "/" + uuid + "/" + index);
|
||||||
deleteFiles();
|
deleteFiles();
|
||||||
if (Settings.IMP.HISTORY.USE_DATABASE) {
|
if (Settings.IMP.HISTORY.USE_DATABASE) {
|
||||||
RollbackDatabase db = DBHandler.INSTANCE.getDatabase(getWorld());
|
RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld());
|
||||||
db.delete(uuid, index);
|
db.delete(uuid, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,61 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc
|
|||||||
return super.getBlock(position);
|
return super.getBlock(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBlockLight(int x, int y, int z) {
|
||||||
|
if (!contains(x, y, z)) {
|
||||||
|
if (!limit.MAX_FAILS()) {
|
||||||
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.getBlockLight(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBrightness(int x, int y, int z) {
|
||||||
|
if (!contains(x, y, z)) {
|
||||||
|
if (!limit.MAX_FAILS()) {
|
||||||
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.getBrightness(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLight(int x, int y, int z) {
|
||||||
|
if (!contains(x, y, z)) {
|
||||||
|
if (!limit.MAX_FAILS()) {
|
||||||
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.getLight(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOpacity(int x, int y, int z) {
|
||||||
|
if (!contains(x, y, z)) {
|
||||||
|
if (!limit.MAX_FAILS()) {
|
||||||
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.getOpacity(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSkyLight(int x, int y, int z) {
|
||||||
|
if (!contains(x, y, z)) {
|
||||||
|
if (!limit.MAX_FAILS()) {
|
||||||
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return super.getSkyLight(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Entity createEntity(Location location, BaseEntity entity) {
|
public Entity createEntity(Location location, BaseEntity entity) {
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.boydti.fawe.object.extent;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
|
||||||
|
public interface LightingExtent extends Extent {
|
||||||
|
int getLight(int x, int y, int z);
|
||||||
|
|
||||||
|
int getSkyLight(int x, int y, int z);
|
||||||
|
|
||||||
|
int getBlockLight(int x, int y, int z);
|
||||||
|
|
||||||
|
int getOpacity(int x, int y, int z);
|
||||||
|
|
||||||
|
int getBrightness(int x, int y, int z);
|
||||||
|
|
||||||
|
public void relightChunk(int chunkX, int chunkZ);
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.object.mask;
|
package com.boydti.fawe.object.mask;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -16,10 +17,10 @@ public class BlockLightMask extends AbstractExtentMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
// if (extent instanceof LightingExtent) {
|
if (extent instanceof LightingExtent) {
|
||||||
// int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||||
// return light >= min && light <= max;
|
return light >= min && light <= max;
|
||||||
// }
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.object.mask;
|
package com.boydti.fawe.object.mask;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -16,10 +17,10 @@ public class BrightnessMask extends AbstractExtentMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
// if (extent instanceof LightingExtent) {
|
if (extent instanceof LightingExtent) {
|
||||||
// int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||||
// return light >= min && light <= max;
|
return light >= min && light <= max;
|
||||||
// }
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.object.mask;
|
package com.boydti.fawe.object.mask;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -16,10 +17,10 @@ public class LightMask extends AbstractExtentMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
// if (extent instanceof LightingExtent) {
|
if (extent instanceof LightingExtent) {
|
||||||
// int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||||
// return light >= min && light <= max;
|
return light >= min && light <= max;
|
||||||
// }
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.object.mask;
|
package com.boydti.fawe.object.mask;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -16,10 +17,10 @@ public class OpacityMask extends AbstractExtentMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
// if (extent instanceof LightingExtent) {
|
if (extent instanceof LightingExtent) {
|
||||||
// int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||||
// return light >= min && light <= max;
|
return light >= min && light <= max;
|
||||||
// }
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.object.mask;
|
package com.boydti.fawe.object.mask;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@ -17,11 +18,11 @@ public class SkyLightMask extends AbstractExtentMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
// if (extent instanceof LightingExtent) {
|
if (extent instanceof LightingExtent) {
|
||||||
// int light = ((LightingExtent) extent)
|
int light = ((LightingExtent) extent)
|
||||||
// .getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
.getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||||
// return light >= min && light <= max;
|
return light >= min && light <= max;
|
||||||
// }
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts the
|
||||||
|
*/
|
||||||
public class XAxisMask extends AbstractMask implements ResettableMask {
|
public class XAxisMask extends AbstractMask implements ResettableMask {
|
||||||
|
|
||||||
private transient int layer = -1;
|
private transient int layer = -1;
|
||||||
|
@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts the
|
||||||
|
*/
|
||||||
public class YAxisMask extends AbstractMask implements ResettableMask {
|
public class YAxisMask extends AbstractMask implements ResettableMask {
|
||||||
|
|
||||||
private transient int layer = -1;
|
private transient int layer = -1;
|
||||||
|
@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts the
|
||||||
|
*/
|
||||||
public class ZAxisMask extends AbstractMask implements ResettableMask {
|
public class ZAxisMask extends AbstractMask implements ResettableMask {
|
||||||
|
|
||||||
private transient int layer = -1;
|
private transient int layer = -1;
|
||||||
|
@ -12,6 +12,6 @@ public class ChatProgressTracker extends DefaultProgressTracker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendTile(Component title, Component sub) {
|
public void sendTile(Component title, Component sub) {
|
||||||
getPlayer().print(TextComponent.builder().append(title).append(TextComponent.newline()).append(sub).build());
|
getPlayer().print(TextComponent.builder().append(title).append("\n").append(sub).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,11 @@ import com.sk89q.worldedit.regions.AbstractRegion;
|
|||||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class FuzzyRegion extends AbstractRegion {
|
public class FuzzyRegion extends AbstractRegion {
|
||||||
|
|
||||||
private final Mask mask;
|
private final Mask mask;
|
||||||
private final BlockVectorSet set = new BlockVectorSet();
|
private BlockVectorSet set = new BlockVectorSet();
|
||||||
private int minX, minY, minZ, maxX, maxY, maxZ;
|
private int minX, minY, minZ, maxX, maxY, maxZ;
|
||||||
private Extent extent;
|
private Extent extent;
|
||||||
|
|
||||||
@ -45,22 +44,24 @@ public class FuzzyRegion extends AbstractRegion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void select(int x, int y, int z) {
|
public void select(int x, int y, int z) {
|
||||||
RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), p -> {
|
RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), new RegionFunction() {
|
||||||
setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ());
|
@Override
|
||||||
return true;
|
public boolean apply(BlockVector3 p) throws WorldEditException {
|
||||||
|
setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}, 256);
|
}, 256);
|
||||||
search.setVisited(set);
|
search.setVisited(set);
|
||||||
search.visit(BlockVector3.at(x, y, z));
|
search.visit(BlockVector3.at(x, y, z));
|
||||||
Operations.completeBlindly(search);
|
Operations.completeBlindly(search);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<BlockVector3> iterator() {
|
public Iterator<BlockVector3> iterator() {
|
||||||
return set.iterator();
|
return set.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMinMax(int x, int y, int z) {
|
private final void setMinMax(int x, int y, int z) {
|
||||||
if (x > maxX) {
|
if (x > maxX) {
|
||||||
maxX = x;
|
maxX = x;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ public class HistorySubCommands {
|
|||||||
BlockVector3
|
BlockVector3
|
||||||
.at(summary.maxX, 255, summary.maxZ));
|
.at(summary.maxX, 255, summary.maxZ));
|
||||||
rollback.setTime(historyFile.lastModified());
|
rollback.setTime(historyFile.lastModified());
|
||||||
RollbackDatabase db = DBHandler.INSTANCE
|
RollbackDatabase db = DBHandler.IMP
|
||||||
.getDatabase(world);
|
.getDatabase(world);
|
||||||
db.logEdit(rollback);
|
db.logEdit(rollback);
|
||||||
actor.print("Logging: " + historyFile);
|
actor.print("Logging: " + historyFile);
|
||||||
|
@ -81,7 +81,7 @@ public class ProvideBindings extends Bindings {
|
|||||||
|
|
||||||
@Binding
|
@Binding
|
||||||
public RollbackDatabase database(World world) {
|
public RollbackDatabase database(World world) {
|
||||||
return DBHandler.INSTANCE.getDatabase(world);
|
return DBHandler.IMP.getDatabase(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AllowedRegion(FaweMaskManager.MaskType.OWNER)
|
@AllowedRegion(FaweMaskManager.MaskType.OWNER)
|
||||||
|
@ -26,6 +26,7 @@ import com.boydti.fawe.beta.IBatchProcessor;
|
|||||||
import com.boydti.fawe.object.HistoryExtent;
|
import com.boydti.fawe.object.HistoryExtent;
|
||||||
import com.boydti.fawe.object.changeset.AbstractChangeSet;
|
import com.boydti.fawe.object.changeset.AbstractChangeSet;
|
||||||
import com.boydti.fawe.object.exception.FaweException;
|
import com.boydti.fawe.object.exception.FaweException;
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.boydti.fawe.util.ExtentTraverser;
|
import com.boydti.fawe.util.ExtentTraverser;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
@ -51,7 +52,7 @@ import org.jetbrains.annotations.Range;
|
|||||||
/**
|
/**
|
||||||
* A base class for {@link Extent}s that merely passes extents onto another.
|
* A base class for {@link Extent}s that merely passes extents onto another.
|
||||||
*/
|
*/
|
||||||
public class AbstractDelegateExtent implements Extent {
|
public class AbstractDelegateExtent implements Extent, LightingExtent {
|
||||||
|
|
||||||
private final Extent extent;
|
private final Extent extent;
|
||||||
|
|
||||||
@ -200,6 +201,54 @@ public class AbstractDelegateExtent implements Extent {
|
|||||||
return extent.setBiome(position.getX(), 0, position.getZ(), biome);
|
return extent.setBiome(position.getX(), 0, position.getZ(), biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSkyLight(int x, int y, int z) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
return ((LightingExtent) extent).getSkyLight(x, y, z);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBlockLight(int x, int y, int z) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
return ((LightingExtent) extent).getBlockLight(x, y, z);
|
||||||
|
}
|
||||||
|
return getBrightness(x, y, z);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getOpacity(int x, int y, int z) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
return ((LightingExtent) extent).getOpacity(x, y, z);
|
||||||
|
}
|
||||||
|
return getBlock(x, y, z).getBlockType().getMaterial().getLightOpacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLight(int x, int y, int z) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
return ((LightingExtent) extent).getLight(x, y, z);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBrightness(int x, int y, int z) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
return ((LightingExtent) extent).getBrightness(x, y, z);
|
||||||
|
}
|
||||||
|
return getBlock(x, y, z).getBlockType().getMaterial().getLightValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void relightChunk(int chunkX, int chunkZ) {
|
||||||
|
if (extent instanceof LightingExtent) {
|
||||||
|
((LightingExtent) extent).relightChunk(chunkX, chunkZ);
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException("Cannot relight");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + ":" + (extent == this ? "" : extent.toString());
|
return super.toString() + ":" + (extent == this ? "" : extent.toString());
|
||||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.world;
|
|||||||
import com.boydti.fawe.beta.IChunkGet;
|
import com.boydti.fawe.beta.IChunkGet;
|
||||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||||
import com.boydti.fawe.beta.IChunkCache;
|
import com.boydti.fawe.beta.IChunkCache;
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
@ -133,6 +134,10 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
|
|||||||
* @return the light level (0-15)
|
* @return the light level (0-15)
|
||||||
*/
|
*/
|
||||||
default int getBlockLightLevel(BlockVector3 position) {
|
default int getBlockLightLevel(BlockVector3 position) {
|
||||||
|
if (this instanceof LightingExtent) {
|
||||||
|
LightingExtent extent = (LightingExtent) this;
|
||||||
|
return extent.getBlockLight(position.getX(), position.getY(), position.getZ());
|
||||||
|
}
|
||||||
return getBlock(position).getMaterial().getLightValue();
|
return getBlock(position).getMaterial().getLightValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user