Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
tastybento 2018-06-16 10:44:13 +09:00
commit 21601089f4
6 changed files with 40 additions and 21 deletions

View File

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

View File

@ -412,6 +412,9 @@ public class Settings implements DataObject, WorldSettings {
@ConfigEntry(path = "island.require-confirmation.leave-wait")
private long leaveWait = 10L;
@ConfigEntry(path = "panel.close-on-click-outside")
private boolean closePanelOnClickOutside = true;
private String uniqueId = "config";
// Getters and setters
@ -1482,4 +1485,12 @@ public class Settings implements DataObject, WorldSettings {
this.worldFlags = worldFlags;
}
public boolean getClosePanelOnClickOutside() {
return closePanelOnClickOutside;
}
public void setClosePanelOnClickOutside(boolean closePanelOnClickOutside) {
this.closePanelOnClickOutside = closePanelOnClickOutside;
}
}

View File

@ -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)) {

View File

@ -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]";

View File

@ -13,6 +13,7 @@ import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.user.User;
@ -23,13 +24,12 @@ public class PanelListenerManager implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
// Close inventory if clicked outside
if (event.getSlotType().equals(SlotType.OUTSIDE)) {
// Close inventory if clicked outside and if setting is true
if (BSkyBlock.getInstance().getSettings().getClosePanelOnClickOutside() && event.getSlotType().equals(SlotType.OUTSIDE)) {
event.getWhoClicked().closeInventory();
return;
}
User user = User.getInstance(event.getWhoClicked()); // The player that
// clicked the item
User user = User.getInstance(event.getWhoClicked()); // The player that clicked the item
Inventory inventory = event.getInventory(); // The inventory that was
// Open the inventory panel that this player has open (they can only ever have one)
if (openPanels.containsKey(user.getUniqueId())) {

View File

@ -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 {