mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2025-01-06 00:17:52 +01:00
Update 8.7. Closes #64
This commit is contained in:
parent
8bb19ad23f
commit
d105854dd0
@ -1,4 +1,8 @@
|
||||
# Changelog
|
||||
## 8.7
|
||||
- When using Minepacks, the backpack item in the inventory will not be moved
|
||||
- Added use-permissions option. If you do not use a permissions plugin, you can set this to false to allow every player to use ChestSort
|
||||
|
||||
## 8.6
|
||||
- Added support for Minepacks
|
||||
|
||||
|
8
pom.xml
8
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.jeffclan</groupId>
|
||||
<artifactId>JeffChestSort</artifactId>
|
||||
<version>8.6</version>
|
||||
<version>8.7</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JeffChestSort</name>
|
||||
@ -105,17 +105,17 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/CrackShot.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.jojodmo.customitems</groupId>
|
||||
<artifactId>CustomItems</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/CustomItemsAPI_PLACEHOLDER.jar</systemPath>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Minepacks-API</artifactId>
|
||||
<version>2.2</version><!-- Check api-version shield for newest version -->
|
||||
<version>2.3.8</version><!-- Check api-version shield for newest version -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
@ -32,6 +32,8 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
plugin.permissionsHandler.addPermissions(event.getPlayer());
|
||||
|
||||
// DEBUG
|
||||
// To enable debug mode, put debug: true into your config.yml
|
||||
@ -48,6 +50,7 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.permissionsHandler.removePermissions(event.getPlayer());
|
||||
plugin.unregisterPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@ -68,7 +71,7 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
void onBackPackUse(Inventory inv, Player p) {
|
||||
if(!minepacksHook.isMinepacksBackpack(inv)) return;
|
||||
if(!p.hasPermission("chestsort.use")) return;
|
||||
if( !p.hasPermission("chestsort.use")) return;
|
||||
plugin.registerPlayerIfNeeded(p);
|
||||
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
if(!setting.sortingEnabled) return;
|
||||
@ -85,7 +88,7 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
Player p = (Player) event.getInventory().getHolder();
|
||||
|
||||
if(!p.hasPermission("chestsort.use.inventory")) return;
|
||||
if( !p.hasPermission("chestsort.use.inventory")) return;
|
||||
plugin.registerPlayerIfNeeded(p);
|
||||
|
||||
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
@ -127,7 +130,7 @@ public class JeffChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onChestClose(InventoryOpenEvent event) {
|
||||
public void onChestOpen(InventoryOpenEvent event) {
|
||||
|
||||
if (!(plugin.getConfig().getString("sort-time").equalsIgnoreCase("open")
|
||||
|| plugin.getConfig().getString("sort-time").equalsIgnoreCase("both"))) {
|
||||
@ -194,7 +197,7 @@ public class JeffChestSortListener implements Listener {
|
||||
}
|
||||
|
||||
private boolean isReadyToSort(Player p) {
|
||||
if (!p.hasPermission("chestsort.use")) {
|
||||
if ( !p.hasPermission("chestsort.use")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -296,7 +299,7 @@ public class JeffChestSortListener implements Listener {
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -365,7 +368,7 @@ public class JeffChestSortListener implements Listener {
|
||||
}
|
||||
if(belongsToChestLikeBlock(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
|
||||
|
||||
if(!p.hasPermission("chestsort.use")) {
|
||||
if( !p.hasPermission("chestsort.use")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -374,7 +377,7 @@ public class JeffChestSortListener implements Listener {
|
||||
plugin.organizer.updateInventoryView(event);
|
||||
return;
|
||||
} else if(holder instanceof Player) {
|
||||
if(!p.hasPermission("chestsort.use.inventory")) {
|
||||
if( !p.hasPermission("chestsort.use.inventory")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -394,9 +397,6 @@ 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;
|
||||
}
|
||||
@ -421,7 +421,7 @@ public class JeffChestSortListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!p.hasPermission("chestsort.use")) return;
|
||||
if( !p.hasPermission("chestsort.use")) return;
|
||||
|
||||
plugin.registerPlayerIfNeeded(p);
|
||||
JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
|
||||
|
@ -407,6 +407,15 @@ public class JeffChestSortOrganizer {
|
||||
//unsortableSlots.add(i);
|
||||
}
|
||||
}*/
|
||||
// Do not move Minepacks' backpacks
|
||||
if(plugin.hookMinepacks) {
|
||||
for(int i = startSlot; i<= endSlot; i++) {
|
||||
if(plugin.listener.minepacksHook.isMinepacksBackpack(items[i])) {
|
||||
items[i] = null;
|
||||
unsortableSlots.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If InventoryPages is installed: get rid of the buttons
|
||||
if(plugin.hookInventoryPages) {
|
||||
for(int i = startSlot; i<= endSlot; i++) {
|
||||
|
@ -0,0 +1,38 @@
|
||||
package de.jeffclan.JeffChestSort;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
public class JeffChestSortPermissionsHandler {
|
||||
|
||||
HashMap<UUID,PermissionAttachment> permissions;
|
||||
JeffChestSortPlugin plugin;
|
||||
|
||||
JeffChestSortPermissionsHandler(JeffChestSortPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.permissions = new HashMap<UUID,PermissionAttachment>();
|
||||
}
|
||||
|
||||
void addPermissions(Player p) {
|
||||
if(plugin.usePermissions) return;
|
||||
if(permissions.containsKey(p.getUniqueId())) return;
|
||||
PermissionAttachment attachment = p.addAttachment(plugin);
|
||||
attachment.setPermission("chestsort.use", true);
|
||||
attachment.setPermission("chestsort.use.inventory", true);
|
||||
permissions.put(p.getUniqueId(), attachment);
|
||||
}
|
||||
|
||||
void removePermissions(Player p) {
|
||||
if(plugin.usePermissions) return;
|
||||
if(!permissions.containsKey(p.getUniqueId())) return;
|
||||
PermissionAttachment attachment = permissions.get(p.getUniqueId());
|
||||
attachment.unsetPermission("chestsort.use");
|
||||
attachment.unsetPermission("chestsort.use.inventory");
|
||||
p.removeAttachment(attachment);
|
||||
permissions.remove(p.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -61,13 +62,15 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
JeffChestSortUpdateChecker updateChecker;
|
||||
JeffChestSortListener listener;
|
||||
JeffChestSortSettingsGUI settingsGUI;
|
||||
JeffChestSortPermissionsHandler permissionsHandler;
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
int currentConfigVersion = 28;
|
||||
int currentConfigVersion = 30;
|
||||
boolean usingMatchingConfig = true;
|
||||
protected boolean debug = false;
|
||||
boolean verbose = true;
|
||||
boolean hotkeyGUI = true;
|
||||
boolean usePermissions;
|
||||
|
||||
public boolean hookCrackShot = false;
|
||||
public boolean hookInventoryPages = false;
|
||||
@ -148,6 +151,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
// values will be used instead
|
||||
// for every missing option.
|
||||
// By default, sorting is disabled. Every player has to run /chestsort once
|
||||
getConfig().addDefault("use-permissions", true);
|
||||
getConfig().addDefault("sorting-enabled-by-default", false);
|
||||
getConfig().addDefault("inv-sorting-enabled-by-default", false);
|
||||
getConfig().addDefault("show-message-when-using-chest", true);
|
||||
@ -204,6 +208,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
// We have to unregister every player to save their perPlayerSettings
|
||||
for (Player p : getServer().getOnlinePlayers()) {
|
||||
unregisterPlayer(p);
|
||||
permissionsHandler.removePermissions(p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,6 +266,10 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
// the Organizer to sort inventories when a player closes a chest, shulkerbox or
|
||||
// barrel inventory
|
||||
listener = new JeffChestSortListener(this);
|
||||
|
||||
permissionsHandler = new JeffChestSortPermissionsHandler(this);
|
||||
|
||||
usePermissions = getConfig().getBoolean("use-permissions");
|
||||
|
||||
// The sorting method will determine how stuff is sorted
|
||||
sortingMethod = getConfig().getString("sorting-method");
|
||||
@ -282,6 +291,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
|
||||
// Does anyone actually need this?
|
||||
if (verbose) {
|
||||
getLogger().info("Use permissions: " + usePermissions);
|
||||
getLogger().info("Current sorting method: " + sortingMethod);
|
||||
getLogger().info("Chest sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default"));
|
||||
getLogger().info("Inventory sorting enabled by default: " + getConfig().getBoolean("inv-sorting-enabled-by-default"));
|
||||
@ -331,6 +341,10 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for(Player p : getServer().getOnlinePlayers()) {
|
||||
permissionsHandler.addPermissions(p);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCategoryList() {
|
||||
|
@ -2,8 +2,10 @@ package de.jeffclan.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
|
||||
import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
|
||||
|
||||
@ -17,30 +19,30 @@ public class MinepacksHook {
|
||||
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
|
||||
if(plugin.hookMinepacks && bukkitPlugin instanceof MinepacksPlugin) {
|
||||
minepacks = (MinepacksPlugin) bukkitPlugin;
|
||||
plugin.getLogger().info("Succesfully hooked into Minepacks");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMinepacksBackpack(ItemStack item) {
|
||||
if(minepacks == null) return false;
|
||||
|
||||
if(minepacks.isBackpackItem(item)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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")) {
|
||||
|
||||
if(inv.getHolder() instanceof 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;
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,14 @@
|
||||
##### Default settings #####
|
||||
############################
|
||||
|
||||
# If you don't want to use a permission plugin, you can set
|
||||
# this to false to allow every player to use ChestSort.
|
||||
# If you use a permissions plugin, set this to true.
|
||||
# There are two permissions used by ChestSort:
|
||||
# - chestsort.use (allow chest sorting by hotkeys and via /chestsort)
|
||||
# - chestsort.use.inventory (allow inventory sorting by hotkeys and via /invsort)
|
||||
use-permissions: true
|
||||
|
||||
# when set to false, new players will have to run /chestsort
|
||||
# once to enable automatic chest sorting.
|
||||
sorting-enabled-by-default: false
|
||||
@ -162,11 +170,8 @@ hook-crackshot-prefix: "crackshot_weapon"
|
||||
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.
|
||||
# When Minepacks version 2.3.8+ is installed, ChestSort can detect your
|
||||
# backpacks and sort them like a regular chest.
|
||||
hook-minepacks: true
|
||||
|
||||
##### Other backpack plugins #####
|
||||
@ -547,4 +552,4 @@ debug: false
|
||||
|
||||
# Please DO NOT change the following line manually!
|
||||
# It is used by the automatic config updater.
|
||||
config-version: 28
|
||||
config-version: 30
|
||||
|
@ -1,6 +1,6 @@
|
||||
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 8.6
|
||||
version: 8.7
|
||||
api-version: 1.13
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
|
Loading…
Reference in New Issue
Block a user