From c3759f8963b28ef8a061d59e3c69a01dbd297850 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 10 Aug 2017 16:46:51 +1000 Subject: [PATCH] Fixes #1672 --- Bukkit/build.gradle | 2 +- .../com/plotsquared/bukkit/BukkitMain.java | 7 +++++ .../bukkit/listeners/PlotPlusListener.java | 15 --------- .../listeners/PlotPlusListener_1_12.java | 31 +++++++++++++++++++ .../listeners/PlotPlusListener_Legacy.java | 27 ++++++++++++++++ .../bukkit/util/BukkitVersion.java | 2 ++ 6 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_1_12.java create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_Legacy.java diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index b372f9044..4d6bb295c 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -7,7 +7,7 @@ repositories { dependencies { compile project(':Core') - compile 'org.spigotmc:spigot-api:1.11.2-R0.1-SNAPSHOT' + compile 'org.spigotmc:spigot-api:1.12.1-R0.1-SNAPSHOT' compile("net.milkbowl.vault:VaultAPI:1.6") { exclude module: 'bukkit' } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ef152f135..9c8d11ef7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -49,6 +49,8 @@ import com.plotsquared.bukkit.listeners.PlayerEvents183; import com.plotsquared.bukkit.listeners.PlayerEvents_1_8; import com.plotsquared.bukkit.listeners.PlayerEvents_1_9; import com.plotsquared.bukkit.listeners.PlotPlusListener; +import com.plotsquared.bukkit.listeners.PlotPlusListener_1_12; +import com.plotsquared.bukkit.listeners.PlotPlusListener_Legacy; import com.plotsquared.bukkit.listeners.WorldEvents; import com.plotsquared.bukkit.titles.DefaultTitle_111; import com.plotsquared.bukkit.util.BukkitChatManager; @@ -532,6 +534,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain public void registerPlotPlusEvents() { PlotPlusListener.startRunnable(this); getServer().getPluginManager().registerEvents(new PlotPlusListener(), this); + if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_12_0)) { + getServer().getPluginManager().registerEvents(new PlotPlusListener_1_12(), this); + } else { + getServer().getPluginManager().registerEvents(new PlotPlusListener_Legacy(), this); + } } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java index d447431e4..7b9d43100 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener.java @@ -24,7 +24,6 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -114,20 +113,6 @@ public class PlotPlusListener extends PlotListener implements Listener { } } - @EventHandler - public void onItemPickup(PlayerPickupItemEvent event) { - Player player = event.getPlayer(); - PlotPlayer pp = BukkitUtil.getPlayer(player); - Plot plot = BukkitUtil.getLocation(player).getOwnedPlot(); - if (plot == null) { - return; - } - UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) { - event.setCancelled(true); - } - } - @EventHandler public void onItemDrop(PlayerDropItemEvent event) { Player player = event.getPlayer(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_1_12.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_1_12.java new file mode 100644 index 000000000..5abf97af5 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_1_12.java @@ -0,0 +1,31 @@ +package com.plotsquared.bukkit.listeners; + +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.plotsquared.bukkit.util.BukkitUtil; +import java.util.UUID; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityPickupItemEvent; + +public class PlotPlusListener_1_12 implements Listener { + @EventHandler + public void onItemPickup(EntityPickupItemEvent event) { + LivingEntity ent = event.getEntity(); + if (ent instanceof Player) { + Player player = (Player) ent; + PlotPlayer pp = BukkitUtil.getPlayer(player); + Plot plot = BukkitUtil.getLocation(player).getOwnedPlot(); + if (plot == null) { + return; + } + UUID uuid = pp.getUUID(); + if (plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) { + event.setCancelled(true); + } + } + } +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_Legacy.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_Legacy.java new file mode 100644 index 000000000..7f1f4977b --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlotPlusListener_Legacy.java @@ -0,0 +1,27 @@ +package com.plotsquared.bukkit.listeners; + +import com.intellectualcrafters.plot.flag.Flags; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.plotsquared.bukkit.util.BukkitUtil; +import java.util.UUID; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupItemEvent; + +public class PlotPlusListener_Legacy implements Listener { + @EventHandler + public void onItemPickup(PlayerPickupItemEvent event) { + Player player = event.getPlayer(); + PlotPlayer pp = BukkitUtil.getPlayer(player); + Plot plot = BukkitUtil.getLocation(player).getOwnedPlot(); + if (plot == null) { + return; + } + UUID uuid = pp.getUUID(); + if (plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) { + event.setCancelled(true); + } + } +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitVersion.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitVersion.java index 401d2aabe..df8424cd8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitVersion.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitVersion.java @@ -1,6 +1,8 @@ package com.plotsquared.bukkit.util; public class BukkitVersion { + public static int[] v1_12_1 = {1, 12, 1}; + public static int[] v1_12_0 = {1, 12, 0}; public static int[] v1_11_0 = {1, 11, 0}; public static int[] v1_10_2 = {1, 10, 2}; public static int[] v1_10_0 = {1, 10, 0};