Use weak map for brush cache

This commit is contained in:
Jesse Boyd 2017-09-03 23:40:20 +10:00
parent 687d1ac890
commit 27152ef8ac
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 7 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.bukkit.util.ItemUtil;
import com.boydti.fawe.object.brush.BrushSettings;
import com.boydti.fawe.object.collection.SoftHashMap;
import com.boydti.fawe.util.ReflectionUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -19,10 +18,11 @@ import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import org.bukkit.inventory.ItemStack;
public class BrushBoundBaseBlock extends BaseBlock implements BrushHolder {
private static SoftHashMap<Object, BrushTool> brushCache = new SoftHashMap<>();
private static WeakHashMap<Object, BrushTool> brushCache = new WeakHashMap<>();
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
private final LocalSession session;

View File

@ -38,7 +38,7 @@ public class BrushSettings {
SCROLL_ACTION,
}
private Map<SettingType, Object> constructor = new ConcurrentHashMap<>();
private final Map<SettingType, Object> constructor = new ConcurrentHashMap<>();
private Brush brush = null;
private Mask mask = null;

View File

@ -95,6 +95,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
Type type = new TypeToken<Map<String, Object>>() {
}.getType();
Map<String, Object> root = gson.fromJson(json, type);
if (root == null) {
Fawe.debug("Failed to load " + json);
return new BrushTool();
}
Map<String, Object> primary = (Map<String, Object>) root.get("primary");
Map<String, Object> secondary = (Map<String, Object>) root.getOrDefault("secondary", primary);