diff --git a/pom.xml b/pom.xml index 686bde7..fe5f6d4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Allows automatic chest sorting! - 11.5.1 + 11.5.2 jar @@ -187,7 +187,7 @@ de.jeff_media JeffLib - 1.0-SNAPSHOT + 5.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 510559c..5d68abd 100644 --- a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java +++ b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java @@ -49,8 +49,8 @@ import de.jeff_media.chestsort.listeners.Listener; import de.jeff_media.chestsort.placeholders.Placeholders; import de.jeff_media.chestsort.utils.Utils; import de.jeff_media.jefflib.JeffLib; +import de.jeff_media.jefflib.McVersion; import de.jeff_media.jefflib.NBTAPI; -import de.jeff_media.jefflib.VersionUtil; import de.jeff_media.updatechecker.UpdateChecker; import io.papermc.lib.PaperLib; import org.bstats.bukkit.Metrics; @@ -657,8 +657,9 @@ public class ChestSortPlugin extends JavaPlugin { boolean rightClick; boolean leftClickFromOutside; boolean changed; + boolean hasSeenMessage; - if (playerFile.exists() || VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_14_4_R01)) { + if (playerFile.exists() || !McVersion.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"); @@ -670,10 +671,11 @@ public class ChestSortPlugin extends JavaPlugin { leftClickFromOutside = playerConfig.getBoolean("leftClickOutside"); leftClick = playerConfig.getBoolean("leftClick"); rightClick = playerConfig.getBoolean("rightClick"); + hasSeenMessage = playerConfig.getBoolean("hasSeenMessage"); changed = true; - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) { + if (McVersion.isAtLeast(1,14,4)) { if (playerFile.delete()) { this.getLogger().info("Converted old .yml playerdata file to NBT tags for player " + p.getName()); } else { @@ -692,16 +694,22 @@ public class ChestSortPlugin extends JavaPlugin { leftClick = Boolean.parseBoolean(NBTAPI.getNBT(p, "leftClick", String.valueOf(playerConfig.getBoolean("leftClick", getConfig().getBoolean("additional-hotkeys.left-click"))))); rightClick = Boolean.parseBoolean(NBTAPI.getNBT(p, "rightClick", String.valueOf(playerConfig.getBoolean("rightClick", getConfig().getBoolean("additional-hotkeys.right-click"))))); leftClickFromOutside = Boolean.parseBoolean(NBTAPI.getNBT(p, "leftClickOutside", String.valueOf(playerConfig.getBoolean("leftClickOutside", getConfig().getBoolean("left-click-to-sort-enabled-by-default"))))); + hasSeenMessage = Boolean.parseBoolean(NBTAPI.getNBT(p, "hasSeenMessage", String.valueOf("false"))); + //System.out.println("Loading playersetting from NBT"); + if(getConfig().getBoolean("show-message-again-after-logout")) { + //System.out.println("show-message-again-after-logout is true, sooo..."); + hasSeenMessage = false; + } changed = true; } - PlayerSetting newSettings = new PlayerSetting(activeForThisPlayer, invActiveForThisPlayer, middleClick, shiftClick, doubleClick, shiftRightClick, leftClick, rightClick, leftClickFromOutside, changed); + PlayerSetting newSettings = new PlayerSetting(activeForThisPlayer, invActiveForThisPlayer, middleClick, shiftClick, doubleClick, shiftRightClick, leftClick, rightClick, leftClickFromOutside, changed, hasSeenMessage); // 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 (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01) && !playerFile.exists()) { + if (McVersion.isAtLeast(1,14,4) && !playerFile.exists()) { NBTAPI.getNBT(p, "hasSeenMessage", String.valueOf(false)); } else { newSettings.hasSeenMessage = playerConfig.getBoolean("hasSeenMessage"); @@ -865,7 +873,7 @@ public class ChestSortPlugin extends JavaPlugin { if (getPerPlayerSettings().containsKey(uniqueId.toString())) { PlayerSetting setting = getPerPlayerSettings().get(p.getUniqueId().toString()); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) { + if (McVersion.isAtLeast(1,14,4)) { NBTAPI.addNBT(p, "sortingEnabled", String.valueOf(setting.sortingEnabled)); NBTAPI.addNBT(p, "invSortingEnabled", String.valueOf(setting.invSortingEnabled)); NBTAPI.addNBT(p, "hasSeenMessage", String.valueOf(setting.hasSeenMessage)); diff --git a/src/main/java/de/jeff_media/chestsort/data/PlayerSetting.java b/src/main/java/de/jeff_media/chestsort/data/PlayerSetting.java index 2d3918c..dbae9e8 100644 --- a/src/main/java/de/jeff_media/chestsort/data/PlayerSetting.java +++ b/src/main/java/de/jeff_media/chestsort/data/PlayerSetting.java @@ -40,7 +40,7 @@ public class PlayerSetting { NONE, RIGHT_CLICK, LEFT_CLICK } - public PlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean leftCLickOutside, boolean changed) { + public PlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean leftCLickOutside, boolean changed, boolean hasSeenMessage) { this.sortingEnabled = sortingEnabled; this.middleClick = middleClick; this.shiftClick = shiftClick; @@ -51,6 +51,7 @@ public class PlayerSetting { this.rightClick = rightClick; this.leftClickOutside = leftCLickOutside; this.changed = changed; + this.hasSeenMessage = hasSeenMessage; } public DoubleClickType getCurrentDoubleClick(ChestSortPlugin plugin, DoubleClickType click) { diff --git a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java index 901d191..639d853 100644 --- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java +++ b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java @@ -9,6 +9,7 @@ import de.jeff_media.chestsort.api.*; 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 net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -62,6 +63,10 @@ public class Listener implements org.bukkit.event.Listener { if(!plugin.getConfig().getBoolean("allow-left-click-to-sort")) return; Block clickedBlock = event.getClickedBlock(); if(!(clickedBlock.getState() instanceof Container)) return; + if(!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock)) { + //System.out.println("ChestSort: cannot interact!"); + return; + } plugin.registerPlayerIfNeeded(event.getPlayer()); PlayerSetting playerSetting = plugin.getPlayerSetting(event.getPlayer()); if(!playerSetting.leftClickOutside) return;