From f9f411cbf23ac5fbd5bfec800e4a13881e6e0fa3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laura=20Endre=C3=9F?= <laura.endress@syntaxphoenix.com>
Date: Tue, 17 Aug 2021 14:54:59 +0200
Subject: [PATCH] Add equals / isSame for IBlockData and fix BlockStateEditor
 parser

---
 .../rwg/legacy/api/block/BlockStateEditor.java       |  2 +-
 .../spigot/rwg/legacy/api/block/IBlockData.java      | 12 ++++++++++--
 .../rwg/legacy/api/block/impl/BaseBlockData.java     |  5 +++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockStateEditor.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockStateEditor.java
index 5808497..e1723f5 100644
--- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockStateEditor.java
+++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockStateEditor.java
@@ -36,7 +36,7 @@ private BlockStateEditor(@NonNull String blockdata) {
             return;
         }
         if (parts[1].contains("?")) {
-            parts = parts[1].split("?", 2);
+            parts = parts[1].split("\\?", 2);
             id = parts[0];
             properties = '?' + parts[1];
             return;
diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockData.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockData.java
index fa0c938..321ced3 100644
--- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockData.java
+++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockData.java
@@ -32,11 +32,11 @@ public interface IBlockData {
 
     @NonNull
     BlockStateEditor asEditor();
-    
+
     default boolean isMinecraft() {
         return getNamespace().equalsIgnoreCase("minecraft");
     }
-    
+
     default IBlockData setConversionPossible(boolean state) {
         getProperties().set(IProperty.of("data_conversion", state));
         return this;
@@ -47,4 +47,12 @@ default boolean isConversionPossible() {
         return property.isPresent() ? property.getValue() : false;
     }
 
+    default boolean isSame(Object obj) {
+        return (obj instanceof IBlockData) ? isSame((IBlockData) obj) : false;
+    }
+
+    default boolean isSame(IBlockData data) {
+        return data != null ? data.asString().equals(asString()) : false;
+    }
+
 }
diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BaseBlockData.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BaseBlockData.java
index 7d7fca3..a9ccb95 100644
--- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BaseBlockData.java
+++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BaseBlockData.java
@@ -13,5 +13,10 @@ public abstract class BaseBlockData implements IBlockData {
     public final IProperties getProperties() {
         return properties;
     }
+    
+    @Override
+    public final boolean equals(Object obj) {
+        return isSame(obj);
+    }
 
 }