8.10 release

This commit is contained in:
mfnalex 2020-06-13 17:27:40 +02:00
parent de1e9b7e37
commit c08b7a3845
8 changed files with 137 additions and 31 deletions

View File

@ -1,7 +1,8 @@
# Changelog
## 8.10-SNAPSHOT1
## 8.10
- Left-Click/Right-Click-Hotkey only works with empty hand now
- Made llama, donkey and mule chests sortable via hotkeys and automatic chest sorting
- Removed "checking for updates" message
- Left-Click/Right-Click-Hotkey only work with empty hand now
## 8.9
- Prevent BossShopPro's GUI from being sorted

View File

@ -9,7 +9,7 @@
<name>JeffChestSort</name>
<url>https://www.chestsort.de</url>
<description>Automatically sorts your chests!</description>
<version>8.10-SNAPSHOT2</version>
<version>8.10</version>
<packaging>jar</packaging>
<properties>

View File

@ -0,0 +1,33 @@
package de.jeff_media.ChestSort;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
public class ChestSortDebugger implements @NotNull Listener {
private ChestSortPlugin plugin;
ChestSortDebugger(ChestSortPlugin plugin) {
plugin.getLogger().warning("=======================================");
plugin.getLogger().warning(" CHESTSORT DEBUG MODE ACTIVATED!");
plugin.getLogger().warning("Only use this for development purposes!");
plugin.getLogger().warning("=======================================");
this.plugin=plugin;
}
@EventHandler
public void onInventoryClickEvent(InventoryClickEvent e) {
// Debug
if(plugin.debug) {
System.out.println(" ");
System.out.println("InventoryClickEvent:");
System.out.println("- Holder: " + e.getInventory().getHolder());
//System.out.println("- Holder (Class): "+e.getInventory().getHolder().getClass().getName());
System.out.println("- Slot: "+e.getRawSlot());
System.out.println(" ");
}
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,6 +21,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import de.jeff_media.ChestSort.hooks.MinepacksHook;
import de.jeff_media.ChestSort.utils.LlamaUtils;
public class ChestSortListener implements Listener {
@ -36,9 +38,6 @@ public class ChestSortListener implements Listener {
plugin.permissionsHandler.addPermissions(event.getPlayer());
// DEBUG
// To enable debug mode, put debug: true into your config.yml
// OPs will get an update notice if a new update is available
if (event.getPlayer().isOp()) {
plugin.updateChecker.sendUpdateMessage(event.getPlayer());
@ -118,16 +117,26 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory)) {
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return;
}
if (isReadyToSort(p)) {
// Finally call the Organizer to sort the inventory
plugin.organizer.sortInventory(event.getInventory());
if (!isReadyToSort(p)) {
return;
}
// Finally call the Organizer to sort the inventory
// Llama inventories need special start/end slots
if(LlamaUtils.belongsToLlama(event.getInventory())) {
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
plugin.organizer.sortInventory(event.getInventory(), 2, LlamaUtils.getLlamaChestSize(llama)+1);
return;
}
// Normal container inventories can be sorted completely
plugin.organizer.sortInventory(event.getInventory());
}
@EventHandler(priority = EventPriority.MONITOR)
@ -149,16 +158,26 @@ public class ChestSortListener implements Listener {
Player p = (Player) event.getPlayer();
Inventory inventory = event.getInventory();
if (!belongsToChestLikeBlock(inventory)) {
if (!belongsToChestLikeBlock(inventory) && !LlamaUtils.belongsToLlama(inventory)) {
return;
}
if (isReadyToSort(p)) {
// Finally call the Organizer to sort the inventory
plugin.organizer.sortInventory(event.getInventory());
if (!isReadyToSort(p)) {
return;
}
// Finally call the Organizer to sort the inventory
// Llama inventories need special start/end slots
if(LlamaUtils.belongsToLlama(event.getInventory())) {
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
plugin.organizer.sortInventory(event.getInventory(), 2, LlamaUtils.getLlamaChestSize(llama)+1);
return;
}
// Normal container inventories can be sorted completely
plugin.organizer.sortInventory(event.getInventory());
}
private boolean belongsToChestLikeBlock(Inventory inventory) {
@ -367,12 +386,19 @@ public class ChestSortListener implements Listener {
if(!sort) {
return;
}
if(belongsToChestLikeBlock(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
if(belongsToChestLikeBlock(event.getClickedInventory()) || LlamaUtils.belongsToLlama(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
if( !p.hasPermission("chestsort.use")) {
return;
}
if(LlamaUtils.belongsToLlama(event.getClickedInventory())) {
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
plugin.organizer.sortInventory(event.getClickedInventory(), 2, LlamaUtils.getLlamaChestSize(llama)+1);
plugin.organizer.updateInventoryView(event);
return;
}
plugin.organizer.sortInventory(event.getClickedInventory());
plugin.organizer.updateInventoryView(event);
@ -399,10 +425,8 @@ public class ChestSortListener implements Listener {
@EventHandler
public void onAdditionalHotkeys(InventoryClickEvent e) {
// Debug
if(plugin.debug) {
System.out.println(e.getInventory().getHolder());
System.out.println(e.getInventory().getHolder().getClass().getName());
if(LlamaUtils.belongsToLlama(e.getInventory()) || LlamaUtils.belongsToLlama(e.getClickedInventory())) {
return;
}
if(!plugin.getConfig().getBoolean("allow-hotkeys")) {

View File

@ -29,6 +29,7 @@ import org.bukkit.potion.PotionData;
import de.jeff_media.ChestSort.hooks.CrackShotHook;
import de.jeff_media.ChestSort.hooks.InventoryPagesHook;
import de.jeff_media.ChestSort.utils.CategoryLinePair;
import de.jeff_media.ChestSort.utils.LlamaUtils;
import de.jeff_media.ChestSort.utils.TypeMatchPositionPair;
public class ChestSortOrganizer {
@ -582,13 +583,16 @@ public class ChestSortOrganizer {
if(destination.getHolder()==null || !(destination.getHolder() instanceof Player) || destination.getType() != InventoryType.PLAYER) {
destinationIsPlayerInventory = false;
}
// Dont fill hotbar
if(destinationIsPlayerInventory) {
for(int i = 0; i<9;i++) {
hotbarStuff[i] = destination.getItem(i);
destination.setItem(i, new ItemStack(placeholderMaterial,64));
}
for(int i = 0; i<9;i++) {
hotbarStuff[i] = destination.getItem(i);
destination.setItem(i, new ItemStack(placeholderMaterial,64));
}
}
ArrayList<ItemStack> leftovers = new ArrayList<ItemStack>();
for(int i = 0;i<source.getSize();i++) {
@ -606,10 +610,14 @@ public class ChestSortOrganizer {
}
origSource.addItem(leftovers.toArray(new ItemStack[leftovers.size()]));
if(destinationIsPlayerInventory) { for(int i=0;i<9;i++) {
destination.setItem(i, hotbarStuff[i]);
}
// Restore hotbar
if(destinationIsPlayerInventory) {
for(int i=0;i<9;i++) {
destination.setItem(i, hotbarStuff[i]);
}
}
updateInventoryView(destination);
updateInventoryView(source);

View File

@ -233,8 +233,16 @@ public class ChestSortPlugin extends JavaPlugin {
// Create the config file, including checks for old config versions, and load
// the default values for unset options
createConfig();
debug = getConfig().getBoolean("debug");
if(debug) {
ChestSortDebugger debugger = new ChestSortDebugger(this);
getServer().getPluginManager().registerEvents(debugger, this);
}
if(getConfig().getBoolean("hook-crackshot")) {
if(Bukkit.getPluginManager().getPlugin("CrackShot") instanceof Plugin) {
hookCrackShot=true;
@ -251,7 +259,7 @@ public class ChestSortPlugin extends JavaPlugin {
}
}
debug = getConfig().getBoolean("debug");
// Save default sorting category files when enabled in the config (default=true)
saveDefaultCategories();

View File

@ -0,0 +1,32 @@
package de.jeff_media.ChestSort.utils;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule;
import org.bukkit.inventory.Inventory;
public class LlamaUtils {
public static int getLlamaChestSize(ChestedHorse llama) {
if(llama==null) return -1;
if(!llama.isCarryingChest()) return -1;
if(llama instanceof Llama) {
return ((Llama) llama).getStrength()*3;
}
if(llama instanceof Donkey || llama instanceof Mule) {
return 15;
}
return -1;
}
public static boolean belongsToLlama(Inventory inv) {
if(inv.getHolder() instanceof ChestedHorse) {
System.out.println("This inventory belongs to a llama");
return true;
}
System.out.println("This inventory does NOT belong to a llama");
return false;
}
}

View File

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