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.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;
@ -25,9 +24,6 @@ import world.bentobox.challenges.utils.GuiUtils;
/**
* 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
{
@ -762,19 +758,29 @@ public class EditChallengeGUI extends CommonGUI
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;
}
@ -785,18 +791,28 @@ public class EditChallengeGUI extends CommonGUI
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;
}
@ -806,20 +822,31 @@ public class EditChallengeGUI extends CommonGUI
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;
}
@ -901,19 +928,29 @@ public class EditChallengeGUI extends CommonGUI
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;
}
@ -1062,19 +1099,32 @@ public class EditChallengeGUI extends CommonGUI
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;
}

View File

@ -28,7 +28,6 @@ import world.bentobox.challenges.utils.GuiUtils;
/**
* 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
{
@ -493,19 +492,29 @@ public class EditLevelGUI extends CommonGUI
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;
}