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
13 changes: 9 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.gradle
.idea
build
test-server/
.gradle/
.idea/
.vscode/

build/
test-server/

.claude/
CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ItemStack getItem(@NotNull final String... arguments) {

cache.put(arguments[0], item);

return item;
return item.clone();
}).get();
} catch (InterruptedException | ExecutionException e) {
plugin.debug(DebugLevel.HIGHEST, Level.SEVERE, "Error getting MMOItem synchronously.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.extendedclip.deluxemenus.DeluxeMenus;
import com.extendedclip.deluxemenus.menu.Menu;
import com.extendedclip.deluxemenus.scheduler.scheduling.schedulers.TaskScheduler;
import com.extendedclip.deluxemenus.utils.DebugLevel;
import com.extendedclip.deluxemenus.utils.StringUtils;
import me.clip.placeholderapi.util.Msg;
Expand All @@ -27,7 +26,6 @@ public class RegistrableMenuCommand extends Command {
private static CommandMap commandMap = null;

private final DeluxeMenus plugin;
private final TaskScheduler scheduler;

private Menu menu;
private boolean registered = false;
Expand All @@ -37,7 +35,6 @@ public RegistrableMenuCommand(final @NotNull DeluxeMenus plugin,
final @NotNull Menu menu) {
super(menu.options().commands().isEmpty() ? menu.options().name() : menu.options().commands().get(0));
this.plugin = plugin;
this.scheduler = plugin.getScheduler();
this.menu = menu;

if (menu.options().commands().size() > 1) {
Expand Down Expand Up @@ -89,36 +86,41 @@ public boolean execute(final @NotNull CommandSender sender, final @NotNull Strin
}

public void register() {
scheduler.runTask(() -> {
if (registered) {
throw new IllegalStateException("This command was already registered!");
}
if (registered) {
throw new IllegalStateException("This command was already registered!");
}

registered = true;

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;
}
}
registered = true;

boolean registered = commandMap.register(FALLBACK_PREFIX, this);
if (registered) {
plugin.debug(
DebugLevel.LOW,
Level.INFO,
"Registered command: " + this.getName() + " for menu: " + menu.options().name()
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(FALLBACK_PREFIX, this);
if (registered) {
plugin.debug(
DebugLevel.LOW,
Level.INFO,
"Registered command: " + this.getName() + " for menu: " + menu.options().name()
);
} else {
plugin.debug(
DebugLevel.HIGHEST,
Level.WARNING,
"Failed to register command: " + this.getName() + " for menu: " + menu.options().name()
+ ". A command with that name already exists. Use /deluxemenus:" + this.getName() + " instead."
);
}
}

public void unregister() {
Expand Down
Loading