Merge pull request #63 from JEFF-Media-GbR/CustomItems

8.6 update
This commit is contained in:
JEFF 2020-05-23 23:27:48 +02:00 committed by GitHub
commit 3c4a13a7ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 179 additions and 88 deletions

View File

@ -1,4 +1,7 @@
# Changelog
## 8.6
- Added support for Minepacks
## 8.5
- Prevent Right-Click-Hotkey from putting items in the hotbar
- Fixed InventoryPages support: when using &f at the beginning of button names, it was not detected by ChestSort as button

View File

@ -131,6 +131,12 @@ All CrackShot weapons will be grouped together and will be put into the default
[B]InventoryPages[/B]
ChestSort will ignore the "Next Page" and "Prev. Page" buttons when you have InventoryPages installed, so that your GUI does not get messed up.
[B]Better Shulker Boxes / Minepacks / ShulkerPacks[/B][/SIZE]
[SIZE=4]Sort your backpacks just like every other chest! Should work with almost every backpack plugin.
[B]Plugins using GUI inventories[/B]
ChestSort tries to detect GUI inventories created by 3rd party plugins. If this detection fails, please message me at GitHub so that I can add support for that plugin.
[SIZE=6]API for plugin developers[/SIZE][/SIZE]
[SIZE=4]ChestSort provides a method to sort any Inventory instance, using the advanced grouping features that ChestSort provides! Read more about the API [URL='https://github.com/JEFF-Media-GbR/Spigot-ChestSort/blob/master/HOW_TO_USE_API.md']here[/URL].
@ -152,4 +158,4 @@ May the odds be ever in your favor! Have an angel protect your loot when you die
[URL='https://www.spigotmc.org/resources/1-13-angelchest.60383/'][1.13+] AngelChest: Stores your inventory in a protected chest when you die![/URL]
Don't want to collect all drops manually? Use Drop2Inventory. Also reduces lag.
[URL='https://www.spigotmc.org/resources/1-13-drop2inventory.62214/'][1.13] Drop2Inventory: No more need to collect drops![/URL][/SIZE]
[URL='https://www.spigotmc.org/resources/1-13-drop2inventory.62214/'][1.13] Drop2Inventory: No more need to collect drops![/URL][/SIZE]

21
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>de.jeffclan</groupId>
<artifactId>JeffChestSort</artifactId>
<version>8.5</version>
<version>8.6</version>
<packaging>jar</packaging>
<name>JeffChestSort</name>
@ -77,6 +77,10 @@
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>pcgf-repo</id>
<url>https://repo.pcgamingfreaks.at/repository/maven-everything</url>
</repository>
</repositories>
<dependencies>
@ -86,12 +90,8 @@
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<scope>compile</scope>
</dependency>-->
<!-- <dependency> <groupId>net.md-5</groupId> <artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version> <scope>compile</scope> </dependency> -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
@ -104,7 +104,12 @@
<version>0.98.9</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CrackShot.jar</systemPath>
</dependency>
</dependency>
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks-API</artifactId>
<version>2.2</version><!-- Check api-version shield for newest version -->
</dependency>
</dependencies>
<description>Automatically sorts your chests!</description>

View File

@ -1,58 +0,0 @@
package de.jeffclan.JeffChestSort;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
public class JeffChestSortAdditionalHotkeyListener implements Listener {
JeffChestSortPlugin plugin;
public JeffChestSortAdditionalHotkeyListener(JeffChestSortPlugin jeffChestSortPlugin) {
this.plugin = jeffChestSortPlugin;
}
@EventHandler
public void onInventoryClickEvent(InventoryClickEvent e) {
if(!plugin.getConfig().getBoolean("allow-hotkeys")) {
return;
}
if(!(e.getWhoClicked() instanceof Player)) {
return;
}
Player p = (Player) e.getWhoClicked();
// Only continue if clicked outside of the chest
if(e.getClickedInventory()!=null) {
return;
}
// Possible fix for #57
if(e.getInventory().getHolder()==null) return;
if(e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) return;
// End Possible fix for #57
if(e.getInventory().getType() != InventoryType.CHEST
&& e.getInventory().getType() != InventoryType.DISPENSER
&& e.getInventory().getType() != InventoryType.DROPPER
&& e.getInventory().getType() != InventoryType.ENDER_CHEST
&& !e.getInventory().getType().name().equalsIgnoreCase("SHULKER_BOX")
&& (e.getInventory().getHolder() == null || !e.getInventory().getHolder().getClass().toString().endsWith(".CraftBarrel"))) {
return;
}
if(!p.hasPermission("chestsort.use")) return;
plugin.registerPlayerIfNeeded(p);
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
if(e.isLeftClick() && setting.leftClick) {
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
plugin.sortInventory(e.getInventory());
plugin.organizer.updateInventoryView(e.getInventory());
} else if(e.isRightClick() && setting.rightClick) {
plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
}
}
}

View File

@ -5,9 +5,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import de.jeffclan.JeffChestSort.JeffChestSortPlayerSetting;
import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
public class JeffChestSortChestSortCommand implements CommandExecutor {
JeffChestSortPlugin plugin;

View File

@ -4,15 +4,12 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.inventory.InventoryType;
@ -21,12 +18,16 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import de.jeffclan.hooks.MinepacksHook;
public class JeffChestSortListener implements Listener {
JeffChestSortPlugin plugin;
MinepacksHook minepacksHook;
JeffChestSortListener(JeffChestSortPlugin plugin) {
this.plugin = plugin;
this.minepacksHook = new MinepacksHook(plugin);
}
@EventHandler
@ -51,6 +52,29 @@ public class JeffChestSortListener implements Listener {
}
@EventHandler
public void onBackPackClose(InventoryCloseEvent event) {
if(plugin.getConfig().getString("sort-time").equalsIgnoreCase("close")
|| plugin.getConfig().getString("sort-time").equalsIgnoreCase("both"))
onBackPackUse(event.getInventory(),(Player)event.getPlayer());
}
@EventHandler
public void onBackPackOpen(InventoryOpenEvent event) {
if(plugin.getConfig().getString("sort-time").equalsIgnoreCase("open")
|| plugin.getConfig().getString("sort-time").equalsIgnoreCase("both"))
onBackPackUse(event.getInventory(),(Player)event.getPlayer());
}
void onBackPackUse(Inventory inv, Player p) {
if(!minepacksHook.isMinepacksBackpack(inv)) return;
if(!p.hasPermission("chestsort.use")) return;
plugin.registerPlayerIfNeeded(p);
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
if(!setting.sortingEnabled) return;
plugin.organizer.sortInventory(inv);
}
@EventHandler
public void onPlayerInventoryClose(InventoryCloseEvent event) {
if(event.getInventory()==null) return;
@ -58,6 +82,7 @@ public class JeffChestSortListener implements Listener {
if(event.getInventory().getType() == null) return;
if(event.getInventory().getType() != InventoryType.CRAFTING) return; // Weird! Returns CRAFTING instead of PLAYER
if(!(event.getInventory().getHolder() instanceof Player)) return;
Player p = (Player) event.getInventory().getHolder();
if(!p.hasPermission("chestsort.use.inventory")) return;
@ -270,7 +295,7 @@ public class JeffChestSortListener implements Listener {
// p.sendMessage("Shift click: " + event.isShiftClick());
// p.sendMessage("=====================");
// DEBUG END
if(!p.hasPermission("chestsort.use") && !p.hasPermission("chestsort.use.inventory")) {
return;
}
@ -294,13 +319,11 @@ public class JeffChestSortListener 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:
//if(plugin.getConfig().getBoolean("hotkeys.middle-click")) {
@ -340,18 +363,17 @@ public class JeffChestSortListener implements Listener {
if(!sort) {
return;
}
if(belongsToChestLikeBlock(event.getClickedInventory())) {
if(belongsToChestLikeBlock(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
if(!p.hasPermission("chestsort.use")) {
return;
}
plugin.organizer.sortInventory(event.getClickedInventory());
plugin.organizer.updateInventoryView(event);
return;
} else if(holder instanceof Player) {
if(!p.hasPermission("chestsort.use.inventory")) {
return;
}
@ -370,6 +392,49 @@ public class JeffChestSortListener implements Listener {
}
}
@EventHandler
public void onAdditionalHotkeys(InventoryClickEvent e) {
// Backpacks must not go into backpacks, however I am unsure on how to
// check if something is a backpack, so will just disable the fill-chest hotkey
if(minepacksHook.isMinepacksBackpack(e.getInventory())) return;
if(!plugin.getConfig().getBoolean("allow-hotkeys")) {
return;
}
if(!(e.getWhoClicked() instanceof Player)) {
return;
}
Player p = (Player) e.getWhoClicked();
// Only continue if clicked outside of the chest
if(e.getClickedInventory()!=null) {
return;
}
// Possible fix for #57
if(e.getInventory().getHolder()==null) return;
if(e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) return;
// End Possible fix for #57
if(e.getInventory().getType() != InventoryType.CHEST
&& e.getInventory().getType() != InventoryType.DISPENSER
&& e.getInventory().getType() != InventoryType.DROPPER
&& e.getInventory().getType() != InventoryType.ENDER_CHEST
&& !e.getInventory().getType().name().equalsIgnoreCase("SHULKER_BOX")
&& (e.getInventory().getHolder() == null || !e.getInventory().getHolder().getClass().toString().endsWith(".CraftBarrel"))) {
return;
}
if(!p.hasPermission("chestsort.use")) return;
plugin.registerPlayerIfNeeded(p);
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
if(e.isLeftClick() && setting.leftClick) {
plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
plugin.sortInventory(e.getInventory());
plugin.organizer.updateInventoryView(e.getInventory());
} else if(e.isRightClick() && setting.rightClick) {
plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
}
}
}

View File

@ -50,6 +50,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeffclan.utils.Utils;
public class JeffChestSortPlugin extends JavaPlugin {
@ -59,11 +60,10 @@ public class JeffChestSortPlugin extends JavaPlugin {
JeffChestSortOrganizer organizer;
JeffChestSortUpdateChecker updateChecker;
JeffChestSortListener listener;
JeffChestSortAdditionalHotkeyListener additionalHotkeys;
JeffChestSortSettingsGUI settingsGUI;
String sortingMethod;
ArrayList<String> disabledWorlds;
int currentConfigVersion = 27;
int currentConfigVersion = 28;
boolean usingMatchingConfig = true;
protected boolean debug = false;
boolean verbose = true;
@ -71,6 +71,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
public boolean hookCrackShot = false;
public boolean hookInventoryPages = false;
public boolean hookMinepacks = false;
private static long updateCheckInterval = 4*60*60; // in seconds. We check on startup and every 4 hours
@ -169,6 +170,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
getConfig().addDefault("hook-crackshot", true);
getConfig().addDefault("hook-crackshot-prefix", "crackshot_weapon");
getConfig().addDefault("hook-inventorypages", true);
getConfig().addDefault("hook-minepacks", true);
getConfig().addDefault("verbose", true); // Prints some information in onEnable()
}
@ -227,6 +229,11 @@ public class JeffChestSortPlugin extends JavaPlugin {
hookInventoryPages=true;
}
}
if(getConfig().getBoolean("hook-minepacks")) {
if(Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin) {
hookMinepacks=true;
}
}
debug = getConfig().getBoolean("debug");
@ -254,14 +261,12 @@ public class JeffChestSortPlugin extends JavaPlugin {
// the Organizer to sort inventories when a player closes a chest, shulkerbox or
// barrel inventory
listener = new JeffChestSortListener(this);
additionalHotkeys = new JeffChestSortAdditionalHotkeyListener(this);
// The sorting method will determine how stuff is sorted
sortingMethod = getConfig().getString("sorting-method");
// Register the events for our Listener
getServer().getPluginManager().registerEvents(listener, this);
getServer().getPluginManager().registerEvents(additionalHotkeys, this);
// Register events for the GUI interaction
getServer().getPluginManager().registerEvents(settingsGUI, this);

View File

@ -0,0 +1,47 @@
package de.jeffclan.hooks;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
public class MinepacksHook {
JeffChestSortPlugin plugin;
MinepacksPlugin minepacks = null;
public MinepacksHook(JeffChestSortPlugin plugin) {
this.plugin = plugin;
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
if(plugin.hookMinepacks && bukkitPlugin instanceof MinepacksPlugin) {
// Do something if Minepacks is not available
minepacks = (MinepacksPlugin) bukkitPlugin;
}
}
public boolean isMinepacksBackpack(Inventory inv) {
if(minepacks == null) return false;
if( inv.getHolder() == null) return false;
if( inv.getHolder().getClass().getName().equalsIgnoreCase("at.pcgamingfreaks.MinepacksStandalone.Bukkit.Backpack")) {
return true;
}
return false;
//System.out.println(inv.getHolder().getClass().getName());
/*if(inv.getHolder() instanceof Backpack) {
return true;
}
if(minepacks.getBackpackCachedOnly(p).getInventory() == inv) {
return true;
}*/
}
}

View File

@ -144,22 +144,43 @@ disabled-worlds:
# installed. ChestSort will automatically check if the plugins
# are installed.
##### CrackShot #####
##### CrackShot ##### -> https://www.spigotmc.org/resources/crackshot-guns.48301/
# When CrackShot is installed, all CrackShot weapons will be
# grouped together and sorted by their name
hook-crackshot: true
# You can define a custom name that will be used as prefix
# for all CrackShot weapon names.
# E.g. when you set this to "crackshot_weapon", an AK-47
# will be called "crackshot_weapon_AK-47"
hook-crackshot-prefix: "crackshot_weapon"
##### InventoryPages #####
##### InventoryPages ##### -> https://www.spigotmc.org/resources/inventorypages.32432/
# When InventoryPages is installed, ChestSort will not sort
# the "Next Page" and "Prev Page" buttons. You should not
# disable this behaviour unless you know what you are doing!
hook-inventorypages: true
##### Minepacks ##### -> https://www.spigotmc.org/resources/minepacks-backpack-plugin-mc-1-7-1-15.19286/
# When Minepacks is installed, ChestSort can detect your
# backpacks and sort them like a regular chest. Please note
# that the left-click and right-click hotkey will not work
# with a Minepack backpack to avoid the possibility of
# putting a backpack inside of itself.
hook-minepacks: true
##### Other backpack plugins #####
# ChestSort is able to detect backpacks from most backpack
# plugins like ShulkerPacks or Better Shulker Boxes.
# This detection is always enabled, you cannot turn it off.
##### Other GUI plugins #####
# ChestSort tries to detect if an inventory belongs to a
# 3rd party plugin's GUI and then prevents it from being sorted.
# If you encounter any problems, like a sortable GUI inventory,
# please open a new issue at Github:
# https://github.com/JEFF-Media-GbR/Spigot-ChestSort/issues
##########################
##### Sorting Method #####
##########################
@ -526,4 +547,4 @@ debug: false
# Please DO NOT change the following line manually!
# It is used by the automatic config updater.
config-version: 27
config-version: 28

View File

@ -1,6 +1,6 @@
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
name: ChestSort
version: 8.5
version: 8.6
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex
@ -8,7 +8,7 @@ website: https://www.chestsort.de
prefix: ChestSort
database: false
loadbefore: [InvUnload]
softdepend: [CrackShot, InventoryPages]
softdepend: [CrackShot, InventoryPages,Minepacks]
commands:
chestsort:
description: Toggle automatic chest sorting.