From c17fd9dc5a2e6bc34d8bae217a89aa583f468e2f Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Thu, 21 May 2020 13:43:18 +0200
Subject: [PATCH] 8.4 update
---
CHANGELOG.md | 3 +++
pom.xml | 2 +-
.../JeffChestSortAdditionalHotkeyListener.java | 6 +++---
.../JeffChestSort/JeffChestSortListener.java | 6 +++---
.../JeffChestSort/JeffChestSortOrganizer.java | 2 +-
.../JeffChestSort/JeffChestSortPlugin.java | 5 ++++-
.../java/de/jeffclan/utils/InventoryHelper.java | 17 +++++++++++++----
src/main/resources/plugin.yml | 2 +-
8 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f59b43..cd27999 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,7 @@
# Changelog
+## 8.4
+- Fixes InventoryPages support for the new hotkeys
+
## 8.3
- This should fix a problem where the player was able to sort inventories belonging to 3rd party plugins' GUIs using hotkeys
diff --git a/pom.xml b/pom.xml
index 96c59f8..e137b8f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
de.jeffclan
JeffChestSort
- 8.3
+ 8.4
jar
JeffChestSort
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
index f39f217..5b23a65 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
@@ -47,11 +47,11 @@ public class JeffChestSortAdditionalHotkeyListener implements Listener {
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
if(e.isLeftClick() && setting.leftClick) {
- de.jeffclan.utils.InventoryHelper.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
+ plugin.invhelper.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
plugin.sortInventory(e.getInventory());
- de.jeffclan.utils.InventoryHelper.updateInventoryView(e.getInventory());
+ plugin.invhelper.updateInventoryView(e.getInventory());
} else if(e.isRightClick() && setting.rightClick) {
- de.jeffclan.utils.InventoryHelper.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
+ plugin.invhelper.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
}
}
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
index dfd82fc..df64c4d 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
@@ -348,7 +348,7 @@ public class JeffChestSortListener implements Listener {
}
plugin.organizer.sortInventory(event.getClickedInventory());
- de.jeffclan.utils.InventoryHelper.updateInventoryView(event);
+ plugin.invhelper.updateInventoryView(event);
return;
} else if(holder instanceof Player) {
@@ -358,12 +358,12 @@ public class JeffChestSortListener implements Listener {
if(event.getSlotType() == SlotType.QUICKBAR) {
plugin.organizer.sortInventory(p.getInventory(),0,8);
- de.jeffclan.utils.InventoryHelper.updateInventoryView(event);
+ plugin.invhelper.updateInventoryView(event);
return;
}
else if(event.getSlotType() == SlotType.CONTAINER) {
plugin.organizer.sortInventory(p.getInventory(),9,35);
- de.jeffclan.utils.InventoryHelper.updateInventoryView(event);
+ plugin.invhelper.updateInventoryView(event);
return;
}
return;
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
index 435b319..c821373 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
@@ -39,7 +39,7 @@ public class JeffChestSortOrganizer {
JeffChestSortPlugin plugin;
CrackShotHook crackShotHook;
- InventoryPagesHook inventoryPagesHook;
+ public InventoryPagesHook inventoryPagesHook; // public for InventoryHelper
// All available colors in the game. We will strip this from the item names and
// keep the color in a separate variable
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
index 958c0e3..cd754e8 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
@@ -50,13 +50,15 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import de.jeffclan.utils.InventoryHelper;
import de.jeffclan.utils.Utils;
public class JeffChestSortPlugin extends JavaPlugin {
Map perPlayerSettings = new HashMap();
JeffChestSortMessages messages;
- JeffChestSortOrganizer organizer;
+ public JeffChestSortOrganizer organizer;
+ InventoryHelper invhelper;
JeffChestSortUpdateChecker updateChecker;
JeffChestSortListener listener;
JeffChestSortAdditionalHotkeyListener additionalHotkeys;
@@ -243,6 +245,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
// Organizer will load all category files and will be ready to sort stuff
organizer = new JeffChestSortOrganizer(this);
+ invhelper = new InventoryHelper(this);
settingsGUI = new JeffChestSortSettingsGUI(this);
diff --git a/src/main/java/de/jeffclan/utils/InventoryHelper.java b/src/main/java/de/jeffclan/utils/InventoryHelper.java
index 18f2c3a..6309277 100644
--- a/src/main/java/de/jeffclan/utils/InventoryHelper.java
+++ b/src/main/java/de/jeffclan/utils/InventoryHelper.java
@@ -12,13 +12,21 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
+import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
+
public class InventoryHelper {
+ private JeffChestSortPlugin plugin;
+
private static final int maxInventorySize=54;
private static final int playerInvStartSlot=9; // Inclusive
private static final int playerInvEndSlot=35; // Inclusive
- public static void updateInventoryView(InventoryClickEvent event) {
+ public InventoryHelper(JeffChestSortPlugin jeffChestSortPlugin) {
+ this.plugin = jeffChestSortPlugin;
+ }
+
+ public void updateInventoryView(InventoryClickEvent event) {
for(HumanEntity viewer : event.getViewers()) {
if(viewer instanceof Player) {
Player playerViewer = (Player) viewer;
@@ -27,7 +35,7 @@ public class InventoryHelper {
}
}
- public static void updateInventoryView(Inventory inventory) {
+ public void updateInventoryView(Inventory inventory) {
for(HumanEntity viewer : inventory.getViewers()) {
if(viewer instanceof Player) {
Player playerViewer = (Player) viewer;
@@ -36,7 +44,7 @@ public class InventoryHelper {
}
}
- public static void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource) {
+ public void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource) {
ArrayList leftovers = new ArrayList();
@@ -60,12 +68,13 @@ public class InventoryHelper {
}
- public static void stuffPlayerInventoryIntoAnother(PlayerInventory source,
+ public void stuffPlayerInventoryIntoAnother(PlayerInventory source,
Inventory destination) {
boolean destinationIsShulkerBox = destination.getType() == InventoryType.SHULKER_BOX;
Inventory temp = Bukkit.createInventory(null, maxInventorySize);
for(int i = playerInvStartSlot;i<=playerInvEndSlot;i++) {
if(source.getItem(i)==null) continue;
+ if(plugin.hookInventoryPages && plugin.organizer.inventoryPagesHook.isButton(source.getItem(i), i, source)) continue;
if(destinationIsShulkerBox && source.getItem(i).getType().name().endsWith("SHULKER_BOX")) continue;
temp.addItem(source.getItem(i));
source.clear(i);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 371c470..63ee604 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
name: ChestSort
-version: 8.3
+version: 8.4
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex