Skip to content

Commit

Permalink
Disable Money and Level buttons in admin panel, if EconomyPlugin or L…
Browse files Browse the repository at this point in the history
…evel addon is missing.
  • Loading branch information
BONNe committed Jan 23, 2019
1 parent c3b87da commit 96cb448
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.ItemParser;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.panel.CommonGUI;
Expand All @@ -25,9 +24,6 @@
/**
* This class contains all necessary methods that creates GUI and allow to edit challenges
* properties.
*
* TODO: In current class set that MONEY are availabe only if ECONOMY exist.
* TODO: In current class set that ISLAND LEVEL are availabe only if LEVEL ADDON exist.
*/
public class EditChallengeGUI extends CommonGUI
{
Expand Down Expand Up @@ -762,19 +758,29 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
this.user.getTranslation("challenges.gui.admin.descriptions.required-level",
"[value]",
Long.toString(this.challenge.getRequiredIslandLevel())));
icon = new ItemStack(Material.BEACON);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> {
if (status)
{
this.challenge.setRequiredIslandLevel(value);
}

this.build();
});
if (this.addon.isLevelProvided())
{
icon = new ItemStack(Material.BEACON);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> {
if (status)
{
this.challenge.setRequiredIslandLevel(value);
}

this.build();
});

return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

return true;
};
glow = false;
break;
}
Expand All @@ -785,18 +791,28 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
this.user.getTranslation("challenges.gui.admin.descriptions.required-money",
"[value]",
Integer.toString(this.challenge.getRequiredMoney())));
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> {
if (status)
{
this.challenge.setRequiredMoney(value);
}

this.build();
});
return true;
};
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> {
if (status)
{
this.challenge.setRequiredMoney(value);
}

this.build();
});
return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

glow = false;
break;
}
Expand All @@ -806,20 +822,31 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)

if (this.challenge.isTakeMoney())
{
description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled"));
description = Collections.singletonList(this.user
.getTranslation("challenges.gui.admin.descriptions.enabled"));
}
else
{
description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled"));
description = Collections.singletonList(this.user
.getTranslation("challenges.gui.admin.descriptions.disabled"));
}

icon = new ItemStack(Material.LEVER);
clickHandler = (panel, user, clickType, slot) -> {
this.challenge.setTakeMoney(!this.challenge.isTakeMoney());
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.LEVER);
clickHandler = (panel, user, clickType, slot) -> {
this.challenge.setTakeMoney(!this.challenge.isTakeMoney());

this.build();
return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

this.build();
return true;
};
glow = this.challenge.isTakeMoney();
break;
}
Expand Down Expand Up @@ -901,19 +928,29 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
this.user.getTranslation("challenges.gui.admin.descriptions.reward-money",
"[value]",
Integer.toString(this.challenge.getRewardMoney())));
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> {
if (status)
{
this.challenge.setRewardMoney(value);
}

this.build();
});
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> {
if (status)
{
this.challenge.setRewardMoney(value);
}

this.build();
});

return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

return true;
};
glow = false;
break;
}
Expand Down Expand Up @@ -1062,19 +1099,32 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money",
"[value]",
Integer.toString(this.challenge.getRepeatMoneyReward())));
icon = new ItemStack(Material.GOLD_NUGGET);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRepeatMoneyReward(), 0, (status, value) -> {
if (status)
{
this.challenge.setRepeatMoneyReward(value);
}

this.build();
});
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_NUGGET);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user,
this.challenge.getRepeatMoneyReward(),
0,
(status, value) -> {
if (status)
{
this.challenge.setRepeatMoneyReward(value);
}

this.build();
});

return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

return true;
};
glow = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

/**
* This class contains all necessary elements to create Levels Edit GUI.
* TODO: In current class set that MONEY are availabe only if ECONOMY exist.
*/
public class EditLevelGUI extends CommonGUI
{
Expand Down Expand Up @@ -493,19 +492,29 @@ private PanelItem createButton(Button button)
this.user.getTranslation("challenges.gui.admin.descriptions.reward-money",
"[value]",
Integer.toString(this.challengeLevel.getRewardMoney())));
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> {
if (status)
{
this.challengeLevel.setRewardMoney(value);
}

this.build();
});
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> {
if (status)
{
this.challengeLevel.setRewardMoney(value);
}

this.build();
});

return true;
};
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}

return true;
};
glow = false;
break;
}
Expand Down

0 comments on commit 96cb448

Please sign in to comment.