Skip to content

Commit

Permalink
Fixes a bug when global commands does not displays in tab-complete.
Browse files Browse the repository at this point in the history
Remove DefaultsCommand.java as it is not used anymore.
  • Loading branch information
BONNe committed Sep 20, 2021
1 parent c1a0eaa commit 24828a3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 184 deletions.
25 changes: 14 additions & 11 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class ChallengesAddon extends Addon {
*/
private boolean levelProvided;

/**
* List of hooked gamemode addons.
*/
private final List<GameModeAddon> hookedGameModes = new ArrayList<>();


// ---------------------------------------------------------------------
// Section: Constants
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -113,6 +119,12 @@ public void onLoad() {
this.saveDefaultConfig();
// Load the plugin's config
this.loadSettings();

if (this.settings.isUseCommonGUI())
{
new ChallengesGlobalPlayerCommand(this, this.hookedGameModes);
new ChallengesGlobalAdminCommand(this, this.hookedGameModes);
}
}


Expand Down Expand Up @@ -151,7 +163,7 @@ public void onEnable() {
// Web content loading
this.webManager = new WebManager(this);

List<GameModeAddon> hookedGameModes = new ArrayList<>();
this.hookedGameModes.clear();

this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
if (!this.settings.getDisabledGameModes().contains(
Expand All @@ -163,7 +175,7 @@ public void onEnable() {
new ChallengesAdminCommand(this, command));

this.hooked = true;
hookedGameModes.add(gameModeAddon);
this.hookedGameModes.add(gameModeAddon);

CHALLENGES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
CHALLENGES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
Expand All @@ -173,15 +185,6 @@ public void onEnable() {
});

if (this.hooked) {

// Create general challenge commands

if (this.settings.isUseCommonGUI())
{
new ChallengesGlobalPlayerCommand(this, hookedGameModes);
new ChallengesGlobalAdminCommand(this, hookedGameModes);
}

// Register the reset listener
this.registerListener(new ResetListener(this));
// Register the autosave listener.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.config.SettingsUtils.GuiMode;
import world.bentobox.challenges.panel.user.GameModePanel;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


Expand Down Expand Up @@ -52,7 +53,12 @@ public boolean execute(User user, String label, List<String> args)
{
// It is not necessary to check 0, as in that case addon will not be hooked.

if (this.gameModeAddons.size() == 1)
if (this.gameModeAddons.isEmpty())
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked"));
return false;
}
else if (this.gameModeAddons.size() == 1)
{
this.gameModeAddons.get(0).getPlayerCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public void setup()
// This method reloads challenges addon
new ReloadChallenges(getAddon(), this);

// Defaults processing command
new DefaultsCommand(this.getAddon(), this);

// Complete challenge command
new CompleteCommand(this.getAddon(), this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.GameModePanel;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


/**
Expand Down Expand Up @@ -49,7 +52,12 @@ public boolean execute(User user, String label, List<String> args)
{
// For single game mode just open correct gui.

if (this.gameModeAddons.size() == 1)
if (this.gameModeAddons.isEmpty())
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked"));
return false;
}
else if (this.gameModeAddons.size() == 1)
{
this.gameModeAddons.get(0).getAdminCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " " +
Expand Down

This file was deleted.

0 comments on commit 24828a3

Please sign in to comment.