Disable Money and Level buttons in admin panel, if EconomyPlugin or Level addon is missing.

This commit is contained in:
BONNe 2019-01-23 21:44:33 +02:00
parent c3b87da88e
commit 96cb4488c3
2 changed files with 127 additions and 68 deletions

View File

@ -11,7 +11,6 @@ import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.ItemParser;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.CommonGUI;
@ -25,9 +24,6 @@ import world.bentobox.challenges.utils.GuiUtils;
/** /**
* This class contains all necessary methods that creates GUI and allow to edit challenges * This class contains all necessary methods that creates GUI and allow to edit challenges
* properties. * 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 public class EditChallengeGUI extends CommonGUI
{ {
@ -762,6 +758,9 @@ public class EditChallengeGUI extends CommonGUI
this.user.getTranslation("challenges.gui.admin.descriptions.required-level", this.user.getTranslation("challenges.gui.admin.descriptions.required-level",
"[value]", "[value]",
Long.toString(this.challenge.getRequiredIslandLevel()))); Long.toString(this.challenge.getRequiredIslandLevel())));
if (this.addon.isLevelProvided())
{
icon = new ItemStack(Material.BEACON); icon = new ItemStack(Material.BEACON);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> {
@ -775,6 +774,13 @@ public class EditChallengeGUI extends CommonGUI
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = false; glow = false;
break; break;
} }
@ -785,6 +791,9 @@ public class EditChallengeGUI extends CommonGUI
this.user.getTranslation("challenges.gui.admin.descriptions.required-money", this.user.getTranslation("challenges.gui.admin.descriptions.required-money",
"[value]", "[value]",
Integer.toString(this.challenge.getRequiredMoney()))); Integer.toString(this.challenge.getRequiredMoney())));
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT); icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> {
@ -797,6 +806,13 @@ public class EditChallengeGUI extends CommonGUI
}); });
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = false; glow = false;
break; break;
} }
@ -806,13 +822,17 @@ public class EditChallengeGUI extends CommonGUI
if (this.challenge.isTakeMoney()) 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 else
{ {
description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); description = Collections.singletonList(this.user
.getTranslation("challenges.gui.admin.descriptions.disabled"));
} }
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.LEVER); icon = new ItemStack(Material.LEVER);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); this.challenge.setTakeMoney(!this.challenge.isTakeMoney());
@ -820,6 +840,13 @@ public class EditChallengeGUI extends CommonGUI
this.build(); this.build();
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = this.challenge.isTakeMoney(); glow = this.challenge.isTakeMoney();
break; break;
} }
@ -901,6 +928,9 @@ public class EditChallengeGUI extends CommonGUI
this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", this.user.getTranslation("challenges.gui.admin.descriptions.reward-money",
"[value]", "[value]",
Integer.toString(this.challenge.getRewardMoney()))); Integer.toString(this.challenge.getRewardMoney())));
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT); icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> {
@ -914,6 +944,13 @@ public class EditChallengeGUI extends CommonGUI
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = false; glow = false;
break; break;
} }
@ -1062,9 +1099,15 @@ public class EditChallengeGUI extends CommonGUI
this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money", this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money",
"[value]", "[value]",
Integer.toString(this.challenge.getRepeatMoneyReward()))); Integer.toString(this.challenge.getRepeatMoneyReward())));
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_NUGGET); icon = new ItemStack(Material.GOLD_NUGGET);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challenge.getRepeatMoneyReward(), 0, (status, value) -> { new NumberGUI(this.user,
this.challenge.getRepeatMoneyReward(),
0,
(status, value) -> {
if (status) if (status)
{ {
this.challenge.setRepeatMoneyReward(value); this.challenge.setRepeatMoneyReward(value);
@ -1075,6 +1118,13 @@ public class EditChallengeGUI extends CommonGUI
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = false; glow = false;
break; break;
} }

View File

@ -28,7 +28,6 @@ import world.bentobox.challenges.utils.GuiUtils;
/** /**
* This class contains all necessary elements to create Levels Edit GUI. * 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 public class EditLevelGUI extends CommonGUI
{ {
@ -493,6 +492,9 @@ public class EditLevelGUI extends CommonGUI
this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", this.user.getTranslation("challenges.gui.admin.descriptions.reward-money",
"[value]", "[value]",
Integer.toString(this.challengeLevel.getRewardMoney()))); Integer.toString(this.challengeLevel.getRewardMoney())));
if (this.addon.isEconomyProvided())
{
icon = new ItemStack(Material.GOLD_INGOT); icon = new ItemStack(Material.GOLD_INGOT);
clickHandler = (panel, user, clickType, slot) -> { clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> {
@ -506,6 +508,13 @@ public class EditLevelGUI extends CommonGUI
return true; return true;
}; };
}
else
{
icon = new ItemStack(Material.BARRIER);
clickHandler = null;
}
glow = false; glow = false;
break; break;
} }