This commit is contained in:
BuildTools committed 2024-04-17 15:20:52 +05:00
1 parent 2c1394f7f1
commit 979705c08a
5 files changed
+97 -12

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.5.2</version>
<version>2.5.2.1</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@@ -0,0 +1,53 @@
package su.nightexpress.nightcore.api.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.menu.api.Menu;
public class PlayerOpenMenuEvent extends Event implements Cancellable {
public static final HandlerList HANDLER_LIST = new HandlerList();
private final Player player;
private final Menu menu;
private boolean cancelled;
public PlayerOpenMenuEvent(@NotNull Player player, @NotNull Menu menu) {
this.player = player;
this.menu = menu;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
@NotNull
public Player getPlayer() {
return player;
}
@NotNull
public Menu getMenu() {
return menu;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}
@@ -29,8 +29,14 @@ public interface Menu {
void flush(@NotNull Player player);
default boolean isViewer(@NotNull Player player) {
return this.getViewer(player) != null;
}
void close();
void close(@NotNull Player player);
boolean close(@NotNull NightCorePlugin plugin);
void runNextTick(@NotNull Runnable runnable);
@@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.api.event.PlayerOpenMenuEvent;
import su.nightexpress.nightcore.dialog.Dialog;
import su.nightexpress.nightcore.menu.api.Menu;
import su.nightexpress.nightcore.menu.link.Linked;
@@ -42,8 +43,7 @@ public abstract class AbstractMenu<P extends NightCorePlugin> 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<P extends NightCorePlugin> 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<P extends NightCorePlugin> 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<P extends NightCorePlugin> 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);
}
@@ -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);