Implement ConfirmationGUIs in Delete operation for ListLevelsGUI and ListChallengesGUI.

This commit is contained in:
BONNe 2019-01-17 23:09:32 +02:00
parent 29dadf3841
commit 13291b450c
3 changed files with 56 additions and 3 deletions

View File

@ -527,4 +527,16 @@ public class ChallengesManager {
{
return new ArrayList<>();
}
public void deleteChallenge(Challenges selectedChallenge)
{
}
public void deleteChallengeLevel(ChallengeLevels valueObject)
{
}
}

View File

@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.user.User;
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;
/**
@ -140,7 +141,8 @@ public class ListChallengesGUI extends CommonGUI
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;
});
}
@ -149,6 +151,25 @@ public class ListChallengesGUI extends CommonGUI
}
/**
* 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
// ---------------------------------------------------------------------

View File

@ -2,7 +2,6 @@ package world.bentobox.challenges.panel.admin;
import org.bukkit.World;
import java.util.List;
import world.bentobox.bentobox.api.panels.PanelItem;
@ -12,6 +11,7 @@ import world.bentobox.bentobox.api.user.User;
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;
/**
@ -141,7 +141,8 @@ public class ListLevelsGUI extends CommonGUI
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;
});
}
@ -150,6 +151,25 @@ public class ListLevelsGUI extends CommonGUI
}
/**
* 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
// ---------------------------------------------------------------------