From c3db5c0cf180dd46acfafab938277cc9a77fcc26 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 24 Aug 2018 07:18:14 +1000 Subject: [PATCH] Fix persistent brushes --- worldedit-bukkit/build.gradle | 4 +--- .../com/boydti/fawe/bukkit/util/ItemUtil.java | 2 ++ .../sk89q/worldedit/bukkit/BukkitAdapter.java | 5 ++--- .../worldedit/bukkit/BukkitItemStack.java | 20 ++++++++++++++++++- .../src/main/resources/plugin.yml | 2 +- worldedit-core/build.gradle | 2 +- .../java/com/boydti/fawe/util/BrushCache.java | 4 +++- .../com/sk89q/worldedit/LocalSession.java | 4 ++-- .../worldedit/command/SchematicCommands.java | 4 ++-- .../src/main/resources/fawe.properties | 2 +- 10 files changed, 34 insertions(+), 15 deletions(-) diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 2b87640d5..caee7b038 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -35,14 +35,12 @@ dependencies { processResources { from (sourceSets.main.resources.srcDirs) { - expand 'version': project.internalVersion + expand 'internalVersion': project.internalVersion include 'plugin.yml' - include 'fawe.properties' } from (sourceSets.main.resources.srcDirs) { exclude 'plugin.yml' - exclude 'fawe.properties' } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java index 77cc84abb..df5f92f87 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java @@ -47,6 +47,8 @@ public class ItemUtil { return null; } + + public CompoundTag getNBT(ItemStack item) { try { if (!item.hasItemMeta()) return null; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index b61eee7dc..afe2e3180 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -349,9 +349,7 @@ public class BukkitAdapter { */ public static BaseItemStack adapt(ItemStack itemStack) { checkNotNull(itemStack); - - - return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount()); + return new BukkitItemStack(itemStack); } /** @@ -362,6 +360,7 @@ public class BukkitAdapter { */ public static ItemStack adapt(BaseItemStack item) { checkNotNull(item); + if (item instanceof BukkitItemStack) return ((BukkitItemStack) item).getBukkitItemStack(); return new ItemStack(adapt(item.getType()), item.getAmount()); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemStack.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemStack.java index a84772161..e1109f6fb 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemStack.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemStack.java @@ -13,6 +13,7 @@ import javax.annotation.Nullable; public class BukkitItemStack extends BaseItemStack { private ItemStack stack; + private Object nativeItem; private boolean loadedNBT; public BukkitItemStack(ItemStack stack) { @@ -33,7 +34,23 @@ public class BukkitItemStack extends BaseItemStack { @Nullable @Override public Object getNativeItem() { - return super.getNativeItem(); + ItemUtil util = Fawe.imp().getItemUtil(); + if (util != null && nativeItem == null) { + return nativeItem = util.getNMSItem(stack); + } + return nativeItem; + } + + public ItemStack getBukkitItemStack() { + return stack; + } + + @Override + public boolean hasNbtData() { + if (!loadedNBT) { + return stack.hasItemMeta(); + } + return super.hasNbtData(); } @Nullable @@ -54,6 +71,7 @@ public class BukkitItemStack extends BaseItemStack { ItemUtil util = Fawe.imp().getItemUtil(); if (util != null) { stack = util.setNBT(stack, nbtData); + nativeItem = null; } super.setNbtData(nbtData); } diff --git a/worldedit-bukkit/src/main/resources/plugin.yml b/worldedit-bukkit/src/main/resources/plugin.yml index 745356577..b62b370f3 100644 --- a/worldedit-bukkit/src/main/resources/plugin.yml +++ b/worldedit-bukkit/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: WorldEdit main: com.sk89q.worldedit.bukkit.WorldEditPlugin -version: "${version}" +version: "${internalVersion}" api-version: 1.13 description: Fast Async WorldEdit plugin authors: [Empire92] diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index aa6e2da87..def65df0e 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -37,7 +37,7 @@ processResources { from('src/main/resources') { include 'fawe.properties' expand( - version: "${project.parent.version}", + internalVersion: "${project.parent.version}", name: project.parent.name, ) } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java index e6185c9a0..cbd21184d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/BrushCache.java @@ -38,7 +38,9 @@ public final class BrushCache { BrushTool cached = brushCache.get(key); if (cached != null) return cached; - StringTag json = (StringTag) item.getNbtData().getValue().get("weBrushJson"); + CompoundTag nbt = item.getNbtData(); + if (nbt == null) return null; + StringTag json = (StringTag) nbt.getValue().get("weBrushJson"); if (json != null) { try { if (RECURSION.get() != null) return null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 4d85bee3f..4a5255207 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -957,7 +957,7 @@ public class LocalSession implements TextureHolder { } public Tool getTool(BaseItem item, Player player) { - if (item.getNativeItem() != null && Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES) { + if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES && item.getNativeItem() != null) { BrushTool tool = BrushCache.getTool(player, this, item); if (tool != null) return tool; } @@ -1034,7 +1034,7 @@ public class LocalSession implements TextureHolder { throw new InvalidToolBindException(type, "Already used for the navigation wand"); } Tool previous; - if (player != null && (tool instanceof BrushTool || tool == null) && item.getNativeItem() != null && Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES) { + if (player != null && (tool instanceof BrushTool || tool == null) && Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES && item.getNativeItem() != null) { previous = BrushCache.getCachedTool(item); if (tool != null) { BrushCache.setTool(item, (BrushTool) tool); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 932a8d8e4..9381ecc2c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -168,8 +168,8 @@ public class SchematicCommands extends MethodCommands { @Command( aliases = {"remap"}, - help = "Remap a clipboard between MCPE/PC values\n", - desc = "Remap a clipboard between MCPE/PC values\n" + help = "Remap a clipboard between MCPE/PC values", + desc = "Remap a clipboard between MCPE/PC values" ) @Deprecated @CommandPermissions({"worldedit.schematic.remap"}) diff --git a/worldedit-core/src/main/resources/fawe.properties b/worldedit-core/src/main/resources/fawe.properties index a50bf5c84..8570852e5 100644 --- a/worldedit-core/src/main/resources/fawe.properties +++ b/worldedit-core/src/main/resources/fawe.properties @@ -1 +1 @@ -version=${version} +version=${internalVersion}