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
+2 -2
View File
@@ -46,7 +46,7 @@
<repositories> <repositories>
<repository> <repository>
<id>md_5-releases</id> <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>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
@@ -74,7 +74,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version> <version>18w03b-R0.1-SNAPSHOT<!-->1.12.2<--></version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
+1 -1
View File
@@ -36,7 +36,7 @@ public class BCauldron {
public void onUpdate() { public void onUpdate() {
// Check if fire still alive // 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) { || block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
// add a minute to cooking time // add a minute to cooking time
state++; state++;
+1 -1
View File
@@ -64,7 +64,7 @@ public class BRecipe {
if (durability == -1 && vaultItem.getSubTypeId() != 0) { if (durability == -1 && vaultItem.getSubTypeId() != 0) {
durability = vaultItem.getSubTypeId(); durability = vaultItem.getSubTypeId();
} }
if (mat == Material.LEAVES) { if (mat.name().contains("LEAVES")) {
if (durability > 3) { if (durability > 3) {
durability -= 4; // Vault has leaves with higher durability durability -= 4; // Vault has leaves with higher durability
} }
+14 -19
View File
@@ -161,7 +161,7 @@ public class Barrel implements InventoryHolder {
if (plugin != null) { if (plugin != null) {
// If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here // 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(); Block sign = getSignOfSpigot();
// If the Barrel does not have a Sign, it cannot be locked // If the Barrel does not have a Sign, it cannot be locked
if (!sign.equals(event.getClickedBlock())) { if (!sign.equals(event.getClickedBlock())) {
@@ -272,7 +272,7 @@ public class Barrel implements InventoryHolder {
// Returns true if this Block is part of this Barrel // Returns true if this Block is part of this Barrel
public boolean hasBlock(Block block) { public boolean hasBlock(Block block) {
if (block != null) { if (block != null) {
if (block.getType().equals(Material.WOOD)) { if (LegacyUtil.isWoodPlanks(block.getType())) {
if (hasWoodBlock(block)) { if (hasWoodBlock(block)) {
return true; return true;
} }
@@ -398,7 +398,7 @@ public class Barrel implements InventoryHolder {
// Get the barrel by its corpus (Wood Planks, Stairs) // Get the barrel by its corpus (Wood Planks, Stairs)
public static Barrel getByWood(Block wood) { public static Barrel getByWood(Block wood) {
if (wood.getType().equals(Material.WOOD)) { if (LegacyUtil.isWoodPlanks(wood.getType())) {
for (Barrel barrel : barrels) { for (Barrel barrel : barrels) {
if (barrel.hasWoodBlock(wood)) { if (barrel.hasWoodBlock(wood)) {
return barrel; return barrel;
@@ -427,7 +427,7 @@ public class Barrel implements InventoryHolder {
if (barrel == null) { if (barrel == null) {
barrel = new Barrel(spigot, signoffset); barrel = new Barrel(spigot, signoffset);
if (barrel.getBrokenBlock(true) == null) { if (barrel.getBrokenBlock(true) == null) {
if (isSign(spigot)) { if (LegacyUtil.isSign(spigot.getType())) {
if (!player.hasPermission("brewery.createbarrel.small")) { if (!player.hasPermission("brewery.createbarrel.small")) {
P.p.msg(player, P.p.languageReader.get("Perms_NoSmallBarrelCreate")); P.p.msg(player, P.p.languageReader.get("Perms_NoSmallBarrelCreate"));
return false; return false;
@@ -582,11 +582,11 @@ public class Barrel implements InventoryHolder {
public static int getDirection(Block spigot) { public static int getDirection(Block spigot) {
int direction = 0;// 1=x+ 2=x- 3=z+ 4=z- int direction = 0;// 1=x+ 2=x- 3=z+ 4=z-
Material type = spigot.getRelative(0, 0, 1).getType(); Material type = spigot.getRelative(0, 0, 1).getType();
if (type == Material.WOOD || isStairs(type)) { if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
direction = 3; direction = 3;
} }
type = spigot.getRelative(0, 0, -1).getType(); type = spigot.getRelative(0, 0, -1).getType();
if (type == Material.WOOD || isStairs(type)) { if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) { if (direction == 0) {
direction = 4; direction = 4;
} else { } else {
@@ -594,7 +594,7 @@ public class Barrel implements InventoryHolder {
} }
} }
type = spigot.getRelative(1, 0, 0).getType(); type = spigot.getRelative(1, 0, 0).getType();
if (type == Material.WOOD || isStairs(type)) { if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) { if (direction == 0) {
direction = 1; direction = 1;
} else { } else {
@@ -602,7 +602,7 @@ public class Barrel implements InventoryHolder {
} }
} }
type = spigot.getRelative(-1, 0, 0).getType(); type = spigot.getRelative(-1, 0, 0).getType();
if (type == Material.WOOD || isStairs(type)) { if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (direction == 0) { if (direction == 0) {
direction = 2; direction = 2;
} else { } else {
@@ -614,12 +614,7 @@ public class Barrel implements InventoryHolder {
// is this a Large barrel? // is this a Large barrel?
public boolean isLarge() { public boolean isLarge() {
return !isSign(spigot); return !LegacyUtil.isSign(spigot.getType());
}
// true for small barrels
public static boolean isSign(Block spigot) {
return spigot.getType() == Material.WALL_SIGN || spigot.getType() == Material.SIGN_POST;
} }
// woodtype of the block the spigot is attached to // 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 // returns the Sign of a large barrel, the spigot if there is none
public Block getSignOfSpigot() { public Block getSignOfSpigot() {
if (signoffset != 0) { if (signoffset != 0) {
if (isSign(spigot)) { if (LegacyUtil.isSign(spigot.getType())) {
return spigot; return spigot;
} }
if (isSign(spigot.getRelative(0, signoffset, 0))) { if (LegacyUtil.isSign(spigot.getRelative(0, signoffset, 0).getType())) {
return spigot.getRelative(0, signoffset, 0); return spigot.getRelative(0, signoffset, 0);
} else { } else {
signoffset = 0; signoffset = 0;
@@ -759,7 +754,7 @@ public class Barrel implements InventoryHolder {
public Block getBrokenBlock(boolean force) { public Block getBrokenBlock(boolean force) {
if (force || spigot.getChunk().isLoaded()) { if (force || spigot.getChunk().isLoaded()) {
spigot = getSpigotOfSign(spigot); spigot = getSpigotOfSign(spigot);
if (isSign(spigot)) { if (LegacyUtil.isSign(spigot.getType())) {
return checkSBarrel(); return checkSBarrel();
} else { } else {
return checkLBarrel(); return checkLBarrel();
@@ -906,8 +901,8 @@ public class Barrel implements InventoryHolder {
continue; continue;
} }
} }
if (type == Material.WOOD || isStairs(type)) { if (LegacyUtil.isWoodPlanks(type) || isStairs(type)) {
if (type == Material.WOOD) { if (LegacyUtil.isWoodPlanks(type)) {
woods.add(block.getX()); woods.add(block.getX());
woods.add(block.getY()); woods.add(block.getY());
woods.add(block.getZ()); woods.add(block.getZ());
+19
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;
}
}
+2
View File
@@ -39,6 +39,7 @@ public class P extends JavaPlugin {
public static boolean debug; public static boolean debug;
public static boolean useUUID; public static boolean useUUID;
public static boolean use1_9; public static boolean use1_9;
public static boolean use1_13;
public static boolean updateCheck; public static boolean updateCheck;
// Third Party Enabled // Third Party Enabled
@@ -70,6 +71,7 @@ public class P extends JavaPlugin {
String v = Bukkit.getBukkitVersion(); String v = Bukkit.getBukkitVersion();
useUUID = !v.matches("(^|.*[^\\.\\d])1\\.[0-6]([^\\d].*|$)") && !v.matches("(^|.*[^\\.\\d])1\\.7\\.[0-5]([^\\d].*|$)"); 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_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 // load the Config
try { try {
@@ -42,7 +42,7 @@ public class PlayerListener implements Listener {
if (materialInHand == null || materialInHand == Material.BUCKET) { if (materialInHand == null || materialInHand == Material.BUCKET) {
return; return;
} else if (materialInHand == Material.WATCH) { } else if (materialInHand == LegacyUtil.CLOCK) {
BCauldron.printTime(player, clickedBlock); BCauldron.printTime(player, clickedBlock);
return; return;
@@ -78,7 +78,7 @@ public class PlayerListener implements Listener {
// Check if fire alive below cauldron when adding ingredients // Check if fire alive below cauldron when adding ingredients
Block down = clickedBlock.getRelative(BlockFace.DOWN); 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); event.setCancelled(true);
boolean handSwap = false; boolean handSwap = false;
@@ -147,7 +147,7 @@ public class PlayerListener implements Listener {
// Access a Barrel // Access a Barrel
Barrel barrel = null; Barrel barrel = null;
if (type == Material.WOOD) { if (LegacyUtil.isWoodPlanks(type)) {
if (openEverywhere) { if (openEverywhere) {
barrel = Barrel.get(clickedBlock); barrel = Barrel.get(clickedBlock);
} }
@@ -160,7 +160,7 @@ public class PlayerListener implements Listener {
break; 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); barrel = Barrel.getBySpigot(clickedBlock);
} }