mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-12-02 23:53:21 +01:00
11.5.4
This commit is contained in:
parent
8d122d19a2
commit
695869f404
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 11.5.4
|
||||||
|
- Fixed CratesReloaded preview GUI not opening when leftclicking chests
|
||||||
|
|
||||||
## 11.5.3
|
## 11.5.3
|
||||||
- Fixed "disabled-worlds" not working for "left-click hotkey"
|
- Fixed "disabled-worlds" not working for "left-click hotkey"
|
||||||
|
|
||||||
|
2
pom.xml
2
pom.xml
@ -9,7 +9,7 @@
|
|||||||
<name>ChestSort</name>
|
<name>ChestSort</name>
|
||||||
<url>https://www.chestsort.de</url>
|
<url>https://www.chestsort.de</url>
|
||||||
<description>Allows automatic chest sorting!</description>
|
<description>Allows automatic chest sorting!</description>
|
||||||
<version>11.5.3</version>
|
<version>11.5.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -1,23 +1,50 @@
|
|||||||
package de.jeff_media.chestsort.hooks;
|
package de.jeff_media.chestsort.hooks;
|
||||||
|
|
||||||
import de.jeff_media.chestsort.ChestSortPlugin;
|
import de.jeff_media.chestsort.ChestSortPlugin;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Who doesn't make their API available in a public maven repository
|
||||||
|
* deserves to be touched using Reflection only.
|
||||||
|
*/
|
||||||
public class CrateReloadedHook {
|
public class CrateReloadedHook {
|
||||||
|
|
||||||
private final ChestSortPlugin main;
|
private static final ChestSortPlugin main = ChestSortPlugin.getInstance();
|
||||||
|
private static Object blockCrateRegistrarObject;
|
||||||
|
private static Method isCrateMethod;
|
||||||
|
|
||||||
public CrateReloadedHook(ChestSortPlugin main) {
|
static {
|
||||||
this.main=main;
|
try {
|
||||||
|
Class<?> crateApiClazz = Class.forName("com.hazebyte.crate.api.CrateAPI");
|
||||||
|
Method getBlockCrateRegistrarMethod = crateApiClazz.getMethod("getBlockCrateRegistrar");
|
||||||
|
Class<?> blockCrateRegistrarClazz = Class.forName("com.hazebyte.crate.api.crate.BlockCrateRegistrar");
|
||||||
|
blockCrateRegistrarObject = getBlockCrateRegistrarMethod.invoke(null);
|
||||||
|
isCrateMethod = blockCrateRegistrarClazz.getMethod("hasCrates", Location.class);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
isCrateMethod = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CrateReloaded inventories seem to have a holder called cratereloaded.bo
|
public static boolean isCrate(@NotNull final Block block) {
|
||||||
// Maybe this changes? We just check if the String starts with cratereloaded
|
try {
|
||||||
public boolean isCrate(Inventory inv) {
|
if(isCrateMethod != null) {
|
||||||
|
return (boolean) isCrateMethod.invoke(blockCrateRegistrarObject, block.getLocation());
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) { }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCrate(@NotNull final Inventory inv) {
|
||||||
if(inv==null) return false;
|
if(inv==null) return false;
|
||||||
if(inv.getHolder()==null) return false;
|
if(inv.getHolder()==null) return false;
|
||||||
if(!main.getConfig().getBoolean("hook-cratereloaded",true)) return false;
|
if(!main.getConfig().getBoolean("hook-cratereloaded",true)) return false;
|
||||||
return inv.getHolder().getClass().getName().startsWith("cratereloaded");
|
return inv.getHolder().getClass().getName().toLowerCase(Locale.ROOT).contains("cratereloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
final ChestSortPlugin plugin;
|
final ChestSortPlugin plugin;
|
||||||
public final MinepacksHook minepacksHook;
|
public final MinepacksHook minepacksHook;
|
||||||
final HeadDatabaseHook headDatabaseHook;
|
final HeadDatabaseHook headDatabaseHook;
|
||||||
final CrateReloadedHook crateReloadedHook;
|
|
||||||
final GoldenCratesHook goldenCratesHook;
|
final GoldenCratesHook goldenCratesHook;
|
||||||
final AdvancedChestsHook advancedChestsHook;
|
final AdvancedChestsHook advancedChestsHook;
|
||||||
|
|
||||||
@ -49,7 +48,6 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.minepacksHook = new MinepacksHook(plugin);
|
this.minepacksHook = new MinepacksHook(plugin);
|
||||||
this.headDatabaseHook = new HeadDatabaseHook(plugin);
|
this.headDatabaseHook = new HeadDatabaseHook(plugin);
|
||||||
this.crateReloadedHook = new CrateReloadedHook(plugin);
|
|
||||||
this.goldenCratesHook = new GoldenCratesHook(plugin);
|
this.goldenCratesHook = new GoldenCratesHook(plugin);
|
||||||
this.advancedChestsHook = new AdvancedChestsHook(plugin);
|
this.advancedChestsHook = new AdvancedChestsHook(plugin);
|
||||||
}
|
}
|
||||||
@ -67,6 +65,9 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
if(!plugin.getConfig().getBoolean("allow-left-click-to-sort")) return;
|
if(!plugin.getConfig().getBoolean("allow-left-click-to-sort")) return;
|
||||||
Block clickedBlock = event.getClickedBlock();
|
Block clickedBlock = event.getClickedBlock();
|
||||||
if(!(clickedBlock.getState() instanceof Container)) return;
|
if(!(clickedBlock.getState() instanceof Container)) return;
|
||||||
|
if(CrateReloadedHook.isCrate(clickedBlock)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock)) {
|
if(!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock)) {
|
||||||
//System.out.println("ChestSort: cannot interact!");
|
//System.out.println("ChestSort: cannot interact!");
|
||||||
return;
|
return;
|
||||||
@ -637,8 +638,8 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CrateReloaded hook
|
// CrateReloaded hook
|
||||||
if(crateReloadedHook.isCrate(e.getClickedInventory())
|
if(CrateReloadedHook.isCrate(e.getClickedInventory())
|
||||||
|| crateReloadedHook.isCrate(e.getInventory())) {
|
|| CrateReloadedHook.isCrate(e.getInventory())) {
|
||||||
//if(plugin.debug) plugin.getLogger().info("Aborting hotkey because this is a CrateReloaded crate");
|
//if(plugin.debug) plugin.getLogger().info("Aborting hotkey because this is a CrateReloaded crate");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user