mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-21 21:01:20 +01:00
Avoid MaterialData in 1.13
This commit is contained in:
parent
27ecf2e196
commit
576ad7f3c9
10
pom.xml
10
pom.xml
@ -50,7 +50,7 @@
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>http://repo.mvdw-software.be/content/groups/public/<!--https://hub.spigotmc.org/nexus/content/groups/public/--></url>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
@ -60,6 +60,10 @@
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dre2n-rpo</id>
|
||||
<url>http://erethon.de/repo/</url>
|
||||
@ -70,7 +74,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>18w03b-R0.1-SNAPSHOT<!--1.12.2--></version>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -92,7 +96,7 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.ryanhamshire</groupId>
|
||||
<groupId>com.github.TechFortress</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.8</version>
|
||||
<scope>provided</scope>
|
||||
|
@ -1,8 +1,9 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: com.dre.brewery.P
|
||||
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan]
|
||||
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
|
||||
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault]
|
||||
#api-version: 1.13
|
||||
commands:
|
||||
brewery:
|
||||
description: Command for Administration
|
||||
|
@ -9,8 +9,6 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.material.Cauldron;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class BCauldron {
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>();
|
||||
@ -36,8 +34,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() == LegacyUtil.LAVA
|
||||
|| block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
if (!block.getChunk().isLoaded() || block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || LegacyUtil.isLava(block.getRelative(BlockFace.DOWN).getType())) {
|
||||
// add a minute to cooking time
|
||||
state++;
|
||||
if (someRemoved) {
|
||||
@ -74,7 +71,7 @@ public class BCauldron {
|
||||
// get cauldron from block and add given ingredient
|
||||
public static boolean ingredientAdd(Block block, ItemStack ingredient) {
|
||||
// if not empty
|
||||
if (getFillLevel(block) != 0) {
|
||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldron.add(ingredient);
|
||||
@ -125,24 +122,6 @@ public class BCauldron {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0 = empty, 1 = something in, 2 = full
|
||||
public static byte getFillLevel(Block block) {
|
||||
if (block.getType() == Material.CAULDRON) {
|
||||
MaterialData data = block.getState().getData();
|
||||
if (data instanceof Cauldron) {
|
||||
Cauldron cauldron = (Cauldron) data;
|
||||
if (cauldron.isEmpty()) {
|
||||
return 0;
|
||||
} else if (cauldron.isFull()) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// prints the current cooking time to the player
|
||||
public static void printTime(Player player, Block block) {
|
||||
if (!player.hasPermission("brewery.cauldron.time")) {
|
||||
@ -161,7 +140,7 @@ public class BCauldron {
|
||||
|
||||
// reset to normal cauldron
|
||||
public static void remove(Block block) {
|
||||
if (getFillLevel(block) != 0) {
|
||||
if (LegacyUtil.getFillLevel(block) != 0) {
|
||||
BCauldron bcauldron = get(block);
|
||||
if (bcauldron != null) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
|
@ -5,7 +5,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.Block;
|
||||
@ -15,10 +14,6 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.Wood;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -612,50 +607,7 @@ public class Barrel implements InventoryHolder {
|
||||
default:
|
||||
wood = spigot.getRelative(0, 0, -1);
|
||||
}
|
||||
|
||||
Material type = wood.getType();
|
||||
if (LegacyUtil.isWoodPlanks(type)) {
|
||||
MaterialData data = wood.getState().getData();
|
||||
TreeSpecies woodType;
|
||||
if (data instanceof Tree) {
|
||||
woodType = ((Tree) data).getSpecies();
|
||||
} else if (data instanceof Wood) {
|
||||
woodType = ((Wood) data).getSpecies();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (woodType) {
|
||||
case GENERIC:
|
||||
return 2;
|
||||
case REDWOOD:
|
||||
return 4;
|
||||
case BIRCH:
|
||||
return 1;
|
||||
case JUNGLE:
|
||||
return 3;
|
||||
case ACACIA:
|
||||
return 5;
|
||||
case DARK_OAK:
|
||||
return 6;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if (type == LegacyUtil.OAK_STAIRS) {
|
||||
return 2;
|
||||
} else if (type == LegacyUtil.SPRUCE_STAIRS) {
|
||||
return 4;
|
||||
} else if (type == LegacyUtil.BIRCH_STAIRS) {
|
||||
return 1;
|
||||
} else if (type == LegacyUtil.JUNGLE_STAIRS) {
|
||||
return 3;
|
||||
} else if (type == LegacyUtil.ACACIA_STAIRS) {
|
||||
return 5;
|
||||
} else if (type == LegacyUtil.DARK_OAK_STAIRS) {
|
||||
return 6;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return LegacyUtil.getWoodType(wood);
|
||||
}
|
||||
|
||||
// returns the Sign of a large barrel, the spigot if there is none
|
||||
@ -751,11 +703,8 @@ public class Barrel implements InventoryHolder {
|
||||
if (LegacyUtil.isWoodStairs(type)) {
|
||||
if (y == 0) {
|
||||
// stairs have to be upside down
|
||||
MaterialData data = block.getState().getData();
|
||||
if (data instanceof Stairs) {
|
||||
if (!((Stairs) data).isInverted()) {
|
||||
return block;
|
||||
}
|
||||
if (!LegacyUtil.areStairsInverted(block)) {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
stairs.add(block.getX());
|
||||
|
@ -4,7 +4,15 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.material.Cauldron;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.Wood;
|
||||
|
||||
public class LegacyUtil {
|
||||
|
||||
@ -19,8 +27,6 @@ public class LegacyUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static final Material FLOWING_LAVA = get("FLOWING_LAVA", "LAVA");
|
||||
public static final Material LAVA = get("LAVA", "STATIONARY_LAVA");
|
||||
public static final Material CLOCK = get("CLOCK", "WATCH");
|
||||
public static final Material OAK_STAIRS = get("OAK_STAIRS", "WOOD_STAIRS");
|
||||
public static final Material SPRUCE_STAIRS = get("SPRUCE_STAIRS", "SPRUCE_WOOD_STAIRS");
|
||||
@ -54,14 +60,105 @@ public class LegacyUtil {
|
||||
|| (type == ACACIA_STAIRS && ACACIA_STAIRS != null) || (type == DARK_OAK_STAIRS && DARK_OAK_STAIRS != null);
|
||||
}
|
||||
|
||||
public static boolean isFence(Material material) {
|
||||
return material.name().endsWith("FENCE");
|
||||
public static boolean isFence(Material type) {
|
||||
return type.name().endsWith("FENCE");
|
||||
}
|
||||
|
||||
public static boolean isSign(Material type) {
|
||||
return type.name().equals("SIGN_POST") || type == Material.SIGN || type == Material.WALL_SIGN;
|
||||
}
|
||||
|
||||
// LAVA and STATIONARY_LAVA are merged as of 1.13
|
||||
public static boolean isLava(Material type) {
|
||||
return type.name().equals("STATIONARY_LAVA") || type == Material.LAVA;
|
||||
}
|
||||
|
||||
public static boolean areStairsInverted(Block block) {
|
||||
if (P.use1_13) {
|
||||
MaterialData data = block.getState().getData();
|
||||
return data instanceof org.bukkit.material.Stairs && (((org.bukkit.material.Stairs) data).isInverted());
|
||||
} else {
|
||||
BlockData data = block.getBlockData();
|
||||
return data instanceof org.bukkit.block.data.type.Stairs && ((org.bukkit.block.data.type.Stairs) data).getHalf() == org.bukkit.block.data.type.Stairs.Half.TOP;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte getWoodType(Block wood) {
|
||||
TreeSpecies woodType = null;
|
||||
|
||||
if (P.use1_13 || isWoodStairs(wood.getType())) {
|
||||
String material = wood.getType().name();
|
||||
if (material.startsWith("OAK")) {
|
||||
woodType = TreeSpecies.GENERIC;
|
||||
} else if (material.startsWith("SPRUCE")) {
|
||||
woodType = TreeSpecies.REDWOOD;
|
||||
} else if (material.startsWith("BIRCH")) {
|
||||
woodType = TreeSpecies.BIRCH;
|
||||
} else if (material.startsWith("JUNGLE")) {
|
||||
woodType = TreeSpecies.JUNGLE;
|
||||
} else if (material.startsWith("ACACIA")) {
|
||||
woodType = TreeSpecies.ACACIA;
|
||||
} else if (material.startsWith("DARK_OAK")) {
|
||||
woodType = TreeSpecies.DARK_OAK;
|
||||
}
|
||||
|
||||
} else {
|
||||
MaterialData data = wood.getState().getData();
|
||||
if (data instanceof Tree) {
|
||||
woodType = ((Tree) data).getSpecies();
|
||||
} else if (data instanceof Wood) {
|
||||
woodType = ((Wood) data).getSpecies();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (woodType) {
|
||||
case GENERIC:
|
||||
return 2;
|
||||
case REDWOOD:
|
||||
return 4;
|
||||
case BIRCH:
|
||||
return 1;
|
||||
case JUNGLE:
|
||||
return 3;
|
||||
case ACACIA:
|
||||
return 5;
|
||||
case DARK_OAK:
|
||||
return 6;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 0 = empty, 1 = something in, 2 = full
|
||||
public static byte getFillLevel(Block block) {
|
||||
if (block.getType() != Material.CAULDRON) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (P.use1_13) {
|
||||
Levelled cauldron = ((Levelled) block);
|
||||
if (cauldron.getLevel() == 0) {
|
||||
return 0;
|
||||
} else if (cauldron.getLevel() == cauldron.getMaximumLevel()) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
Cauldron cauldron = (Cauldron) block.getState().getData();
|
||||
if (cauldron.isEmpty()) {
|
||||
return 0;
|
||||
} else if (cauldron.isFull()) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Material getMaterial(int id) {
|
||||
try {
|
||||
return GET_MATERIAL != null ? (Material) GET_MATERIAL.invoke(null, id) : null;
|
||||
|
@ -67,18 +67,17 @@ public class PlayerListener implements Listener {
|
||||
// reset cauldron when refilling to prevent unlimited source of potions
|
||||
} else if (materialInHand == Material.WATER_BUCKET) {
|
||||
if (!P.use1_9) {
|
||||
if (BCauldron.getFillLevel(clickedBlock) != 0 && BCauldron.getFillLevel(clickedBlock) < 2) {
|
||||
if (LegacyUtil.getFillLevel(clickedBlock) == 1) {
|
||||
// will only remove when existing
|
||||
BCauldron.remove(clickedBlock);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Check if fire alive below cauldron when adding ingredients
|
||||
Block down = clickedBlock.getRelative(BlockFace.DOWN);
|
||||
if (down.getType() == Material.FIRE || down.getType() == LegacyUtil.LAVA || down.getType() == LegacyUtil.FLOWING_LAVA) {
|
||||
if (down.getType() == Material.FIRE || LegacyUtil.isLava(down.getType())) {
|
||||
|
||||
event.setCancelled(true);
|
||||
boolean handSwap = false;
|
||||
|
Loading…
Reference in New Issue
Block a user