From 1334d90cbc2e9153eb05dff361dfa541acf36ee4 Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Wed, 10 Jun 2020 18:21:41 +0200 Subject: [PATCH] 8.9 release --- CHANGELOG.md | 5 ++ HOW_TO_USE_API.md | 57 ++++++++++++++++--- README.md | 24 ++++++++ pom.xml | 43 +++++++------- .../jeff_media/ChestSort/ChestSortEvent.java | 19 ++++++- .../ChestSort/ChestSortListener.java | 24 ++++++-- .../ChestSort/ChestSortOrganizer.java | 3 +- src/main/resources/plugin.yml | 2 +- 8 files changed, 138 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50eeed5..3a0623d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## 8.9 +- Prevent BossShopPro's GUI from being sorted +- Added custom event to let 3rd party plugins cancel sorting an inventory, see updated API doc for more information +- Published ChestSort in public maven repository repo.jeff-media.de/maven2, see updated API doc for more information + ## 8.8.2 - Fixes exception when sorting inventories containing potions in ancient Minecraft versions like 1.8 diff --git a/HOW_TO_USE_API.md b/HOW_TO_USE_API.md index 81aadad..33f2c2d 100644 --- a/HOW_TO_USE_API.md +++ b/HOW_TO_USE_API.md @@ -2,32 +2,71 @@ If you want to use ChestSort's advanced sorting features for your own plugin, you can use the ChestSort API. It provides methods to sort any given inventory, following the rules you have specified in your ChestSort's plugin.yml and the corresponding category files. -To use ChestSort's sorting features in your Spigot/Bukkit plugin, you have to import ChestSort.jar into your BuildPath. +## Maven repository +You can use maven to add ChestSort as a dependency to your Spigot-/Bukkit-Plugin: +``` + + + jeff-media-repo + https://repo.jeff-media.de/maven2 + + + + + de.jeff_media + ChestSort + 8.9 + + +``` + +## Accessing the API Then you can access it via the plugin manager: ``` -JeffChestSortPlugin chestSort = (JeffChestSortPlugin) getServer().getPluginManager().getPlugin("ChestSort"); - -if(chestSort==null || !(chestSort instanceof JeffChestSortPlugin)) { - getLogger().warning("ChestSort plugin not found."); +ChestSortPlugin chestSort = (ChestSortPlugin) getServer().getPluginManager().getPlugin("ChestSort"); +if(chestSort==null || !(chestSort instanceof ChestSortPlugin)) { + getLogger().severe("Error: ChestSort is not installed."); + return; } + +ChestSortAPI chestSortAPI = chestSort.getAPI(); ``` +### Sorting inventories + Now, you can sort any Inventory! Just like this: ``` -chestSort.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. ``` -chestSort.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: ``` -boolean sortingEnabled = chestSort.sortingEnabled(Player player); -``` \ No newline at end of file +boolean sortingEnabled = chestSortAPI.sortingEnabled(Player player); +``` + +### Custom ChestSort event + +If you want to prevent ChestSort from sorting a certain inventory, you can listen to the ChestSortEvent event. + +``` +@EventHandler +public void onChestSortEvent(ChestSortEvent event) { + if(event.getInventory() == whatever) { + event.setCancelled(true); + } +} +``` + +## 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) \ No newline at end of file diff --git a/README.md b/README.md index 0673141..b6339d3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,25 @@ Please see the related topic at spigotmc.org for information regarding the comma https://www.spigotmc.org/resources/1-13-chestsort.59773/ +## Maven repository +If you want to use ChestSort as dependency for your own plugin, you can use our public maven repository: + +``` + + + jeff-media-repo + https://repo.jeff-media.de/maven2 + + + + + de.jeff_media + ChestSort + 8.9 + + +``` + ## Building .jar file To build the .jar file, you will need maven. Also, the CrackShot library is in no public repository, so please create a directory called `lib` and put the latest CrackShot.jar file [(available here)](https://www.spigotmc.org/resources/crackshot-guns.48301/) inside it. Now you can do `mvn install` @@ -13,6 +32,11 @@ To build the .jar file, you will need maven. Also, the CrackShot library is in n ChestSort takes an instance of org.bukkit.inventory.Inventory and copies the contents. The resulting array is sorted by rules defined in the config.yml. This takes far less than one millisecond for a whole chest. So there should be no problems even on big servers, where hundreds of players are using chests at the same time. The plugin should cause no lag at all. +## API +If you want to use ChestSort's advanced sorting features for your own plugin, you can use the ChestSort API. It provides methods to sort any given inventory, following the rules you have specified in your ChestSort's plugin.yml and the corresponding category files. + +More information about the API can be found [HERE](https://github.com/JEFF-Media-GbR/Spigot-ChestSort/blob/master/HOW_TO_USE_API.md). + ## Screenshots

Screenshot ChestSort

diff --git a/pom.xml b/pom.xml index 67ed5b3..c9962a6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.jeffclan - JeffChestSort - 8.8.3-pre1 - jar - + de.jeff_media + ChestSort JeffChestSort https://www.chestsort.de + Automatically sorts your chests! + 8.9 + jar UTF-8 @@ -18,6 +18,7 @@ + org.apache.maven.plugins @@ -34,11 +35,8 @@ 3.1.0 ChestSort - - - org.apache.maven.plugins maven-shade-plugin @@ -60,8 +58,16 @@ - + + + + org.apache.maven.wagon + wagon-ftp + 3.4.1 + + + @@ -90,8 +96,6 @@ 1.15.2-R0.1-SNAPSHOT provided - org.bstats bstats-bukkit @@ -105,19 +109,18 @@ system ${project.basedir}/lib/CrackShot.jar - at.pcgamingfreaks Minepacks-API 2.3.8 - - Automatically sorts your chests! + + + + jeff-ftp + ftps://ftp.jeff-media.de/maven2 + + + diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortEvent.java b/src/main/java/de/jeff_media/ChestSort/ChestSortEvent.java index 94c06f5..22b9f9b 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortEvent.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortEvent.java @@ -1,24 +1,39 @@ package de.jeff_media.ChestSort; import org.bukkit.Location; +import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.Nullable; public class ChestSortEvent extends Event implements Cancellable { boolean cancelled = false; Location loc; + Inventory inv; + Player p; private static final HandlerList HANDLERS = new HandlerList(); - public ChestSortEvent(Location loc) { - this.loc=loc; + public ChestSortEvent(Inventory inv) { + this.inv = inv; } + @Nullable public Location getLocation() { return loc; } + + public Inventory getInventory() { + return inv; + } + + @Nullable + public Player getPlayer() { + return p; + } public HandlerList getHandlers() { return HANDLERS; diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java index 4ac712a..c3552c1 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java @@ -399,12 +399,10 @@ public class ChestSortListener implements Listener { @EventHandler public void onAdditionalHotkeys(InventoryClickEvent e) { - if(e.getClickedInventory() != null && e.getClickedInventory().getLocation()!=null) { - ChestSortEvent chestSortEvent = new ChestSortEvent(e.getClickedInventory().getLocation()); - Bukkit.getPluginManager().callEvent(chestSortEvent); - if (chestSortEvent.isCancelled()) { - return; - } + // Debug + if(plugin.debug) { + System.out.println(e.getInventory().getHolder()); + System.out.println(e.getInventory().getHolder().getClass().getName()); } if(!plugin.getConfig().getBoolean("allow-hotkeys")) { @@ -431,12 +429,26 @@ public class ChestSortListener implements Listener { return; } + // Don't sort inventories belonging to BossShopPro + if(e.getInventory()!=null && e.getInventory().getHolder()!=null && e.getInventory().getHolder().getClass().getName().equalsIgnoreCase("org.black_ixx.bossshop.core.BSShopHolder")) { + return; + } + if( !p.hasPermission("chestsort.use")) return; plugin.registerPlayerIfNeeded(p); ChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString()); + + ChestSortEvent chestSortEvent = new ChestSortEvent(e.getInventory()); + chestSortEvent.loc=e.getWhoClicked().getLocation(); + Bukkit.getPluginManager().callEvent(chestSortEvent); + if (chestSortEvent.isCancelled()) { + return; + } + if(e.isLeftClick() && setting.leftClick) { + plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory()); plugin.organizer.sortInventory(e.getInventory()); plugin.organizer.updateInventoryView(e.getInventory()); diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java index ad92fec..82bbb13 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java @@ -388,7 +388,8 @@ public class ChestSortOrganizer { void sortInventory(Inventory inv, int startSlot, int endSlot) { if(inv.getLocation() != null) { - ChestSortEvent chestSortEvent = new ChestSortEvent(inv.getLocation()); + ChestSortEvent chestSortEvent = new ChestSortEvent(inv); + chestSortEvent.loc = inv.getLocation(); Bukkit.getPluginManager().callEvent(chestSortEvent); if (chestSortEvent.isCancelled()) { return; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7b22db5..72f40c6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: de.jeff_media.ChestSort.ChestSortPlugin name: ChestSort -version: 8.8.3-pre1 +version: 8.9 api-version: 1.13 description: Allows automatic chest sorting author: mfnalex