From ffe73d777cb4fa794110bb92b4125185c1c834e2 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 22 Jul 2018 17:39:51 +0200 Subject: [PATCH] Compile against 1.13 final Bukkit build --- pom.xml | 4 +- .../erethon/dungeonsxl/config/MainConfig.java | 3 +- .../de/erethon/dungeonsxl/global/DPortal.java | 3 +- .../dungeonsxl/player/DGlobalPlayer.java | 3 +- .../dungeonsxl/player/DPlayerData.java | 3 +- .../de/erethon/dungeonsxl/sign/BlockSign.java | 7 +-- .../sign/message/SoundMessageSign.java | 5 +- .../de/erethon/dungeonsxl/util/DColor.java | 3 +- .../dungeonsxl/util/MagicValueUtil.java | 46 +++++++++++++++++++ .../dungeonsxl/world/block/TeamFlag.java | 3 +- 10 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 src/main/java/de/erethon/dungeonsxl/util/MagicValueUtil.java diff --git a/pom.xml b/pom.xml index 3382899a..8c6c0199 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ org.spigotmc spigot-api - 1.13-pre7-R0.1-SNAPSHOT + 1.13-R0.1-SNAPSHOT provided @@ -89,7 +89,7 @@ net.citizensnpcs citizens - 2.0.22-SNAPSHOT + 2.0.23-SNAPSHOT provided diff --git a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java index 8e5763c0..ce286b6b 100644 --- a/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java +++ b/src/main/java/de/erethon/dungeonsxl/config/MainConfig.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.config; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.config.DREConfig; import de.erethon.commons.misc.EnumUtil; @@ -682,7 +681,7 @@ public class MainConfig extends DREConfig { } if (config.contains("tweaksEnabled")) { - if (Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals())) { + if (Internals.isAtLeast(Internals.v1_9_R1)) { tweaksEnabled = config.getBoolean("tweaksEnabled"); } else { tweaksEnabled = false; diff --git a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java index 6b15a679..ccbb32f5 100644 --- a/src/main/java/de/erethon/dungeonsxl/global/DPortal.java +++ b/src/main/java/de/erethon/dungeonsxl/global/DPortal.java @@ -26,6 +26,7 @@ import de.erethon.dungeonsxl.game.Game; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGlobalPlayer; import de.erethon.dungeonsxl.player.DGroup; +import de.erethon.dungeonsxl.util.MagicValueUtil; import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DResourceWorld; import java.util.HashSet; @@ -168,7 +169,7 @@ public class DPortal extends GlobalProtection { Block block = getWorld().getBlockAt(xx, yy, zz); block.setType(material.getMaterial(), false); if (material == VanillaItem.NETHER_PORTAL) { - block.setData(axis); + MagicValueUtil.setBlockData(block, axis); } } diff --git a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java index 5dff9170..93c6485d 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DGlobalPlayer.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.player.PlayerUtil; import de.erethon.commons.player.PlayerWrapper; @@ -48,7 +47,7 @@ public class DGlobalPlayer implements PlayerWrapper { DungeonsXL plugin = DungeonsXL.getInstance(); - boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals()); + boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); protected Player player; diff --git a/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java b/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java index e7f4916e..1c93651f 100644 --- a/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java +++ b/src/main/java/de/erethon/dungeonsxl/player/DPlayerData.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.config.DREConfig; import de.erethon.commons.misc.EnumUtil; @@ -46,7 +45,7 @@ import org.bukkit.potion.PotionEffect; */ public class DPlayerData extends DREConfig { - boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals()); + boolean is1_9 = Internals.isAtLeast(Internals.v1_9_R1); public static final int CONFIG_VERSION = 4; diff --git a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java index 7279fb5e..13e75d3a 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/BlockSign.java @@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.sign; import de.erethon.caliburn.item.ExItem; import de.erethon.caliburn.item.VanillaItem; import de.erethon.commons.misc.NumberUtil; +import de.erethon.dungeonsxl.util.MagicValueUtil; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Sign; @@ -80,7 +81,7 @@ public class BlockSign extends DSign { getSign().getBlock().setType(offBlock.getMaterial()); try { - getSign().getBlock().setData(offBlockData); + MagicValueUtil.setBlockData(getSign().getBlock(), offBlockData); } catch (IllegalArgumentException exception) { markAsErroneous("offBlock data value " + offBlockData + " cannot be applied to given type " + offBlock.getId()); return; @@ -93,7 +94,7 @@ public class BlockSign extends DSign { if (initialized && !active) { getSign().getBlock().setType(onBlock.getMaterial()); try { - getSign().getBlock().setData(onBlockData); + MagicValueUtil.setBlockData(getSign().getBlock(), onBlockData); } catch (IllegalArgumentException exception) { markAsErroneous("onBlock data value " + onBlockData + " cannot be applied to given type " + onBlock.getId()); return; @@ -106,7 +107,7 @@ public class BlockSign extends DSign { public void onDisable() { if (initialized && active) { getSign().getBlock().setType(offBlock.getMaterial()); - getSign().getBlock().setData(offBlockData); + MagicValueUtil.setBlockData(getSign().getBlock(), offBlockData); active = false; } } diff --git a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java index fb6f6ef9..1addddc3 100644 --- a/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java +++ b/src/main/java/de/erethon/dungeonsxl/sign/message/SoundMessageSign.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.sign.message; import de.erethon.caliburn.item.VanillaItem; -import de.erethon.commons.compatibility.CompatibilityHandler; import de.erethon.commons.compatibility.Internals; import de.erethon.commons.misc.EnumUtil; import de.erethon.commons.misc.NumberUtil; @@ -64,7 +63,7 @@ public class SoundMessageSign extends DSign { sound = lines[1]; if (!lines[2].isEmpty()) { String[] args = lines[2].split(","); - if (args.length >= 1 && args.length != 2 && Internals.andHigher(Internals.v1_11_R1).contains(CompatibilityHandler.getInstance().getInternals())) { + if (args.length >= 1 && args.length != 2 && Internals.isAtLeast(Internals.v1_11_R1)) { category = EnumUtil.getEnumIgnoreCase(SoundCategory.class, args[0]); if (category == null) { category = SoundCategory.MASTER; @@ -100,7 +99,7 @@ public class SoundMessageSign extends DSign { if (initialized) { if (!done.contains(player)) { done.add(player); - if (Internals.andHigher(Internals.v1_11_R1).contains(CompatibilityHandler.getInstance().getInternals())) { + if (Internals.isAtLeast(Internals.v1_11_R1)) { player.playSound(getSign().getLocation(), sound, category, volume, pitch); } else { player.playSound(getSign().getLocation(), sound, volume, pitch); diff --git a/src/main/java/de/erethon/dungeonsxl/util/DColor.java b/src/main/java/de/erethon/dungeonsxl/util/DColor.java index 7af76425..a06f5f1b 100644 --- a/src/main/java/de/erethon/dungeonsxl/util/DColor.java +++ b/src/main/java/de/erethon/dungeonsxl/util/DColor.java @@ -17,6 +17,7 @@ package de.erethon.dungeonsxl.util; import de.erethon.caliburn.item.VanillaItem; +import de.erethon.commons.compatibility.Internals; import org.bukkit.ChatColor; import org.bukkit.DyeColor; @@ -29,7 +30,7 @@ public enum DColor { BLACK(ChatColor.BLACK, DyeColor.BLACK, VanillaItem.BLACK_WOOL), DARK_GRAY(ChatColor.DARK_GRAY, DyeColor.GRAY, VanillaItem.GRAY_WOOL), - LIGHT_GRAY(ChatColor.GRAY, DyeColor.SILVER, VanillaItem.LIGHT_GRAY_WOOL), + LIGHT_GRAY(ChatColor.GRAY, DyeColor.valueOf(Internals.isAtLeast(Internals.v1_13_R1) ? "LIGHT_GRAY" : "SILVER"), VanillaItem.LIGHT_GRAY_WOOL), WHITE(ChatColor.WHITE, DyeColor.WHITE, VanillaItem.WHITE_WOOL), DARK_GREEN(ChatColor.DARK_GREEN, DyeColor.GREEN, VanillaItem.GREEN_WOOL), LIGHT_GREEN(ChatColor.GREEN, DyeColor.LIME, VanillaItem.LIME_WOOL), diff --git a/src/main/java/de/erethon/dungeonsxl/util/MagicValueUtil.java b/src/main/java/de/erethon/dungeonsxl/util/MagicValueUtil.java new file mode 100644 index 00000000..6e06c18c --- /dev/null +++ b/src/main/java/de/erethon/dungeonsxl/util/MagicValueUtil.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2012-2018 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.erethon.dungeonsxl.util; + +import de.erethon.commons.misc.ReflectionUtil; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import org.bukkit.block.Block; + +/** + * @author Daniel Saukel + */ +@Deprecated +public class MagicValueUtil { + + private static Method CRAFT_BLOCK_SET_DATA; + + static { + try { + CRAFT_BLOCK_SET_DATA = Class.forName(ReflectionUtil.ORG_BUKKIT_CRAFTBUKKIT + ".block.CraftBlock").getDeclaredMethod("setData", byte.class); + } catch (NoSuchMethodException | SecurityException | ClassNotFoundException exception) { + } + } + + public static void setBlockData(Block block, byte data) { + try { + CRAFT_BLOCK_SET_DATA.invoke(block, data); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { + } + } + +} diff --git a/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java b/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java index 852fc16c..f8f4d2f9 100644 --- a/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java +++ b/src/main/java/de/erethon/dungeonsxl/world/block/TeamFlag.java @@ -23,6 +23,7 @@ import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGamePlayer; import de.erethon.dungeonsxl.player.DGroup; import de.erethon.dungeonsxl.util.DColor; +import de.erethon.dungeonsxl.util.MagicValueUtil; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; @@ -67,7 +68,7 @@ public class TeamFlag extends TeamBlock { public static void setBlockWoolColor(Block block, DColor color) { block.setType(color.getWoolMaterial().getMaterial()); if (!CompatibilityHandler.getInstance().getVersion().useNewMaterials()) { - block.setData(color.getWoolData()); + MagicValueUtil.setBlockData(block, color.getWoolData()); } }