From b05316c000e57790502b84cc88bec46c0922ef12 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Wed, 26 Dec 2018 15:29:39 +0100 Subject: [PATCH] Recommend paper just like FAWE. I want to be like the cool kids. Oh, and fix an issue with `/plot music`. Still broken. Just not the same kind of broken. --- .../plotsquared/bukkit/BukkitMain.java | 9 +++++++++ .../plotsquared/bukkit/listeners/PlayerEvents.java | 2 ++ .../plotsquared/plot/PlotSquared.java | 12 ++++++++++-- .../plotsquared/plot/listener/PlotListener.java | 10 +++++----- .../plotsquared/plot/util/StringMan.java | 8 ++++---- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 0023a6b0f..701532472 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -158,6 +158,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); + if (Bukkit.getVersion().contains("git-Spigot")) { + // Uses System.out.println because the logger isn't initialized yet + System.out.println("[P2] ====== USE PAPER ======"); + System.out.println("[P2] DOWNLOAD: https://papermc.io/downloads"); + System.out.println("[P2] GUIDE: https://www.spigotmc.org/threads/21726/"); + System.out.println("[P2] - This is only a recommendation"); + System.out.println("[P2] =============================="); + } + new PlotSquared(this, "Bukkit"); if (Settings.Enabled_Components.METRICS) { this.startMetrics(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 97c0fb1fa..bb001769c 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -24,6 +24,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Piston; import org.bukkit.command.PluginCommand; import org.bukkit.entity.*; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -1516,6 +1517,7 @@ import java.util.regex.Pattern; PlotInventory inventory = pp.getMeta("inventory"); if (inventory != null && event.getRawSlot() == event.getSlot()) { if (!inventory.onClick(event.getSlot())) { + event.setResult(Event.Result.DENY); event.setCancelled(true); inventory.close(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 1de0905b9..5bc3fa0f2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -314,7 +314,11 @@ import java.util.zip.ZipInputStream; if (message == null || message.toString().isEmpty()) { return; } - PlotSquared.get().getLogger().log(StringMan.getString(message)); + if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { + System.out.printf("[P2][Info] %s\n", StringMan.getString(message)); + } else { + PlotSquared.get().getLogger().log(StringMan.getString(message)); + } } /** @@ -325,7 +329,11 @@ import java.util.zip.ZipInputStream; */ public static void debug(@Nullable Object message) { if (Settings.DEBUG) { - PlotSquared.log(message); + if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { + System.out.printf("[P2][Debug] %s\n", StringMan.getString(message)); + } else { + PlotSquared.get().getLogger().log(StringMan.getString(message)); + } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index 5eca8d910..d47d7a94f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -128,20 +128,20 @@ public class PlotListener { Optional musicFlag = plot.getFlag(Flags.MUSIC); if (musicFlag.isPresent()) { - Integer id = musicFlag.get(); - if ((id >= 2256 && id <= 2267) || (id == 0)) { + Number id = musicFlag.get(); + if ((id.intValue() >= 2256 && id.intValue() <= 2267) || (id.intValue() == 0)) { Location loc = player.getLocation(); Location lastLoc = player.getMeta("music"); if (lastLoc != null) { player.playMusic(lastLoc, 0); - if (id == 0) { + if (id.intValue() == 0) { player.deleteMeta("music"); } } - if (id != 0) { + if (id.intValue() != 0) { try { player.setMeta("music", loc); - player.playMusic(loc, id); + player.playMusic(loc, id.intValue()); } catch (Exception ignored) { } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/StringMan.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/StringMan.java index f24bbb08f..a0236c653 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/StringMan.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/StringMan.java @@ -45,19 +45,19 @@ public class StringMan { return (String) obj; } if (obj.getClass().isArray()) { - String result = ""; + StringBuilder result = new StringBuilder(); String prefix = ""; for (int i = 0; i < Array.getLength(obj); i++) { - result += prefix + getString(Array.get(obj, i)); + result.append(prefix).append(getString(Array.get(obj, i))); prefix = ","; } return "( " + result + " )"; } else if (obj instanceof Collection) { - String result = ""; + StringBuilder result = new StringBuilder(); String prefix = ""; for (Object element : (Collection) obj) { - result += prefix + getString(element); + result.append(prefix).append(getString(element)); prefix = ","; } return "[ " + result + " ]";