implements Menu { Menu menu = getMenu(player); if (menu == null) return; - menu.close(); - PLAYER_MENUS.remove(player.getUniqueId()); + menu.close(player); } protected final P plugin; @@ -86,10 +86,22 @@ public abstract class AbstractMenu
implements Menu { @Override public void close() { - new HashSet<>(this.getViewers()).forEach(viewer -> viewer.getPlayer().closeInventory()); + new HashSet<>(this.getViewers()).forEach(viewer -> this.close(viewer.getPlayer())); this.viewers.clear(); } + @Override + public void close(@NotNull Player player) { + Menu current = getMenu(player); + + if (current == this && player.getOpenInventory().getType() != InventoryType.CRAFTING) { + player.closeInventory(); + } + else { + this.onClose(player); + } + } + @Override public boolean close(@NotNull NightCorePlugin plugin) { if (this.plugin == plugin) { @@ -128,6 +140,13 @@ public abstract class AbstractMenu
implements Menu { public boolean open(@NotNull Player player) { if (!this.canOpen(player)) return false; + PlayerOpenMenuEvent event = new PlayerOpenMenuEvent(player, this); + this.plugin.getPluginManager().callEvent(event); + if (event.isCancelled()) { + //this.close(player); + return false; + } + MenuOptions options = new MenuOptions(this.getOptions()); MenuViewer viewer = this.getViewerOrCreate(player); @@ -190,14 +209,18 @@ public abstract class AbstractMenu
implements Menu { @Override public void onClose(@NotNull MenuViewer viewer, @NotNull InventoryCloseEvent event) { - Player player = viewer.getPlayer(); + this.onClose(viewer.getPlayer()); + } - this.getViewersMap().remove(player.getUniqueId()); - this.getItems().removeIf(menuItem -> menuItem.getOptions().canBeDestroyed(viewer)); + public void onClose(@NotNull Player player) { + MenuViewer viewer = this.viewers.remove(player.getUniqueId()); + if (viewer != null) { + this.getItems().removeIf(menuItem -> menuItem.getOptions().canBeDestroyed(viewer)); + } PLAYER_MENUS.remove(player.getUniqueId()); // Do not clear link if entered Editor, so it can reopen menu without data loss when done. - if (this instanceof Linked> linked && !Dialog.contains(player)) { + if (viewer != null && this instanceof Linked> linked && !Dialog.contains(player)) { linked.getLink().clear(viewer); } diff --git a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java b/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java index b8856f0..3ed9b99 100644 --- a/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java +++ b/src/main/java/su/nightexpress/nightcore/util/wrapper/UniSound.java @@ -43,13 +43,16 @@ public class UniSound { public static UniSound read(@NotNull FileConfig cfg, @NotNull String path) { String soundName = ConfigValue.create(path + ".Name", "null", "Sound name. You can use Spigot sound names, or ones from your resource pack.", - "Spigot Sounds: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html").read(cfg); + "Spigot Sounds: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html" + ).read(cfg); - float volume = ConfigValue.create(path + ".Volume", 0.8F, - "Sound volume. From 0.0 to 1.0.").read(cfg).floatValue(); + float volume = ConfigValue.create(path + ".Volume", 0.8D, + "Sound volume. From 0.0 to 1.0." + ).read(cfg).floatValue(); float pitch = ConfigValue.create(path + ".Pitch", 1D, - "Sound speed. From 0.5 to 2.0").read(cfg).floatValue(); + "Sound speed. From 0.5 to 2.0" + ).read(cfg).floatValue(); Sound soundType = StringUtil.getEnum(soundName, Sound.class).orElse(null);