mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-06-28 10:44:48 +02:00
More merge fixes
and use "Levelled" for Cauldrons in 1.13
This commit is contained in:
parent
dd495d5204
commit
54a05b83fe
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,6 +12,7 @@
|
|||
|
||||
# IntelliJ
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
# various other potential build files
|
||||
/build
|
||||
|
@ -23,4 +24,4 @@
|
|||
.DS_Store
|
||||
|
||||
# maven
|
||||
/target
|
||||
/target
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -35,8 +35,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
name: Brewery
|
||||
version: 1.7
|
||||
main: com.dre.brewery.P
|
||||
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, Citadel]
|
||||
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.dre.brewery;
|
|||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -9,6 +10,7 @@ import org.bukkit.block.BlockFace;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.material.Cauldron;
|
||||
|
||||
public class BCauldron {
|
||||
public static CopyOnWriteArrayList<BCauldron> bcauldrons = new CopyOnWriteArrayList<>();
|
||||
|
@ -94,21 +96,37 @@ public class BCauldron {
|
|||
}
|
||||
ItemStack potion = bcauldron.ingredients.cook(bcauldron.state);
|
||||
if (potion != null) {
|
||||
byte data = block.getData();
|
||||
if (data > 3) {
|
||||
data = 3;
|
||||
LegacyUtil.setData(block, data);
|
||||
} else if (data <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
return false;
|
||||
}
|
||||
data -= 1;
|
||||
LegacyUtil.setData(block, data);
|
||||
|
||||
if (data == 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
if (P.use1_13) {
|
||||
Levelled cauldron = ((Levelled) block.getBlockData());
|
||||
if (cauldron.getLevel() <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
return false;
|
||||
}
|
||||
cauldron.setLevel(cauldron.getLevel() - 1);
|
||||
|
||||
if (cauldron.getLevel() <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
byte data = block.getData();
|
||||
if (data > 3) {
|
||||
data = 3;
|
||||
} else if (data <= 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
return false;
|
||||
}
|
||||
data -= 1;
|
||||
LegacyUtil.setData(block, data);
|
||||
|
||||
if (data == 0) {
|
||||
bcauldrons.remove(bcauldron);
|
||||
} else {
|
||||
bcauldron.someRemoved = true;
|
||||
}
|
||||
}
|
||||
// Bukkit Bug, inventory not updating while in event so this
|
||||
// will delay the give
|
||||
|
@ -201,4 +219,4 @@ public class BCauldron {
|
|||
}, 1L);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,196 +1,197 @@
|
|||
package com.dre.brewery;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.Bukkit;
|
||||
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 {
|
||||
|
||||
private static Method GET_MATERIAL;
|
||||
private static Method GET_BLOCK_TYPE_ID_AT;
|
||||
private static Method SET_DATA;
|
||||
|
||||
static {
|
||||
// -1.12.2 methods
|
||||
try {
|
||||
GET_MATERIAL = Material.class.getDeclaredMethod("getMaterial", int.class);
|
||||
GET_BLOCK_TYPE_ID_AT = World.class.getDeclaredMethod("getBlockTypeIdAt", Location.class);
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
}
|
||||
// 1.13+ methods
|
||||
try {
|
||||
SET_DATA = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".block.CraftBlock").getDeclaredMethod("setData", byte.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
public static final Material BIRCH_STAIRS = get("BIRCH_STAIRS", "BIRCH_WOOD_STAIRS");
|
||||
public static final Material JUNGLE_STAIRS = get("JUNGLE_STAIRS", "JUNGLE_WOOD_STAIRS");
|
||||
public static final Material ACACIA_STAIRS = get("ACACIA_STAIRS");
|
||||
public static final Material DARK_OAK_STAIRS = get("DARK_OAK_STAIRS");
|
||||
|
||||
private static Material get(String name) {
|
||||
try {
|
||||
return Material.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Material get(String newName, String oldName) {
|
||||
try {
|
||||
return Material.valueOf(P.use1_13 ? newName : oldName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWoodPlanks(Material type) {
|
||||
return type.name().contains("PLANKS") || type.name().equals("WOOD");
|
||||
}
|
||||
|
||||
public static boolean isWoodStairs(Material type) {
|
||||
return type == OAK_STAIRS || type == SPRUCE_STAIRS || type == BIRCH_STAIRS || type == JUNGLE_STAIRS
|
||||
|| (type == ACACIA_STAIRS && ACACIA_STAIRS != null) || (type == DARK_OAK_STAIRS && DARK_OAK_STAIRS != null);
|
||||
}
|
||||
|
||||
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 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} 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.getBlockData());
|
||||
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;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBlockTypeIdAt(Location location) {
|
||||
try {
|
||||
return GET_BLOCK_TYPE_ID_AT != null ? (int) GET_BLOCK_TYPE_ID_AT.invoke(location.getWorld(), location) : 0;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Setting byte data to blocks works in 1.13, but isn't part of the API anymore
|
||||
public static void setData(Block block, byte data) {
|
||||
try {
|
||||
SET_DATA.invoke(block, data);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.dre.brewery;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.Bukkit;
|
||||
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.Stairs;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.Wood;
|
||||
|
||||
public class LegacyUtil {
|
||||
|
||||
private static Method GET_MATERIAL;
|
||||
private static Method GET_BLOCK_TYPE_ID_AT;
|
||||
private static Method SET_DATA;
|
||||
|
||||
static {
|
||||
// <= 1.12.2 methods
|
||||
try {
|
||||
GET_MATERIAL = Material.class.getDeclaredMethod("getMaterial", int.class);
|
||||
GET_BLOCK_TYPE_ID_AT = World.class.getDeclaredMethod("getBlockTypeIdAt", Location.class);
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
}
|
||||
try {
|
||||
SET_DATA = Class.forName(Bukkit.getServer().getClass().getPackage().getName() + ".block.CraftBlock").getDeclaredMethod("setData", byte.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
public static final Material BIRCH_STAIRS = get("BIRCH_STAIRS", "BIRCH_WOOD_STAIRS");
|
||||
public static final Material JUNGLE_STAIRS = get("JUNGLE_STAIRS", "JUNGLE_WOOD_STAIRS");
|
||||
public static final Material ACACIA_STAIRS = get("ACACIA_STAIRS");
|
||||
public static final Material DARK_OAK_STAIRS = get("DARK_OAK_STAIRS");
|
||||
|
||||
private static Material get(String name) {
|
||||
try {
|
||||
return Material.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Material get(String newName, String oldName) {
|
||||
try {
|
||||
return Material.valueOf(P.use1_13 ? newName : oldName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWoodPlanks(Material type) {
|
||||
return type.name().endsWith("PLANKS") || type.name().equals("WOOD");
|
||||
}
|
||||
|
||||
public static boolean isWoodStairs(Material type) {
|
||||
return type == OAK_STAIRS || type == SPRUCE_STAIRS || type == BIRCH_STAIRS || type == JUNGLE_STAIRS
|
||||
|| (type == ACACIA_STAIRS && ACACIA_STAIRS != null) || (type == DARK_OAK_STAIRS && DARK_OAK_STAIRS != null);
|
||||
}
|
||||
|
||||
public static boolean isFence(Material type) {
|
||||
return type.name().endsWith("FENCE");
|
||||
}
|
||||
|
||||
public static boolean isSign(Material type) {
|
||||
return type == Material.SIGN || type == Material.WALL_SIGN || (!P.use1_13 && type.name().equals("SIGN_POST"));
|
||||
}
|
||||
|
||||
// LAVA and STATIONARY_LAVA are merged as of 1.13
|
||||
public static boolean isLava(Material type) {
|
||||
return type == Material.LAVA || (!P.use1_13 && type.name().equals("STATIONARY_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 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} 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.getBlockData());
|
||||
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;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Only used for very old versions of LogBlock
|
||||
public static int getBlockTypeIdAt(Location location) {
|
||||
try {
|
||||
return GET_BLOCK_TYPE_ID_AT != null ? (int) GET_BLOCK_TYPE_ID_AT.invoke(location.getWorld(), location) : 0;
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Setting byte data to blocks for older versions
|
||||
public static void setData(Block block, byte data) {
|
||||
try {
|
||||
SET_DATA.invoke(block, data);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,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_12 = !v.matches("(^|.*[^\\.\\d])1\\.[0-11]([^\\d].*|$)");
|
||||
use1_12 = !v.matches("(^|.*[^\\.\\d])1\\.1[0-1]([^\\d].*|$)") && !v.matches("(^|.*[^\\.\\d])1\\.[0-9]([^\\d].*|$)");
|
||||
use1_13 = !v.matches("(^|.*[^\\.\\d])1\\.1[0-2]([^\\d].*|$)") && !v.matches("(^|.*[^\\.\\d])1\\.[0-9]([^\\d].*|$)");
|
||||
|
||||
// load the Config
|
||||
|
@ -95,7 +95,11 @@ public class P extends JavaPlugin {
|
|||
readData();
|
||||
|
||||
// Setup Metrics
|
||||
new Metrics(this);
|
||||
try {
|
||||
new Metrics(this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Listeners
|
||||
blockListener = new BlockListener();
|
||||
|
|
|
@ -24,7 +24,7 @@ public class WGBarrel7 implements WGBarrel {
|
|||
WorldGuardPlugin wg = (WorldGuardPlugin) plugin;
|
||||
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||
|
||||
World world = platform.getWorldByName(spigot.getWorld().getName());
|
||||
World world = platform.getWorldByName(spigot.getWorld().getName());
|
||||
if (!platform.getGlobalStateManager().get(world).useRegions) return true; // Region support disabled
|
||||
WorldEditPlugin we = JavaPlugin.getPlugin(WorldEditPlugin.class);
|
||||
if (new RegionPermissionModel((Actor) we.wrapPlayer(player)).mayIgnoreRegionProtection(world)) return true; // Whitelisted cause
|
||||
|
|
Loading…
Reference in New Issue
Block a user