From fd47607f69b3177e4b2dc86d75350f95cbeafe0c Mon Sep 17 00:00:00 2001 From: mfnalex Date: Tue, 19 Jul 2022 11:08:08 +0200 Subject: [PATCH] 13.3.0 release --- CHANGELOG.md | 3 + pom.xml | 9 ++- .../jeff_media/chestsort/ChestSortPlugin.java | 25 +++--- .../chestsort/hooks/AdvancedChestsHook.java | 77 +++++++++++-------- .../{Listener.java => ChestSortListener.java} | 20 +++-- 5 files changed, 82 insertions(+), 52 deletions(-) rename src/main/java/de/jeff_media/chestsort/listeners/{Listener.java => ChestSortListener.java} (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09849fc..2c5ee4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 13.2.1 +- Fixed exceptions when using the latest version of AdvancedChests + ## 13.0.5 Sorry for 3 updates within 10 minutes! diff --git a/pom.xml b/pom.xml index 793ff32..34688d5 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Allows automatic chest sorting! - 13.2.0 + 13.3.0 jar @@ -171,6 +171,11 @@ https://repo.codemc.org/repository/maven-public + + jeff-media-public + https://hub.jeff-media.com/nexus/repository/jeff-media-public/ + + pcgf-repo https://repo.pcgamingfreaks.at/repository/maven-everything @@ -202,7 +207,7 @@ de.jeff_media JeffLib - 8.0.0-SNAPSHOT + 9.0.0-SNAPSHOT compile diff --git a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java index 0defd13..69d737d 100644 --- a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java +++ b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java @@ -29,7 +29,6 @@ package de.jeff_media.chestsort; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin; import com.jeff_media.updatechecker.UpdateChecker; -import de.jeff_media.chestsort.commands.AdminCommand; import de.jeff_media.chestsort.commands.ChestSortCommand; import de.jeff_media.chestsort.commands.InvSortCommand; import de.jeff_media.chestsort.commands.TabCompleter; @@ -48,7 +47,7 @@ import de.jeff_media.chestsort.handlers.Logger; import de.jeff_media.chestsort.hooks.EnderContainersHook; import de.jeff_media.chestsort.hooks.GenericGUIHook; import de.jeff_media.chestsort.hooks.PlayerVaultsHook; -import de.jeff_media.chestsort.listeners.Listener; +import de.jeff_media.chestsort.listeners.ChestSortListener; import de.jeff_media.chestsort.placeholders.Placeholders; import de.jeff_media.chestsort.utils.Utils; import de.jeff_media.jefflib.JeffLib; @@ -62,9 +61,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.yaml.snakeyaml.Yaml; import java.io.*; import java.util.*; @@ -86,7 +83,7 @@ public class ChestSortPlugin extends JavaPlugin { private ArrayList disabledWorlds; private HashMap hotkeyCooldown; private Logger lgr; - private Listener listener; + private ChestSortListener chestSortListener; // 1.14.4 = 1_14_R1 // 1.8.0 = 1_8_R1 private int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ... @@ -252,12 +249,12 @@ public class ChestSortPlugin extends JavaPlugin { this.lgr = lgr; } - public Listener getListener() { - return listener; + public ChestSortListener getListener() { + return chestSortListener; } - public void setListener(Listener listener) { - this.listener = listener; + public void setListener(ChestSortListener chestSortListener) { + this.chestSortListener = chestSortListener; } public int getMcMinorVersion() { @@ -492,7 +489,7 @@ public class ChestSortPlugin extends JavaPlugin { getLogger().severe("The Update Checker will NOT work when using CraftBukkit instead of Spigot/Paper!"); PaperLib.suggestPaper(this); } - setListener(new Listener(this)); + setListener(new ChestSortListener(this)); setHotkeyCooldown(new HashMap<>()); setPermissionsHandler(new ChestSortPermissionsHandler(this)); setUpdateCheckInterval(getConfig().getDouble("check-interval")); @@ -699,7 +696,7 @@ public class ChestSortPlugin extends JavaPlugin { boolean changed; boolean hasSeenMessage; - if (playerFile.exists() || !McVersion.isAtLeast(1,14,4)) { + if (playerFile.exists() || !McVersion.current().isAtLeast(1,14,4)) { // If the player settings file does not exist for this player, set it to the // default value activeForThisPlayer = playerConfig.getBoolean("sortingEnabled"); @@ -715,7 +712,7 @@ public class ChestSortPlugin extends JavaPlugin { changed = true; - if (McVersion.isAtLeast(1,14,4)) { + if (McVersion.current().isAtLeast(1,14,4)) { if (playerFile.delete()) { this.getLogger().info("Converted old .yml playerdata file to NBT tags for player " + p.getName()); } else { @@ -752,7 +749,7 @@ public class ChestSortPlugin extends JavaPlugin { // when "show-message-again-after-logout" is enabled, we don't care if the // player already saw the message if (!getConfig().getBoolean("show-message-again-after-logout")) { - if (McVersion.isAtLeast(1,14,4) && !playerFile.exists()) { + if (McVersion.current().isAtLeast(1,14,4) && !playerFile.exists()) { NBTAPI.getNBT(p, "hasSeenMessage", String.valueOf(false)); } else { newSettings.hasSeenMessage = playerConfig.getBoolean("hasSeenMessage"); @@ -926,7 +923,7 @@ public class ChestSortPlugin extends JavaPlugin { if (getPerPlayerSettings().containsKey(uniqueId.toString())) { PlayerSetting setting = getPerPlayerSettings().get(p.getUniqueId().toString()); - if (McVersion.isAtLeast(1,14,4)) { + if (McVersion.current().isAtLeast(1,14,4)) { for(NamespacedKey key : p.getPersistentDataContainer().getKeys()) { if(key.getKey().equals(new NamespacedKey(this,"test").getKey())) { diff --git a/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java b/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java index 4d9e5b7..22fff59 100644 --- a/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java +++ b/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java @@ -14,45 +14,62 @@ public class AdvancedChestsHook { public AdvancedChestsHook(ChestSortPlugin plugin) { this.plugin = plugin; - if(plugin.isHookAdvancedChests()){ - double version = Double.parseDouble(plugin.getServer().getPluginManager() - .getPlugin("AdvancedChests") - .getDescription().getVersion()); - if(version >= 20.3) { - plugin.getLogger().info("Successfully hooked into AdvancedChests"); - }else plugin.setHookAdvancedChests(false); - } + try { + if (plugin.isHookAdvancedChests()) { + double version = Double.parseDouble(plugin.getServer().getPluginManager() + .getPlugin("AdvancedChests") + .getDescription().getVersion()); + if (version >= 20.3) { + plugin.getLogger().info("Successfully hooked into AdvancedChests"); + } else plugin.setHookAdvancedChests(false); + } + } catch (Throwable t) { + plugin.setHookAdvancedChests(false); + } + } public boolean isAnAdvancedChest(Inventory inventory){ - return plugin.isHookAdvancedChests() - && inventory != null - && AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory) != null; + try { + return plugin.isHookAdvancedChests() + && inventory != null + && AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory) != null; + } catch (Throwable ignored) { + return false; // TODO: Remove once everyone updated AC + } } public boolean handleAChestSortingIfPresent(Inventory inventory){ - if(!plugin.isHookAdvancedChests())return false; - InteractiveInventory interactiveInventory = AdvancedChestsAPI.getInventoryManager().getInteractiveByBukkit(inventory); - if(interactiveInventory != null) { - if (interactiveInventory instanceof ChestPage) { - plugin.getOrganizer().sortInventory(inventory, 0, inventory.getSize() - 10); - } - return true; - }else { - return false; - } + if(!plugin.isHookAdvancedChests()) return false; + try { + InteractiveInventory interactiveInventory = AdvancedChestsAPI.getInventoryManager().getInteractiveByBukkit(inventory); + if (interactiveInventory != null) { + if (interactiveInventory instanceof ChestPage) { + plugin.getOrganizer().sortInventory(inventory, 0, inventory.getSize() - 10); + } + return true; + } else { + return false; + } + } catch (Throwable ignored) { + return false; // TODO: Remove once everyone updated AC + } } public boolean handleAChestSortingIfPresent(Location location){ if(!plugin.isHookAdvancedChests())return false; - AdvancedChest chest = AdvancedChestsAPI.getChestManager().getAdvancedChest(location); - if(chest != null){ - for (ChestPage page : chest.getPages()) { - Inventory inventory = page.getBukkitInventory(); - plugin.getOrganizer().sortInventory(inventory,0,inventory.getSize()-10); - } - return true; - } - return false; + try { + AdvancedChest chest = AdvancedChestsAPI.getChestManager().getAdvancedChest(location); + if (chest != null) { + for (ChestPage page : chest.getPages()) { + Inventory inventory = page.getBukkitInventory(); + plugin.getOrganizer().sortInventory(inventory, 0, inventory.getSize() - 10); + } + return true; + } + return false; + } catch (Throwable ignored) { + return false; // TODO: Remove once everyone updated AC + } } } diff --git a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java b/src/main/java/de/jeff_media/chestsort/listeners/ChestSortListener.java similarity index 98% rename from src/main/java/de/jeff_media/chestsort/listeners/Listener.java rename to src/main/java/de/jeff_media/chestsort/listeners/ChestSortListener.java index e311aa3..0f32cab 100644 --- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java +++ b/src/main/java/de/jeff_media/chestsort/listeners/ChestSortListener.java @@ -11,7 +11,6 @@ import de.jeff_media.chestsort.data.PlayerSetting; import de.jeff_media.chestsort.hooks.*; import de.jeff_media.chestsort.utils.LlamaUtils; import de.jeff_media.jefflib.ProtectionUtils; -import de.jeff_media.jefflib.data.ShadowPlayer; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -39,7 +38,7 @@ import org.bukkit.inventory.ItemStack; import java.util.HashMap; -public class Listener implements org.bukkit.event.Listener { +public class ChestSortListener implements org.bukkit.event.Listener { final ChestSortPlugin plugin; public final MinepacksHook minepacksHook; @@ -49,7 +48,7 @@ public class Listener implements org.bukkit.event.Listener { private static Event ignoredEvent; - public Listener(ChestSortPlugin plugin) { + public ChestSortListener(ChestSortPlugin plugin) { this.plugin = plugin; this.minepacksHook = new MinepacksHook(plugin); this.headDatabaseHook = new HeadDatabaseHook(plugin); @@ -97,9 +96,14 @@ public class Listener implements org.bukkit.event.Listener { Container containerState = (Container) clickedBlock.getState(); Inventory inventory = containerState.getInventory(); - if(!advancedChestsHook.handleAChestSortingIfPresent(clickedBlock.getLocation())) { - plugin.getOrganizer().sortInventory(inventory); - } + + try { + if (!advancedChestsHook.handleAChestSortingIfPresent(clickedBlock.getLocation())) { + plugin.getOrganizer().sortInventory(inventory); + } + } catch (Throwable ignored) { + // TODO: Remove when everyone updated AdvancedChests + } event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Messages.MSG_CONTAINER_SORTED)); } @@ -316,6 +320,10 @@ public class Listener implements org.bukkit.event.Listener { return true; } + if (inventory.getHolder() != null && inventory.getHolder().getClass().getName().toLowerCase().contains("boat")) { + return true; + } + // Possible Fix for https://github.com/JEFF-Media-GbR/Spigot-ChestSort/issues/13 if (inventory.getHolder() == null) { return false;