mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 03:35:11 +01:00
Refactored toPanelItem to make it easier to understand
This commit is contained in:
parent
af25bba60c
commit
7a7ca42383
@ -299,46 +299,54 @@ public class Flag implements Comparable<Flag> {
|
|||||||
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
|
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
|
||||||
return pib.build();
|
return pib.build();
|
||||||
}
|
}
|
||||||
// Check if this is a setting or world setting
|
Island island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
|
||||||
if (getType().equals(Type.WORLD_SETTING)) {
|
switch(getType()) {
|
||||||
String worldDetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active")
|
case PROTECTION:
|
||||||
: user.getTranslation("protection.panel.flag-item.setting-disabled");
|
return createProtectionFlag(plugin, user, island, pib).build();
|
||||||
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
|
case SETTING:
|
||||||
, "[setting]", worldDetting));
|
return createSettingFlag(plugin, user, island, pib).build();
|
||||||
|
case WORLD_SETTING:
|
||||||
|
return createWorldSettingFlag(plugin, user, pib).build();
|
||||||
|
default:
|
||||||
return pib.build();
|
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()));
|
|
||||||
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)) {
|
|
||||||
// Protection flag
|
|
||||||
String d = user.getTranslation(getDescriptionReference());
|
|
||||||
d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, d);
|
|
||||||
pib.description(d);
|
|
||||||
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));
|
|
||||||
} else if (score <= RanksManager.OWNER_RANK && score > island.getFlag(this)) {
|
|
||||||
pib.description(user.getTranslation("protection.panel.flag-item.allowed-rank") + user.getTranslation(reference));
|
|
||||||
} else if (score == island.getFlag(this)) {
|
|
||||||
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pib.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PanelItemBuilder createProtectionFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
|
||||||
|
if (island != null) {
|
||||||
|
// Protection flag
|
||||||
|
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));
|
||||||
|
} else if (score <= RanksManager.OWNER_RANK && score > island.getFlag(this)) {
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.allowed-rank") + user.getTranslation(reference));
|
||||||
|
} else if (score == island.getFlag(this)) {
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return pib;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
|
Loading…
Reference in New Issue
Block a user