From 7cfb33dd3b9d807fa98949cdfc8457dfcd521b9e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 9 Feb 2016 21:15:03 +1100 Subject: [PATCH] Add `crash-mitigation` option. --- pom.xml | 10 ++-- .../com/boydti/fawe/bukkit/FaweBukkit.java | 60 ++++++++++++++----- .../fawe/bukkit/v1_8/BukkitQueue_1_8.java | 3 - .../java/com/boydti/fawe/config/Settings.java | 3 + .../java/com/boydti/fawe/util/SetQueue.java | 3 +- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index d13d83c9..ffa2031b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 FastAsyncWorldEdit - 1.3.0 + 1.3.1 FastAsyncWorldEdit jar @@ -113,14 +113,14 @@ - - techcable-repo - http://repo.techcable.net/content/groups/public/ - empcraft-repo http://empcraft.com/maven2 + + techcable-repo + http://repo.techcable.net/content/groups/public/ + spigot-repo http://hub.spigotmc.org/nexus/content/groups/public/ diff --git a/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index cdb8540b..f2df650e 100644 --- a/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -49,7 +49,7 @@ public class FaweBukkit extends JavaPlugin implements IFawe { } return worldedit; } - + @Override public void onEnable() { try { @@ -66,7 +66,7 @@ public class FaweBukkit extends JavaPlugin implements IFawe { getServer().shutdown(); } } - + @Override public void debug(final String s) { getLogger().info(ChatColor.translateAlternateColorCodes('&', s)); @@ -146,22 +146,34 @@ public class FaweBukkit extends JavaPlugin implements IFawe { final Plugin worldguardPlugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"); final ArrayList managers = new ArrayList<>(); if ((worldguardPlugin != null) && worldguardPlugin.isEnabled()) { - managers.add(new Worldguard(worldguardPlugin, this)); - Fawe.debug("Plugin 'WorldGuard' found. Using it now."); + try { + managers.add(new Worldguard(worldguardPlugin, this)); + Fawe.debug("Plugin 'WorldGuard' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'WorldGuard' not found. Worldguard features disabled."); } final Plugin plotmePlugin = Bukkit.getServer().getPluginManager().getPlugin("PlotMe"); if ((plotmePlugin != null) && plotmePlugin.isEnabled()) { - managers.add(new PlotMeFeature(plotmePlugin, this)); - Fawe.debug("Plugin 'PlotMe' found. Using it now."); + try { + managers.add(new PlotMeFeature(plotmePlugin, this)); + Fawe.debug("Plugin 'PlotMe' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'PlotMe' not found. PlotMe features disabled."); } final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny"); if ((townyPlugin != null) && townyPlugin.isEnabled()) { - managers.add(new TownyFeature(townyPlugin, this)); - Fawe.debug("Plugin 'Towny' found. Using it now."); + try { + managers.add(new TownyFeature(townyPlugin, this)); + Fawe.debug("Plugin 'Towny' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'Towny' not found. Towny features disabled."); } @@ -179,29 +191,45 @@ public class FaweBukkit extends JavaPlugin implements IFawe { } final Plugin residencePlugin = Bukkit.getServer().getPluginManager().getPlugin("Residence"); if ((residencePlugin != null) && residencePlugin.isEnabled()) { - managers.add(new ResidenceFeature(residencePlugin, this)); - Fawe.debug("Plugin 'Residence' found. Using it now."); + try { + managers.add(new ResidenceFeature(residencePlugin, this)); + Fawe.debug("Plugin 'Residence' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'Residence' not found. Factions features disabled."); } final Plugin griefpreventionPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefPrevention"); if ((griefpreventionPlugin != null) && griefpreventionPlugin.isEnabled()) { - managers.add(new GriefPreventionFeature(griefpreventionPlugin, this)); - Fawe.debug("Plugin 'GriefPrevention' found. Using it now."); + try { + managers.add(new GriefPreventionFeature(griefpreventionPlugin, this)); + Fawe.debug("Plugin 'GriefPrevention' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'GriefPrevention' not found. GriefPrevention features disabled."); } final Plugin plotsquaredPlugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); if ((plotsquaredPlugin != null) && plotsquaredPlugin.isEnabled()) { - managers.add(new PlotSquaredFeature(plotsquaredPlugin, this)); - Fawe.debug("Plugin 'PlotSquared' found. Using it now."); + try { + managers.add(new PlotSquaredFeature(plotsquaredPlugin, this)); + Fawe.debug("Plugin 'PlotSquared' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'PlotSquared' not found. PlotSquared features disabled."); } final Plugin preciousstonesPlugin = Bukkit.getServer().getPluginManager().getPlugin("PreciousStones"); if ((preciousstonesPlugin != null) && preciousstonesPlugin.isEnabled()) { - managers.add(new PreciousStonesFeature(preciousstonesPlugin, this)); - Fawe.debug("Plugin 'PreciousStones' found. Using it now."); + try { + managers.add(new PreciousStonesFeature(preciousstonesPlugin, this)); + Fawe.debug("Plugin 'PreciousStones' found. Using it now."); + } catch (Throwable e) { + e.printStackTrace(); + } } else { Fawe.debug("Plugin 'PreciousStones' not found. PreciousStones features disabled."); } diff --git a/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java b/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java index cf73f452..da6a96f2 100644 --- a/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java +++ b/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java @@ -56,7 +56,6 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 { private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer"); private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); private final RefClass classWorld = getRefClass("{nms}.World"); - private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); private final RefField mustSave = classChunk.getField("mustSave"); private final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition"); private final RefClass classChunkSection = getRefClass("{nms}.ChunkSection"); @@ -71,7 +70,6 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 { private RefConstructor classChunkSectionConstructor; private RefMethod methodX; private RefMethod methodAreNeighborsLoaded; - private RefMethod methodD; private RefField fieldSections; private RefField fieldWorld; private RefMethod methodGetIdArray; @@ -88,7 +86,6 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 { send = classConnection.getMethod("sendPacket", classPacket.getRealClass()); classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class); methodX = classWorld.getMethod("x", classBlockPosition.getRealClass()); - methodD = classChunk.getMethod("d", int.class, int.class, int.class); fieldSections = classChunk.getField("sections"); fieldWorld = classChunk.getField("world"); methodGetIdArray = classChunkSection.getMethod("getIdArray"); diff --git a/src/main/java/com/boydti/fawe/config/Settings.java b/src/main/java/com/boydti/fawe/config/Settings.java index 51ed8c2f..b0160dc6 100644 --- a/src/main/java/com/boydti/fawe/config/Settings.java +++ b/src/main/java/com/boydti/fawe/config/Settings.java @@ -21,6 +21,7 @@ public class Settings { public static boolean COMMAND_PROCESSOR = false; public static List WE_BLACKLIST = Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks"); public static long MEM_FREE = 95; + public static boolean ENABLE_HARD_LIMIT = true; public static void setup(final File file) { if (!file.exists()) { @@ -42,6 +43,7 @@ public class Settings { options.put("command-blacklist", WE_BLACKLIST); options.put("command-processor", COMMAND_PROCESSOR); options.put("max-memory-percent", MEM_FREE); + options.put("crash-mitigation", ENABLE_HARD_LIMIT); options.put("fix-all-lighting", FIX_ALL_LIGHTING); for (final Entry node : options.entrySet()) { @@ -58,6 +60,7 @@ public class Settings { MEM_FREE = config.getInt("max-memory-percent"); REQUIRE_SELECTION = config.getBoolean("require-selection-in-mask"); WE_BLACKLIST = config.getStringList("command-blacklist"); + ENABLE_HARD_LIMIT = config.getBoolean("crash-mitigation"); try { diff --git a/src/main/java/com/boydti/fawe/util/SetQueue.java b/src/main/java/com/boydti/fawe/util/SetQueue.java index 475ca901..1c3aa4ee 100644 --- a/src/main/java/com/boydti/fawe/util/SetQueue.java +++ b/src/main/java/com/boydti/fawe/util/SetQueue.java @@ -3,6 +3,7 @@ package com.boydti.fawe.util; import java.util.ArrayDeque; import java.util.concurrent.atomic.AtomicInteger; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweChunk; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -25,7 +26,7 @@ public class SetQueue { if (!MemUtil.isMemoryFree()) { final int mem = MemUtil.calculateMemory(); if (mem != Integer.MAX_VALUE) { - if (mem <= 1) { + if (mem <= 1 && Settings.ENABLE_HARD_LIMIT) { queue.saveMemory(); return; }