Skip to content

Commit

Permalink
Add VisitAdminCommand and AdminPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jun 18, 2020
1 parent a0df592 commit f9bdae1
Show file tree
Hide file tree
Showing 3 changed files with 561 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@


import java.util.List;
import java.util.Optional;
import java.util.UUID;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.visit.VisitAddon;
import world.bentobox.visit.panels.admin.AdminPanel;
import world.bentobox.visit.panels.player.ConfigurePanel;


/**
* This class manages {@code /{admin_command} visit} command call.
*/
public class VisitSettingsCommand extends CompositeCommand
public class VisitAdminCommand extends CompositeCommand
{
/**
* This is simple constructor for initializing /{admin_command} visit command.
* @param addon Our Visit addon.
* @param parentCommand Parent Command where we hook our command into.
*/
public VisitSettingsCommand(VisitAddon addon, CompositeCommand parentCommand)
public VisitAdminCommand(VisitAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "visit");
}
Expand Down Expand Up @@ -47,25 +52,6 @@ public void setup()
}


/**
* Returns whether the command can be executed by this user or not. It is recommended
* to send messages to let this user know why they could not execute the command. Note
* that this is run previous to {@link #execute(User, String, List)}.
*
* @param user the {@link User} who is executing this command.
* @param label the label which has been used to execute this command. It can be
* {@link CompositeCommand#getLabel()} or an alias.
* @param args the command arguments.
* @return {@code true} if this command can be executed, {@code false} otherwise.
* @since 1.3.0
*/
@Override
public boolean canExecute(User user, String label, List<String> args)
{
return false;
}


/**
* Defines what will be executed when this command is run.
*
Expand All @@ -78,23 +64,40 @@ public boolean canExecute(User user, String label, List<String> args)
@Override
public boolean execute(User user, String label, List<String> args)
{
return false;
}
if (args.isEmpty())
{
AdminPanel.openPanel(this.getAddon(), this.getWorld(), user);
}
else if (args.size() == 1)
{
UUID targetUUID = Util.getUUID(args.get(0));

if (targetUUID == null)
{
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
}
else
{
// Use getIsland as it returns island even if player is in team.
Island island = this.getIslands().getIsland(this.getWorld(), targetUUID);

/**
* Tab Completer for CompositeCommands. Note that any registered sub-commands will be
* automatically added to the list. Use this to add tab-complete for things like
* names.
*
* @param user the {@link User} who is executing this command.
* @param alias alias for command
* @param args command arguments
* @return List of strings that could be used to complete this command.
*/
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args)
{
return Optional.empty();
if (island == null)
{
// There is no place to teleport.
user.sendMessage("general.errors.player-has-no-island");
}
else
{
// Process config opening
ConfigurePanel.openPanel(this.getAddon(), island, user);
}
}
}
else
{
this.showHelp(this, user);
}

return true;
}
}

0 comments on commit f9bdae1

Please sign in to comment.