8.13.1-SNAPSHOT

This commit is contained in:
mfnalex 2020-07-12 02:51:51 +02:00
parent 19faf837d9
commit 64ed22546c
9 changed files with 91 additions and 32 deletions

View File

@ -1,6 +1,7 @@
# Changelog # Changelog
## 8.13.1 ## 8.13.1
- Updated Russian and Turkish translation - Updated Russian and Turkish translation
- Separated ChestSort plugin and API
## 8.13.0 ## 8.13.0
- Updated Chinese (Traditional) and Spanish translation - Updated Chinese (Traditional) and Spanish translation

View File

@ -5,7 +5,7 @@ If you want to use ChestSort's advanced sorting features for your own plugin, or
## Maven repository ## Maven repository
You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin: You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin:
``` ```xml
<repositories> <repositories>
<repository> <repository>
<id>jeff-media-repo</id> <id>jeff-media-repo</id>
@ -15,15 +15,37 @@ You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>de.jeff_media</groupId> <groupId>de.jeff_media</groupId>
<artifactId>ChestSort</artifactId> <artifactId>ChestSortAPI</artifactId>
<version>8.12.0</version> <!-- Check www.chestsort.de for latest version --> <version>8.13.1</version> <!-- Check www.chestsort.de for latest version -->
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
``` ```
If you use the `Sortable`class or the `ISortable` interface, you must also shade the ChestSortAPI into your plugin:
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
## Accessing the API ## Accessing the API
Then you can access it via the plugin manager: Then you can access the API via the plugin manager:
``` ```
ChestSortPlugin chestSort = (ChestSortPlugin) getServer().getPluginManager().getPlugin("ChestSort"); ChestSortPlugin chestSort = (ChestSortPlugin) getServer().getPluginManager().getPlugin("ChestSort");
@ -39,19 +61,19 @@ ChestSortAPI chestSortAPI = chestSort.getAPI();
Now, you can sort any Inventory! Just like this: Now, you can sort any Inventory! Just like this:
``` ```java
chestSortAPI.sortInventory(Inventory inventory); chestSortAPI.sortInventory(Inventory inventory);
``` ```
To sort only specific slots, you can pass slot numbers where to start and end sorting. ChestSort will not modify the inventory outside the given slot range. To sort only specific slots, you can pass slot numbers where to start and end sorting. ChestSort will not modify the inventory outside the given slot range.
``` ```java
chestSortAPI.sortInventory(Inventory inventory, int startSlot, int endSlot); chestSortAPI.sortInventory(Inventory inventory, int startSlot, int endSlot);
``` ```
You can also check if a player has automatic sorting enabled or disabled: You can also check if a player has automatic sorting enabled or disabled:
``` ```java
boolean sortingEnabled = chestSortAPI.sortingEnabled(Player player); boolean sortingEnabled = chestSortAPI.sortingEnabled(Player player);
``` ```
@ -59,7 +81,7 @@ boolean sortingEnabled = chestSortAPI.sortingEnabled(Player player);
If you want to prevent ChestSort from sorting a certain inventory, you can listen to the ChestSortEvent event. If you want to prevent ChestSort from sorting a certain inventory, you can listen to the ChestSortEvent event.
``` ```java
@EventHandler @EventHandler
public void onChestSortEvent(ChestSortEvent event) { public void onChestSortEvent(ChestSortEvent event) {
if(event.getInventory() == whatever) { if(event.getInventory() == whatever) {
@ -68,6 +90,15 @@ public void onChestSortEvent(ChestSortEvent event) {
} }
``` ```
### Making custom inventories sortable
If you create a new Inventory inside your plugin, you can use the `Sortable` class to tell ChestSort that your custom inventory should be sortable.
```java
Sortable holder = new Sortable();
Inventory inv = Bukkit.createInventory(holder, 9, "Example");
```
## Example Plugin ## Example Plugin
Here is a complete example plugin that shows to add and use the ChestSort API: [LINK](https://github.com/JEFF-Media-GbR/ChestSortAPIExample) Here is a complete example plugin that shows to add and use the ChestSort API: [LINK](https://github.com/JEFF-Media-GbR/ChestSortAPIExample)

14
pom.xml
View File

@ -9,7 +9,7 @@
<name>JeffChestSort</name> <name>JeffChestSort</name>
<url>https://www.chestsort.de</url> <url>https://www.chestsort.de</url>
<description>Automatically sorts your chests!</description> <description>Automatically sorts your chests!</description>
<version>8.13.0</version> <version>8.13.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@ -52,6 +52,12 @@
<shadedPattern>de.jeff_media.ChestSort</shadedPattern> <shadedPattern>de.jeff_media.ChestSort</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
<artifactSet>
<excludes>
<exclude>org.jetbrains:*</exclude>
<exclude>org.intellij.lang:*</exclude>
</excludes>
</artifactSet>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -104,6 +110,12 @@
<version>1.16.1-R0.1-SNAPSHOT</version> <version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>8.13.1</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>

View File

@ -3,25 +3,28 @@ package de.jeff_media.ChestSort;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public class ChestSortAPI { public class ChestSortAPIHandler implements ChestSortAPI {
final ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortAPI(ChestSortPlugin plugin) { ChestSortAPIHandler(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
// Public API method to sort any given inventory // Public API method to sort any given inventory
@Override
public void sortInventory(Inventory inv) { public void sortInventory(Inventory inv) {
plugin.organizer.sortInventory(inv); plugin.organizer.sortInventory(inv);
} }
// Public API method to sort any given inventory inbetween startSlot and endSlot // Public API method to sort any given inventory inbetween startSlot and endSlot
@Override
public void sortInventory(Inventory inv, int startSlot, int endSlot) { public void sortInventory(Inventory inv, int startSlot, int endSlot) {
plugin.organizer.sortInventory(inv, startSlot, endSlot); plugin.organizer.sortInventory(inv, startSlot, endSlot);
} }
// Public API method to check if player has automatic chest sorting enabled // Public API method to check if player has automatic chest sorting enabled
@Override
public boolean sortingEnabled(Player p) { public boolean sortingEnabled(Player p) {
return plugin.isSortingEnabled(p); return plugin.isSortingEnabled(p);
} }

View File

@ -24,6 +24,9 @@ public class ChestSortDebugger implements @NotNull Listener {
System.out.println(" "); System.out.println(" ");
System.out.println("InventoryClickEvent:"); System.out.println("InventoryClickEvent:");
System.out.println("- Holder: " + e.getInventory().getHolder()); System.out.println("- Holder: " + e.getInventory().getHolder());
if(e.getInventory().getHolder()!=null) {
System.out.println("- Holder class: "+e.getInventory().getHolder().getClass());
}
System.out.println("- Slot: "+e.getRawSlot()); System.out.println("- Slot: "+e.getRawSlot());
System.out.println("- Left-Click: "+e.isLeftClick()); System.out.println("- Left-Click: "+e.isLeftClick());
System.out.println("- Right-Click: "+e.isRightClick()); System.out.println("- Right-Click: "+e.isRightClick());

View File

@ -116,7 +116,7 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer(); Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory(); Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) { if (!isAPICall(inventory) && !belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return; return;
} }
@ -159,7 +159,7 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer(); Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory(); Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) { if (!isAPICall(inventory) && !belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return; return;
} }
@ -315,14 +315,6 @@ public class ChestSortListener implements Listener {
return; return;
} }
// DEBUG START
// p.sendMessage("=====================");
// p.sendMessage("Click type: " + event.getClick().name());
// p.sendMessage("Right click: " + event.isRightClick());
// p.sendMessage("Shift click: " + event.isShiftClick());
// p.sendMessage("=====================");
// DEBUG END
if (!p.hasPermission("chestsort.use") && !p.hasPermission("chestsort.use.inventory")) { if (!p.hasPermission("chestsort.use") && !p.hasPermission("chestsort.use.inventory")) {
return; return;
} }
@ -331,10 +323,17 @@ public class ChestSortListener implements Listener {
if (event.getClickedInventory() == null) { if (event.getClickedInventory() == null) {
return; return;
} }
boolean isAPICall = isAPICall(event.getClickedInventory());
// Possible fix for #57 // Possible fix for #57
if (event.getClickedInventory().getHolder() != null if (!isAPICall && (event.getClickedInventory().getHolder() != null
&& event.getClickedInventory().getHolder() == p && event.getClickedInventory().getHolder() == p
&& event.getClickedInventory() != p.getInventory()) return; && event.getClickedInventory() != p.getInventory())) {
if(plugin.debug) System.out.println("10");
return;
}
// End Possible fix for #57 // End Possible fix for #57
InventoryHolder holder = event.getClickedInventory().getHolder(); InventoryHolder holder = event.getClickedInventory().getHolder();
@ -347,11 +346,13 @@ public class ChestSortListener implements Listener {
if (event.getClickedInventory() == setting.guiInventory) { if (event.getClickedInventory() == setting.guiInventory) {
return; return;
} }
// Prevent player from putting items into GUI inventory // Prevent player from putting items into GUI inventory
if (event.getInventory() == setting.guiInventory) { if (event.getInventory() == setting.guiInventory) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
switch (event.getClick()) { switch (event.getClick()) {
case MIDDLE: case MIDDLE:
cause = ChestSortLogger.SortCause.H_MIDDLE; cause = ChestSortLogger.SortCause.H_MIDDLE;
@ -402,7 +403,7 @@ public class ChestSortListener implements Listener {
return; return;
} }
if (belongsToChestLikeBlock(event.getClickedInventory()) || LlamaUtils.belongsToLlama(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) { if (isAPICall || belongsToChestLikeBlock(event.getClickedInventory()) || LlamaUtils.belongsToLlama(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
if (!p.hasPermission("chestsort.use")) { if (!p.hasPermission("chestsort.use")) {
return; return;
@ -435,6 +436,10 @@ public class ChestSortListener implements Listener {
} }
} }
private boolean isAPICall(Inventory inv) {
return inv.getHolder() instanceof ISortable;
}
@EventHandler @EventHandler
public void onAdditionalHotkeys(InventoryClickEvent e) { public void onAdditionalHotkeys(InventoryClickEvent e) {

View File

@ -127,7 +127,7 @@ public class ChestSortOrganizer {
} }
static boolean doesInventoryContain(Inventory inv, Material mat) { static boolean doesInventoryContain(Inventory inv, Material mat) {
for (ItemStack item : inv.getContents()) { for (ItemStack item : inv.getStorageContents()) {
if (item == null) continue; if (item == null) continue;
if (item.getType() == mat) { if (item.getType() == mat) {
return true; return true;

View File

@ -55,7 +55,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeff_media.ChestSort.utils.Utils; import de.jeff_media.ChestSort.utils.Utils;
public class ChestSortPlugin extends JavaPlugin { public class ChestSortPlugin extends JavaPlugin implements ChestSort {
ChestSortLogger lgr; ChestSortLogger lgr;
Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>(); Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>();
@ -67,7 +67,7 @@ public class ChestSortPlugin extends JavaPlugin {
ChestSortPermissionsHandler permissionsHandler; ChestSortPermissionsHandler permissionsHandler;
String sortingMethod; String sortingMethod;
ArrayList<String> disabledWorlds; ArrayList<String> disabledWorlds;
ChestSortAPI api; ChestSortAPIHandler api;
final int currentConfigVersion = 35; final int currentConfigVersion = 35;
boolean usingMatchingConfig = true; boolean usingMatchingConfig = true;
protected boolean debug = false; protected boolean debug = false;
@ -85,12 +85,14 @@ public class ChestSortPlugin extends JavaPlugin {
// 1.8.0 = 1_8_R1 // 1.8.0 = 1_8_R1
int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ... int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ...
public ChestSortAPI getAPI() { @Override
public ChestSortAPIHandler getAPI() {
return this.api; return this.api;
} }
// Public API method to sort any given inventory // Public API method to sort any given inventory
@Deprecated @Deprecated
@Override
public void sortInventory(Inventory inv) { public void sortInventory(Inventory inv) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2])); getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2]));
@ -99,6 +101,7 @@ public class ChestSortPlugin extends JavaPlugin {
// Public API method to sort any given inventory inbetween startSlot and endSlot // Public API method to sort any given inventory inbetween startSlot and endSlot
@Deprecated @Deprecated
@Override
public void sortInventory(Inventory inv, int startSlot, int endSlot) { public void sortInventory(Inventory inv, int startSlot, int endSlot) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2])); getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2]));
@ -107,6 +110,7 @@ public class ChestSortPlugin extends JavaPlugin {
// Public API method to check if player has automatic chest sorting enabled // Public API method to check if player has automatic chest sorting enabled
@Deprecated @Deprecated
@Override
public boolean sortingEnabled(Player p) { public boolean sortingEnabled(Player p) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2])); getLogger().warning(String.format("%s has performed a call to a deprecated ChestSort API method. This is NOT a ChestSort error.",stackTraceElements[2]));
@ -452,7 +456,7 @@ public class ChestSortPlugin extends JavaPlugin {
settingsGUI = new ChestSortSettingsGUI(this); settingsGUI = new ChestSortSettingsGUI(this);
updateChecker = new PluginUpdateChecker(this, "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt", "https://chestsort.de", "https://chestsort.de/changelog", "https://chestsort.de/donate"); updateChecker = new PluginUpdateChecker(this, "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt", "https://chestsort.de", "https://chestsort.de/changelog", "https://chestsort.de/donate");
listener = new ChestSortListener(this); listener = new ChestSortListener(this);
api = new ChestSortAPI(this); api = new ChestSortAPIHandler(this);
permissionsHandler = new ChestSortPermissionsHandler(this); permissionsHandler = new ChestSortPermissionsHandler(this);
updateCheckInterval = (int) (getConfig().getDouble("check-interval")*60*60); updateCheckInterval = (int) (getConfig().getDouble("check-interval")*60*60);
sortingMethod = getConfig().getString("sorting-method"); sortingMethod = getConfig().getString("sorting-method");

View File

@ -1,6 +1,6 @@
main: de.jeff_media.ChestSort.ChestSortPlugin main: de.jeff_media.ChestSort.ChestSortPlugin
name: ChestSort name: ChestSort
version: 8.13.0 version: 8.13.1
api-version: "1.13" api-version: "1.13"
description: Allows automatic chest sorting description: Allows automatic chest sorting
author: mfnalex author: mfnalex