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
## 8.13.1
- Updated Russian and Turkish translation
- Separated ChestSort plugin and API
## 8.13.0
- 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
You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin:
```
```xml
<repositories>
<repository>
<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>
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSort</artifactId>
<version>8.12.0</version> <!-- Check www.chestsort.de for latest version -->
<scope>provided</scope>
<artifactId>ChestSortAPI</artifactId>
<version>8.13.1</version> <!-- Check www.chestsort.de for latest version -->
<scope>compile</scope>
</dependency>
</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
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");
@ -39,19 +61,19 @@ ChestSortAPI chestSortAPI = chestSort.getAPI();
Now, you can sort any Inventory! Just like this:
```
```java
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.
```
```java
chestSortAPI.sortInventory(Inventory inventory, int startSlot, int endSlot);
```
You can also check if a player has automatic sorting enabled or disabled:
```
```java
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.
```
```java
@EventHandler
public void onChestSortEvent(ChestSortEvent event) {
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
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>
<url>https://www.chestsort.de</url>
<description>Automatically sorts your chests!</description>
<version>8.13.0</version>
<version>8.13.1</version>
<packaging>jar</packaging>
<properties>
@ -52,6 +52,12 @@
<shadedPattern>de.jeff_media.ChestSort</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<excludes>
<exclude>org.jetbrains:*</exclude>
<exclude>org.intellij.lang:*</exclude>
</excludes>
</artifactSet>
</configuration>
<executions>
<execution>
@ -104,6 +110,12 @@
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.jeff_media</groupId>
<artifactId>ChestSortAPI</artifactId>
<version>8.13.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>

View File

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

View File

@ -24,6 +24,9 @@ public class ChestSortDebugger implements @NotNull Listener {
System.out.println(" ");
System.out.println("InventoryClickEvent:");
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("- Left-Click: "+e.isLeftClick());
System.out.println("- Right-Click: "+e.isRightClick());

View File

@ -116,7 +116,7 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
if (!isAPICall(inventory) && !belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return;
}
@ -159,7 +159,7 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
if (!isAPICall(inventory) && !belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return;
}
@ -315,14 +315,6 @@ public class ChestSortListener implements Listener {
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")) {
return;
}
@ -331,10 +323,17 @@ public class ChestSortListener implements Listener {
if (event.getClickedInventory() == null) {
return;
}
boolean isAPICall = isAPICall(event.getClickedInventory());
// Possible fix for #57
if (event.getClickedInventory().getHolder() != null
if (!isAPICall && (event.getClickedInventory().getHolder() != null
&& 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
InventoryHolder holder = event.getClickedInventory().getHolder();
@ -347,11 +346,13 @@ public class ChestSortListener implements Listener {
if (event.getClickedInventory() == setting.guiInventory) {
return;
}
// Prevent player from putting items into GUI inventory
if (event.getInventory() == setting.guiInventory) {
event.setCancelled(true);
return;
}
switch (event.getClick()) {
case MIDDLE:
cause = ChestSortLogger.SortCause.H_MIDDLE;
@ -402,7 +403,7 @@ public class ChestSortListener implements Listener {
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")) {
return;
@ -435,6 +436,10 @@ public class ChestSortListener implements Listener {
}
}
private boolean isAPICall(Inventory inv) {
return inv.getHolder() instanceof ISortable;
}
@EventHandler
public void onAdditionalHotkeys(InventoryClickEvent e) {

View File

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

View File

@ -55,7 +55,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeff_media.ChestSort.utils.Utils;
public class ChestSortPlugin extends JavaPlugin {
public class ChestSortPlugin extends JavaPlugin implements ChestSort {
ChestSortLogger lgr;
Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>();
@ -67,7 +67,7 @@ public class ChestSortPlugin extends JavaPlugin {
ChestSortPermissionsHandler permissionsHandler;
String sortingMethod;
ArrayList<String> disabledWorlds;
ChestSortAPI api;
ChestSortAPIHandler api;
final int currentConfigVersion = 35;
boolean usingMatchingConfig = true;
protected boolean debug = false;
@ -85,12 +85,14 @@ public class ChestSortPlugin extends JavaPlugin {
// 1.8.0 = 1_8_R1
int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ...
public ChestSortAPI getAPI() {
@Override
public ChestSortAPIHandler getAPI() {
return this.api;
}
// Public API method to sort any given inventory
@Deprecated
@Override
public void sortInventory(Inventory inv) {
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]));
@ -99,6 +101,7 @@ public class ChestSortPlugin extends JavaPlugin {
// Public API method to sort any given inventory inbetween startSlot and endSlot
@Deprecated
@Override
public void sortInventory(Inventory inv, int startSlot, int endSlot) {
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]));
@ -107,6 +110,7 @@ public class ChestSortPlugin extends JavaPlugin {
// Public API method to check if player has automatic chest sorting enabled
@Deprecated
@Override
public boolean sortingEnabled(Player p) {
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]));
@ -452,7 +456,7 @@ public class ChestSortPlugin extends JavaPlugin {
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");
listener = new ChestSortListener(this);
api = new ChestSortAPI(this);
api = new ChestSortAPIHandler(this);
permissionsHandler = new ChestSortPermissionsHandler(this);
updateCheckInterval = (int) (getConfig().getDouble("check-interval")*60*60);
sortingMethod = getConfig().getString("sorting-method");

View File

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