Skip to content

Commit

Permalink
Implement ConfirmationGUIs in Delete operation for ListLevelsGUI and …
Browse files Browse the repository at this point in the history
…ListChallengesGUI.
  • Loading branch information
BONNe committed Jan 17, 2019
1 parent 29dadf3 commit 13291b4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,16 @@ public List<Challenges> getChallengesList()
{
return new ArrayList<>();
}


public void deleteChallenge(Challenges selectedChallenge)
{

}


public void deleteChallengeLevel(ChallengeLevels valueObject)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenges;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.ConfirmationGUI;


/**
Expand Down Expand Up @@ -140,7 +141,8 @@ private PanelItem createChallengeIcon(Challenges challenge)
else if (this.currentMode.equals(Mode.DELETE))
{
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
// TODO: Conformation GUI for DELETING.
new ConfirmationGUI(this, this.user);
this.valueObject = challenge;
return true;
});
}
Expand All @@ -149,6 +151,25 @@ else if (this.currentMode.equals(Mode.DELETE))
}


/**
* Overwriting set value allows to catch if ConfirmationGui returns true.
* @param value new Value of valueObject.
*/
@Override
public void setValue(Object value)
{
if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null)
{
this.addon.getChallengesManager().deleteChallenge((Challenges) this.valueObject);
this.valueObject = null;
}
else
{
this.valueObject = null;
}
}


// ---------------------------------------------------------------------
// Section: Enums
// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import org.bukkit.World;

import java.util.List;

import world.bentobox.bentobox.api.panels.PanelItem;
Expand All @@ -12,6 +11,7 @@
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.ChallengeLevels;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.ConfirmationGUI;


/**
Expand Down Expand Up @@ -141,7 +141,8 @@ private PanelItem createLevelIcon(ChallengeLevels challengeLevel)
else if (this.currentMode.equals(Mode.DELETE))
{
itemBuilder.clickHandler((panel, user1, clickType, i) -> {
// TODO: Conformation GUI for DELETING.
new ConfirmationGUI(this, this.user);
this.valueObject = challengeLevel;
return true;
});
}
Expand All @@ -150,6 +151,25 @@ else if (this.currentMode.equals(Mode.DELETE))
}


/**
* Overwriting set value allows to catch if ConfirmationGui returns true.
* @param value new Value of valueObject.
*/
@Override
public void setValue(Object value)
{
if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null)
{
this.addon.getChallengesManager().deleteChallengeLevel((ChallengeLevels) this.valueObject);
this.valueObject = null;
}
else
{
this.valueObject = null;
}
}


// ---------------------------------------------------------------------
// Section: Enums
// ---------------------------------------------------------------------
Expand Down

0 comments on commit 13291b4

Please sign in to comment.