Refactored toPanelItem to make it easier to understand

This commit is contained in:
tastybento 2019-03-23 18:59:30 -07:00
parent af25bba60c
commit 7a7ca42383

View File

@ -299,32 +299,42 @@ public class Flag implements Comparable<Flag> {
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
return pib.build();
}
// Check if this is a setting or world setting
if (getType().equals(Type.WORLD_SETTING)) {
String worldDetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active")
: user.getTranslation("protection.panel.flag-item.setting-disabled");
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
, "[setting]", worldDetting));
Island island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
switch(getType()) {
case PROTECTION:
return createProtectionFlag(plugin, user, island, pib).build();
case SETTING:
return createSettingFlag(plugin, user, island, pib).build();
case WORLD_SETTING:
return createWorldSettingFlag(plugin, user, pib).build();
default:
return pib.build();
}
}
// Get the island this user is on or their own
Island island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
private PanelItemBuilder createWorldSettingFlag(BentoBox plugin, User user, PanelItemBuilder pib) {
String worldSetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active")
: user.getTranslation("protection.panel.flag-item.setting-disabled");
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
, "[setting]", worldSetting));
return pib;
}
private PanelItemBuilder createSettingFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
if (island != null) {
if (getType().equals(Type.SETTING)) {
String islandSetting = island.isAllowed(this) ? user.getTranslation("protection.panel.flag-item.setting-active")
: user.getTranslation("protection.panel.flag-item.setting-disabled");
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
, "[setting]", islandSetting));
return pib.build();
}
// TODO: Get the world settings - the player has no island and is not in an island location
// Dynamic rank list
if (getType().equals(Type.PROTECTION)) {
return pib;
}
private PanelItemBuilder createProtectionFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
if (island != null) {
// Protection flag
String d = user.getTranslation(getDescriptionReference());
d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, d);
pib.description(d);
pib.description(user.getTranslation("protection.panel.flag-item.description-layout",
TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
plugin.getRanksManager().getRanks().forEach((reference, score) -> {
if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) {
pib.description(user.getTranslation("protection.panel.flag-item.blocked-rank") + user.getTranslation(reference));
@ -335,10 +345,8 @@ public class Flag implements Comparable<Flag> {
}
});
}
return pib;
}
return pib.build();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()