Skip to content

Commit

Permalink
Add an ability to use different command aliases for all player comman…
Browse files Browse the repository at this point in the history
…ds and main admin command.
  • Loading branch information
BONNe committed Dec 4, 2020
1 parent 3975cfa commit 6657429
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public class GeneratorAdminCommand extends CompositeCommand
*/
public GeneratorAdminCommand(StoneGeneratorAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "generator");
super(addon,
parentCommand,
addon.getSettings().getAdminMainCommand().split(" ")[0],
addon.getSettings().getAdminMainCommand().split(" "));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class GeneratorPlayerCommand extends CompositeCommand
*/
public GeneratorPlayerCommand(StoneGeneratorAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "generator");
super(addon,
parentCommand,
addon.getSettings().getPlayerMainCommand().split(" ")[0],
addon.getSettings().getPlayerMainCommand().split(" "));
}


Expand Down Expand Up @@ -134,7 +137,12 @@ private static class GeneratorViewPlayerCommand extends CompositeCommand
*/
public GeneratorViewPlayerCommand(CompositeCommand parentCommand)
{
super(parentCommand.getAddon(), parentCommand, "view");
// Not an optimal way how to do it, but I do not care when I wrote it.
// Copy-paste in a nutshell.
super(parentCommand.getAddon(),
parentCommand,
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerViewCommand().split(" ")[0],
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerViewCommand().split(" "));
}


Expand Down Expand Up @@ -225,7 +233,10 @@ private static class GeneratorBuyPlayerCommand extends CompositeCommand
*/
public GeneratorBuyPlayerCommand(CompositeCommand parentCommand)
{
super(parentCommand.getAddon(), parentCommand, "buy");
super(parentCommand.getAddon(),
parentCommand,
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerBuyCommand().split(" ")[0],
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerBuyCommand().split(" "));
}


Expand Down Expand Up @@ -336,7 +347,10 @@ private static class GeneratorActivatePlayerCommand extends CompositeCommand
*/
public GeneratorActivatePlayerCommand(CompositeCommand parentCommand)
{
super(parentCommand.getAddon(), parentCommand, "activate");
super(parentCommand.getAddon(),
parentCommand,
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerActivateCommand().split(" ")[0],
parentCommand.<StoneGeneratorAddon>getAddon().getSettings().getPlayerActivateCommand().split(" "));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package world.bentobox.magiccobblestonegenerator.config;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


Expand Down Expand Up @@ -150,9 +152,119 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* Gets player main command.
*
* @return the player main command
*/
public String getPlayerMainCommand()
{
return playerMainCommand;
}


/**
* Sets player main command.
*
* @param playerMainCommand the player main command
*/
public void setPlayerMainCommand(String playerMainCommand)
{
this.playerMainCommand = playerMainCommand;
}


/**
* Gets player view command.
*
* @return the player view command
*/
public String getPlayerViewCommand()
{
return playerViewCommand;
}


/**
* Sets player view command.
*
* @param playerViewCommand the player view command
*/
public void setPlayerViewCommand(String playerViewCommand)
{
this.playerViewCommand = playerViewCommand;
}


/**
* Gets player buy command.
*
* @return the player buy command
*/
public String getPlayerBuyCommand()
{
return playerBuyCommand;
}


/**
* Sets player buy command.
*
* @param playerBuyCommand the player buy command
*/
public void setPlayerBuyCommand(String playerBuyCommand)
{
this.playerBuyCommand = playerBuyCommand;
}


/**
* Gets player activate command.
*
* @return the player activate command
*/
public String getPlayerActivateCommand()
{
return playerActivateCommand;
}


/**
* Sets player activate command.
*
* @param playerActivateCommand the player activate command
*/
public void setPlayerActivateCommand(String playerActivateCommand)
{
this.playerActivateCommand = playerActivateCommand;
}


/**
* Gets admin main command.
*
* @return the admin main command
*/
public String getAdminMainCommand()
{
return adminMainCommand;
}


/**
* Sets admin main command.
*
* @param adminMainCommand the admin main command
*/
public void setAdminMainCommand(String adminMainCommand)
{
this.adminMainCommand = adminMainCommand;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------


@ConfigComment("")
Expand Down Expand Up @@ -188,4 +300,35 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes", needsRestart = true)
private Set<String> disabledGameModes = new HashSet<>();

@ConfigComment("")
@ConfigComment("Player main sub-command to access the addon.")
@ConfigComment("This command label will be required to write after gamemode player command label, f.e. /[label] generator")
@ConfigComment("Each alias must be separated with an empty space.")
@ConfigEntry(path = "commands.player.main", needsRestart = true)
private String playerMainCommand = "generator";

@ConfigComment("Player view sub-command that allows to see detailed generator view.")
@ConfigComment("This command label will be required to write after player main command, f.e. /[label] generator view")
@ConfigComment("Each alias must be separated with an empty space.")
@ConfigEntry(path = "commands.player.view", needsRestart = true)
private String playerViewCommand = "view";

@ConfigComment("Player buy sub-command that allows to buy generator with a command.")
@ConfigComment("This command label will be required to write after player main command, f.e. /[label] generator buy")
@ConfigComment("Each alias must be separated with an empty space.")
@ConfigEntry(path = "commands.player.buy", needsRestart = true)
private String playerBuyCommand = "buy";

@ConfigComment("Player activate sub-command that allows to activate or deactivate generator with a command.")
@ConfigComment("This command label will be required to write after player main command, f.e. /[label] generator activate")
@ConfigComment("Each alias must be separated with an empty space.")
@ConfigEntry(path = "commands.player.activate", needsRestart = true)
private String playerActivateCommand = "activate";

@ConfigComment("Admin main sub-command to access the addon.")
@ConfigComment("This command label will be required to write after gamemode admin command label, f.e. /[label] generator")
@ConfigComment("Each alias must be separated with an empty space.")
@ConfigEntry(path = "commands.admin.main", needsRestart = true)
private String adminMainCommand = "generator";
}
31 changes: 30 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,33 @@ default-active-generators: 3
# disabled-gamemodes:
# - BSkyBlock
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
disabled-gamemodes: []
disabled-gamemodes: []
commands:
player:
#
# Player main sub-command to access the addon.
# This command label will be required to write after gamemode player command label, f.e. /[label] generator
# Each alias must be separated with an empty space.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
main: generator
# Player view sub-command that allows to see detailed generator view.
# This command label will be required to write after player main command, f.e. /[label] generator view
# Each alias must be separated with an empty space.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
view: view
# Player buy sub-command that allows to buy generator with a command.
# This command label will be required to write after player main command, f.e. /[label] generator buy
# Each alias must be separated with an empty space.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
buy: buy
# Player activate sub-command that allows to activate or deactivate generator with a command.
# This command label will be required to write after player main command, f.e. /[label] generator activate
# Each alias must be separated with an empty space.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
activate: activate
admin:
# Admin main sub-command to access the addon.
# This command label will be required to write after gamemode admin command label, f.e. /[label] generator
# Each alias must be separated with an empty space.
# /!\ In order to apply the changes made to this option, you must restart your server. Reloading BentoBox or the server won't work.
main: generator

0 comments on commit 6657429

Please sign in to comment.