mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-11-30 06:33:27 +01:00
added middle click support
This commit is contained in:
parent
cf6bbb6e2b
commit
366bcaff56
@ -9,6 +9,7 @@ import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.EnderChest;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,6 +19,7 @@ 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.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -270,6 +272,11 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClickEvent(InventoryClickEvent event) {
|
||||
|
||||
if(!plugin.getConfig().getBoolean("allow-shortcut")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
@ -282,14 +289,41 @@ public class JeffChestSortListener implements Listener {
|
||||
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
|
||||
if(!(holder instanceof Player) && !belongsToChestLikeBlock(event.getInventory())) {
|
||||
if(event.getClick() != ClickType.MIDDLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getClick() == ClickType.MIDDLE) {
|
||||
if(belongsToChestLikeBlock(event.getInventory())) {
|
||||
//p.sendMessage("Sorting chest");
|
||||
plugin.organizer.sortInventory(event.getInventory());
|
||||
updateInventoryView(event);
|
||||
return;
|
||||
} else if(holder instanceof Player) {
|
||||
//p.sendMessage("Sorting player inv");
|
||||
if(event.getSlotType() == SlotType.QUICKBAR) {
|
||||
//p.sendMessage("Sorting Hotbar");
|
||||
plugin.organizer.sortInventory(p.getInventory(),0,8);
|
||||
updateInventoryView(event);
|
||||
return;
|
||||
}
|
||||
else if(event.getSlotType() == SlotType.CONTAINER) {
|
||||
//p.sendMessage("Sorting container");
|
||||
plugin.organizer.sortInventory(p.getInventory(),9,35);
|
||||
updateInventoryView(event);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void updateInventoryView(InventoryClickEvent event) {
|
||||
for(HumanEntity viewer : event.getViewers()) {
|
||||
if(viewer instanceof Player) {
|
||||
Player playerViewer = (Player) viewer;
|
||||
playerViewer.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
JeffChestSortListener listener;
|
||||
String sortingMethod;
|
||||
ArrayList<String> disabledWorlds;
|
||||
int currentConfigVersion = 11;
|
||||
int currentConfigVersion = 12;
|
||||
boolean usingMatchingConfig = true;
|
||||
boolean debug = false;
|
||||
boolean verbose = true;
|
||||
@ -134,6 +134,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
getConfig().addDefault("check-for-updates", "true");
|
||||
getConfig().addDefault("auto-generate-category-files", true);
|
||||
getConfig().addDefault("sort-time", "close");
|
||||
getConfig().addDefault("allow-shortcut", true);
|
||||
getConfig().addDefault("verbose", true); // Prints some information in onEnable()
|
||||
}
|
||||
|
||||
@ -251,6 +252,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
|
||||
getLogger().info("Sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default"));
|
||||
getLogger().info("Auto generate category files: " + getConfig().getBoolean("auto-generate-category-files"));
|
||||
getLogger().info("Sort time: " + getConfig().getString("sort-time"));
|
||||
getLogger().info("Allow shortcut: " + getConfig().getString("allow-shortcut"));
|
||||
getLogger().info("Check for updates: " + getConfig().getString("check-for-updates"));
|
||||
getLogger().info("Categories: " + getCategoryList());
|
||||
}
|
||||
|
@ -63,6 +63,11 @@ auto-generate-category-files: true
|
||||
# Available options: open, close, both
|
||||
sort-time: close
|
||||
|
||||
# Instead of automatic sorting, you can also use middle-click
|
||||
# when using an inventory to have it sorted immediately.
|
||||
# You can disable this by setting this to false.
|
||||
allow-shortcut: true
|
||||
|
||||
# should we check for updates?
|
||||
# when enabled, a message is printed in the console if a new
|
||||
# version has been found, and OPs will be notified when they join the server
|
||||
@ -274,4 +279,4 @@ message-error-invalid-options: "&cError: Unknown option %s. Valid options are %s
|
||||
#########################
|
||||
|
||||
# please do not change the following line manually!
|
||||
config-version: 11
|
||||
config-version: 12
|
||||
|
Loading…
Reference in New Issue
Block a user