Added a description variable to the "Island protected" message

Added "[description]" in TextVariables
added getName- and getDescriptionReference() in Flag
This commit is contained in:
Florian CUNY 2018-06-11 15:55:01 +02:00
parent 63dd2d95b2
commit d2697e1525
4 changed files with 25 additions and 17 deletions

View File

@ -455,7 +455,7 @@ protection:
description: "Toggle access" description: "Toggle access"
name: "Trap doors" name: "Trap doors"
locked: "&cThis island is locked!" locked: "&cThis island is locked!"
protected: "&cIsland protected!" protected: "&cIsland protected: [description]"
panel: panel:
title: "Island flags" title: "Island flags"

View File

@ -25,10 +25,6 @@ public class Flag implements Comparable<Flag> {
WORLD_SETTING WORLD_SETTING
} }
private static final String PRO_FLAGS = "protection.flags.";
private static final String DOT_DESC = ".description";
private static final String DESC_PLACEHOLDER = "[description]";
private final String id; private final String id;
private final Material icon; private final Material icon;
private final Listener listener; private final Listener listener;
@ -141,6 +137,14 @@ public class Flag implements Comparable<Flag> {
return type == other.type; return type == other.type;
} }
public String getNameReference() {
return "protection.flags." + this.id + ".name";
}
public String getDescriptionReference() {
return "protection.flags." + this.id + ".description";
}
/** /**
* Converts a flag to a panel item. The content of the flag will change depending on who the user is and where they are. * Converts a flag to a panel item. The content of the flag will change depending on who the user is and where they are.
* @param plugin - plugin * @param plugin - plugin
@ -151,17 +155,17 @@ public class Flag implements Comparable<Flag> {
// Start the flag conversion // Start the flag conversion
PanelItemBuilder pib = new PanelItemBuilder() PanelItemBuilder pib = new PanelItemBuilder()
.icon(new ItemStack(icon)) .icon(new ItemStack(icon))
.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(PRO_FLAGS + id + ".name"))) .name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(getNameReference())))
.clickHandler(clickHandler); .clickHandler(clickHandler);
if (getType().equals(Type.MENU)) { if (getType().equals(Type.MENU)) {
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC))); 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 // Check if this is a setting or world setting
if (getType().equals(Type.WORLD_SETTING)) { if (getType().equals(Type.WORLD_SETTING)) {
String worldDetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active") String worldDetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active")
: user.getTranslation("protection.panel.flag-item.setting-disabled"); : user.getTranslation("protection.panel.flag-item.setting-disabled");
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC) pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
, "[setting]", worldDetting)); , "[setting]", worldDetting));
return pib.build(); return pib.build();
} }
@ -172,7 +176,7 @@ public class Flag implements Comparable<Flag> {
if (getType().equals(Type.SETTING)) { if (getType().equals(Type.SETTING)) {
String islandSetting = island.isAllowed(this) ? user.getTranslation("protection.panel.flag-item.setting-active") String islandSetting = island.isAllowed(this) ? user.getTranslation("protection.panel.flag-item.setting-active")
: user.getTranslation("protection.panel.flag-item.setting-disabled"); : user.getTranslation("protection.panel.flag-item.setting-disabled");
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", DESC_PLACEHOLDER, user.getTranslation(PRO_FLAGS + id + DOT_DESC) pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
, "[setting]", islandSetting)); , "[setting]", islandSetting));
return pib.build(); return pib.build();
} }
@ -180,8 +184,8 @@ public class Flag implements Comparable<Flag> {
// Dynamic rank list // Dynamic rank list
if (getType().equals(Type.PROTECTION)) { if (getType().equals(Type.PROTECTION)) {
// Protection flag // Protection flag
String d = user.getTranslation(PRO_FLAGS + id + DOT_DESC); String d = user.getTranslation(getDescriptionReference());
d = user.getTranslation("protection.panel.flag-item.description-layout", DESC_PLACEHOLDER, d); d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, d);
pib.description(d); pib.description(d);
plugin.getRanksManager().getRanks().forEach((reference, score) -> { plugin.getRanksManager().getRanks().forEach((reference, score) -> {
if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) { if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) {

View File

@ -7,6 +7,7 @@ package us.tastybento.bskyblock.api.localization;
public class TextVariables { public class TextVariables {
public static final String NAME = "[name]"; public static final String NAME = "[name]";
public static final String DESCRIPTION = "[description]";
public static final String NUMBER = "[number]"; public static final String NUMBER = "[number]";
public static final String RANK = "[rank]"; public static final String RANK = "[rank]";
public static final String LABEL = "[label]"; public static final String LABEL = "[label]";

View File

@ -12,6 +12,7 @@ import org.bukkit.event.Listener;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.Flag.Type; import us.tastybento.bskyblock.api.flags.Flag.Type;
import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.IslandWorldManager; import us.tastybento.bskyblock.managers.IslandWorldManager;
@ -79,23 +80,25 @@ public abstract class AbstractFlagListener implements Listener {
/** /**
* Cancels the event and sends the island public message to user * Cancels the event and sends the island public message to user
* @param e - event * @param e - event
* @param flag - the flag that has been checked
*/ */
public void noGo(Event e) { public void noGo(Event e, Flag flag) {
noGo(e, false); noGo(e, flag,false);
} }
/** /**
* Cancels the event and sends the island protected message to user unless silent is true * Cancels the event and sends the island protected message to user unless silent is true
* @param e - event * @param e - event
* @param flag - the flag that has been checked
* @param silent - if true, message is not sent * @param silent - if true, message is not sent
*/ */
public void noGo(Event e, boolean silent) { public void noGo(Event e, Flag flag, boolean silent) {
if (e instanceof Cancellable) { if (e instanceof Cancellable) {
((Cancellable)e).setCancelled(true); ((Cancellable)e).setCancelled(true);
} }
if (user != null) { if (user != null) {
if (!silent) { if (!silent) {
user.notify("protection.protected"); user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(flag.getDescriptionReference()));
} }
user.updateInventory(); user.updateInventory();
} }
@ -148,7 +151,7 @@ public abstract class AbstractFlagListener implements Listener {
if (island.isPresent()) { if (island.isPresent()) {
if (!island.get().isAllowed(user, flag)) { if (!island.get().isAllowed(user, flag)) {
noGo(e, silent); noGo(e, flag, silent);
// Clear the user for the next time // Clear the user for the next time
user = null; user = null;
return false; return false;
@ -159,7 +162,7 @@ public abstract class AbstractFlagListener implements Listener {
} }
// The player is in the world, but not on an island, so general world settings apply // The player is in the world, but not on an island, so general world settings apply
if (!flag.isSetForWorld(loc.getWorld())) { if (!flag.isSetForWorld(loc.getWorld())) {
noGo(e, silent); noGo(e, flag, silent);
user = null; user = null;
return false; return false;
} else { } else {