mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-29 12:37:37 +01:00
Added a description variable to the "Island protected" message
Added "[description]" in TextVariables added getName- and getDescriptionReference() in Flag
This commit is contained in:
parent
63dd2d95b2
commit
d2697e1525
@ -455,7 +455,7 @@ protection:
|
||||
description: "Toggle access"
|
||||
name: "Trap doors"
|
||||
locked: "&cThis island is locked!"
|
||||
protected: "&cIsland protected!"
|
||||
protected: "&cIsland protected: [description]"
|
||||
|
||||
panel:
|
||||
title: "Island flags"
|
||||
|
@ -25,10 +25,6 @@ public class Flag implements Comparable<Flag> {
|
||||
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 Material icon;
|
||||
private final Listener listener;
|
||||
@ -141,6 +137,14 @@ public class Flag implements Comparable<Flag> {
|
||||
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.
|
||||
* @param plugin - plugin
|
||||
@ -151,17 +155,17 @@ public class Flag implements Comparable<Flag> {
|
||||
// Start the flag conversion
|
||||
PanelItemBuilder pib = new PanelItemBuilder()
|
||||
.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);
|
||||
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();
|
||||
}
|
||||
// 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", 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));
|
||||
return pib.build();
|
||||
}
|
||||
@ -172,7 +176,7 @@ public class Flag implements Comparable<Flag> {
|
||||
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", 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));
|
||||
return pib.build();
|
||||
}
|
||||
@ -180,8 +184,8 @@ public class Flag implements Comparable<Flag> {
|
||||
// Dynamic rank list
|
||||
if (getType().equals(Type.PROTECTION)) {
|
||||
// Protection flag
|
||||
String d = user.getTranslation(PRO_FLAGS + id + DOT_DESC);
|
||||
d = user.getTranslation("protection.panel.flag-item.description-layout", DESC_PLACEHOLDER, d);
|
||||
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)) {
|
||||
|
@ -7,6 +7,7 @@ package us.tastybento.bskyblock.api.localization;
|
||||
public class TextVariables {
|
||||
|
||||
public static final String NAME = "[name]";
|
||||
public static final String DESCRIPTION = "[description]";
|
||||
public static final String NUMBER = "[number]";
|
||||
public static final String RANK = "[rank]";
|
||||
public static final String LABEL = "[label]";
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.event.Listener;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
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.database.objects.Island;
|
||||
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
|
||||
* @param e - event
|
||||
* @param flag - the flag that has been checked
|
||||
*/
|
||||
public void noGo(Event e) {
|
||||
noGo(e, false);
|
||||
public void noGo(Event e, Flag flag) {
|
||||
noGo(e, flag,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the event and sends the island protected message to user unless silent is true
|
||||
* @param e - event
|
||||
* @param flag - the flag that has been checked
|
||||
* @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) {
|
||||
((Cancellable)e).setCancelled(true);
|
||||
}
|
||||
if (user != null) {
|
||||
if (!silent) {
|
||||
user.notify("protection.protected");
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(flag.getDescriptionReference()));
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
@ -148,7 +151,7 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
|
||||
if (island.isPresent()) {
|
||||
if (!island.get().isAllowed(user, flag)) {
|
||||
noGo(e, silent);
|
||||
noGo(e, flag, silent);
|
||||
// Clear the user for the next time
|
||||
user = null;
|
||||
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
|
||||
if (!flag.isSetForWorld(loc.getWorld())) {
|
||||
noGo(e, silent);
|
||||
noGo(e, flag, silent);
|
||||
user = null;
|
||||
return false;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user