Replace old materials with dynamic calls

This commit is contained in:
Daniel Saukel 2018-01-28 20:48:27 +01:00
parent 1a9e9e3a13
commit 951fb18dc9
7 changed files with 43 additions and 27 deletions

View File

@ -46,7 +46,7 @@
<repositories>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
<url>http://repo.mvdw-software.be/content/groups/public/<!--->http://repo.md-5.net/content/repositories/releases/<--></url>
</repository>
<repository>
<id>spigot-repo</id>
@ -74,7 +74,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<version>18w03b-R0.1-SNAPSHOT<!-->1.12.2<--></version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -36,7 +36,7 @@ public class BCauldron {
public void onUpdate() {
// Check if fire still alive
if (!block.getChunk().isLoaded() || block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA
if (!block.getChunk().isLoaded() || block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == LegacyUtil.LAVA
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
// add a minute to cooking time
state++;

View File

@ -64,7 +64,7 @@ public class BRecipe {
if (durability == -1 && vaultItem.getSubTypeId() != 0) {
durability = vaultItem.getSubTypeId();
}
if (mat == Material.LEAVES) {
if (mat.name().contains("LEAVES")) {
if (durability > 3) {
durability -= 4; // Vault has leaves with higher durability
}

View File

@ -161,7 +161,7 @@ public class Barrel implements InventoryHolder {
if (plugin != null) {
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here
if (!isSign(event.getClickedBlock())) {
if (!LegacyUtil.isSign(event.getClickedBlock().getType())) {
Block sign = getSignOfSpigot();
// If the Barrel does not have a Sign, it cannot be locked
if (!sign.equals(event.getClickedBlock())) {
@ -272,7 +272,7 @@ public class Barrel implements InventoryHolder {
// Returns true if this Block is part of this Barrel
public boolean hasBlock(Block block) {
if (block != null) {
if (block.getType().equals(Material.WOOD)) {
if (LegacyUtil.isWoodPlanks(block.getType())) {
if (hasWoodBlock(block)) {
return true;
}
@ -398,7 +398,7 @@ public class Barrel implements InventoryHolder {
// Get the barrel by its corpus (Wood Planks, Stairs)
public static Barrel getByWood(Block wood) {
if (wood.getType().equals(Material.WOOD)) {
if (LegacyUtil.isWoodPlanks(wood.getType())) {
for (Barrel barrel : barrels) {
if (barrel.hasWoodBlock(wood)) {
return barrel;
@ -427,7 +427,7 @@ public class Barrel implements InventoryHolder {
if (barrel == null) {
barrel = new Barrel(spigot, signoffset);
if (barrel.getBrokenBlock(true) == null) {
if (isSign(spigot)) {
if (LegacyUtil.isSign(spigot.getType())) {
if (!player.hasPermission("brewery.createbarrel.small")) {
P.p.msg(player, P.p.languageReader.get("Perms_NoSmallBarrelCreate"));
return false;
@ -582,11 +582,11 @@ public class Barrel implements InventoryHolder {
public static int getDirection(Block spigot) {
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
Material type = spigot.getRelative(0, 0, 1).getType();
if (type == Material.WOOD || isStairs(type)) {
if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
direction = 3;
}
type = spigot.getRelative(0, 0, -1).getType();
if (type == Material.WOOD || isStairs(type)) {
if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) {
direction = 4;
} else {
@ -594,7 +594,7 @@ public class Barrel implements InventoryHolder {
}
}
type = spigot.getRelative(1, 0, 0).getType();
if (type == Material.WOOD || isStairs(type)) {
if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) {
direction = 1;
} else {
@ -602,7 +602,7 @@ public class Barrel implements InventoryHolder {
}
}
type = spigot.getRelative(-1, 0, 0).getType();
if (type == Material.WOOD || isStairs(type)) {
if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) {
direction = 2;
} else {
@ -614,12 +614,7 @@ public class Barrel implements InventoryHolder {
// is this a Large barrel?
public boolean isLarge() {
return !isSign(spigot);
}
// true for small barrels
public static boolean isSign(Block spigot) {
return spigot.getType() == Material.WALL_SIGN || spigot.getType() == Material.SIGN_POST;
return !LegacyUtil.isSign(spigot.getType());
}
// woodtype of the block the spigot is attached to
@ -695,11 +690,11 @@ public class Barrel implements InventoryHolder {
// returns the Sign of a large barrel, the spigot if there is none
public Block getSignOfSpigot() {
if (signoffset != 0) {
if (isSign(spigot)) {
if (LegacyUtil.isSign(spigot.getType())) {
return spigot;
}
if (isSign(spigot.getRelative(0, signoffset, 0))) {
if (LegacyUtil.isSign(spigot.getRelative(0, signoffset, 0).getType())) {
return spigot.getRelative(0, signoffset, 0);
} else {
signoffset = 0;
@ -759,7 +754,7 @@ public class Barrel implements InventoryHolder {
public Block getBrokenBlock(boolean force) {
if (force || spigot.getChunk().isLoaded()) {
spigot = getSpigotOfSign(spigot);
if (isSign(spigot)) {
if (LegacyUtil.isSign(spigot.getType())) {
return checkSBarrel();
} else {
return checkLBarrel();
@ -906,8 +901,8 @@ public class Barrel implements InventoryHolder {
continue;
}
}
if (type == Material.WOOD || isStairs(type)) {
if (type == Material.WOOD) {
if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (LegacyUtil.isWoodPlanks(type)) {
woods.add(block.getX());
woods.add(block.getY());
woods.add(block.getZ());

View File

@ -0,0 +1,19 @@
package com.dre.brewery;
import org.bukkit.Material;
public class LegacyUtil {
public static final Material FLOWING_LAVA = Material.valueOf(P.use1_13 ? "FLOWING_LAVA" : "LAVA");
public static final Material LAVA = Material.valueOf(P.use1_13 ? "LAVA" : "STATIONARY_LAVA");
public static final Material CLOCK = Material.valueOf(P.use1_13 ? "CLOCK" : "WATCH");
public static boolean isWoodPlanks(Material type) {
return type.name().contains("PLANKS") || type.name().equals("WOOD");
}
public static boolean isSign(Material type) {
return type.name().equals("LEGACY_SIGN_POST") || type == Material.SIGN || type == Material.WALL_SIGN;
}
}

View File

@ -39,6 +39,7 @@ public class P extends JavaPlugin {
public static boolean debug;
public static boolean useUUID;
public static boolean use1_9;
public static boolean use1_13;
public static boolean updateCheck;
// Third Party Enabled
@ -70,6 +71,7 @@ public class P extends JavaPlugin {
String v = Bukkit.getBukkitVersion();
useUUID = !v.matches("(^|.*[^\\.\\d])1\\.[0-6]([^\\d].*|$)") && !v.matches("(^|.*[^\\.\\d])1\\.7\\.[0-5]([^\\d].*|$)");
use1_9 = !v.matches("(^|.*[^\\.\\d])1\\.[0-8]([^\\d].*|$)");
use1_13 = !v.matches("(^|.*[^\\.\\d])1\\.1[0-2]([^\\d].*|$)") && !v.matches("(^|.*[^\\.\\d])1\\.[0-9]([^\\d].*|$)");
// load the Config
try {

View File

@ -42,7 +42,7 @@ public class PlayerListener implements Listener {
if (materialInHand == null || materialInHand == Material.BUCKET) {
return;
} else if (materialInHand == Material.WATCH) {
} else if (materialInHand == LegacyUtil.CLOCK) {
BCauldron.printTime(player, clickedBlock);
return;
@ -78,7 +78,7 @@ public class PlayerListener implements Listener {
// Check if fire alive below cauldron when adding ingredients
Block down = clickedBlock.getRelative(BlockFace.DOWN);
if (down.getType() == Material.FIRE || down.getType() == Material.STATIONARY_LAVA || down.getType() == Material.LAVA) {
if (down.getType() == Material.FIRE || down.getType() == LegacyUtil.LAVA || down.getType() == LegacyUtil.FLOWING_LAVA) {
event.setCancelled(true);
boolean handSwap = false;
@ -147,7 +147,7 @@ public class PlayerListener implements Listener {
// Access a Barrel
Barrel barrel = null;
if (type == Material.WOOD) {
if (LegacyUtil.isWoodPlanks(type)) {
if (openEverywhere) {
barrel = Barrel.get(clickedBlock);
}
@ -160,7 +160,7 @@ public class PlayerListener implements Listener {
break;
}
}
} else if (Barrel.isFence(type) || type == Material.SIGN_POST || type == Material.WALL_SIGN) {
} else if (Barrel.isFence(type) || LegacyUtil.isSign(type)) {
barrel = Barrel.getBySpigot(clickedBlock);
}