mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 14:38:46 +00:00
v2.5.2.1
This commit is contained in:
1 parent
2c1394f7f1
commit
979705c08a
5 files changed
+97
-12
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>su.nightexpress.nightcore</groupId>
|
<groupId>su.nightexpress.nightcore</groupId>
|
||||||
<artifactId>nightcore</artifactId>
|
<artifactId>nightcore</artifactId>
|
||||||
<version>2.5.2</version>
|
<version>2.5.2.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<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);
|
void flush(@NotNull Player player);
|
||||||
|
|
||||||
|
default boolean isViewer(@NotNull Player player) {
|
||||||
|
return this.getViewer(player) != null;
|
||||||
|
}
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
void close(@NotNull Player player);
|
||||||
|
|
||||||
boolean close(@NotNull NightCorePlugin plugin);
|
boolean close(@NotNull NightCorePlugin plugin);
|
||||||
|
|
||||||
void runNextTick(@NotNull Runnable runnable);
|
void runNextTick(@NotNull Runnable runnable);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import su.nightexpress.nightcore.NightCorePlugin;
|
import su.nightexpress.nightcore.NightCorePlugin;
|
||||||
|
import su.nightexpress.nightcore.api.event.PlayerOpenMenuEvent;
|
||||||
import su.nightexpress.nightcore.dialog.Dialog;
|
import su.nightexpress.nightcore.dialog.Dialog;
|
||||||
import su.nightexpress.nightcore.menu.api.Menu;
|
import su.nightexpress.nightcore.menu.api.Menu;
|
||||||
import su.nightexpress.nightcore.menu.link.Linked;
|
import su.nightexpress.nightcore.menu.link.Linked;
|
||||||
@@ -42,8 +43,7 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
Menu menu = getMenu(player);
|
Menu menu = getMenu(player);
|
||||||
if (menu == null) return;
|
if (menu == null) return;
|
||||||
|
|
||||||
menu.close();
|
menu.close(player);
|
||||||
PLAYER_MENUS.remove(player.getUniqueId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final P plugin;
|
protected final P plugin;
|
||||||
@@ -86,10 +86,22 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
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();
|
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
|
@Override
|
||||||
public boolean close(@NotNull NightCorePlugin plugin) {
|
public boolean close(@NotNull NightCorePlugin plugin) {
|
||||||
if (this.plugin == plugin) {
|
if (this.plugin == plugin) {
|
||||||
@@ -128,6 +140,13 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
public boolean open(@NotNull Player player) {
|
public boolean open(@NotNull Player player) {
|
||||||
if (!this.canOpen(player)) return false;
|
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());
|
MenuOptions options = new MenuOptions(this.getOptions());
|
||||||
MenuViewer viewer = this.getViewerOrCreate(player);
|
MenuViewer viewer = this.getViewerOrCreate(player);
|
||||||
|
|
||||||
@@ -190,14 +209,18 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose(@NotNull MenuViewer viewer, @NotNull InventoryCloseEvent event) {
|
public void onClose(@NotNull MenuViewer viewer, @NotNull InventoryCloseEvent event) {
|
||||||
Player player = viewer.getPlayer();
|
this.onClose(viewer.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
this.getViewersMap().remove(player.getUniqueId());
|
public void onClose(@NotNull Player player) {
|
||||||
this.getItems().removeIf(menuItem -> menuItem.getOptions().canBeDestroyed(viewer));
|
MenuViewer viewer = this.viewers.remove(player.getUniqueId());
|
||||||
|
if (viewer != null) {
|
||||||
|
this.getItems().removeIf(menuItem -> menuItem.getOptions().canBeDestroyed(viewer));
|
||||||
|
}
|
||||||
PLAYER_MENUS.remove(player.getUniqueId());
|
PLAYER_MENUS.remove(player.getUniqueId());
|
||||||
|
|
||||||
// Do not clear link if entered Editor, so it can reopen menu without data loss when done.
|
// 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);
|
linked.getLink().clear(viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,16 @@ public class UniSound {
|
|||||||
public static UniSound read(@NotNull FileConfig cfg, @NotNull String path) {
|
public static UniSound read(@NotNull FileConfig cfg, @NotNull String path) {
|
||||||
String soundName = ConfigValue.create(path + ".Name", "null",
|
String soundName = ConfigValue.create(path + ".Name", "null",
|
||||||
"Sound name. You can use Spigot sound names, or ones from your resource pack.",
|
"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,
|
float volume = ConfigValue.create(path + ".Volume", 0.8D,
|
||||||
"Sound volume. From 0.0 to 1.0.").read(cfg).floatValue();
|
"Sound volume. From 0.0 to 1.0."
|
||||||
|
).read(cfg).floatValue();
|
||||||
|
|
||||||
float pitch = ConfigValue.create(path + ".Pitch", 1D,
|
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);
|
Sound soundType = StringUtil.getEnum(soundName, Sound.class).orElse(null);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user