Skip to content

Commit

Permalink
Remove command existing check from ConfirmationGUI.
Browse files Browse the repository at this point in the history
Add CompositeCommand as class variable.
  • Loading branch information
BONNe committed Jan 17, 2019
1 parent 6903fa5 commit c79173b
Showing 1 changed file with 17 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package world.bentobox.challenges.panel.util;




import org.bukkit.Material;

import java.util.*;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand All @@ -23,31 +19,23 @@ public class ConfirmationGUI
{
/**
* This constructor inits and opens ConfirmationGUI.
*
* @param user Gui Caller.
* @param parentGUI Parent GUI.
* @param commandLabels Command labels.
* @param variables Variables at the end of command.
* @param command Command .
* @param parameters Variables at the end of command.
*/
public ConfirmationGUI(BentoBox plugin,
public ConfirmationGUI(CommonGUI parentGUI,
User user,
CommonGUI parentGUI,
List<String> commandLabels,
String... variables)
CompositeCommand command,
String... parameters)
{
this.plugin = plugin;
this.user = user;
this.parentGUI = parentGUI;
this.commandLabels = commandLabels;
this.variables = variables;

if (this.commandLabels.isEmpty())
{
this.user.sendMessage("challenges.errors.missing-command");
}
else
{
this.build();
}
this.command = command;
this.parameters = parameters;

this.build();
}


Expand All @@ -56,36 +44,16 @@ public ConfirmationGUI(BentoBox plugin,
*/
public void build()
{
PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.admin.confirm-title"));
PanelBuilder panelBuilder = new PanelBuilder()
.name(this.user.getTranslation("challenges.gui.admin.confirm-title"));

panelBuilder.item(3, new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")).
icon(Material.GREEN_STAINED_GLASS_PANE).
clickHandler((panel, user1, clickType, index) ->
{
Iterator<String> iterator = this.commandLabels.iterator();

CompositeCommand command = this.plugin.getCommandsManager().getCommand(iterator.next());

while (iterator.hasNext() && command != null)
{
Optional<CompositeCommand> commandOptional = command.getSubCommand(iterator.next());

if (commandOptional.isPresent())
{
command = commandOptional.get();
}
else
{
this.user.sendMessage("challenges.errors.missing-command");
command = null;
}
}

if (command != null)
{
command.execute(this.user, "CONFIRMATION", Arrays.asList(this.variables));
}
this.command
.execute(this.user, "CONFIRMATION", Arrays.asList(this.parameters));

this.user.closeInventory();
this.parentGUI.build();
Expand All @@ -111,11 +79,6 @@ public void build()
// Section: Variables
// ---------------------------------------------------------------------

/**
* BentoBox plugin.
*/
private BentoBox plugin;

/**
* User who wants to run command.
*/
Expand All @@ -127,12 +90,12 @@ public void build()
private CommonGUI parentGUI;

/**
* List of command labels.
* Command that must be run on confirmation.
*/
private List<String> commandLabels;
private CompositeCommand command;

/**
* List of variables.
*/
private String[] variables;
private String[] parameters;
}

0 comments on commit c79173b

Please sign in to comment.