mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-09-27 14:42:37 +02:00
Persistent brush lore
This commit is contained in:
parent
23c44d89e2
commit
687d1ac890
@ -102,16 +102,6 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
e.printStackTrace();
|
||||
debug("===================================");
|
||||
}
|
||||
if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES) {
|
||||
try {
|
||||
this.itemUtil = new ItemUtil();
|
||||
} catch (Throwable e) {
|
||||
Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES = false;
|
||||
debug("===== PERSISTENT BRUSH FAILED =====");
|
||||
e.printStackTrace();
|
||||
debug("===================================");
|
||||
}
|
||||
}
|
||||
if (Bukkit.getVersion().contains("git-Spigot")) {
|
||||
debug("====== USE PAPER ======");
|
||||
debug("DOWNLOAD: https://ci.destroystokyo.com/job/PaperSpigot/");
|
||||
@ -249,7 +239,18 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
}
|
||||
|
||||
public ItemUtil getItemUtil() {
|
||||
return itemUtil;
|
||||
ItemUtil tmp = itemUtil;
|
||||
if (tmp == null) {
|
||||
try {
|
||||
this.itemUtil = tmp = new ItemUtil();
|
||||
} catch (Throwable e) {
|
||||
Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES = false;
|
||||
debug("===== PERSISTENT BRUSH FAILED =====");
|
||||
e.printStackTrace();
|
||||
debug("===================================");
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,14 @@
|
||||
package com.boydti.fawe.bukkit.block;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
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;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
@ -18,7 +22,9 @@ import java.util.Map;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BrushBoundBaseBlock extends BaseBlock implements BrushHolder {
|
||||
public static SoftHashMap<Object, BrushTool> brushCache = new SoftHashMap<>();
|
||||
private static SoftHashMap<Object, BrushTool> brushCache = new SoftHashMap<>();
|
||||
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private final LocalSession session;
|
||||
private final Player player;
|
||||
|
||||
@ -78,11 +84,36 @@ public class BrushBoundBaseBlock extends BaseBlock implements BrushHolder {
|
||||
map = ReflectionUtils.getMap(nbt.getValue());
|
||||
}
|
||||
brushCache.remove(getKey(item));
|
||||
CompoundTag display = (CompoundTag) map.get("display");
|
||||
Map<String, Tag> displayMap;
|
||||
if (tool != null) {
|
||||
String json = tool.toString();
|
||||
String json = tool.toString(gson);
|
||||
map.put("weBrushJson", new StringTag(json));
|
||||
if (display == null) {
|
||||
map.put("display", new CompoundTag(displayMap = new HashMap()));
|
||||
} else {
|
||||
displayMap = ReflectionUtils.getMap(display.getValue());
|
||||
}
|
||||
displayMap.put("Lore", FaweCache.asTag(json.split("\\r?\\n")));
|
||||
String primary = (String) tool.getPrimary().getSettings().get(BrushSettings.SettingType.BRUSH);
|
||||
String secondary = (String) tool.getSecondary().getSettings().get(BrushSettings.SettingType.BRUSH);
|
||||
if (primary == null) primary = secondary;
|
||||
if (secondary == null) secondary = primary;
|
||||
if (primary != null) {
|
||||
String name = primary == secondary ? primary.split(" ")[0] : primary.split(" ")[0] + " / " + secondary.split(" ")[0];
|
||||
displayMap.put("Name", new StringTag(name));
|
||||
}
|
||||
} else if (map.containsKey("weBrushJson")) {
|
||||
map.remove("weBrushJson");
|
||||
if (display != null) {
|
||||
displayMap = ReflectionUtils.getMap(display.getValue());
|
||||
displayMap.remove("Lore");
|
||||
displayMap.remove("Name");
|
||||
if (displayMap.isEmpty()) {
|
||||
map.remove("display");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return tool;
|
||||
}
|
||||
|
@ -148,76 +148,76 @@ public class FaweCache {
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
||||
int id = i >> 4;
|
||||
int data = i & 0xf;
|
||||
if (FaweCache.hasNBT(id)) {
|
||||
CACHE_BLOCK[i] = new ImmutableNBTBlock(id, data);
|
||||
} else if (FaweCache.hasData(id)) {
|
||||
CACHE_BLOCK[i] = new ImmutableBlock(id, data);
|
||||
} else {
|
||||
CACHE_BLOCK[i] = new ImmutableDatalessBlock(id);
|
||||
}
|
||||
CACHE_ITEM[i] = new BaseItem(id, (short) data) {
|
||||
|
||||
@Override
|
||||
public void setData(short data) {
|
||||
throw new IllegalStateException("Cannot set data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(short data) {
|
||||
throw new IllegalStateException("Cannot set data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(int id) {
|
||||
throw new IllegalStateException("Cannot set id");
|
||||
}
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < 256; i++) {
|
||||
CACHE_BIOME[i] = new BaseBiome(i) {
|
||||
@Override
|
||||
public void setId(int id) {
|
||||
throw new IllegalStateException("Cannot set id");
|
||||
}
|
||||
};
|
||||
}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
final short i = (short) (y >> 4);
|
||||
final short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
|
||||
CACHE_I[y][z][x] = i;
|
||||
CACHE_J[y][z][x] = j;
|
||||
CACHE_X[i][j] = (byte) x;
|
||||
CACHE_Y[i][j] = (short) y;
|
||||
CACHE_Z[i][j] = (byte) z;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
BundledBlockData bundled = BundledBlockData.getInstance();
|
||||
bundled.loadFromResource();
|
||||
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
||||
int id = i >> 4;
|
||||
int data = i & 0xf;
|
||||
if (FaweCache.hasNBT(id)) {
|
||||
CACHE_BLOCK[i] = new ImmutableNBTBlock(id, data);
|
||||
} else if (FaweCache.hasData(id)) {
|
||||
CACHE_BLOCK[i] = new ImmutableBlock(id, data);
|
||||
} else {
|
||||
CACHE_BLOCK[i] = new ImmutableDatalessBlock(id);
|
||||
}
|
||||
CACHE_ITEM[i] = new BaseItem(id, (short) data) {
|
||||
|
||||
@Override
|
||||
public void setData(short data) {
|
||||
throw new IllegalStateException("Cannot set data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(short data) {
|
||||
throw new IllegalStateException("Cannot set data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(int id) {
|
||||
throw new IllegalStateException("Cannot set id");
|
||||
}
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < 256; i++) {
|
||||
CACHE_BIOME[i] = new BaseBiome(i) {
|
||||
@Override
|
||||
public void setId(int id) {
|
||||
throw new IllegalStateException("Cannot set id");
|
||||
}
|
||||
};
|
||||
}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
final short i = (short) (y >> 4);
|
||||
final short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
|
||||
CACHE_I[y][z][x] = i;
|
||||
CACHE_J[y][z][x] = j;
|
||||
CACHE_X[i][j] = (byte) x;
|
||||
CACHE_Y[i][j] = (short) y;
|
||||
CACHE_Z[i][j] = (byte) z;
|
||||
CACHE_TRANSLUSCENT[i] = BlockType.isTranslucent(id);
|
||||
CACHE_PASSTHROUGH[i] = BlockType.canPassThrough(id, data);
|
||||
BundledBlockData.BlockEntry blockEntry = bundled.findById(id);
|
||||
if (blockEntry != null) {
|
||||
BundledBlockData.FaweBlockMaterial material = blockEntry.material;
|
||||
if (material != null) {
|
||||
CACHE_TRANSLUSCENT[i] = !material.isOpaque();
|
||||
CACHE_PASSTHROUGH[i] = !material.isMovementBlocker();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
BundledBlockData bundled = BundledBlockData.getInstance();
|
||||
bundled.loadFromResource();
|
||||
for (int i = 0; i < Character.MAX_VALUE; i++) {
|
||||
int id = i >> 4;
|
||||
int data = i & 0xf;
|
||||
CACHE_TRANSLUSCENT[i] = BlockType.isTranslucent(id);
|
||||
CACHE_PASSTHROUGH[i] = BlockType.canPassThrough(id, data);
|
||||
BundledBlockData.BlockEntry blockEntry = bundled.findById(id);
|
||||
if (blockEntry != null) {
|
||||
BundledBlockData.FaweBlockMaterial material = blockEntry.material;
|
||||
if (material != null) {
|
||||
CACHE_TRANSLUSCENT[i] = !material.isOpaque();
|
||||
CACHE_PASSTHROUGH[i] = !material.isMovementBlocker();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
try {
|
||||
CACHE_COLOR[getCombined(0, 0)] = new Color(128, 128, 128); //Air
|
||||
CACHE_COLOR[getCombined(1, 0)] = new Color(180, 180, 180); //stone
|
||||
CACHE_COLOR[getCombined(2, 0)] = new Color(0, 225, 0); //grass
|
||||
@ -288,7 +288,6 @@ public class FaweCache {
|
||||
CACHE_COLOR[getCombined(35, 15)] = new Color(0, 0, 0); // Black
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,6 +804,8 @@ public class FaweCache {
|
||||
return asTag((Map) value);
|
||||
} else if (value instanceof Collection) {
|
||||
return asTag((Collection) value);
|
||||
} else if (value instanceof Object[]) {
|
||||
return asTag((Object[]) value);
|
||||
} else if (value instanceof byte[]) {
|
||||
return asTag((byte[]) value);
|
||||
} else if (value instanceof int[]) {
|
||||
@ -835,7 +836,7 @@ public class FaweCache {
|
||||
|
||||
public static ListTag asTag(Object... values) {
|
||||
Class clazz = null;
|
||||
List<Tag> list = new ArrayList<>();
|
||||
List<Tag> list = new ArrayList<>(values.length);
|
||||
for (Object value : values) {
|
||||
Tag tag = asTag(value);
|
||||
if (clazz == null) {
|
||||
@ -848,7 +849,7 @@ public class FaweCache {
|
||||
|
||||
public static ListTag asTag(Collection values) {
|
||||
Class clazz = null;
|
||||
List<Tag> list = new ArrayList<>();
|
||||
List<Tag> list = new ArrayList<>(values.size());
|
||||
for (Object value : values) {
|
||||
Tag tag = asTag(value);
|
||||
if (clazz == null) {
|
||||
|
@ -149,7 +149,7 @@ public class BrushSettings {
|
||||
}
|
||||
|
||||
public Map<SettingType, Object> getSettings() {
|
||||
return Collections.unmodifiableMap(constructor);
|
||||
return (constructor);
|
||||
}
|
||||
|
||||
public BrushSettings setMask(Mask mask) {
|
||||
|
@ -129,24 +129,28 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(new Gson());
|
||||
}
|
||||
|
||||
public String toString(Gson gson) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("primary", primary.getSettings());
|
||||
if (primary != secondary) {
|
||||
map.put("secondary", secondary.getSettings());
|
||||
}
|
||||
if (visualMode != null) {
|
||||
if (visualMode != null && visualMode != VisualMode.NONE) {
|
||||
map.put("visual", visualMode);
|
||||
}
|
||||
if (targetMode != TargetMode.TARGET_BLOCK_RANGE) {
|
||||
map.put("target", targetMode);
|
||||
}
|
||||
if (range != -1) {
|
||||
if (range != -1 && range != 240) {
|
||||
map.put("range", range);
|
||||
}
|
||||
if (targetOffset != 0) {
|
||||
map.put("offset", targetOffset);
|
||||
}
|
||||
return new Gson().toJson(map);
|
||||
return gson.toJson(map);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
Loading…
Reference in New Issue
Block a user