From e4b1cc376b3889551acbfd2eddd0ea1f3d23a6a6 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 21 Jun 2016 20:35:09 +1000 Subject: [PATCH] Document some stuff --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 6 +- .../fawe/bukkit/v0/BukkitChunk_All.java | 3 +- .../fawe/bukkit/v0/BukkitQueue_All.java | 6 +- .../boydti/fawe/bukkit/v0/ChunkListener.java | 4 +- .../com/thevoxelbox/voxelsniper/Sniper.java | 4 +- core/src/main/java/com/boydti/fawe/Fawe.java | 18 +- .../main/java/com/boydti/fawe/FaweAPI.java | 2 +- .../java/com/boydti/fawe/config/Config.java | 7 +- .../java/com/boydti/fawe/config/Settings.java | 357 ++++++++++-------- .../boydti/fawe/example/MappedFaweQueue.java | 4 +- .../fawe/example/NMSMappedFaweQueue.java | 4 +- .../com/boydti/fawe/object/FaweChunk.java | 2 +- .../com/boydti/fawe/object/FaweLimit.java | 12 +- .../com/boydti/fawe/object/FawePlayer.java | 4 +- .../com/boydti/fawe/object/FaweQueue.java | 3 +- .../object/changeset/DiskStorageHistory.java | 75 ++-- .../object/changeset/FaweStreamChangeSet.java | 2 +- .../changeset/MemoryOptimizedHistory.java | 10 +- .../clipboard/DiskOptimizedClipboard.java | 4 +- .../progress/DefaultProgressTracker.java | 2 +- .../fawe/object/schematic/FaweFormat.java | 2 +- .../java/com/boydti/fawe/util/MainUtil.java | 16 +- .../java/com/boydti/fawe/util/MemUtil.java | 2 +- .../java/com/boydti/fawe/util/SetQueue.java | 30 +- .../com/boydti/fawe/util/TaskManager.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 16 +- .../com/sk89q/worldedit/LocalSession.java | 2 +- .../worldedit/command/SchematicCommands.java | 2 +- .../extent/clipboard/BlockArrayClipboard.java | 4 +- .../sk89q/worldedit/regions/CuboidRegion.java | 2 +- 30 files changed, 331 insertions(+), 276 deletions(-) diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index ef1ba078..4281455b 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -195,8 +195,8 @@ public class FaweBukkit implements IFawe, Listener { // ignore.printStackTrace(); } // Disable incompatible settings - Settings.PARALLEL_THREADS = 1; // BukkitAPI placer is too slow to parallel thread at the chunk level - Settings.COMBINE_HISTORY_STAGE = false; // Performing a chunk copy (if possible) wouldn't be faster using the BukkitAPI + Settings.QUEUE.PARALLEL_THREADS = 1; // BukkitAPI placer is too slow to parallel thread at the chunk level + Settings.HISTORY.COMBINE_STAGES = false; // Performing a chunk copy (if possible) wouldn't be faster using the BukkitAPI if (hasNMS) { debug("====== NO NMS BLOCK PLACER FOUND ======"); debug("FAWE couldn't find a fast block placer"); @@ -321,7 +321,7 @@ public class FaweBukkit implements IFawe, Listener { public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); FawePlayer fp = FawePlayer.wrap(player); - if (Settings.STORE_HISTORY_ON_DISK) { + if (Settings.HISTORY.USE_DISK) { fp.getSession().clearHistory(); fp.loadSessionsFromDisk(fp.getWorld()); } diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java index e6e60784..b1cfcabb 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java @@ -1,7 +1,6 @@ package com.boydti.fawe.bukkit.v0; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.config.Settings; import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; @@ -108,7 +107,7 @@ public class BukkitChunk_All extends CharFaweChunk { continue; } boolean checkTime = !((getAir(layer) == 4096 || (getCount(layer) == 4096 && getAir(layer) == 0) || (getCount(layer) == getAir(layer))) && getRelight(layer) == 0); - if (!checkTime || Settings.PARALLEL_THREADS > 1) { + if (!checkTime) { ArrayList threads = new ArrayList(); for (int k = 0; k < 16; k++) { final int l = k << 8; diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index d27f79b9..af38c44b 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -17,9 +17,9 @@ public class BukkitQueue_All extends BukkitQueue_0 { public BukkitQueue_All(String world) { super(world); - if (Settings.ALLOCATE != Integer.MIN_VALUE) { - ALLOCATE = Settings.ALLOCATE; - Settings.ALLOCATE = Integer.MIN_VALUE; + if (Settings.QUEUE.EXTRA_TIME_MS != Integer.MIN_VALUE) { + ALLOCATE = Settings.QUEUE.EXTRA_TIME_MS; + Settings.QUEUE.EXTRA_TIME_MS = Integer.MIN_VALUE; } } diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java index b0579ceb..eedf4270 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java @@ -18,8 +18,8 @@ public class ChunkListener implements Listener { @Override public void run() { physicsFreeze = false; - physicsLimit = Settings.PHYSICS_PER_TICK; - itemLimit = Settings.ITEMS_PER_TICK; + physicsLimit = Settings.TICK_LIMITER.PHYSICS; + itemLimit = Settings.TICK_LIMITER.PHYSICS; } }, 1); } diff --git a/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java b/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java index 8d209af8..a0406e5e 100644 --- a/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java +++ b/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java @@ -94,7 +94,7 @@ public class Sniper { RegionWrapper[] mask = WEManager.IMP.getMask(fp); this.maskQueue = new MaskedFaweQueue(baseQueue, mask); com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); - FaweStreamChangeSet changeSet = Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(worldEditWorld, fp.getUUID()) : new MemoryOptimizedHistory(worldEditWorld); + FaweStreamChangeSet changeSet = Settings.HISTORY.USE_DISK ? new DiskStorageHistory(worldEditWorld, fp.getUUID()) : new MemoryOptimizedHistory(worldEditWorld); this.changeQueue = new ChangeSetFaweQueue(changeSet, maskQueue); tmpWorld = new AsyncWorld(player.getWorld(), changeQueue); } @@ -403,7 +403,7 @@ public class Sniper { session.remember(changeSet.toEditSession(fp)); changeQueue.flush(); com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); - changeQueue.setChangeSet(Settings.STORE_HISTORY_ON_DISK ? new DiskStorageHistory(worldEditWorld, fp.getUUID()) : new MemoryOptimizedHistory(worldEditWorld)); + changeQueue.setChangeSet(Settings.HISTORY.USE_DISK ? new DiskStorageHistory(worldEditWorld, fp.getUUID()) : new MemoryOptimizedHistory(worldEditWorld)); } } diff --git a/core/src/main/java/com/boydti/fawe/Fawe.java b/core/src/main/java/com/boydti/fawe/Fawe.java index 71c8d5ba..2cf07063 100644 --- a/core/src/main/java/com/boydti/fawe/Fawe.java +++ b/core/src/main/java/com/boydti/fawe/Fawe.java @@ -175,8 +175,8 @@ public class Fawe { * Implementation dependent stuff */ this.setupConfigs(); - MainUtil.deleteOlder(new File(IMP.getDirectory(), "history"), TimeUnit.DAYS.toMillis(Settings.DELETE_HISTORY_AFTER_DAYS)); - MainUtil.deleteOlder(new File(IMP.getDirectory(), "clipboard"), TimeUnit.DAYS.toMillis(Settings.DELETE_CLIPBOARD_AFTER_DAYS)); + MainUtil.deleteOlder(new File(IMP.getDirectory(), "history"), TimeUnit.DAYS.toMillis(Settings.HISTORY.DELETE_AFTER_DAYS)); + MainUtil.deleteOlder(new File(IMP.getDirectory(), "clipboard"), TimeUnit.DAYS.toMillis(Settings.CLIPBOARD.DELETE_AFTER_DAYS)); TaskManager.IMP = this.IMP.getTaskManager(); TaskManager.IMP.repeat(timer = new FaweTimer(), 50); @@ -228,7 +228,9 @@ public class Fawe { public void setupConfigs() { // Setting up config.yml - Settings.setup(new File(this.IMP.getDirectory(), "config.yml")); + File file = new File(this.IMP.getDirectory(), "config.yml"); + Settings.load(file); + Settings.save(file); // Setting up message.yml BBC.load(new File(this.IMP.getDirectory(), "message.yml")); // Block rotation @@ -238,10 +240,10 @@ public class Fawe { MainUtil.handleError(e); } File jar = MainUtil.getJarFile(); - File file = MainUtil.copyFile(jar, "extrablocks.json", null); - if (file != null && file.exists()) { + File extraBlocks = MainUtil.copyFile(jar, "extrablocks.json", null); + if (extraBlocks != null && extraBlocks.exists()) { try { - BundledBlockData.getInstance().add(file.toURI().toURL(), false); + BundledBlockData.getInstance().add(extraBlocks.toURI().toURL(), false); } catch (Throwable ignore) {} } } @@ -371,7 +373,7 @@ public class Fawe { } private void setupMemoryListener() { - if (Settings.MEM_FREE < 1) { + if (Settings.MAX_MEMORY_PERCENT < 1) { return; } try { @@ -393,7 +395,7 @@ public class Fawe { if (max < 0) { continue; } - final long alert = (max * Settings.MEM_FREE) / 100; + final long alert = (max * Settings.MAX_MEMORY_PERCENT) / 100; mp.setUsageThreshold(alert); } diff --git a/core/src/main/java/com/boydti/fawe/FaweAPI.java b/core/src/main/java/com/boydti/fawe/FaweAPI.java index a47a3807..309601ec 100644 --- a/core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -214,7 +214,7 @@ public class FaweAPI { if (!file.getName().toLowerCase().endsWith(".bd")) { throw new IllegalArgumentException("Not a BD file!"); } - if (Settings.STORE_HISTORY_ON_DISK) { + if (Settings.HISTORY.USE_DISK) { throw new IllegalArgumentException("History on disk not enabled!"); } String[] path = file.getPath().split(File.separator); diff --git a/core/src/main/java/com/boydti/fawe/config/Config.java b/core/src/main/java/com/boydti/fawe/config/Config.java index a75e736e..eb45f632 100644 --- a/core/src/main/java/com/boydti/fawe/config/Config.java +++ b/core/src/main/java/com/boydti/fawe/config/Config.java @@ -64,14 +64,17 @@ public class Config { if (field.getAnnotation(Final.class) != null) { return; } + if (field.getType() == String.class && !(value instanceof String)) { + value = value + ""; + } field.set(instance, value); return; - } catch (IllegalAccessException e) { + } catch (Throwable e) { e.printStackTrace(); } } } - Fawe.debug("Failed to set config option: " + key + ": " + value + " | " + instance); + Fawe.debug("Failed to set config option: " + key + ": " + value + " | " + instance + " | " + root.getSimpleName() + ".yml"); } public static boolean load(File file, Class root) { diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index 9c985733..242f74ec 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -1,67 +1,227 @@ package com.boydti.fawe.config; -import com.boydti.fawe.configuration.file.YamlConfiguration; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FawePlayer; -import com.boydti.fawe.util.MainUtil; import java.io.File; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -public class Settings { +public class Settings extends Config { - public static long MEM_FREE = 95; - public static boolean ENABLE_HARD_LIMIT = true; - public static boolean STORE_HISTORY_ON_DISK = false; - public static boolean STORE_CLIPBOARD_ON_DISK = false; - public static boolean CONSOLE_HISTORY = true; - public static int DELETE_HISTORY_AFTER_DAYS = 7; - public static boolean CLEAN_HISTORY_ON_LOGOUT = true; - public static int DELETE_CLIPBOARD_AFTER_DAYS = 1; + @Comment("These first 4 aren't configurable") // This is a comment + @Final // Indicates that this value isn't configurable + public static final String ISSUES = "https://github.com/boy0001/FastAsyncWorldedit/issues"; + @Final + public static final String WIKI = "https://github.com/boy0001/FastAsyncWorldedit/wiki/"; + @Final + public static String VERSION = null; // These values are set from PS before loading + @Final + public static String PLATFORM = null; // These values are set from PS before loading + + @Comment("Send anonymous usage statistics to MCStats.org") public static boolean METRICS = true; - public static int CHUNK_WAIT = 100; + @Comment("If fawe should try to prevent server crashes") + public static boolean CRASH_MITIGATION = true; + @Comment({ + "Set true to enable WorldEdit restrictions per region (e.g. PlotSquared or WorldGuard).", + "To be allowed to WorldEdit in a region, users need the appropriate", + "fawe. permission. See the Permissions page for supported region plugins." + }) public static boolean REGION_RESTRICTIONS = true; - public static int ALLOCATE = 0; - public static int QUEUE_SIZE = 64; - public static int QUEUE_MAX_WAIT = 1000; - public static boolean DISPLAY_PROGRESS = false; - public static int DISPLAY_PROGRESS_INTERVAL = 1; - public static List ALLOWED_3RDPARTY_EXTENTS; - public static boolean EXTENT_DEBUG = true; - public static boolean FIX_ALL_LIGHTING = true; - public static boolean ASYNC_LIGHTING = true; - public static int PHYSICS_PER_TICK = 500000; - public static int ITEMS_PER_TICK = 50000; - public static String WEB_URL = "http://empcraft.com/fawe/"; + @Comment({ + "FAWE will start cancelling non-admin edits if used-memory % exceeds", + "this value. Effects anyone who doesn't have bypass enabled", + "(e.g. /wea , or fastmode //fast , or fawe.bypass permission )." + }) + public static int MAX_MEMORY_PERCENT = 95; - // Maybe confusing? - // - `compression: false` just uses cheaper compression, but still compresses - public static int COMPRESSION_LEVEL = 1; - public static boolean COMBINE_HISTORY_STAGE = false; - public static int PARALLEL_THREADS = 1; + @Create // This value will be generated automatically + public static ConfigBlock LIMITS = null; - // Non configurable (yet / shouldn't be?) - public static int BUFFER_SIZE = 531441; - public static int QUEUE_DISCARD_AFTER = 60000; + @Comment({ + "The \"default\" limit group affects those without a specific limit permission.", + "To grant someone different limits, copy the default limits group", + "and give it a different name (e.g. newbie). Then give the user the limit ", + "permission node with that limit name (e.g. fawe.limit.newbie )" + }) + @BlockName("default") // The name for the default block + public static final class LIMITS extends ConfigBlock { + @Comment("Max number of block changes (e.g. by `//set stone`).") + public int MAX_CHANGES = 50000000; + @Comment("Max number of blocks checked (e.g. `//count stone` which doesn't change blocks)") + public int MAX_CHECKS = 50000000; + @Comment("Number of times a change can fail (e.g. if the player can't access that region)") + public int MAX_FAILS = 50000000; + @Comment("Allowed brush iterations (e.g. `//brush smooth`)") + public int MAX_ITERATIONS = 1000; + @Comment("Max allowed entities (e.g. cows)") + public int MAX_ENTITIES = 1337; + @Comment({ + "Blockstates include Banner, Beacon, BrewingStand, Chest, CommandBlock, ", + "CreatureSpawner, Dispenser, Dropper, EndGateway, Furnace, Hopper, Jukebox, ", + "NoteBlock, Sign, Skull, Structure" + }) + public int MAX_BLOCKSTATES = 1337; + } - public static HashMap limits; + public static class HISTORY { + @Comment({ + "Should history be saved on disk:", + " - Frees up a lot of memory", + " - Persists restarts", + " - Unlimited undo", + " - Enables the rollback command" + }) + public static boolean USE_DISK = false; + @Comment({ + "Record history with dispatching:", + " - Faster as it avoids duplicate block checks", + " - Worse compression since dispatch order is different" + }) + public static boolean COMBINE_STAGES = false; + @Comment({ + "Higher compression reduces the size of history at the expense of CPU", + "0 = Uncompressed byte array", + "1 = 1 pass fast compressor (default)", + "2 = 2 x fast", + "3 = 3 x fast", + "4 = 1 x medium, 1 x fast", + "5 = 1 x medium, 2 x fast", + "6 = 1 x medium, 3 x fast", + "7 = 1 x high, 1 x medium, 1 x fast", + "8 = 1 x high, 1 x medium, 2 x fast", + "9 = 1 x high, 1 x medium, 3 x fast", + "NOTE: If using disk, do some compression as smaller files save faster" + }) + public static int COMPRESSION_LEVEL = 1; + @Comment({ + "The buffer size for compression:", + " - Larger = better ratio but uses more upfront memory" + }) + public static int BUFFER_SIZE = 531441; + + + @Comment({ + "The maximum time in milliseconds to wait for a chunk to load for an edit.", + " (50ms = 1 server tick, 0 = Fastest).", + " The default value of 100 should be safe for most cases.", + "", + "Actions which require loaded chunks (e.g. copy) which do not load in time", + " will use the last chunk as filler, which may appear as bands of duplicated blocks.", + "Actions usually wait about 25-50ms for the chunk to load, more if the server is lagging.", + "A value of 100ms does not force it to wait 100ms if the chunk loads in 10ms.", + "", + "This value is a timeout in case a chunk is never going to load (for whatever odd reason).", + "If the action times out, the operation continues by using the previous chunk as filler,", + " and displaying an error message. In this case, either copy a smaller section,", + " or increase chunk-wait-ms.", + "A value of 0 is faster simply because it doesn't bother loading the chunks or waiting.", + }) + public static int CHUNK_WAIT_MS = 100; + @Comment("Delete history on disk after a number of days") + public static int DELETE_AFTER_DAYS = 7; + @Comment("Delete history in memory on logout (does not effect disk)") + public static boolean DELETE_ON_LOGOUT = true; + @Comment({ + "If history should be enabled by default for plugins using WorldEdit:", + " - It is faster to have disabled", + " - Use of the FAWE API will not be effected" + }) + public static boolean ENABLE_FOR_CONSOLE = true; + } + + public static class QUEUE { + @Comment({ + "If no blocks from completed edits are queued, and if the global queue has more available ", + "chunks to place from still-processing edits than the target size setting, it will begin", + "placing available blocks from edits still in the preprocessing stage." + }) + public static int TARGET_SIZE = 64; + @Comment({ + "This should equal the number of processors you have" + }) + public static int PARALLEL_THREADS = Math.max(1, Runtime.getRuntime().availableProcessors()); + @Comment({ + "The time in milliseconds that the global queue can be idle before it is forced to start", + "on edits which are still in the preprocessing stage." + }) + public static int MAX_WAIT_MS = 1000; + + @Comment({ + "Increase or decrease queue intensity (0 = balance of performance / stability)", + "Should not need to change this. Increasing it (positive value) too high ", + "will probably cause the server to freeze, and decreasing it (negative value)", + "may reduce load on the server but should not be necessary." + }) + public static int EXTRA_TIME_MS = 0; + + @Comment({ + "Discard edits which have been idle for a certain amount of time (ms) (e.g. a plugin creates", + "an EditSession but never does anything with it)." + }) + public static int DISCARD_AFTER_MS = 60000; + + public static class PROGRESS { + @Comment("Display constant titles about the progress of a user's edit") + public static boolean DISPLAY = false; + @Comment("How often edit progress is displayed") + public static int INTERVAL = 1; + } + } + + public static class WEB { + @Comment("I am already hosting a web interface for you here") + public static String URL = "http://empcraft.com/fawe/"; + } + + public static class EXTENT { + @Comment({ + "Don't bug console when these plugins slow down WorldEdit operations" + }) + public static List ALLOWED_PLUGINS = new ArrayList<>(); + @Comment("Disable the messages completely") + public static boolean DEBUG = true; + } + + @Comment("Generic tick limiter (not necessarily WorldEdit related, but still useful)") + public static class TICK_LIMITER { + @Comment("Max physics per tick") + public static int PHYSICS = 500000; + @Comment("Max item spawns per tick") + public static int ITEMS = 50000; + } + + public static class CLIPBOARD { + public static boolean USE_DISK = false; + + public static int DELETE_AFTER_DAYS = 1; + } + + public static class LIGHTING { + @Comment("If chunk lighting should be done asynchronously") + public static boolean ASYNC = true; + @Comment("If all lighting should be fixed in a chunk that is edited") + public static boolean FIX_ALL = true; + } + + public static void save(File file) { + save(file, Settings.class); + } + + public static void load(File file) { + load(file, Settings.class); + } public static FaweLimit getLimit(FawePlayer player) { + if (player.hasWorldEditBypass()) { + return FaweLimit.MAX.copy(); + } FaweLimit limit = new FaweLimit(); - limit.MAX_CHANGES = 0; - limit.MAX_FAILS = 0; - limit.MAX_CHECKS = 0; - limit.MAX_ENTITIES = 0; - limit.MAX_BLOCKSTATES = 0; - limit.MAX_ITERATIONS = 0; - for (Entry entry : limits.entrySet()) { - String key = entry.getKey(); + Collection keys = LIMITS.getSections(); + for (String key : keys) { if (key.equals("default") || (player != null && player.hasPermission("fawe.limit." + key))) { - FaweLimit newLimit = entry.getValue(); + LIMITS newLimit = LIMITS.get(key); limit.MAX_CHANGES = Math.max(limit.MAX_CHANGES, newLimit.MAX_CHANGES != -1 ? newLimit.MAX_CHANGES : Integer.MAX_VALUE); limit.MAX_BLOCKSTATES = Math.max(limit.MAX_BLOCKSTATES, newLimit.MAX_BLOCKSTATES != -1 ? newLimit.MAX_BLOCKSTATES : Integer.MAX_VALUE); limit.MAX_CHECKS = Math.max(limit.MAX_CHECKS, newLimit.MAX_CHECKS != -1 ? newLimit.MAX_CHECKS : Integer.MAX_VALUE); @@ -72,109 +232,4 @@ public class Settings { } return limit; } - - public static void setup(final File file) { - if (!file.exists()) { - file.getParentFile().mkdirs(); - try { - file.createNewFile(); - } catch (final IOException e) { - MainUtil.handleError(e); - } - } - final YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - config.set("DOCUMENTATION","https://github.com/boy0001/FastAsyncWorldedit/wiki/Configuration"); - - limits = new HashMap<>(); - - final Map options = new HashMap<>(); - options.put("max-memory-percent", MEM_FREE); - options.put("crash-mitigation", ENABLE_HARD_LIMIT); - options.put("lighting.fix-all", FIX_ALL_LIGHTING); - options.put("lighting.async", ASYNC_LIGHTING); - options.put("clipboard.use-disk", STORE_CLIPBOARD_ON_DISK); - options.put("clipboard.delete-after-days", DELETE_CLIPBOARD_AFTER_DAYS); - options.put("history.use-disk", STORE_HISTORY_ON_DISK); - options.put("history.chunk-wait-ms", CHUNK_WAIT); - options.put("history.delete-after-days", DELETE_HISTORY_AFTER_DAYS); - options.put("history.delete-on-logout", CLEAN_HISTORY_ON_LOGOUT); - options.put("history.enable-for-console", CONSOLE_HISTORY); - options.put("history.compression-level", config.getBoolean("history.compress", false) ? 4 : COMPRESSION_LEVEL); - options.put("history.compress", null); - options.put("region-restrictions", REGION_RESTRICTIONS); - options.put("queue.extra-time-ms", ALLOCATE); - options.put("queue.progress.display", DISPLAY_PROGRESS); - options.put("queue.progress.interval", DISPLAY_PROGRESS_INTERVAL); - options.put("queue.target-size", QUEUE_SIZE); - options.put("queue.max-wait-ms", QUEUE_MAX_WAIT); - options.put("extent.allowed-plugins", new ArrayList()); - options.put("extent.debug", EXTENT_DEBUG); - options.put("web.url", WEB_URL); - options.put("metrics", METRICS); - - // Possibly confusing? - leave configurable since not entirely stable yet - options.put("history.combine-stages", COMBINE_HISTORY_STAGE); - options.put("queue.parallel-threads", Math.max(1, Runtime.getRuntime().availableProcessors())); - - if (config.getInt("tick-limiter.physics") == 1337) { - config.set("tick-limiter.physics", PHYSICS_PER_TICK); - } - options.put("tick-limiter.physics", PHYSICS_PER_TICK); - options.put("tick-limiter.items", ITEMS_PER_TICK); - - // Default limit - FaweLimit defaultLimit = new FaweLimit(); - if (!config.contains("limits.default")) { - config.createSection("limits.default"); - } - defaultLimit.load(config.getConfigurationSection("limits.default"), null, true); - for (String key : config.getConfigurationSection("limits").getKeys(false)) { - FaweLimit limit = new FaweLimit(); - limit.load(config.getConfigurationSection("limits." + key), defaultLimit, false); - limits.put(key, limit); - } - for (final Entry node : options.entrySet()) { - if (!config.contains(node.getKey())) { - config.set(node.getKey(), node.getValue()); - } - } - FIX_ALL_LIGHTING = config.getBoolean("lighting.fix-all"); - ASYNC_LIGHTING = config.getBoolean("lighting.async"); - MEM_FREE = config.getInt("max-memory-percent"); - ENABLE_HARD_LIMIT = config.getBoolean("crash-mitigation"); - REGION_RESTRICTIONS = config.getBoolean("region-restrictions"); - METRICS = config.getBoolean("metrics"); - COMPRESSION_LEVEL = config.getInt("history.compression-level"); - DELETE_HISTORY_AFTER_DAYS = config.getInt("history.delete-after-days"); - CLEAN_HISTORY_ON_LOGOUT = config.getBoolean("history.delete-on-logout"); - CHUNK_WAIT = config.getInt("history.chunk-wait-ms"); - CONSOLE_HISTORY = config.getBoolean("history.enable-for-console"); - ALLOCATE = config.getInt("queue.extra-time-ms"); - QUEUE_SIZE = config.getInt("queue.target-size"); - QUEUE_MAX_WAIT = config.getInt("queue.max-wait-ms"); - DISPLAY_PROGRESS = config.getBoolean("queue.progress.display"); - DISPLAY_PROGRESS_INTERVAL = config.getInt("queue.progress.interval"); - PARALLEL_THREADS = config.getInt("queue.parallel-threads", Math.max(1, Runtime.getRuntime().availableProcessors())); - ALLOWED_3RDPARTY_EXTENTS = config.getStringList("extent.allowed-plugins"); - EXTENT_DEBUG = config.getBoolean("extent.debug"); - STORE_CLIPBOARD_ON_DISK = config.getBoolean("clipboard.use-disk"); - DELETE_CLIPBOARD_AFTER_DAYS = config.getInt("clipboard.delete-after-days"); - PHYSICS_PER_TICK = config.getInt("tick-limiter.physics"); - ITEMS_PER_TICK = config.getInt("tick-limiter.items"); - - // Not usually configurable - BUFFER_SIZE = config.getInt("history.buffer-size", BUFFER_SIZE); - QUEUE_DISCARD_AFTER = config.getInt("queue.discard-after-ms", QUEUE_DISCARD_AFTER); - COMBINE_HISTORY_STAGE = config.getBoolean("history.combine-stages", COMBINE_HISTORY_STAGE); - - WEB_URL = config.getString("web.url"); - - STORE_HISTORY_ON_DISK = config.getBoolean("history.use-disk"); - - try { - config.save(file); - } catch (final IOException e) { - MainUtil.handleError(e); - } - } } diff --git a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java index 68bb3b65..109a992d 100644 --- a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java @@ -380,9 +380,9 @@ public abstract class MappedFaweQueue extends FaweQueue { boolean sync = Thread.currentThread() == Fawe.get().getMainThread(); if (sync) { loadChunk(getWorld(), cx, cz, true); - } else if (Settings.CHUNK_WAIT > 0) { + } else if (Settings.HISTORY.CHUNK_WAIT_MS > 0) { loadChunk.value = new IntegerPair(cx, cz); - TaskManager.IMP.sync(loadChunk, Settings.CHUNK_WAIT); + TaskManager.IMP.sync(loadChunk, Settings.HISTORY.CHUNK_WAIT_MS); if (!isChunkLoaded(cx, cz)) { throw new FaweException.FaweChunkLoadException(); } diff --git a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java index 70906290..ef804e92 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java @@ -19,7 +19,7 @@ public abstract class NMSMappedFaweQueue ex @Override public void sendChunk(final FaweChunk fc, RelightMode mode) { if (mode == null) { - mode = Settings.FIX_ALL_LIGHTING ? FaweQueue.RelightMode.OPTIMAL : FaweQueue.RelightMode.MINIMAL; + mode = Settings.LIGHTING.FIX_ALL ? FaweQueue.RelightMode.OPTIMAL : FaweQueue.RelightMode.MINIMAL; } final RelightMode finalMode = mode; TaskManager.IMP.taskSyncSoon(new Runnable() { @@ -37,7 +37,7 @@ public abstract class NMSMappedFaweQueue ex } }, false); } - }, Settings.ASYNC_LIGHTING); + }, Settings.LIGHTING.ASYNC); } public abstract void refreshChunk(WORLD world, CHUNK chunk); diff --git a/core/src/main/java/com/boydti/fawe/object/FaweChunk.java b/core/src/main/java/com/boydti/fawe/object/FaweChunk.java index 80155f31..2cb8b5a5 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweChunk.java @@ -82,7 +82,7 @@ public abstract class FaweChunk { * Fix the lighting in this chunk */ public void fixLighting() { - parent.fixLighting(this, Settings.FIX_ALL_LIGHTING ? FaweQueue.RelightMode.OPTIMAL : FaweQueue.RelightMode.MINIMAL); + parent.fixLighting(this, Settings.LIGHTING.FIX_ALL ? FaweQueue.RelightMode.OPTIMAL : FaweQueue.RelightMode.MINIMAL); } /** diff --git a/core/src/main/java/com/boydti/fawe/object/FaweLimit.java b/core/src/main/java/com/boydti/fawe/object/FaweLimit.java index 817b3495..72c66413 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweLimit.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweLimit.java @@ -8,12 +8,12 @@ import java.util.Map; * Created by Jesse on 4/5/2016. */ public class FaweLimit { - public int MAX_CHANGES = 50000000; - public int MAX_FAILS = 50000000; - public int MAX_CHECKS = 50000000; - public int MAX_ITERATIONS = 1000; - public int MAX_BLOCKSTATES = 1337; - public int MAX_ENTITIES = 1337; + public int MAX_CHANGES = 0; + public int MAX_FAILS = 0; + public int MAX_CHECKS = 0; + public int MAX_ITERATIONS = 0; + public int MAX_BLOCKSTATES = 0; + public int MAX_ENTITIES = 0; public static FaweLimit MAX; static { diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index c26ed8a8..8990d6ad 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -90,7 +90,7 @@ public abstract class FawePlayer { public FawePlayer(final T parent) { this.parent = parent; Fawe.get().register(this); - if (getSession() == null || getPlayer() == null || session.getSize() != 0 || !Settings.STORE_HISTORY_ON_DISK) { + if (getSession() == null || getPlayer() == null || session.getSize() != 0 || !Settings.HISTORY.USE_DISK) { return; } try { @@ -381,7 +381,7 @@ public abstract class FawePlayer { * - Usually called on logout */ public void unregister() { - if (Settings.CLEAN_HISTORY_ON_LOGOUT) { + if (Settings.HISTORY.DELETE_ON_LOGOUT) { getSession().setClipboard(null); getSession().clearHistory(); WorldEdit.getInstance().removeSession(getPlayer()); diff --git a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java index 7474e9c7..a3971814 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -2,7 +2,6 @@ package com.boydti.fawe.object; import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; -import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MemUtil; @@ -208,7 +207,7 @@ public abstract class FaweQueue { TaskManager.IMP.notify(running); } }); - TaskManager.IMP.wait(running, Settings.QUEUE_DISCARD_AFTER); + TaskManager.IMP.wait(running, 10000); } } } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index c91de05a..2df7a99b 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -63,8 +63,6 @@ public class DiskStorageHistory extends FaweStreamChangeSet { // Entity Create To private NBTOutputStream osENTCT; - private World world; - public void deleteFiles() { bdFile.delete(); nbtfFile.delete(); @@ -89,18 +87,17 @@ public class DiskStorageHistory extends FaweStreamChangeSet { } } } - init(world, uuid, ++max); + init(uuid, ++max); } public DiskStorageHistory(World world, UUID uuid, int index) { super(world); - init(world, uuid, index); + init(uuid, index); } - private void init(World world, UUID uuid, int i) { + private void init(UUID uuid, int i) { this.uuid = uuid; - this.world = world; - String base = "history" + File.separator + world.getName() + File.separator + uuid; + String base = "history" + File.separator + getWorld().getName() + File.separator + uuid; base += File.separator + i; nbtfFile = new File(Fawe.imp().getDirectory(), base + ".nbtf"); nbttFile = new File(Fawe.imp().getDirectory(), base + ".nbtt"); @@ -271,45 +268,45 @@ public class DiskStorageHistory extends FaweStreamChangeSet { if (summary != null) { return summary; } - if (bdFile.exists()) { - int ox = getOriginX(); - int oz = getOriginZ(); - if ((ox != 0 || oz != 0) && !requiredRegion.isIn(ox, oz)) { - return summary = new DiskStorageSummary(ox, oz); - } - try (FileInputStream fis = new FileInputStream(bdFile)) { - FaweInputStream gis = MainUtil.getCompressedIS(fis); - // skip mode - gis.skip(1); - // origin - ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0)); - oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0)); - setOrigin(ox, oz); - summary = new DiskStorageSummary(ox, oz); - if (!requiredRegion.isIn(ox, oz)) { - fis.close(); - gis.close(); - return summary; + if (bdFile.exists()) { + int ox = getOriginX(); + int oz = getOriginZ(); + if ((ox != 0 || oz != 0) && !requiredRegion.isIn(ox, oz)) { + return summary = new DiskStorageSummary(ox, oz); } - byte[] buffer = new byte[9]; - int i = 0; - int amount = (Settings.BUFFER_SIZE - HEADER_SIZE) / 9; - while (!shallow && ++i < amount) { - if (gis.read(buffer) == -1) { + try (FileInputStream fis = new FileInputStream(bdFile)) { + FaweInputStream gis = MainUtil.getCompressedIS(fis); + // skip mode + gis.skip(1); + // origin + ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0)); + oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + (gis.read() << 0)); + setOrigin(ox, oz); + summary = new DiskStorageSummary(ox, oz); + if (!requiredRegion.isIn(ox, oz)) { fis.close(); gis.close(); return summary; } - int x = ((byte) buffer[0] & 0xFF) + ((byte) buffer[1] << 8) + ox; - int z = ((byte) buffer[2] & 0xFF) + ((byte) buffer[3] << 8) + oz; - int combined1 = buffer[7] & 0xFF; - int combined2 = buffer[8] & 0xFF; - summary.add(x, z, ((combined2 << 4) + (combined1 >> 4))); + byte[] buffer = new byte[9]; + int i = 0; + int amount = (Settings.HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9; + while (!shallow && ++i < amount) { + if (gis.read(buffer) == -1) { + fis.close(); + gis.close(); + return summary; + } + int x = ((byte) buffer[0] & 0xFF) + ((byte) buffer[1] << 8) + ox; + int z = ((byte) buffer[2] & 0xFF) + ((byte) buffer[3] << 8) + oz; + int combined1 = buffer[7] & 0xFF; + int combined2 = buffer[8] & 0xFF; + summary.add(x, z, ((combined2 << 4) + (combined1 >> 4))); + } + } catch (IOException e) { + MainUtil.handleError(e); } - } catch (IOException e) { - MainUtil.handleError(e); } - } return summary; } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 9431447b..63296fbf 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -25,7 +25,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { private final int compression; public FaweStreamChangeSet(World world) { - this(world, Settings.COMPRESSION_LEVEL); + this(world, Settings.HISTORY.COMPRESSION_LEVEL); } public FaweStreamChangeSet(World world, int compression) { diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java index e35a2611..56cb1b80 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java @@ -97,7 +97,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { return idsStreamZip; } setOrigin(x, z); - idsStream = new ByteArrayOutputStream(Settings.BUFFER_SIZE); + idsStream = new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); idsStreamZip = getCompressedOS(idsStream); idsStreamZip.write(FaweStreamChangeSet.MODE); idsStreamZip.writeInt(x); @@ -117,7 +117,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { if (entCStreamZip != null) { return entCStreamZip; } - entCStream = new ByteArrayOutputStream(Settings.BUFFER_SIZE); + entCStream = new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); return entCStreamZip = new NBTOutputStream(getCompressedOS(entCStream)); } @@ -126,7 +126,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { if (entRStreamZip != null) { return entRStreamZip; } - entRStream = new ByteArrayOutputStream(Settings.BUFFER_SIZE); + entRStream = new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); return entRStreamZip = new NBTOutputStream(getCompressedOS(entRStream)); } @@ -135,7 +135,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { if (tileCStreamZip != null) { return tileCStreamZip; } - tileCStream = new ByteArrayOutputStream(Settings.BUFFER_SIZE); + tileCStream = new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); return tileCStreamZip = new NBTOutputStream(getCompressedOS(tileCStream)); } @@ -144,7 +144,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { if (tileRStreamZip != null) { return tileRStreamZip; } - tileRStream = new ByteArrayOutputStream(Settings.BUFFER_SIZE); + tileRStream = new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE); return tileRStreamZip = new NBTOutputStream(getCompressedOS(tileRStream)); } diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index bd55faa3..f90bc17c 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -63,7 +63,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { entities = new HashSet<>();this.buffer = new byte[2]; this.file = file; this.lastAccessed = System.currentTimeMillis(); - this.raf = new BufferedRandomAccessFile(file, "rw", Settings.BUFFER_SIZE); + this.raf = new BufferedRandomAccessFile(file, "rw", Settings.HISTORY.BUFFER_SIZE); raf.setLength(file.length()); long size = (raf.length() - HEADER_SIZE) >> 1; raf.seek(2); @@ -176,7 +176,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { close(); } lastAccessed = System.currentTimeMillis(); - this.raf = new BufferedRandomAccessFile(file, "rw", Settings.BUFFER_SIZE); + this.raf = new BufferedRandomAccessFile(file, "rw", Settings.HISTORY.BUFFER_SIZE); long size = width * height * length * 2l + HEADER_SIZE; if (raf.length() != size) { raf.setLength(size); diff --git a/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java b/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java index 4551a972..1a0b42fe 100644 --- a/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java +++ b/core/src/main/java/com/boydti/fawe/object/progress/DefaultProgressTracker.java @@ -64,7 +64,7 @@ public class DefaultProgressTracker extends RunnableVal2 lastTick + Settings.DISPLAY_PROGRESS_INTERVAL) { + if (currentTick > lastTick + Settings.QUEUE.PROGRESS.INTERVAL) { lastTick = currentTick; TaskManager.IMP.task(new Runnable() { // Run on main thread @Override diff --git a/core/src/main/java/com/boydti/fawe/object/schematic/FaweFormat.java b/core/src/main/java/com/boydti/fawe/object/schematic/FaweFormat.java index bb5c4aaf..87b8f7f8 100644 --- a/core/src/main/java/com/boydti/fawe/object/schematic/FaweFormat.java +++ b/core/src/main/java/com/boydti/fawe/object/schematic/FaweFormat.java @@ -96,7 +96,7 @@ public class FaweFormat implements ClipboardReader, ClipboardWriter { case 1: { ox = in.readInt(); oz = in.readInt(); - FaweOutputStream tmp = new FaweOutputStream(new ByteArrayOutputStream(Settings.BUFFER_SIZE)); + FaweOutputStream tmp = new FaweOutputStream(new ByteArrayOutputStream(Settings.HISTORY.BUFFER_SIZE)); int width = 0; int height = 0; int length = 0; diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index c68246ba..fa8d8e6e 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -84,12 +84,12 @@ public class MainUtil { } public static FaweOutputStream getCompressedOS(OutputStream os) throws IOException { - return getCompressedOS(os, Settings.COMPRESSION_LEVEL); + return getCompressedOS(os, Settings.HISTORY.COMPRESSION_LEVEL); } public static FaweOutputStream getCompressedOS(OutputStream os, int amount) throws IOException { os.write((byte) amount); - os = new BufferedOutputStream(os, Settings.BUFFER_SIZE); + os = new BufferedOutputStream(os, Settings.HISTORY.BUFFER_SIZE); if (amount == 0) { return new FaweOutputStream(os); } @@ -100,18 +100,18 @@ public class MainUtil { LZ4Factory factory = LZ4Factory.fastestInstance(); int fastAmount = 1 + ((amount - 1) % 3); for (int i = 0; i < fastAmount; i++) { - os = new LZ4OutputStream(os, Settings.BUFFER_SIZE, factory.fastCompressor()); + os = new LZ4OutputStream(os, Settings.HISTORY.BUFFER_SIZE, factory.fastCompressor()); } int highAmount = amount > 3 ? 1 : 0; for (int i = 0; i < highAmount; i++) { - os = new LZ4OutputStream(os, Settings.BUFFER_SIZE, factory.highCompressor()); + os = new LZ4OutputStream(os, Settings.HISTORY.BUFFER_SIZE, factory.highCompressor()); } return new FaweOutputStream(os); } public static FaweInputStream getCompressedIS(InputStream is) throws IOException { int amount = is.read(); - is = new BufferedInputStream(is, Settings.BUFFER_SIZE); + is = new BufferedInputStream(is, Settings.HISTORY.BUFFER_SIZE); if (amount == 0) { return new FaweInputStream(is); } @@ -136,15 +136,15 @@ public class MainUtil { final String website; if (uuid == null) { uuid = UUID.randomUUID(); - website = Settings.WEB_URL + "upload.php?" + uuid; + website = Settings.WEB.URL + "upload.php?" + uuid; filename = "plot." + extension; } else { - website = Settings.WEB_URL + "save.php?" + uuid; + website = Settings.WEB.URL + "save.php?" + uuid; filename = file + '.' + extension; } final URL url; try { - url = new URL(Settings.WEB_URL + "?key=" + uuid + "&type=" + extension); + url = new URL(Settings.WEB.URL + "?key=" + uuid + "&type=" + extension); String boundary = Long.toHexString(System.currentTimeMillis()); URLConnection con = new URL(website).openConnection(); con.setDoOutput(true); diff --git a/core/src/main/java/com/boydti/fawe/util/MemUtil.java b/core/src/main/java/com/boydti/fawe/util/MemUtil.java index defc1d0f..56eca141 100644 --- a/core/src/main/java/com/boydti/fawe/util/MemUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MemUtil.java @@ -35,7 +35,7 @@ public class MemUtil { } final long heapFreeSize = Runtime.getRuntime().freeMemory(); final int size = (int) ((heapFreeSize * 100) / heapMaxSize); - if (size > (100 - Settings.MEM_FREE)) { + if (size > (100 - Settings.MAX_MEMORY_PERCENT)) { memoryPlentifulTask(); return Integer.MAX_VALUE; } diff --git a/core/src/main/java/com/boydti/fawe/util/SetQueue.java b/core/src/main/java/com/boydti/fawe/util/SetQueue.java index 06c5751d..62030ee7 100644 --- a/core/src/main/java/com/boydti/fawe/util/SetQueue.java +++ b/core/src/main/java/com/boydti/fawe/util/SetQueue.java @@ -67,7 +67,7 @@ public class SetQueue { if (!MemUtil.isMemoryFree()) { final int mem = MemUtil.calculateMemory(); if (mem != Integer.MAX_VALUE) { - if ((mem <= 1) && Settings.ENABLE_HARD_LIMIT) { + if ((mem <= 1) && Settings.CRASH_MITIGATION) { for (FaweQueue queue : getAllQueues()) { queue.saveMemory(); } @@ -81,7 +81,7 @@ public class SetQueue { return; } } - SET_TASK.value1 = Settings.ALLOCATE + 50 + Math.min((50 + SetQueue.this.last) - (SetQueue.this.last = System.currentTimeMillis()), SetQueue.this.secondLast - System.currentTimeMillis()); + SET_TASK.value1 = Settings.QUEUE.EXTRA_TIME_MS + 50 + Math.min((50 + SetQueue.this.last) - (SetQueue.this.last = System.currentTimeMillis()), SetQueue.this.secondLast - System.currentTimeMillis()); SET_TASK.value2 = getNextQueue(); if (SET_TASK.value2 == null) { return; @@ -90,14 +90,14 @@ public class SetQueue { throw new IllegalStateException("This shouldn't be possible for placement to occur off the main thread"); } // Disable the async catcher as it can't discern async vs parallel - boolean parallel = Settings.PARALLEL_THREADS > 1; + boolean parallel = Settings.QUEUE.PARALLEL_THREADS > 1; SET_TASK.value2.startSet(parallel); try { - if (Settings.PARALLEL_THREADS <= 1) { + if (Settings.QUEUE.PARALLEL_THREADS <= 1) { SET_TASK.run(); } else { ArrayList threads = new ArrayList(); - for (int i = 0; i < Settings.PARALLEL_THREADS; i++) { + for (int i = 0; i < Settings.QUEUE.PARALLEL_THREADS; i++) { threads.add(new Thread(SET_TASK)); } for (Thread thread : threads) { @@ -188,14 +188,14 @@ public class SetQueue { throw new IllegalStateException("Must be flushed on the main thread!"); } // Disable the async catcher as it can't discern async vs parallel - boolean parallel = Settings.PARALLEL_THREADS > 1; + boolean parallel = Settings.QUEUE.PARALLEL_THREADS > 1; SET_TASK.value2.startSet(parallel); try { if (parallel) { SET_TASK.run(); } else { ArrayList threads = new ArrayList(); - for (int i = 0; i < Settings.PARALLEL_THREADS; i++) { + for (int i = 0; i < Settings.QUEUE.PARALLEL_THREADS; i++) { threads.add(new Thread(SET_TASK)); } for (Thread thread : threads) { @@ -240,7 +240,7 @@ public class SetQueue { long age = now - queue.getModified(); total += queue.size(); if (queue.size() == 0) { - if (age > Settings.QUEUE_DISCARD_AFTER) { + if (age > Settings.QUEUE.DISCARD_AFTER_MS) { iter.remove(); } continue; @@ -248,11 +248,11 @@ public class SetQueue { if (firstNonEmpty == null) { firstNonEmpty = queue; } - if (total > Settings.QUEUE_SIZE) { + if (total > Settings.QUEUE.TARGET_SIZE) { firstNonEmpty.setModified(now); return firstNonEmpty; } - if (age > Settings.QUEUE_MAX_WAIT) { + if (age > Settings.QUEUE.MAX_WAIT_MS) { queue.setModified(now); return queue; } @@ -277,32 +277,32 @@ public class SetQueue { } if (inactiveQueues.size() > 0) { ArrayList tmp = new ArrayList<>(inactiveQueues); - if (Settings.QUEUE_MAX_WAIT != -1) { + if (Settings.QUEUE.MAX_WAIT_MS != -1) { long now = System.currentTimeMillis(); if (lastSuccess == 0) { lastSuccess = now; } long diff = now - lastSuccess; - if (diff > Settings.QUEUE_MAX_WAIT) { + if (diff > Settings.QUEUE.MAX_WAIT_MS) { for (FaweQueue queue : tmp) { FaweChunk result = queue.next(); if (result != null) { return result; } } - if (diff > Settings.QUEUE_DISCARD_AFTER) { + if (diff > Settings.QUEUE.DISCARD_AFTER_MS) { // These edits never finished inactiveQueues.clear(); } return null; } } - if (Settings.QUEUE_SIZE != -1) { + if (Settings.QUEUE.TARGET_SIZE != -1) { int total = 0; for (FaweQueue queue : tmp) { total += queue.size(); } - if (total > Settings.QUEUE_SIZE) { + if (total > Settings.QUEUE.TARGET_SIZE) { for (FaweQueue queue : tmp) { FaweChunk result = queue.next(); if (result != null) { diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index ea957b4c..92048d32 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -50,7 +50,7 @@ public abstract class TaskManager { return; } if (numThreads == null) { - numThreads = Settings.PARALLEL_THREADS; + numThreads = Settings.QUEUE.PARALLEL_THREADS; } if (numThreads <= 1) { for (Runnable run : runnables) { diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index fed5ef38..9f7d0691 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -194,10 +194,10 @@ public class EditSession implements Extent { } this.player = player; if (changeSet == null) { - if (Settings.STORE_HISTORY_ON_DISK) { + if (Settings.HISTORY.USE_DISK) { UUID uuid = player == null ? CONSOLE : player.getUUID(); changeSet = new DiskStorageHistory(world, uuid); - } else if (Settings.COMBINE_HISTORY_STAGE && Settings.COMPRESSION_LEVEL == 0) { + } else if (Settings.HISTORY.COMBINE_STAGES && Settings.HISTORY.COMPRESSION_LEVEL == 0) { changeSet = new CPUOptimizedChangeSet(world); } else { changeSet = new MemoryOptimizedHistory(world); @@ -223,7 +223,7 @@ public class EditSession implements Extent { } if (fastmode == null) { if (player == null) { - fastmode = Settings.CONSOLE_HISTORY; + fastmode = Settings.HISTORY.ENABLE_FOR_CONSOLE; } else { fastmode = player.getSession().hasFastMode(); } @@ -232,7 +232,7 @@ public class EditSession implements Extent { checkMemory = player != null && !fastmode; } if (combineStages == null) { - combineStages = Settings.COMBINE_HISTORY_STAGE; + combineStages = Settings.HISTORY.COMBINE_STAGES; } if (checkMemory) { if (MemUtil.isMemoryLimitedSlow()) { @@ -363,12 +363,12 @@ public class EditSession implements Extent { final Extent toReturn = event.getExtent(); if (toReturn != extent) { String className = toReturn.getClass().getName().toLowerCase(); - for (String allowed : Settings.ALLOWED_3RDPARTY_EXTENTS) { + for (String allowed : Settings.EXTENT.ALLOWED_PLUGINS) { if (className.contains(allowed.toLowerCase())) { return toReturn; } } - if (Settings.EXTENT_DEBUG) { + if (Settings.EXTENT.DEBUG) { Fawe.debug("&cPotentially inefficient WorldEdit extent: " + toReturn.getClass().getName()); Fawe.debug("&8 - &7For area restrictions, it is recommended to use the FaweAPI"); Fawe.debug("&8 - &7To allow this plugin add it to the FAWE `allowed-plugins` list"); @@ -1030,7 +1030,7 @@ public class EditSession implements Extent { queue.dequeue(); } if (getChangeSet() != null) { - if (Settings.COMBINE_HISTORY_STAGE && queue.size() > 0) { + if (Settings.HISTORY.COMBINE_STAGES && queue.size() > 0) { if (Fawe.get().isMainThread()) { SetQueue.IMP.flush(queue); } else { @@ -1041,7 +1041,7 @@ public class EditSession implements Extent { TaskManager.IMP.notify(running); } }); - TaskManager.IMP.wait(running, Settings.QUEUE_DISCARD_AFTER); + TaskManager.IMP.wait(running, Settings.QUEUE.DISCARD_AFTER_MS); } } ((FaweChangeSet) getChangeSet()).flush(); diff --git a/core/src/main/java/com/sk89q/worldedit/LocalSession.java b/core/src/main/java/com/sk89q/worldedit/LocalSession.java index 897cbdbd..154d938b 100644 --- a/core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -202,7 +202,7 @@ public class LocalSession { } // It should have already been flushed, but just in case! editSession.flushQueue(); - if (Settings.STORE_HISTORY_ON_DISK) { + if (Settings.HISTORY.USE_DISK) { MAX_HISTORY_SIZE = Integer.MAX_VALUE; } else if (MAX_HISTORY_SIZE == Integer.MAX_VALUE) { MAX_HISTORY_SIZE = 15; diff --git a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 3857ab1f..8f281c58 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -98,7 +98,7 @@ public class SchematicCommands { try { if (filename.startsWith("url:")) { UUID uuid = UUID.fromString(filename.substring(4)); - URL base = new URL(Settings.WEB_URL); + URL base = new URL(Settings.WEB.URL); URL url = new URL(base, "uploads/" + uuid + ".schematic"); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); in = Channels.newInputStream(rbc); diff --git a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 5ce30c25..c39999ba 100644 --- a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -70,7 +70,7 @@ public class BlockArrayClipboard implements Clipboard { checkNotNull(region); this.region = region.clone(); this.size = getDimensions(); - this.IMP = Settings.STORE_CLIPBOARD_ON_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); + this.IMP = Settings.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); this.origin = region.getMinimumPoint(); this.mx = origin.getBlockX(); this.my = origin.getBlockY(); @@ -88,7 +88,7 @@ public class BlockArrayClipboard implements Clipboard { checkNotNull(region); this.region = region.clone(); this.size = getDimensions(); - this.IMP = Settings.STORE_CLIPBOARD_ON_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); + this.IMP = Settings.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()); this.origin = region.getMinimumPoint(); this.mx = origin.getBlockX(); this.my = origin.getBlockY(); diff --git a/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index b6adf668..8b6d3ab8 100644 --- a/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -348,7 +348,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public Iterator iterator() { - if (Settings.COMPRESSION_LEVEL == 9) { + if (Settings.HISTORY.COMPRESSION_LEVEL == 9) { return iterator_old(); } final BlockVector v = new BlockVector(0,0,0);