Skip to content

Commit

Permalink
merge: branch 'hotfix/1.21-compatibility'
Browse files Browse the repository at this point in the history
Signed-off-by: Cristóbal Veas <cristobal.veas@proton.me>
  • Loading branch information
zetastormy committed Jul 21, 2024
2 parents 5b23e3c + 973f497 commit d892f65
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
projectVersion=1.5.4
projectVersion=1.5.3
libsPackage=team.devblook.akropolis.libs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public List<UUID> getOpenInventories() {

@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (event.getView().getTopInventory().getHolder() instanceof InventoryBuilder && refreshEnabled) {
if (InventoryManager.getTopInventory(event).getHolder() instanceof InventoryBuilder && refreshEnabled) {
openInventories.remove(event.getPlayer().getUniqueId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class InventoryListener implements Listener {

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (event.getView().getTopInventory().getHolder() instanceof InventoryBuilder) {
if (InventoryManager.getTopInventory(event).getHolder() instanceof InventoryBuilder) {
event.setCancelled(true);

if (event.getWhoClicked() instanceof Player player) {
Expand All @@ -40,7 +40,7 @@ public void onInventoryClick(InventoryClickEvent event) {
if (itemStack == null || itemStack.getType() == Material.AIR)
return;

InventoryBuilder customHolder = (InventoryBuilder) event.getView().getTopInventory().getHolder();
InventoryBuilder customHolder = (InventoryBuilder) InventoryManager.getTopInventory(event).getHolder();
InventoryItem item = customHolder.getIcon(event.getRawSlot());

if (item == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.inventory.Inventory;
import team.devblook.akropolis.AkropolisPlugin;
import team.devblook.akropolis.inventory.inventories.CustomGUI;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -114,6 +118,17 @@ private void loadCustomMenus() {
}
}

public static Inventory getTopInventory(InventoryEvent event) {
try {
Object view = event.getView();
Method getTopInventory = view.getClass().getMethod("getTopInventory");
getTopInventory.setAccessible(true);
return (Inventory) getTopInventory.invoke(view);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

public Map<String, AbstractInventory> getInventories() {
return inventories;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public class ItemStackBuilder {
// Fix: unknown "ARROW_INFINITE" field on versions 1.20.6 or newer.
try {
// 1.20.6 -> 206
final int version = Integer.parseInt(Bukkit.getMinecraftVersion().substring(2).replace(".", ""));
String strippedVersion = Bukkit.getMinecraftVersion()
.substring(2)
.replace(".", "");
// 1.21 -> 21 -> 210
int version = Integer.parseInt(strippedVersion.length() == 2 ? strippedVersion + "0" : strippedVersion);

Field field = null;
// This would correspond to check if the version is higher or equals to
// 1.20.6.
Expand Down

0 comments on commit d892f65

Please sign in to comment.