Merge branch 'development'

This commit is contained in:
Brianna 2020-10-30 14:58:14 -05:00
commit cf55965247
20 changed files with 82 additions and 30 deletions

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../</relativePath>
</parent>

View File

@ -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

View File

@ -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.
*
* <p>
* return
*/
public CompatibleMaterial getBurnResult() {

View File

@ -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);
}
}

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -3,7 +3,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<relativePath>../../</relativePath>
</parent>

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.4.19</version>
<version>2.4.20</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>