From 240fad3f34c085ce99ef7ce7e5abecfc58783156 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sun, 27 Dec 2020 22:19:57 +0100 Subject: [PATCH] Fixed blockstates resetting when normal blocks were regenerated using custom mining --- .../net/Indyuce/mmocore/api/block/BlockType.java | 1 + .../Indyuce/mmocore/api/block/SkullBlockType.java | 14 +++++++++++--- .../mmocore/api/block/VanillaBlockType.java | 7 +++++++ .../mmocore/manager/CustomBlockManager.java | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java index 265ec318..f9af5a46 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/BlockType.java @@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock; public interface BlockType { void place(Location loc, RegeneratingBlock regenerating); + void regen(Location loc, RegeneratingBlock regenerating); /** * Generates a key used to store the BlockInfo instance in the manager map, diff --git a/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java index 98917c63..5482de8d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/SkullBlockType.java @@ -1,13 +1,12 @@ package net.Indyuce.mmocore.api.block; -import org.bukkit.Location; -import org.bukkit.block.Block; - import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.version.VersionMaterial; +import org.bukkit.Location; +import org.bukkit.block.Block; public class SkullBlockType implements BlockType { private final String value; @@ -37,6 +36,15 @@ public class SkullBlockType implements BlockType { MMOLib.plugin.getVersion().getWrapper().setSkullValue(loc.getBlock(), value); } + @Override + public void regen(Location loc, RegeneratingBlock block) { + // This makes sure that if a skull loses it's original rotation + // it can revert back to it when the base block is regenerated + loc.getBlock().setBlockData(block.getBlockData()); + MMOLib.plugin.getVersion().getWrapper().setSkullValue(loc.getBlock(), value); + } + + @Override public String generateKey() { return "vanilla-skull-" + value; diff --git a/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java b/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java index a2580775..cfa368b1 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/VanillaBlockType.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.block; +import net.mmogroup.mmolib.MMOLib; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -48,6 +49,12 @@ public class VanillaBlockType implements BlockType { } } + @Override + public void regen(Location loc, RegeneratingBlock block) { + // Sets the original blocks old data (only when regenerating) + loc.getBlock().setBlockData(block.getBlockData()); + } + @Override public String generateKey() { return "vanilla-block-" + type.name(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java index 0b498f1b..c9c74abb 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java @@ -124,6 +124,7 @@ public class CustomBlockManager extends MMOManager { // Get the chunk and load it async if needed. PaperLib.getChunkAtAsync(infoLocation).whenComplete((chunk, ex) -> { info.getRegeneratingBlock().getBlock().place(infoLocation, info); + info.getRegeneratingBlock().getBlock().regen(infoLocation, info); info.getLocation().getBlock().getState().update(); if (!shutdown) active.remove(info);