mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-12 13:54:22 +01:00
Add DefaultPlayerCommand and DefaultAdminCommand (#1293)
Helps to implement #498. Also added 4 new WorldSettings methods: * getAdminCommandAliases() * getPlayerCommandAliases() * getDefaultPlayerAction() * getDefaultNewPlayerAction() Co-Authored-By: Florian CUNY <poslovitch@bentobox.world>
This commit is contained in:
parent
f08c7dece3
commit
97341ce657
@ -0,0 +1,118 @@
|
||||
package world.bentobox.bentobox.api.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.commands.admin.blueprints.AdminBlueprintCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.deaths.AdminDeathsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.purge.AdminPurgeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.resets.AdminResetsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamAddCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamDisbandCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamKickCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamSetownerCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* This is default Admin command for console and op. It contains all necessary parts that
|
||||
* for main command.
|
||||
* @since 1.13.0
|
||||
* @author BONNe
|
||||
*/
|
||||
public abstract class DefaultAdminCommand extends CompositeCommand
|
||||
{
|
||||
/**
|
||||
* This is the top-level command constructor for commands that have no parent.
|
||||
*
|
||||
* @param addon - GameMode addon
|
||||
*/
|
||||
public DefaultAdminCommand(GameModeAddon addon)
|
||||
{
|
||||
// Register command with alias from config.
|
||||
super(addon,
|
||||
addon.getWorldSettings().getAdminCommandAliases().split(" ")[0],
|
||||
addon.getWorldSettings().getAdminCommandAliases().split(" "));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setups anything that is necessary for default main admin command.
|
||||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#setup()
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.setPermission("admin.*");
|
||||
this.setOnlyPlayer(false);
|
||||
|
||||
this.setParametersHelp("commands.admin.help.parameters");
|
||||
this.setDescription("commands.admin.help.description");
|
||||
|
||||
new AdminVersionCommand(this);
|
||||
new AdminTeleportCommand(this, "tp");
|
||||
new AdminTeleportCommand(this, "tpnether");
|
||||
new AdminTeleportCommand(this, "tpend");
|
||||
new AdminGetrankCommand(this);
|
||||
new AdminSetrankCommand(this);
|
||||
new AdminInfoCommand(this);
|
||||
// Team commands
|
||||
new AdminTeamAddCommand(this);
|
||||
new AdminTeamKickCommand(this);
|
||||
new AdminTeamDisbandCommand(this);
|
||||
new AdminTeamSetownerCommand(this);
|
||||
// Schems
|
||||
new AdminBlueprintCommand(this);
|
||||
// Register/unregister islands
|
||||
new AdminRegisterCommand(this);
|
||||
new AdminUnregisterCommand(this);
|
||||
// Range
|
||||
new AdminRangeCommand(this);
|
||||
// Resets
|
||||
new AdminResetsCommand(this);
|
||||
// Delete
|
||||
new AdminDeleteCommand(this);
|
||||
// Why
|
||||
new AdminWhyCommand(this);
|
||||
// Deaths
|
||||
new AdminDeathsCommand(this);
|
||||
// Reload
|
||||
new AdminReloadCommand(this);
|
||||
// Spawn
|
||||
new AdminSetspawnCommand(this);
|
||||
// Reset flags
|
||||
new AdminResetFlagsCommand(this);
|
||||
// Trash
|
||||
//new AdminTrashCommand(this);
|
||||
//new AdminEmptyTrashCommand(this);
|
||||
//new AdminSwitchtoCommand(this);
|
||||
// Switch
|
||||
new AdminSwitchCommand(this);
|
||||
// Purge
|
||||
new AdminPurgeCommand(this);
|
||||
// Settings
|
||||
new AdminSettingsCommand(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines what will be executed when this command is run.
|
||||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List<String>)
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
if (user != null && !args.isEmpty())
|
||||
{
|
||||
user.sendMessage("general.errors.unknown-command", TextVariables.LABEL, getTopLabel());
|
||||
return false;
|
||||
}
|
||||
|
||||
// By default run the attached help command, if it exists (it should)
|
||||
return this.showHelp(this, user);
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* This is default player command class. It contains all necessary parts for main /[gamemode] command.
|
||||
* @since 1.13.0
|
||||
* @author BONNe
|
||||
*/
|
||||
public abstract class DefaultPlayerCommand extends CompositeCommand
|
||||
{
|
||||
/**
|
||||
* This is the top-level command constructor for commands that have no parent.
|
||||
*
|
||||
* @param addon - GameMode addon
|
||||
*/
|
||||
public DefaultPlayerCommand(GameModeAddon addon)
|
||||
{
|
||||
// Register command with alias from config.
|
||||
super(addon,
|
||||
addon.getWorldSettings().getPlayerCommandAliases().split(" ")[0],
|
||||
addon.getWorldSettings().getPlayerCommandAliases().split(" "));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setups anything that is necessary for default main user command.
|
||||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#setup()
|
||||
*/
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
// Description
|
||||
this.setDescription("commands.island.help.description");
|
||||
// Limit to player
|
||||
this.setOnlyPlayer(true);
|
||||
// Permission
|
||||
this.setPermission("island");
|
||||
|
||||
// Set up default subcommands
|
||||
|
||||
// Teleport commands
|
||||
new IslandGoCommand(this);
|
||||
new IslandSpawnCommand(this);
|
||||
|
||||
// Allows to create/reset island.
|
||||
new IslandCreateCommand(this);
|
||||
new IslandResetCommand(this);
|
||||
|
||||
// Displays info about the island.
|
||||
new IslandInfoCommand(this);
|
||||
|
||||
// Settings related commands
|
||||
new IslandSettingsCommand(this);
|
||||
new IslandSethomeCommand(this);
|
||||
new IslandSetnameCommand(this);
|
||||
new IslandResetnameCommand(this);
|
||||
new IslandLanguageCommand(this);
|
||||
|
||||
// Ban related commands
|
||||
new IslandBanCommand(this);
|
||||
new IslandUnbanCommand(this);
|
||||
new IslandBanlistCommand(this);
|
||||
|
||||
// Kicks visitors or coops/trusted from island
|
||||
new IslandExpelCommand(this);
|
||||
|
||||
// Tells owner of adjacent islands
|
||||
new IslandNearCommand(this);
|
||||
|
||||
// Team commands
|
||||
new IslandTeamCommand(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines what will be executed when this command is run.
|
||||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(User, String, List<String>)
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!args.isEmpty())
|
||||
{
|
||||
user.sendMessage("general.errors.unknown-command", TextVariables.LABEL, this.getTopLabel());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if user has an island.
|
||||
if (this.getIslands().getIsland(this.getWorld(), user.getUniqueId()) != null)
|
||||
{
|
||||
// Default command if user has an island.
|
||||
String command = this.<GameModeAddon>getAddon().getWorldSettings().getDefaultPlayerAction();
|
||||
|
||||
// If command exists, the call it.
|
||||
// Otherwise, just use "go" command.
|
||||
if (command != null && this.getSubCommand(command).isPresent())
|
||||
{
|
||||
return this.getSubCommand(command).get().call(user, label, Collections.emptyList());
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.getSubCommand("go").
|
||||
map(goCmd -> goCmd.call(user, goCmd.getLabel(), Collections.emptyList())).
|
||||
orElse(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default command if user does not have an island.
|
||||
String command = this.<GameModeAddon>getAddon().getWorldSettings().getDefaultNewPlayerAction();
|
||||
|
||||
// If command exists, the call it.
|
||||
// Otherwise, just use "create" command.
|
||||
if (command != null && this.getSubCommand(command).isPresent())
|
||||
{
|
||||
return this.getSubCommand(command).get().call(user, label, Collections.emptyList());
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.getSubCommand("create").
|
||||
map(createCmd -> createCmd.call(user, createCmd.getLabel(), Collections.emptyList())).
|
||||
orElse(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -467,4 +467,61 @@ public interface WorldSettings extends ConfigObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all aliases for main admin command.
|
||||
* It is assumed that all aliases are split with whitespace between them.
|
||||
* String cannot be empty.
|
||||
* Default value: {@code getFriendlyName() + "admin"} (to retain backward compatibility).
|
||||
* @return String value
|
||||
* @since 1.13.0
|
||||
*/
|
||||
default String getAdminCommandAliases()
|
||||
{
|
||||
return this.getFriendlyName().toLowerCase() + "admin";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all aliases for main player command.
|
||||
* It is assumed that all aliases are split with whitespace between them.
|
||||
* String cannot be empty.
|
||||
* Default value: {@code getFriendlyName()} (to retain backward compatibility).
|
||||
* @return String value
|
||||
* @since 1.13.0
|
||||
*/
|
||||
default String getPlayerCommandAliases()
|
||||
{
|
||||
return this.getFriendlyName().toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns sub-command for users when they execute main user command and they have an
|
||||
* island.
|
||||
* If defined sub-command does not exist in accessible user command list, then it will
|
||||
* still call "go" sub-command.
|
||||
* Default value: {@code "go"} (to retain backward compatibility)
|
||||
* @return name of default sub-command for main command if user does have an island.
|
||||
* @since 1.13.0
|
||||
*/
|
||||
default String getDefaultPlayerAction()
|
||||
{
|
||||
return "go";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns default sub-command for users when they execute main user command and they
|
||||
* do not have an island.
|
||||
* If defined sub-command does not exist in accessible user command list, then it will
|
||||
* still call "create" sub-command.
|
||||
* Default value: {@code "create"} (to retain backward compatibility)
|
||||
* @return name of default sub-command for main command if user does not have an island.
|
||||
* @since 1.13.0
|
||||
*/
|
||||
default String getDefaultNewPlayerAction()
|
||||
{
|
||||
return "create";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user