diff --git a/Core/pom.xml b/Core/pom.xml index 59e524b5..81b3b759 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../ diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index 5ee872cf..88279773 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -54,7 +54,7 @@ public class SongodaCore { /** * This has been added as of Rev 6 */ - private final static String coreVersion = "2.4.19"; + private final static String coreVersion = "2.4.20"; /** * This is specific to the website api diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index 0842ab8d..80ad177a 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -2,7 +2,6 @@ package com.songoda.core.compatibility; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.inventory.ItemStack; @@ -1336,7 +1335,14 @@ public enum CompatibleMaterial { * @return LegacyMaterial or null if none found */ public static CompatibleMaterial getMaterial(Material mat) { - return mat == null ? null : lookupMap.get(mat.name()); + if (mat == null) + return null; + if (useLegacy) { + CompatibleMaterial compatibleMaterial = lookupMap.get(mat.name() + ":0"); + if (compatibleMaterial != null) + return compatibleMaterial; + } + return lookupMap.get(mat.name()); } /** @@ -1381,6 +1387,7 @@ public enum CompatibleMaterial { } private static Method methodGetBlockData; + static { if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { try { @@ -1395,7 +1402,6 @@ public enum CompatibleMaterial { * Lookup a Material by FallingBlock, corrected for legacy * * @param block falling block to check - * * @return LegacyMaterial or null if none found */ public static CompatibleMaterial getMaterial(FallingBlock block) { @@ -1446,12 +1452,13 @@ public enum CompatibleMaterial { } Material mat = block.getType(); if (useLegacy) { - LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name()); + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name(), block.getData()); if (legacyBlock != null) { return lookupMap.get(legacyBlock.name()); } } - return lookupMap.get(mat.name()); + CompatibleMaterial withData = lookupMap.get(mat.name() + ":" + block.getData()); + return withData == null ? lookupMap.get(mat.name()) : withData; } /** @@ -1548,6 +1555,34 @@ public enum CompatibleMaterial { return mat != null ? new ItemStack(mat) : null; } + private static Method methodSetData; + static { + if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + try { + methodSetData = Block.class.getDeclaredMethod("setData", byte.class); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + } + + /** + * Apply the current material to a block. + * + * @param block the block to apply the material to. + */ + public void applyToBlock(Block block) { + if (block == null) return; + block.setType(material); + if (data != -1 && ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + try { + methodSetData.invoke(block, data); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + } + /** * Check to see if an item matches this specific material type * @@ -1872,7 +1907,7 @@ public enum CompatibleMaterial { /** * Get the result of putting this item * into a furnace. - * + *

* return */ public CompatibleMaterial getBurnResult() { diff --git a/Core/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java b/Core/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java index 01e57278..b92f0a0a 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java +++ b/Core/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java @@ -14,6 +14,13 @@ import java.util.Map; */ public enum LegacyMaterialBlockType { + OAK_LEAVES("LEAVES", (byte)8, true), + SPRUCE_LEAVES("LEAVES", (byte)9, true), + BIRCH_LEAVES("LEAVES", (byte)10, true), + JUNGLE_LEAVES("LEAVES", (byte)11, true), + ACACIA_LEAVES("LEAVES_2", (byte)8, true), + DARK_OAK_LEAVES("LEAVES_2", (byte)9, true), + ACACIA_DOOR("ACACIA_DOOR", true), BED("BED_BLOCK", true), BIRCH_DOOR("BIRCH_DOOR", true), @@ -45,6 +52,7 @@ public enum LegacyMaterialBlockType { WATER("STATIONARY_WATER"), WHEAT("CROPS"); final String blockMaterialName; + final byte blockData; final String alternateBlockMaterialName; final Material blockMaterial, alternateBlockMaterial; final boolean requiresData; // some blocks require data to render properly (double blocks) @@ -54,7 +62,7 @@ public enum LegacyMaterialBlockType { static { for (LegacyMaterialBlockType t : values()) { lookupTable.put(t.name(), t); - reverseLookupTable.put(t.blockMaterialName, t); + reverseLookupTable.put(t.blockMaterialName + ":" + t.blockData, t); if (t.alternateBlockMaterialName != null) { reverseLookupTable.put(t.alternateBlockMaterialName, t); } @@ -62,23 +70,28 @@ public enum LegacyMaterialBlockType { } private LegacyMaterialBlockType(String blockMaterial) { - this(blockMaterial, null, false); + this(blockMaterial, (byte)-1, null,false); } private LegacyMaterialBlockType(String blockMaterial, boolean requiresData) { - this(blockMaterial, null, requiresData); + this(blockMaterial, (byte)-1, null, requiresData); + } + + private LegacyMaterialBlockType(String blockMaterial, byte data, boolean requiresData) { + this(blockMaterial, data, null, requiresData); } private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial) { - this(blockMaterial, alternateMaterial, false); + this(blockMaterial, (byte)-1, alternateMaterial, false); } - private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial, boolean requiresData) { + private LegacyMaterialBlockType(String blockMaterial, byte data, String alternateMaterial, boolean requiresData) { this.blockMaterialName = blockMaterial; this.alternateBlockMaterialName = alternateMaterial; this.requiresData = requiresData; this.blockMaterial = Material.getMaterial(blockMaterialName); this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName); + this.blockData = data; } public String getBlockMaterialName() { @@ -105,8 +118,12 @@ public enum LegacyMaterialBlockType { return lookupTable.get(lookup); } + public static LegacyMaterialBlockType getFromLegacy(String lookup, byte data) { + return reverseLookupTable.get(lookup + ":" + data); + } + public static LegacyMaterialBlockType getFromLegacy(String lookup) { - return reverseLookupTable.get(lookup); + return getFromLegacy(lookup, (byte)-1); } } diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index 05ce4f78..d5c067bf 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 3d999f05..8146f6d4 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 2bd8c26d..af6fe72f 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index dc010ffd..5c9b4faa 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index 77bc0277..ed524b6a 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index 299996ce..bed9ab34 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 0a0a3cfa..8279f619 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index ee6d55b1..1b381d39 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index 45435eda..179554ca 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index a50e5706..5b6763d8 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 84090077..a629f69c 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index af3f5604..08818378 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index 87d9dc9a..30859828 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 94472a34..c5b7cc1e 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 2036967d..1979aa6e 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 ../../ diff --git a/pom.xml b/pom.xml index 727137f8..832520a5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda SongodaCore-Modules - 2.4.19 + 2.4.20 4.0.0 pom