mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-13 22:26:03 +01:00
Fixes a bug when global commands does not displays in tab-complete.
Remove DefaultsCommand.java as it is not used anymore.
This commit is contained in:
parent
c1a0eaa2bf
commit
24828a3a1b
@ -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
|
||||
// ---------------------------------------------------------------------
|
||||
@ -113,6 +119,12 @@ public class ChallengesAddon extends Addon {
|
||||
this.saveDefaultConfig();
|
||||
// Load the plugin's config
|
||||
this.loadSettings();
|
||||
|
||||
if (this.settings.isUseCommonGUI())
|
||||
{
|
||||
new ChallengesGlobalPlayerCommand(this, this.hookedGameModes);
|
||||
new ChallengesGlobalAdminCommand(this, this.hookedGameModes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -151,7 +163,7 @@ public class ChallengesAddon extends Addon {
|
||||
// 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(
|
||||
@ -163,7 +175,7 @@ public class ChallengesAddon extends Addon {
|
||||
new ChallengesAdminCommand(this, command));
|
||||
|
||||
this.hooked = true;
|
||||
hookedGameModes.add(gameModeAddon);
|
||||
this.hookedGameModes.add(gameModeAddon);
|
||||
|
||||
CHALLENGES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
|
||||
CHALLENGES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
|
||||
@ -173,15 +185,6 @@ public class ChallengesAddon extends Addon {
|
||||
});
|
||||
|
||||
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.
|
||||
|
@ -9,6 +9,7 @@ import world.bentobox.bentobox.api.user.User;
|
||||
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;
|
||||
|
||||
|
||||
@ -52,7 +53,12 @@ public class ChallengesGlobalPlayerCommand extends CompositeCommand
|
||||
{
|
||||
// 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() + " " +
|
||||
|
@ -37,9 +37,6 @@ public class ChallengesAdminCommand extends CompositeCommand
|
||||
// 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);
|
||||
|
||||
|
@ -6,8 +6,11 @@ import java.util.List;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
@ -49,7 +52,12 @@ public class ChallengesGlobalAdminCommand extends CompositeCommand
|
||||
{
|
||||
// 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() + " " +
|
||||
|
@ -1,168 +0,0 @@
|
||||
package world.bentobox.challenges.commands.admin;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* This method generates default challenges file.
|
||||
*/
|
||||
public class DefaultsCommand extends CompositeCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor that inits generate defaults command.
|
||||
*
|
||||
* @param addon Addon that inits this command
|
||||
* @param cmd Parent command
|
||||
*/
|
||||
public DefaultsCommand(Addon addon, CompositeCommand cmd)
|
||||
{
|
||||
super(addon, cmd, "defaults");
|
||||
this.addon = (ChallengesAddon) addon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.setPermission("admin.challenges");
|
||||
this.setParametersHelp("challenges.commands.admin.defaults.parameters");
|
||||
this.setDescription("challenges.commands.admin.defaults.description");
|
||||
|
||||
// Register sub commands
|
||||
// This method reloads challenges addon
|
||||
new ImportCommand(this);
|
||||
// Import ASkyBlock Challenges
|
||||
new GenerateCommand(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
return this.showHelp(this, user);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Private Classes
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This class allows to process import command.
|
||||
*/
|
||||
private class ImportCommand extends CompositeCommand
|
||||
{
|
||||
/**
|
||||
* Default constructor for import method.
|
||||
* @param parent composite command
|
||||
*/
|
||||
private ImportCommand(CompositeCommand parent)
|
||||
{
|
||||
super(DefaultsCommand.this.addon, parent, "import");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.setPermission("admin.challenges");
|
||||
this.setParametersHelp("challenges.commands.admin.defaults-import.parameters");
|
||||
this.setDescription("challenges.commands.admin.defaults-import.description");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
DefaultsCommand.this.addon.getImportManager().loadDownloadedChallenges(user, this.getWorld(), "default");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class allows to process generate command.
|
||||
*/
|
||||
private class GenerateCommand extends CompositeCommand
|
||||
{
|
||||
/**
|
||||
* Default constructor for generate method.
|
||||
* @param parent composite command
|
||||
*/
|
||||
private GenerateCommand(CompositeCommand parent)
|
||||
{
|
||||
super(DefaultsCommand.this.addon, parent, "generate");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.setPermission("admin.challenges");
|
||||
this.setParametersHelp("challenges.commands.admin.defaults-generate.parameters");
|
||||
this.setDescription("challenges.commands.admin.defaults-generate.description");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
DefaultsCommand.this.addon.getImportManager().generateDatabaseFile(
|
||||
user,
|
||||
this.getWorld(),
|
||||
"defaults");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args)
|
||||
{
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size() - 1) : "";
|
||||
return Optional.of(Util.tabLimit(Collections.singletonList("overwrite"), lastArg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Holds challenges addon as variable.
|
||||
*/
|
||||
private ChallengesAddon addon;
|
||||
}
|
Loading…
Reference in New Issue
Block a user