Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.github.johnrengelman.shadow") version("8.1.1")
id("com.github.ben-manes.versions") version "0.48.0"
id("com.gradleup.shadow") version("8.3.5")
id("com.github.ben-manes.versions") version("0.51.0")
}

// Change to true when releasing
Expand All @@ -18,6 +18,7 @@ repositories {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.glaremasters.me/repository/public/")
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
maven("https://repo.oraxen.com/releases")
maven("https://jitpack.io")
}

Expand Down
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[versions]
# Compile only
spigot = "1.21.3-R0.1-SNAPSHOT"
spigot = "1.21.4-R0.1-SNAPSHOT"
vault = "1.7.1"
authlib = "1.5.25"
headdb = "1.3.1"
itemsadder = "3.2.5"
oraxen = "1.159.0"
mythiclib = "1.6.2-SNAPSHOT"
mmoitems = "6.9.5-SNAPSHOT"
headdb = "1.3.2"
itemsadder = "3.6.3-beta-14"
oraxen = "1.187.0"
mythiclib = "1.7.1-SNAPSHOT"
mmoitems = "6.10-SNAPSHOT"
papi = "2.11.6"
score = "4.23.10.8"
score = "4.24.3.5"

# Implementation
nashorn = "15.4"
nashorn = "15.6"
adventure-platform = "4.3.4"
adventure-minimessage = "4.17.0"
adventure-minimessage = "4.18.0"

[libraries]
# Compile only
Expand All @@ -23,7 +23,7 @@ vault = { module = "com.github.milkbowl:VaultAPI", version.ref = "vault" }
authlib = { module = "com.mojang:authlib", version.ref = "authlib" }
headdb = { module = "com.arcaniax:HeadDatabase-API", version.ref = "headdb" }
itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version.ref = "itemsadder" }
oraxen = { module = "com.github.oraxen:oraxen", version.ref = "oraxen" }
oraxen = { module = "io.th0rgal:oraxen", version.ref = "oraxen" }
mythiclib = { module = "io.lumine:MythicLib-dist", version.ref = "mythiclib"}
mmoitems = { module = "net.Indyuce:MMOItems-API", version.ref = "mmoitems" }
papi = { module = "me.clip:placeholderapi", version.ref = "papi" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
16 changes: 8 additions & 8 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.extendedclip.deluxemenus.action.ClickActionTask;
import com.extendedclip.deluxemenus.action.ClickHandler;
import com.extendedclip.deluxemenus.hooks.ItemHook;
import com.extendedclip.deluxemenus.menu.LoreAppendMode;
import com.extendedclip.deluxemenus.menu.options.LoreAppendMode;
import com.extendedclip.deluxemenus.menu.Menu;
import com.extendedclip.deluxemenus.menu.MenuHolder;
import com.extendedclip.deluxemenus.menu.MenuItem;
Expand Down
137 changes: 21 additions & 116 deletions src/main/java/com/extendedclip/deluxemenus/menu/Menu.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@
package com.extendedclip.deluxemenus.menu;

import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.menu.command.RegistrableMenuCommand;
import com.extendedclip.deluxemenus.menu.options.MenuOptions;
import com.extendedclip.deluxemenus.requirement.RequirementList;
import com.extendedclip.deluxemenus.utils.DebugLevel;
import com.extendedclip.deluxemenus.utils.StringUtils;

import java.lang.reflect.Field;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;

import me.clip.placeholderapi.util.Msg;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class Menu extends Command {
public class Menu {

private static final Map<String, Menu> menus = new HashMap<>();
private static final Set<MenuHolder> menuHolders = new HashSet<>();
private static final Map<UUID, Menu> lastOpenedMenus = new HashMap<>();
private static CommandMap commandMap = null;

private final DeluxeMenus plugin;
private final MenuOptions options;
private final Map<Integer, TreeMap<Integer, MenuItem>> items;
// menu path starting from the plugin directory
private final String path;

private RegistrableMenuCommand command = null;

public Menu(
final @NotNull DeluxeMenus plugin,
final @NotNull MenuOptions options,
final @NotNull Map<Integer, TreeMap<Integer, MenuItem>> items,
final @NotNull String path
) {
super(options.commands().isEmpty() ? options.name() : options.commands().get(0));

this.plugin = plugin;
this.options = options;
this.items = items;
this.path = path;

if (this.options.registerCommands()) {
if (this.options.commands().size() > 1) {
this.setAliases(this.options.commands().subList(1, this.options.commands().size()));
}

addCommand();
this.command = new RegistrableMenuCommand(plugin, this);
this.command.register();
}

menus.put(this.options.name(), this);
}

Expand All @@ -67,12 +59,12 @@ public static void unload(final @NotNull DeluxeMenus plugin, final @NotNull Stri
}
}

Optional<Menu> menu = Menu.getMenuByName(name);
if (menu.isEmpty()) {
Optional<Menu> optionalMenu = Menu.getMenuByName(name);
if (optionalMenu.isEmpty()) {
return;
}

menu.get().removeCommand();
optionalMenu.get().unregisterCommand();
menus.remove(name);
}

Expand All @@ -83,13 +75,23 @@ public static void unload(final @NotNull DeluxeMenus plugin) {
}
}
for (Menu menu : Menu.getAllMenus()) {
menu.removeCommand();
menu.unregisterCommand();
}
menus.clear();
menuHolders.clear();
lastOpenedMenus.clear();
}

private void unregisterCommand() {
if (this.command != null) {
this.command.unregister();
}

// WARNING! A reference to the command is stored by CraftBukkit for their `/help` command. There is currently
// no way to remove this reference!
this.command = null;
}

public static void unloadForShutdown(final @NotNull DeluxeMenus plugin) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (isInMenu(player)) {
Expand Down Expand Up @@ -208,103 +210,6 @@ public static void closeMenu(final @NotNull DeluxeMenus plugin, final @NotNull P
closeMenu(plugin, player, close, false);
}

private void addCommand() {
if (commandMap == null) {
try {
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
f.setAccessible(true);
commandMap = (CommandMap) f.get(Bukkit.getServer());
} catch (final @NotNull Exception exception) {
plugin.printStacktrace(
"Something went wrong while trying to register command: " + this.getName(),
exception
);
return;
}
}
boolean registered = commandMap.register("DeluxeMenus", this);
if (registered) {
plugin.debug(
DebugLevel.LOW,
Level.INFO,
"Registered command: " + this.getName() + " for menu: " + this.options.name()
);
}
}

private void removeCommand() {
if (commandMap != null && this.options.registerCommands()) {
Field cMap;
Field knownCommands;
try {
cMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
cMap.setAccessible(true);
knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommands.setAccessible(true);
((Map<String, Command>) knownCommands.get((SimpleCommandMap) cMap.get(Bukkit.getServer())))
.remove(this.getName());
boolean unregistered = this.unregister((CommandMap) cMap.get(Bukkit.getServer()));
this.unregister(commandMap);
if (unregistered) {
plugin.debug(
DebugLevel.HIGH,
Level.INFO,
"Successfully unregistered command: " + this.getName()
);
} else {
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Failed to unregister command: " + this.getName()
);
}
} catch (final @NotNull Exception exception) {
plugin.printStacktrace(
"Something went wrong while trying to unregister command: " + this.getName(),
exception
);
}
}
}

@Override
public boolean execute(final @NotNull CommandSender sender, final @NotNull String commandLabel, final @NotNull String[] typedArgs) {
if (!(sender instanceof Player)) {
Msg.msg(sender, "Menus can only be opened by players!");
return true;
}

Map<String, String> argMap = null;

if (!this.options.arguments().isEmpty()) {
plugin.debug(DebugLevel.LOWEST, Level.INFO, "has args");
if (typedArgs.length < this.options.arguments().size()) {
if (this.options.argumentsUsageMessage().isPresent()) {
Msg.msg(sender, this.options.argumentsUsageMessage().get());
}
return true;
}
argMap = new HashMap<>();
int index = 0;
for (String arg : this.options.arguments()) {
if (index + 1 == this.options.arguments().size()) {
String last = String.join(" ", Arrays.asList(typedArgs).subList(index, typedArgs.length));
plugin.debug(DebugLevel.LOWEST, Level.INFO, "arg: " + arg + " => " + last);
argMap.put(arg, last);
} else {
argMap.put(arg, typedArgs[index]);
plugin.debug(DebugLevel.LOWEST, Level.INFO, "arg: " + arg + " => " + typedArgs[index]);
}
index++;
}
}

Player player = (Player) sender;
plugin.debug(DebugLevel.LOWEST, Level.INFO, "opening menu: " + this.options.name());
openMenu(player, argMap, null);
return true;
}

private boolean hasOpenBypassPerm(final @NotNull Player viewer) {
return viewer.hasPermission("deluxemenus.openrequirement.bypass." + this.options.name())
|| viewer.hasPermission("deluxemenus.openrequirement.bypass.*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.hooks.ItemHook;
import com.extendedclip.deluxemenus.menu.options.HeadType;
import com.extendedclip.deluxemenus.menu.options.LoreAppendMode;
import com.extendedclip.deluxemenus.menu.options.MenuItemOptions;
import com.extendedclip.deluxemenus.nbt.NbtProvider;
import com.extendedclip.deluxemenus.utils.DebugLevel;
Expand Down
Loading
Loading