Update all commands.

Commands now will have an option to change their call values.
This commit is contained in:
BONNe 2021-09-19 15:02:15 +03:00
parent 5da823c7e5
commit 670513e37a
10 changed files with 224 additions and 239 deletions

View File

@ -178,12 +178,8 @@ public class ChallengesAddon extends Addon {
if (this.settings.isUseCommonGUI()) if (this.settings.isUseCommonGUI())
{ {
new ChallengesGlobalPlayerCommand(this, new ChallengesGlobalPlayerCommand(this, hookedGameModes);
this.settings.getGlobalUserCommand(), new ChallengesGlobalAdminCommand(this, hookedGameModes);
hookedGameModes);
new ChallengesGlobalAdminCommand(this,
this.settings.getGlobalAdminCommand(),
hookedGameModes);
} }
// Register the reset listener // Register the reset listener

View File

@ -9,26 +9,25 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.config.SettingsUtils.GuiMode; import world.bentobox.challenges.config.SettingsUtils.GuiMode;
import world.bentobox.challenges.panel.user.GameModePanel; import world.bentobox.challenges.panel.user.GameModePanel;
import world.bentobox.challenges.utils.Utils;
/** /**
* This class provides all necessary thing to implement challenges user command * This class provides all necessary thing to implement challenges user command
*/ */
public class ChallengesUserCommand extends CompositeCommand public class ChallengesGlobalPlayerCommand extends CompositeCommand
{ {
/** /**
* Constructor that inits command with given string. * Constructor that inits command with given string.
* @param addon Challenges Addon * @param addon Challenges Addon
* @param commands String that contains main command and its alias separated via whitespace.
* @param gameModeAddons List with GameModes where challenges addon operates. * @param gameModeAddons List with GameModes where challenges addon operates.
*/ */
public ChallengesUserCommand(ChallengesAddon addon, String commands, List<GameModeAddon> gameModeAddons) public ChallengesGlobalPlayerCommand(ChallengesAddon addon, List<GameModeAddon> gameModeAddons)
{ {
super(addon, super(addon,
commands.split(" ")[0], addon.getChallengesSettings().getPlayerGlobalCommand().split(" ")[0],
commands.split(" ")); addon.getChallengesSettings().getPlayerGlobalCommand().split(" "));
this.gameModeAddons = gameModeAddons; this.gameModeAddons = gameModeAddons;
this.addon = addon;
} }
@ -56,10 +55,11 @@ public class ChallengesUserCommand extends CompositeCommand
if (this.gameModeAddons.size() == 1) if (this.gameModeAddons.size() == 1)
{ {
this.gameModeAddons.get(0).getPlayerCommand().ifPresent(compositeCommand -> this.gameModeAddons.get(0).getPlayerCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " challenges")); user.performCommand(compositeCommand.getTopLabel() + " " +
this.<ChallengesAddon>getAddon().getChallengesSettings().getPlayerMainCommand().split(" ")[0]));
return true; return true;
} }
else if (this.addon.getChallengesSettings().getUserGuiMode() == GuiMode.CURRENT_WORLD) else if (this.<ChallengesAddon>getAddon().getChallengesSettings().getUserGuiMode() == GuiMode.CURRENT_WORLD)
{ {
// Find GameMode and run command // Find GameMode and run command
for (GameModeAddon addon : this.gameModeAddons) for (GameModeAddon addon : this.gameModeAddons)
@ -67,15 +67,18 @@ public class ChallengesUserCommand extends CompositeCommand
if (addon.inWorld(user.getWorld())) if (addon.inWorld(user.getWorld()))
{ {
addon.getPlayerCommand().ifPresent(compositeCommand -> addon.getPlayerCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " challenges")); user.performCommand(compositeCommand.getTopLabel() + " " +
this.<ChallengesAddon>getAddon().getChallengesSettings().getPlayerMainCommand().split(" ")[0]));
return true; return true;
} }
} }
Utils.sendMessage(user, user.getTranslation("general.errors.wrong-world"));
} }
else if (this.addon.getChallengesSettings().getUserGuiMode() == GuiMode.GAMEMODE_LIST) else if (this.<ChallengesAddon>getAddon().getChallengesSettings().getUserGuiMode() == GuiMode.GAMEMODE_LIST)
{ {
GameModePanel.open(this.addon, GameModePanel.open(this.getAddon(),
this.getWorld(), this.getWorld(),
user, user,
this.gameModeAddons, this.gameModeAddons,
@ -96,9 +99,4 @@ public class ChallengesUserCommand extends CompositeCommand
* List with hooked GameMode addons. * List with hooked GameMode addons.
*/ */
private final List<GameModeAddon> gameModeAddons; private final List<GameModeAddon> gameModeAddons;
/**
* Challenges addon for easier operations.
*/
private final ChallengesAddon addon;
} }

View File

@ -9,14 +9,14 @@ import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.ChallengesPanel; import world.bentobox.challenges.panel.user.ChallengesPanel;
public class ChallengesCommand extends CompositeCommand public class ChallengesPlayerCommand extends CompositeCommand
{ {
public static final String CHALLENGE_COMMAND = "challenges"; public ChallengesPlayerCommand(ChallengesAddon addon, CompositeCommand cmd)
public ChallengesCommand(ChallengesAddon addon, CompositeCommand cmd)
{ {
super(addon, cmd, CHALLENGE_COMMAND); super(addon,
cmd,
addon.getChallengesSettings().getPlayerMainCommand().split(" ")[0],
addon.getChallengesSettings().getPlayerMainCommand().split(" "));
} }
@ -40,9 +40,10 @@ public class ChallengesCommand extends CompositeCommand
// Show admin better explanation. // Show admin better explanation.
if (user.isOp() || user.hasPermission(this.getPermissionPrefix() + "admin.challenges")) if (user.isOp() || user.hasPermission(this.getPermissionPrefix() + "admin.challenges"))
{ {
String topLabel = getIWM().getAddon(this.getWorld()) String topLabel = this.getIWM().getAddon(this.getWorld()).
.map(GameModeAddon::getAdminCommand) map(GameModeAddon::getAdminCommand).
.map(optionalAdminCommand -> optionalAdminCommand.map(ac -> ac.getTopLabel()).orElse(this.getTopLabel())).orElse(this.getTopLabel()); map(optionalAdminCommand -> optionalAdminCommand.map(CompositeCommand::getTopLabel).orElse(this.getTopLabel())).
orElse(this.getTopLabel());
user.sendMessage("challenges.errors.no-challenges-admin", "[command]", topLabel + " challenges"); user.sendMessage("challenges.errors.no-challenges-admin", "[command]", topLabel + " challenges");
} }
else else
@ -87,7 +88,7 @@ public class ChallengesCommand extends CompositeCommand
@Override @Override
public void setup() public void setup()
{ {
this.setPermission(CHALLENGE_COMMAND); this.setPermission("challenges");
this.setParametersHelp("challenges.commands.user.main.parameters"); this.setParametersHelp("challenges.commands.user.main.parameters");
this.setDescription("challenges.commands.user.main.description"); this.setDescription("challenges.commands.user.main.description");

View File

@ -6,7 +6,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -26,10 +25,12 @@ public class CompleteChallengeCommand extends CompositeCommand
* @param addon Challenges addon. * @param addon Challenges addon.
* @param cmd Parent Command. * @param cmd Parent Command.
*/ */
public CompleteChallengeCommand(Addon addon, CompositeCommand cmd) public CompleteChallengeCommand(ChallengesAddon addon, CompositeCommand cmd)
{ {
super(addon, cmd, "complete"); super(addon,
this.addon = (ChallengesAddon) addon; cmd,
addon.getChallengesSettings().getPlayerCompleteCommand().split(" ")[0],
addon.getChallengesSettings().getPlayerCompleteCommand().split(" "));
} }
@ -62,11 +63,11 @@ public class CompleteChallengeCommand extends CompositeCommand
{ {
// Add world name back at the start // Add world name back at the start
String challengeName = Utils.getGameMode(this.getWorld()) + "_" + args.get(0); String challengeName = Utils.getGameMode(this.getWorld()) + "_" + args.get(0);
Challenge challenge = this.addon.getChallengesManager().getChallenge(challengeName); Challenge challenge = this.<ChallengesAddon>getAddon().getChallengesManager().getChallenge(challengeName);
if (challenge != null) if (challenge != null)
{ {
int count = args.size() == 2 ? Integer.valueOf(args.get(1)) : 1; int count = args.size() == 2 ? Integer.parseInt(args.get(1)) : 1;
boolean canMultipleTimes = boolean canMultipleTimes =
user.hasPermission(this.getPermission() + ".multiple"); user.hasPermission(this.getPermission() + ".multiple");
@ -77,7 +78,7 @@ public class CompleteChallengeCommand extends CompositeCommand
count = 1; count = 1;
} }
return TryToComplete.complete(this.addon, return TryToComplete.complete(this.getAddon(),
user, user,
challenge, challenge,
this.getWorld(), this.getWorld(),
@ -113,10 +114,12 @@ public class CompleteChallengeCommand extends CompositeCommand
case 3: case 3:
// Create suggestions with all challenges that is available for users. // Create suggestions with all challenges that is available for users.
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream(). returnList.addAll(this.<ChallengesAddon>getAddon().getChallengesManager().getAllChallengesNames(this.getWorld()).
filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_")). stream().
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)). filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") ||
collect(Collectors.toList())); challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")).
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
collect(Collectors.toList()));
break; break;
case 4: case 4:
// Suggest a number of completions. // Suggest a number of completions.
@ -135,14 +138,4 @@ public class CompleteChallengeCommand extends CompositeCommand
return Optional.of(Util.tabLimit(returnList, lastString)); return Optional.of(Util.tabLimit(returnList, lastString));
} }
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* Variable that holds challenge addon. Single casting.
*/
private ChallengesAddon addon;
} }

View File

@ -1,68 +0,0 @@
package world.bentobox.challenges.commands.admin;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.admin.AdminPanel;
public class Challenges extends CompositeCommand
{
/**
* Admin command for challenges
*
* @param parent
*/
public Challenges(ChallengesAddon addon, CompositeCommand parent)
{
super(addon, parent, "challenges");
}
@Override
public void setup()
{
this.setPermission("admin.challenges");
this.setParametersHelp("challenges.commands.admin.main.parameters");
this.setDescription("challenges.commands.admin.main.description");
// Register sub commands
// 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);
// Reset challenge command
new ResetCommand(this.getAddon(), this);
new ShowChallenges(this.getAddon(), this);
new MigrateCommand(this.getAddon(), this);
}
@Override
public boolean execute(User user, String label, List<String> args)
{
// Open up the admin challenges GUI
if (user.isPlayer())
{
AdminPanel.open(this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix());
return true;
}
return false;
}
}

View File

@ -1,85 +1,71 @@
package world.bentobox.challenges.commands.admin; package world.bentobox.challenges.commands.admin;
import java.util.List; import java.util.List;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.GameModePanel; import world.bentobox.challenges.panel.admin.AdminPanel;
/**
* This class provides all necessary thing to implement challenges admin command
*/
public class ChallengesAdminCommand extends CompositeCommand public class ChallengesAdminCommand extends CompositeCommand
{ {
/**
* Constructor that inits command with given string. /**
* @param addon Challenges Addon * Admin command for challenges
* @param commands String that contains main command and its alias separated via whitespace. *
* @param gameModeAddons List with GameModes where challenges addon operates. * @param parent
*/ */
public ChallengesAdminCommand(ChallengesAddon addon, String commands, List<GameModeAddon> gameModeAddons) public ChallengesAdminCommand(ChallengesAddon addon, CompositeCommand parent)
{ {
super(addon, super(addon,
commands.split(" ")[0], parent,
commands.split(" ")); addon.getChallengesSettings().getAdminMainCommand().split(" ")[0],
this.gameModeAddons = gameModeAddons; addon.getChallengesSettings().getAdminMainCommand().split(" "));
this.addon = addon; }
}
/** @Override
* {@inheritDoc} public void setup()
*/ {
@Override this.setPermission("admin.challenges");
public void setup() this.setParametersHelp("challenges.commands.admin.main.parameters");
{ this.setDescription("challenges.commands.admin.main.description");
this.setPermission("admin.challenges");
this.setParametersHelp("challenges.commands.admin.main.parameters"); // Register sub commands
this.setDescription("challenges.commands.admin.main.description");
} // 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);
// Reset challenge command
new ResetCommand(this.getAddon(), this);
new ShowChallenges(this.getAddon(), this);
new MigrateCommand(this.getAddon(), this);
}
/** @Override
* {@inheritDoc} public boolean execute(User user, String label, List<String> args)
*/ {
@Override // Open up the admin challenges GUI
public boolean execute(User user, String label, List<String> args) if (user.isPlayer())
{ {
// For single game mode just open correct gui. AdminPanel.open(this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix());
if (this.gameModeAddons.size() == 1) return true;
{ }
this.gameModeAddons.get(0).getAdminCommand().ifPresent(compositeCommand -> return false;
user.performCommand(compositeCommand.getTopLabel() + " challenges")); }
}
else
{
GameModePanel.open(this.addon,
this.getWorld(),
user,
this.gameModeAddons,
true);
}
return true;
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* This variable stores challenges addon.
*/
private final ChallengesAddon addon;
/**
* This variable stores List with game modes where challenges addon are hooked in.
*/
private final List<GameModeAddon> gameModeAddons;
} }

View File

@ -0,0 +1,80 @@
package world.bentobox.challenges.commands.admin;
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.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.GameModePanel;
/**
* This class provides all necessary thing to implement challenges admin command
*/
public class ChallengesGlobalAdminCommand extends CompositeCommand
{
/**
* Constructor that inits command with given string.
* @param addon Challenges Addon
* @param gameModeAddons List with GameModes where challenges addon operates.
*/
public ChallengesGlobalAdminCommand(ChallengesAddon addon, List<GameModeAddon> gameModeAddons)
{
super(addon,
addon.getChallengesSettings().getAdminGlobalCommand().split(" ")[0],
addon.getChallengesSettings().getAdminGlobalCommand().split(" "));
this.gameModeAddons = gameModeAddons;
}
/**
* {@inheritDoc}
*/
@Override
public void setup()
{
this.setPermission("admin.challenges");
this.setParametersHelp("challenges.commands.admin.main.parameters");
this.setDescription("challenges.commands.admin.main.description");
}
/**
* {@inheritDoc}
*/
@Override
public boolean execute(User user, String label, List<String> args)
{
// For single game mode just open correct gui.
if (this.gameModeAddons.size() == 1)
{
this.gameModeAddons.get(0).getAdminCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " " +
this.<ChallengesAddon>getAddon().getChallengesSettings().getAdminMainCommand().split(" ")[0]));
}
else
{
GameModePanel.open(this.getAddon(),
this.getWorld(),
user,
this.gameModeAddons,
true);
}
return true;
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* This variable stores List with game modes where challenges addon are hooked in.
*/
private final List<GameModeAddon> gameModeAddons;
}

View File

@ -50,20 +50,20 @@ public class Settings implements ConfigObject
@ConfigComment("only if `global-commands` is enabled. This allows to execute `/challenges`") @ConfigComment("only if `global-commands` is enabled. This allows to execute `/challenges`")
@ConfigComment("without referring to the gamemode.") @ConfigComment("without referring to the gamemode.")
@ConfigEntry(path = "commands.player.global", needsRestart = true) @ConfigEntry(path = "commands.player.global", needsRestart = true)
private String globalUserCommand = "challenges c"; private String playerGlobalCommand = "challenges c";
@ConfigComment("") @ConfigComment("")
@ConfigComment("Allows to define user command for opening challenges GUI's.") @ConfigComment("Allows to define user command for opening challenges GUI's.")
@ConfigComment("Unlike `global` command, this requires to have gamemode player command before it.") @ConfigComment("Unlike `global` command, this requires to have gamemode player command before it.")
@ConfigComment("This will look like: `/[player_cmd] challenges`") @ConfigComment("This will look like: `/[player_cmd] challenges`")
@ConfigEntry(path = "commands.player.main", needsRestart = true) @ConfigEntry(path = "commands.player.main", needsRestart = true)
private String mainUserCommand = "challenges"; private String playerMainCommand = "challenges";
@ConfigComment("") @ConfigComment("")
@ConfigComment("Allows to define complete command.") @ConfigComment("Allows to define complete command.")
@ConfigComment("This will look like: `/[player_cmd] challenges complete`") @ConfigComment("This will look like: `/[player_cmd] challenges complete`")
@ConfigEntry(path = "commands.player.complete", needsRestart = true) @ConfigEntry(path = "commands.player.complete", needsRestart = true)
private String completeUserCommand = "complete"; private String playerCompleteCommand = "complete";
@ConfigComment("") @ConfigComment("")
@ConfigComment("Allows to define a global challenges admin command. This command will work") @ConfigComment("Allows to define a global challenges admin command. This command will work")
@ -71,14 +71,14 @@ public class Settings implements ConfigObject
@ConfigComment("without referring to the gamemode.") @ConfigComment("without referring to the gamemode.")
@ConfigComment("Note, this must not be the same as user global command.") @ConfigComment("Note, this must not be the same as user global command.")
@ConfigEntry(path = "commands.admin.global", needsRestart = true) @ConfigEntry(path = "commands.admin.global", needsRestart = true)
private String globalAdminCommand = "challengesadmin chadmin"; private String adminGlobalCommand = "challengesadmin chadmin";
@ConfigComment("") @ConfigComment("")
@ConfigComment("Allows to define admin command for opening challenges GUI's.") @ConfigComment("Allows to define admin command for opening challenges GUI's.")
@ConfigComment("Unlike `global` command, this requires to have gamemode admin command before it.") @ConfigComment("Unlike `global` command, this requires to have gamemode admin command before it.")
@ConfigComment("This will look like: `/[admin_cmd] challenges`") @ConfigComment("This will look like: `/[admin_cmd] challenges`")
@ConfigEntry(path = "commands.admin.main", needsRestart = true) @ConfigEntry(path = "commands.admin.main", needsRestart = true)
private String mainAdminCommand = "challenges"; private String adminMainCommand = "challenges";
@ConfigComment("") @ConfigComment("")
@ConfigComment("This indicate if player challenges data history will be stored or not.") @ConfigComment("This indicate if player challenges data history will be stored or not.")
@ -251,9 +251,9 @@ public class Settings implements ConfigObject
* This method returns the userCommand value. * This method returns the userCommand value.
* @return the value of userCommand. * @return the value of userCommand.
*/ */
public String getGlobalUserCommand() public String getPlayerGlobalCommand()
{ {
return globalUserCommand; return playerGlobalCommand;
} }
@ -262,9 +262,9 @@ public class Settings implements ConfigObject
* *
* @return the main user command * @return the main user command
*/ */
public String getMainUserCommand() public String getPlayerMainCommand()
{ {
return mainUserCommand; return playerMainCommand;
} }
@ -273,9 +273,9 @@ public class Settings implements ConfigObject
* *
* @return the complete user command * @return the complete user command
*/ */
public String getCompleteUserCommand() public String getPlayerCompleteCommand()
{ {
return completeUserCommand; return playerCompleteCommand;
} }
@ -284,9 +284,9 @@ public class Settings implements ConfigObject
* *
* @return the main admin command * @return the main admin command
*/ */
public String getMainAdminCommand() public String getAdminMainCommand()
{ {
return mainAdminCommand; return adminMainCommand;
} }
@ -294,9 +294,9 @@ public class Settings implements ConfigObject
* This method returns the adminCommand value. * This method returns the adminCommand value.
* @return the value of adminCommand. * @return the value of adminCommand.
*/ */
public String getGlobalAdminCommand() public String getAdminGlobalCommand()
{ {
return globalAdminCommand; return adminGlobalCommand;
} }
@ -516,54 +516,54 @@ public class Settings implements ConfigObject
/** /**
* This method sets the userCommand value. * This method sets the userCommand value.
* @param globalUserCommand the userCommand new value. * @param playerGlobalCommand the userCommand new value.
*/ */
public void setGlobalUserCommand(String globalUserCommand) public void setPlayerGlobalCommand(String playerGlobalCommand)
{ {
this.globalUserCommand = globalUserCommand; this.playerGlobalCommand = playerGlobalCommand;
} }
/** /**
* Sets main user command. * Sets main user command.
* *
* @param mainUserCommand the main user command * @param playerMainCommand the main user command
*/ */
public void setMainUserCommand(String mainUserCommand) public void setPlayerMainCommand(String playerMainCommand)
{ {
this.mainUserCommand = mainUserCommand; this.playerMainCommand = playerMainCommand;
} }
/** /**
* Sets complete user command. * Sets complete user command.
* *
* @param completeUserCommand the complete user command * @param playerCompleteCommand the complete user command
*/ */
public void setCompleteUserCommand(String completeUserCommand) public void setPlayerCompleteCommand(String playerCompleteCommand)
{ {
this.completeUserCommand = completeUserCommand; this.playerCompleteCommand = playerCompleteCommand;
} }
/** /**
* Sets main admin command. * Sets main admin command.
* *
* @param mainAdminCommand the main admin command * @param adminMainCommand the main admin command
*/ */
public void setMainAdminCommand(String mainAdminCommand) public void setAdminMainCommand(String adminMainCommand)
{ {
this.mainAdminCommand = mainAdminCommand; this.adminMainCommand = adminMainCommand;
} }
/** /**
* This method sets the adminCommand value. * This method sets the adminCommand value.
* @param globalAdminCommand the adminCommand new value. * @param adminGlobalCommand the adminCommand new value.
*/ */
public void setGlobalAdminCommand(String globalAdminCommand) public void setAdminGlobalCommand(String adminGlobalCommand)
{ {
this.globalAdminCommand = globalAdminCommand; this.adminGlobalCommand = adminGlobalCommand;
} }

View File

@ -170,19 +170,18 @@ public class GameModePanel extends CommonPanel
{ {
if (clickType == action.clickType()) if (clickType == action.clickType())
{ {
Optional<CompositeCommand> command;
if (this.adminMode) if (this.adminMode)
{ {
command = gameModeAddon.getAdminCommand(); gameModeAddon.getAdminCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " " +
this.addon.getChallengesSettings().getAdminMainCommand().split(" ")[0]));
} }
else else
{ {
command = gameModeAddon.getPlayerCommand(); gameModeAddon.getPlayerCommand().ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " " +
this.addon.getChallengesSettings().getPlayerMainCommand().split(" ")[0]));
} }
command.ifPresent(compositeCommand ->
user.performCommand(compositeCommand.getTopLabel() + " challenges"));
} }
} }

View File

@ -66,7 +66,7 @@ public class ChallengesCommandTest {
private Island island; private Island island;
@Mock @Mock
private ChallengesAddon addon; private ChallengesAddon addon;
private ChallengesCommand cc; private ChallengesPlayerCommand cc;
@Mock @Mock
private World world; private World world;
@Mock @Mock
@ -151,11 +151,11 @@ public class ChallengesCommandTest {
when(im.getIsland(any(), any(User.class))).thenReturn(island); when(im.getIsland(any(), any(User.class))).thenReturn(island);
// Command under test // Command under test
cc = new ChallengesCommand(addon, ic); cc = new ChallengesPlayerCommand(addon, ic);
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteWrongWorld() { public void testCanExecuteWrongWorld() {
@ -165,7 +165,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteNoChallenges() { public void testCanExecuteNoChallenges() {
@ -176,7 +176,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteNoChallengesOp() { public void testCanExecuteNoChallengesOp() {
@ -189,7 +189,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteNoChallengesHasPerm() { public void testCanExecuteNoChallengesHasPerm() {
@ -202,7 +202,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteNoAdminCommand() { public void testCanExecuteNoAdminCommand() {
@ -216,7 +216,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteNoIsland() { public void testCanExecuteNoIsland() {
@ -226,7 +226,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testCanExecuteSuccess() { public void testCanExecuteSuccess() {
@ -235,7 +235,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testExecuteUserStringListOfStringConsole() { public void testExecuteUserStringListOfStringConsole() {
@ -245,7 +245,7 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link ChallengesPlayerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testExecuteUserStringListOfStringUser() { public void testExecuteUserStringListOfStringUser() {
@ -253,11 +253,11 @@ public class ChallengesCommandTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.commands.ChallengesCommand#setup()}. * Test method for {@link ChallengesPlayerCommand#setup()}.
*/ */
@Test @Test
public void testSetup() { public void testSetup() {
assertEquals("bskyblock." + ChallengesCommand.CHALLENGE_COMMAND, cc.getPermission()); assertEquals("bskyblock.challenges", cc.getPermission());
assertEquals("challenges.commands.user.main.parameters", cc.getParameters()); assertEquals("challenges.commands.user.main.parameters", cc.getParameters());
assertEquals("challenges.commands.user.main.description", cc.getDescription()); assertEquals("challenges.commands.user.main.description", cc.getDescription());
assertTrue(cc.isOnlyPlayer()); assertTrue(cc.isOnlyPlayer());