UI requests can be silent now.
parent
58e1e9476b
commit
47264cab00
|
@ -10,14 +10,16 @@ Date format: (YYYY-MM-DD)
|
|||
* Config: Added some more examples for the 'name-regex' setting to the default config.
|
||||
* Fixed: Some messages would print an empty line when set to an empty text, instead of being disabled.
|
||||
|
||||
Internal:
|
||||
* Internal API: UIHandler#canOpen is public and has an additional 'silent' flag now.
|
||||
* Editor UIs are setup lazily now, only when required for the first time.
|
||||
API:
|
||||
* PlayerOpenUIEvent indicates whether the UI request has been silent now.
|
||||
|
||||
Internal:
|
||||
* Moved the installation of Spigot dependencies into a separate script.
|
||||
* Added support for building with Jitpack. This uses a Maven wrapper with a fixed version, because Jitpack uses a buggy Maven version currently (3.6.1).
|
||||
* Updated building instructions in readme.
|
||||
* Internal API: UIHandler#canOpen is public and has an additional 'silent' flag now.
|
||||
* Internal API: UI requests can be silent now.
|
||||
* Editor UIs are setup lazily now, only when required for the first time.
|
||||
|
||||
## v2.11.0 (2020-08-13)
|
||||
### Supported MC versions: 1.16.2, 1.16.1, 1.15.2, 1.14.4
|
||||
|
|
|
@ -19,11 +19,13 @@ public class PlayerOpenUIEvent extends Event implements Cancellable {
|
|||
|
||||
private final UIType uiType;
|
||||
private final Player player;
|
||||
private final boolean silentRequest;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerOpenUIEvent(UIType uiType, Player player) {
|
||||
public PlayerOpenUIEvent(UIType uiType, Player player, boolean silentRequest) {
|
||||
this.uiType = uiType;
|
||||
this.player = player;
|
||||
this.silentRequest = silentRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +47,23 @@ public class PlayerOpenUIEvent extends Event implements Cancellable {
|
|||
}
|
||||
|
||||
/**
|
||||
* If cancelled the UI won't open.
|
||||
* Checks if this UI request is silent.
|
||||
* <p>
|
||||
* A silent request is not supposed to produce any output if it fails. For example, the player is not supposed to
|
||||
* receive a 'You do not have the permission to access this UI'-message if access is denied due to a missing
|
||||
* permission.
|
||||
* <p>
|
||||
* Silent UI requests may for example be used if there is a default fallback behavior that is supposed to be used
|
||||
* for players which do not have access to a specific type of UI.
|
||||
*
|
||||
* @return <code>true</code> if this is a silent UI request
|
||||
*/
|
||||
public boolean isSilentRequest() {
|
||||
return silentRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* If cancelled, the UI won't open.
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
|
|
|
@ -12,8 +12,8 @@ public class ShopkeeperOpenUIEvent extends PlayerOpenUIEvent {
|
|||
|
||||
private final Shopkeeper shopkeeper;
|
||||
|
||||
public ShopkeeperOpenUIEvent(Shopkeeper shopkeeper, UIType uiType, Player player) {
|
||||
super(uiType, player);
|
||||
public ShopkeeperOpenUIEvent(Shopkeeper shopkeeper, UIType uiType, Player player, boolean silentRequest) {
|
||||
super(uiType, player, silentRequest);
|
||||
this.shopkeeper = shopkeeper;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,10 @@ public class SKUIRegistry extends AbstractTypeRegistry<AbstractUIType> implement
|
|||
}
|
||||
|
||||
public boolean requestUI(UIHandler uiHandler, Player player) {
|
||||
return this.requestUI(uiHandler, player, false);
|
||||
}
|
||||
|
||||
public boolean requestUI(UIHandler uiHandler, Player player, boolean silentRequest) {
|
||||
Validate.notNull(uiHandler, "uiHandler is null");
|
||||
Validate.notNull(player, "player is null");
|
||||
UIType uiType = uiHandler.getUIType();
|
||||
|
@ -80,7 +84,7 @@ public class SKUIRegistry extends AbstractTypeRegistry<AbstractUIType> implement
|
|||
}
|
||||
|
||||
String playerName = player.getName();
|
||||
if (!uiHandler.canOpen(player, false)) {
|
||||
if (!uiHandler.canOpen(player, silentRequest)) {
|
||||
Log.debug(() -> "The player '" + playerName + "' cannot open UI '" + uiIdentifier + "'.");
|
||||
return false;
|
||||
}
|
||||
|
@ -95,9 +99,9 @@ public class SKUIRegistry extends AbstractTypeRegistry<AbstractUIType> implement
|
|||
// Call event:
|
||||
PlayerOpenUIEvent openUIEvent;
|
||||
if (shopkeeper == null) {
|
||||
openUIEvent = new PlayerOpenUIEvent(uiType, player);
|
||||
openUIEvent = new PlayerOpenUIEvent(uiType, player, silentRequest);
|
||||
} else {
|
||||
openUIEvent = new ShopkeeperOpenUIEvent(shopkeeper, uiType, player);
|
||||
openUIEvent = new ShopkeeperOpenUIEvent(shopkeeper, uiType, player, silentRequest);
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(openUIEvent);
|
||||
if (openUIEvent.isCancelled()) {
|
||||
|
|
Loading…
Reference in New Issue