mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-03 06:28:52 +00:00
v2.7.3.1
This commit is contained in:
1 parent
28a703ab1f
commit
dbaaea15dc
32 files changed
+1018
-93
No files matched your search
@@ -9,6 +9,7 @@ import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.PluginDetails;
|
||||
import su.nightexpress.nightcore.language.LangManager;
|
||||
import su.nightexpress.nightcore.menu.impl.AbstractMenu;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuRegistry;
|
||||
import su.nightexpress.nightcore.util.*;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniPermission;
|
||||
|
||||
@@ -146,6 +147,7 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
this.disable();
|
||||
|
||||
AbstractMenu.clearAll(this); // Close all GUIs.
|
||||
MenuRegistry.closeAll();
|
||||
HandlerList.unregisterAll(this); // Unregister all plugin listeners.
|
||||
|
||||
this.commandManager.shutdown();
|
||||
@@ -154,7 +156,7 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
}
|
||||
|
||||
protected void postLoad() {
|
||||
this.debug("Inject post-loading code...");
|
||||
//this.debug("Inject post-loading code...");
|
||||
this.postLoaders.forEach(Runnable::run);
|
||||
this.postLoaders.clear();
|
||||
this.postLoaders = null; // Prevent from adding post-load code during runtime.
|
||||
|
||||
@@ -247,6 +247,9 @@ public class ConfigValue<T> {
|
||||
return map;
|
||||
};
|
||||
|
||||
forMap("a", s -> s, s -> s, (cfg, path2) -> null, map -> {});
|
||||
forMap("a", s -> s, s -> s, (cfg, path2, id) -> null, map -> {});
|
||||
|
||||
return create(path, reader, writer, defaultValue, description);
|
||||
}
|
||||
|
||||
@@ -254,15 +257,14 @@ public class ConfigValue<T> {
|
||||
public static <K, V extends Writeable> ConfigValue<Map<K, V>> forMap(@NotNull String path,
|
||||
@NotNull Function<String, K> keyReadFun,
|
||||
@NotNull Function<K, String> keyWriteFun,
|
||||
@NotNull BiFunction<FileConfig, String, V> valReadFun,
|
||||
//@NotNull Supplier<Map<K, V>> mapSupplier,
|
||||
@NotNull ReadFunction<V> valReadFun,
|
||||
@NotNull Consumer<Map<K, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
Reader<Map<K, V>> reader = (cfg, readPath, def) -> {
|
||||
var map = new HashMap<K, V>();//mapSupplier.get();
|
||||
var map = new HashMap<K, V>();
|
||||
for (String keyRaw : cfg.getSection(readPath)) {
|
||||
K key = keyReadFun.apply(keyRaw);
|
||||
V val = valReadFun.apply(cfg, readPath + "." + keyRaw);
|
||||
V val = valReadFun.read(cfg, readPath + "." + keyRaw, keyRaw);
|
||||
if (key == null || val == null) continue;
|
||||
|
||||
map.put(key, val);
|
||||
@@ -284,6 +286,42 @@ public class ConfigValue<T> {
|
||||
return create(path, reader, writer, defaultMap, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <K, V extends Writeable> ConfigValue<Map<K, V>> forMap(@NotNull String path,
|
||||
@NotNull Function<String, K> keyReadFun,
|
||||
@NotNull Function<K, String> keyWriteFun,
|
||||
@NotNull BiFunction<FileConfig, String, V> valReadFun,
|
||||
//@NotNull Supplier<Map<K, V>> mapSupplier,
|
||||
@NotNull Consumer<Map<K, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
return forMap(path,keyReadFun, keyWriteFun, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
|
||||
|
||||
// Reader<Map<K, V>> reader = (cfg, readPath, def) -> {
|
||||
// var map = new HashMap<K, V>();//mapSupplier.get();
|
||||
// for (String keyRaw : cfg.getSection(readPath)) {
|
||||
// K key = keyReadFun.apply(keyRaw);
|
||||
// V val = valReadFun.apply(cfg, readPath + "." + keyRaw);
|
||||
// if (key == null || val == null) continue;
|
||||
//
|
||||
// map.put(key, val);
|
||||
// }
|
||||
// return map;
|
||||
// };
|
||||
//
|
||||
// Writer<Map<K, V>> writer = (cfg, writePath, map) -> {
|
||||
// map.forEach((key, value) -> {
|
||||
// String keyRaw = keyWriteFun.apply(key);
|
||||
// value.write(cfg, writePath + "." + keyRaw);
|
||||
// });
|
||||
// };
|
||||
//
|
||||
// // Linked map used only to preserve the order of default values when writing it in the config.
|
||||
// Map<K, V> defaultMap = new LinkedHashMap<>();
|
||||
// defaultValue.accept(defaultMap);
|
||||
//
|
||||
// return create(path, reader, writer, defaultMap, description);
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
// public static <K, V extends Writeable> ConfigValue<HashMap<K, V>> forHashMap(@NotNull String path,
|
||||
// @NotNull Function<String, K> keyReadFun,
|
||||
@@ -299,6 +337,15 @@ public class ConfigValue<T> {
|
||||
@NotNull BiFunction<FileConfig, String, V> valReadFun,
|
||||
@NotNull Consumer<Map<String, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
//return forMap(path, String::toLowerCase, key -> key, valReadFun, defaultValue, description);
|
||||
return forMapById(path, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <V extends Writeable> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
|
||||
@NotNull ReadFunction<V> valReadFun,
|
||||
@NotNull Consumer<Map<String, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
return forMap(path, String::toLowerCase, key -> key, valReadFun, defaultValue, description);
|
||||
}
|
||||
|
||||
@@ -308,6 +355,17 @@ public class ConfigValue<T> {
|
||||
@NotNull BiFunction<FileConfig, String, V> valReadFun,
|
||||
@NotNull Consumer<Map<E, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
//return forMap(path, str -> StringUtil.getEnum(str, clazz).orElse(null), Enum::name, valReadFun, defaultValue, description);
|
||||
|
||||
return forMapByEnum(path, clazz, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <E extends Enum<E>, V extends Writeable> ConfigValue<Map<E, V>> forMapByEnum(@NotNull String path,
|
||||
@NotNull Class<E> clazz,
|
||||
@NotNull ReadFunction<V> valReadFun,
|
||||
@NotNull Consumer<Map<E, V>> defaultValue,
|
||||
@Nullable String... description) {
|
||||
return forMap(path, str -> StringUtil.getEnum(str, clazz).orElse(null), Enum::name, valReadFun, defaultValue, description);
|
||||
}
|
||||
|
||||
@@ -337,6 +395,15 @@ public class ConfigValue<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigValue<T> whenRead(@NotNull Consumer<T> onRead) {
|
||||
this.onRead(object -> {
|
||||
onRead.accept(object);
|
||||
return object;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T read(@NotNull FileConfig config) {
|
||||
if (!config.contains(this.getPath())) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package su.nightexpress.nightcore.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ReadFunction<V> {
|
||||
|
||||
@Nullable V read(@NotNull FileConfig config, @NotNull String path, @NotNull String id);
|
||||
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import su.nightexpress.nightcore.menu.MenuListener;
|
||||
import su.nightexpress.nightcore.menu.impl.AbstractMenu;
|
||||
import su.nightexpress.nightcore.ui.UIListener;
|
||||
import su.nightexpress.nightcore.ui.dialog.DialogManager;
|
||||
import su.nightexpress.nightcore.ui.menu.Menu;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuRegistry;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -52,11 +52,10 @@ public class CoreManager extends AbstractManager<NightCore> {
|
||||
}
|
||||
});
|
||||
|
||||
MenuRegistry.getViewers().stream().map(MenuViewer::getMenu).distinct().forEach(menu -> {
|
||||
if (menu.isReadyToRefresh()) {
|
||||
menu.flush();
|
||||
menu.setAutoRefreshDate(TimeUtil.createFutureTimestamp(menu.getAutoRefreshInterval()));
|
||||
}
|
||||
});
|
||||
// if (menu.isReadyToRefresh()) {
|
||||
// menu.flush();
|
||||
// menu.setAutoRefreshIn(TimeUtil.createFutureTimestamp(menu.getAutoRefreshInterval()));
|
||||
// }
|
||||
MenuRegistry.getViewers().stream().map(MenuViewer::getMenu).distinct().forEach(Menu::tick);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package su.nightexpress.nightcore.manager;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
import su.nightexpress.nightcore.ui.menu.Menu;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightTask;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniTask;
|
||||
|
||||
@@ -13,12 +14,14 @@ import java.util.Set;
|
||||
public abstract class AbstractManager<P extends NightCorePlugin> extends SimpleManager<P> {
|
||||
|
||||
protected final Set<SimpeListener> listeners;
|
||||
protected final Set<Menu> menus;
|
||||
protected final List<UniTask> tasks;
|
||||
protected final List<NightTask> taskList;
|
||||
|
||||
public AbstractManager(@NotNull P plugin) {
|
||||
super(plugin);
|
||||
this.listeners = new HashSet<>();
|
||||
this.menus = new HashSet<>();
|
||||
this.tasks = new ArrayList<>();
|
||||
this.taskList = new ArrayList<>();
|
||||
}
|
||||
@@ -29,6 +32,8 @@ public abstract class AbstractManager<P extends NightCorePlugin> extends SimpleM
|
||||
this.tasks.clear();
|
||||
this.taskList.forEach(NightTask::stop);
|
||||
this.taskList.clear();
|
||||
this.menus.forEach(Menu::clear);
|
||||
this.menus.clear();
|
||||
this.listeners.forEach(SimpeListener::unregisterListeners);
|
||||
this.listeners.clear();
|
||||
super.shutdown();
|
||||
@@ -40,6 +45,12 @@ public abstract class AbstractManager<P extends NightCorePlugin> extends SimpleM
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <T extends Menu> T addMenu(@NotNull T menu) {
|
||||
this.menus.add(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
protected void addTask(@NotNull Runnable runnable, int interval) {
|
||||
this.addTask(NightTask.create(plugin, runnable, interval));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.function.Consumer;
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public interface Menu {
|
||||
|
||||
void tick();
|
||||
|
||||
void clear();
|
||||
|
||||
void flush();
|
||||
@@ -86,9 +88,9 @@ public interface Menu {
|
||||
|
||||
boolean isReadyToRefresh();
|
||||
|
||||
long getAutoRefreshDate();
|
||||
long getAutoRefreshIn();
|
||||
|
||||
void setAutoRefreshDate(long autoRefreshDate);
|
||||
void setAutoRefreshIn(long autoRefreshIn);
|
||||
|
||||
boolean isApplyPlaceholderAPI();
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ public class MenuRegistry {
|
||||
|
||||
private static final Map<UUID, MenuViewer> VIEWER_BY_ID = new HashMap<>();
|
||||
|
||||
public static void closeAll() {
|
||||
getViewers().stream().map(MenuViewer::getMenu).distinct().forEach(Menu::clear);
|
||||
VIEWER_BY_ID.clear();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<MenuViewer> getViewers() {
|
||||
return new HashSet<>(VIEWER_BY_ID.values());
|
||||
|
||||
@@ -20,7 +20,8 @@ public class MenuViewer {
|
||||
private int page;
|
||||
private int pages;
|
||||
private long lastClickTime;
|
||||
private boolean updateTitle;
|
||||
|
||||
private boolean rebuildMenu;
|
||||
|
||||
public MenuViewer(@NotNull Menu menu, @NotNull Player player) {
|
||||
this.menu = menu;
|
||||
@@ -50,6 +51,10 @@ public class MenuViewer {
|
||||
this.items.remove(menuItem);
|
||||
}
|
||||
|
||||
public boolean hasItem(@NotNull MenuItem menuItem) {
|
||||
return this.items.contains(menuItem);
|
||||
}
|
||||
|
||||
public void removeItems() {
|
||||
this.items.clear();
|
||||
}
|
||||
@@ -103,11 +108,11 @@ public class MenuViewer {
|
||||
this.lastClickTime = lastClickTime;
|
||||
}
|
||||
|
||||
public boolean isUpdateTitle() {
|
||||
return this.updateTitle;
|
||||
public boolean isRebuildMenu() {
|
||||
return this.rebuildMenu;
|
||||
}
|
||||
|
||||
public void setUpdateTitle(boolean updateTitle) {
|
||||
this.updateTitle = updateTitle;
|
||||
public void setRebuildMenu(boolean rebuildMenu) {
|
||||
this.rebuildMenu = rebuildMenu;
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,14 @@ import su.nightexpress.nightcore.ui.menu.item.ItemClick;
|
||||
import su.nightexpress.nightcore.ui.menu.item.ItemOptions;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface Linked<T> extends Menu {
|
||||
|
||||
boolean open(@NotNull Player player, @NotNull T obj);
|
||||
|
||||
boolean open(@NotNull Player player, @NotNull T obj, @NotNull Consumer<MenuViewer> onViewSet);
|
||||
|
||||
@NotNull LinkCache<T> getCache();
|
||||
|
||||
T getLink(@NotNull MenuViewer viewer);
|
||||
@@ -32,6 +36,10 @@ public interface Linked<T> extends Menu {
|
||||
|
||||
void addItem(@NotNull ItemStack itemStack, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler);
|
||||
|
||||
void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ItemHandler {
|
||||
(viewer, event) -> {
|
||||
if (viewer.getPage() < viewer.getPages()) {
|
||||
viewer.setPage(viewer.getPage() + 1);
|
||||
viewer.setUpdateTitle(true);
|
||||
viewer.setRebuildMenu(true);
|
||||
menu.flush(viewer.getPlayer());
|
||||
}
|
||||
},
|
||||
@@ -82,7 +82,7 @@ public class ItemHandler {
|
||||
(viewer, event) -> {
|
||||
if (viewer.getPage() > 1) {
|
||||
viewer.setPage(viewer.getPage() - 1);
|
||||
viewer.setUpdateTitle(true);
|
||||
viewer.setRebuildMenu(true);
|
||||
menu.flush(viewer.getPlayer());
|
||||
}
|
||||
},
|
||||
@@ -112,7 +112,7 @@ public class ItemHandler {
|
||||
|
||||
@NotNull
|
||||
public static <T> ItemHandler forLink(@NotNull Linked<T> menu, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
return new ItemHandler(randomName(), (viewer, event) -> menu.manageLink(handler), options);
|
||||
return new ItemHandler(randomName(), menu.manageLink(handler), options);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.view.builder.LocationInventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.NightPlugin;
|
||||
@@ -18,10 +19,12 @@ import su.nightexpress.nightcore.ui.menu.Menu;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuRegistry;
|
||||
import su.nightexpress.nightcore.ui.menu.MenuViewer;
|
||||
import su.nightexpress.nightcore.ui.menu.click.ClickResult;
|
||||
import su.nightexpress.nightcore.ui.menu.data.Linked;
|
||||
import su.nightexpress.nightcore.ui.menu.item.ItemHandler;
|
||||
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
|
||||
import su.nightexpress.nightcore.util.Lists;
|
||||
import su.nightexpress.nightcore.util.TimeUtil;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
import su.nightexpress.nightcore.util.bridge.ServerBridge;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
@@ -41,7 +44,7 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
protected String title;
|
||||
protected boolean persistent;
|
||||
protected int autoRefreshInterval;
|
||||
protected long autoRefreshDate;
|
||||
protected long autoRefreshIn;
|
||||
protected boolean applyPlaceholderAPI;
|
||||
|
||||
public AbstractMenu(@NotNull P plugin, @NotNull MenuType menuType, @NotNull String title) {
|
||||
@@ -53,6 +56,7 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
this.setPersistent(true);
|
||||
this.setApplyPlaceholderAPI(false);
|
||||
this.setAutoRefreshInterval(-1);
|
||||
this.setAutoRefreshIn(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,6 +83,20 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
this.onClose(viewer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.autoRefreshInterval > 0) {
|
||||
if (this.isReadyToRefresh()) {
|
||||
this.flush();
|
||||
this.setAutoRefreshIn(this.autoRefreshInterval);
|
||||
}
|
||||
|
||||
if (this.autoRefreshIn > 0) {
|
||||
this.autoRefreshIn--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runNextTick(@NotNull Runnable runnable) {
|
||||
this.plugin.runTask(task -> runnable.run());
|
||||
@@ -124,17 +142,33 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
viewer.removeItems();
|
||||
onViewSet.accept(viewer);
|
||||
|
||||
String title = NightMessage.asLegacy(this.getTitle(viewer));
|
||||
//String title = NightMessage.asLegacy(this.getTitle(viewer));
|
||||
|
||||
InventoryView view = viewer.getView();
|
||||
if (view == null) {
|
||||
view = this.menuType.typed().create(player, title);
|
||||
if (view == null || viewer.isRebuildMenu()) {
|
||||
|
||||
// Save cache so its not wiped by .openInventory call due to internal InventoryCloseEvent.
|
||||
if (view != null && this instanceof Linked<?> linked) {
|
||||
linked.getCache().addAnchor(player);
|
||||
}
|
||||
|
||||
if (Version.isAtLeast(Version.MC_1_21_3)) {
|
||||
var builder = this.menuType.typed().builder();
|
||||
// Stupid hack to bypass 9X3 (and probably other container-based) menu types to be bound to real container(s) at player's location.
|
||||
if (builder instanceof LocationInventoryViewBuilder<?> locationBuilder) {
|
||||
locationBuilder.location(player.getEyeLocation());
|
||||
}
|
||||
view = ServerBridge.createView(builder, this.getTitle(viewer), player);
|
||||
}
|
||||
else {
|
||||
view = this.menuType.typed().create(player, NightMessage.asLegacy(this.getTitle(viewer)));
|
||||
}
|
||||
viewer.assignInventory(view);
|
||||
player.openInventory(view);
|
||||
}
|
||||
else {
|
||||
view.getTopInventory().clear();
|
||||
if (viewer.isUpdateTitle()) view.setTitle(title);
|
||||
//if (viewer.isUpdateTitle()) view.setTitle(NightMessage.asLegacy(this.getTitle(viewer)));
|
||||
}
|
||||
|
||||
this.onPrepare(viewer, view);
|
||||
@@ -153,6 +187,8 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
handler.getOptions().modifyDisplay(viewer, item);
|
||||
}
|
||||
|
||||
this.onItemPrepare(viewer, menuItem, item);
|
||||
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
|
||||
for (int slot : menuItem.getSlots()) {
|
||||
@@ -171,6 +207,10 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
|
||||
protected abstract void onReady(@NotNull MenuViewer viewer, @NotNull Inventory inventory);
|
||||
|
||||
protected void onItemPrepare(@NotNull MenuViewer viewer, @NotNull MenuItem menuItem, @NotNull NightItem item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(@NotNull MenuViewer viewer, @NotNull ClickResult result, @NotNull InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
@@ -334,21 +374,22 @@ public abstract class AbstractMenu<P extends NightPlugin> implements Menu {
|
||||
@Override
|
||||
public void setAutoRefreshInterval(int autoRefreshInterval) {
|
||||
this.autoRefreshInterval = autoRefreshInterval;
|
||||
this.setAutoRefreshIn(autoRefreshInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAutoRefreshDate() {
|
||||
return this.autoRefreshDate;
|
||||
public long getAutoRefreshIn() {
|
||||
return this.autoRefreshIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoRefreshDate(long autoRefreshDate) {
|
||||
this.autoRefreshDate = autoRefreshDate;
|
||||
public void setAutoRefreshIn(long autoRefreshIn) {
|
||||
this.autoRefreshIn = autoRefreshIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyToRefresh() {
|
||||
return this.autoRefreshInterval > 0 && TimeUtil.isPassed(this.autoRefreshDate);
|
||||
return /*this.autoRefreshInterval > 0 && */this.autoRefreshIn == 0L;//TimeUtil.isPassed(this.autoRefreshIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,8 @@ import su.nightexpress.nightcore.ui.menu.item.ItemOptions;
|
||||
import su.nightexpress.nightcore.ui.menu.item.MenuItem;
|
||||
import su.nightexpress.nightcore.util.bukkit.NightItem;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public abstract class LinkedMenu<P extends NightPlugin, T> extends AbstractMenu<P> implements Linked<T> {
|
||||
|
||||
@@ -61,8 +63,14 @@ public abstract class LinkedMenu<P extends NightPlugin, T> extends AbstractMenu<
|
||||
|
||||
@Override
|
||||
public boolean open(@NotNull Player player, @NotNull T obj) {
|
||||
return this.open(player, obj, viewer -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean open(@NotNull Player player, @NotNull T obj, @NotNull Consumer<MenuViewer> onViewSet) {
|
||||
return this.open(player, viewer -> {
|
||||
this.cache.set(player, obj);
|
||||
onViewSet.accept(viewer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,6 +110,16 @@ public abstract class LinkedMenu<P extends NightPlugin, T> extends AbstractMenu<
|
||||
this.addItem(new NightItem(itemStack).localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(item, locale, slot, handler, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, @NotNull LangItem locale, int slot, @NotNull LinkHandler<T> handler, @Nullable ItemOptions options) {
|
||||
this.addItem(item.localized(locale), slot, handler, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(@NotNull NightItem item, int slot, @NotNull LinkHandler<T> handler) {
|
||||
this.addItem(item, slot, handler, null);
|
||||
|
||||
@@ -29,7 +29,18 @@ public class ItemUtil {
|
||||
@NotNull
|
||||
public static String getItemName(@NotNull ItemStack item) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
return (meta == null || !meta.hasDisplayName()) ? LangAssets.get(item.getType()) : meta.getDisplayName();
|
||||
if (meta != null) {
|
||||
if (Version.isAtLeast(Version.MC_1_21) && meta.hasItemName()) {
|
||||
// MiniMessage.miniMessage().serialize(meta.itemName()));
|
||||
return meta.getItemName();
|
||||
}
|
||||
else if (meta.hasDisplayName()) {
|
||||
// MiniMessage.miniMessage().serialize(meta.displayName()));
|
||||
return meta.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
return LangAssets.get(item.getType());
|
||||
}
|
||||
|
||||
public static void editMeta(@NotNull ItemStack item, @NotNull Consumer<ItemMeta> function) {
|
||||
|
||||
@@ -269,7 +269,7 @@ public class StringUtil {
|
||||
|
||||
@NotNull
|
||||
public static String transformForID(@NotNull String str, int length) {
|
||||
char[] chars = str.toCharArray();
|
||||
char[] chars = str.toLowerCase().toCharArray();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int index = 0; index < chars.length; index++) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class PaperBridge {
|
||||
|
||||
public static InventoryView create(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
Component component = JSONComponentSerializer.json().deserialize(NightMessage.asJson(title)); // TODO Direct NightMessage to component
|
||||
|
||||
return builder.title(component).build(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ServerBridge {
|
||||
|
||||
@NotNull
|
||||
public static InventoryView createView(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
if (Version.isSpigot()) {
|
||||
return SpigotBridge.create(builder, title, player);
|
||||
}
|
||||
else {
|
||||
return PaperBridge.create(builder, title, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package su.nightexpress.nightcore.util.bridge;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.view.builder.InventoryViewBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.Reflex;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class SpigotBridge {
|
||||
|
||||
public static InventoryView create(@NotNull InventoryViewBuilder<?> builder, @NotNull String title, @NotNull Player player) {
|
||||
Reflex.setFieldValue(builder, "title", NightMessage.asLegacy(title));
|
||||
return builder.build(player);//menuType.typed().builder().title(title).build(player);
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,12 @@ public class NightItem implements Writeable {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightItem setReplacer(@Nullable Replacer replacer) {
|
||||
this.meta.setReplacer(replacer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NightItem replacement(@NotNull Consumer<Replacer> consumer) {
|
||||
this.meta.replacement(consumer);
|
||||
|
||||
@@ -147,7 +147,7 @@ public class Replacer {
|
||||
public Replacer replacePlaceholderAPI(@NotNull Player player) {
|
||||
if (!Plugins.hasPlaceholderAPI()) return this;
|
||||
|
||||
return this.replace(line -> PlaceholderAPI.setPlaceholders(player, line));
|
||||
return this.replaceOperator(line -> PlaceholderAPI.setPlaceholders(player, line));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -160,28 +160,43 @@ public class Replacer {
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull String key, @NotNull List<String> replacer) {
|
||||
return this.replace(key, () -> String.join(Placeholders.TAG_LINE_BREAK, replacer));
|
||||
return this.replacePlaceholder(key, () -> String.join(Placeholders.TAG_LINE_BREAK, replacer));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> Replacer replace(@NotNull T source, @NotNull PlaceholderList<T> placeholders) {
|
||||
return this.replace(placeholders.replacer(source));
|
||||
return this.replaceOperator(placeholders.replacer(source));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull String key, @NotNull Supplier<String> value) {
|
||||
return this.replacePlaceholder(key, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull String key, @NotNull Object value) {
|
||||
return this.replacePlaceholder(key, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull UnaryOperator<String> replacer) {
|
||||
return this.replaceOperator(replacer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Replacer replacePlaceholder(@NotNull String key, @NotNull Supplier<String> value) {
|
||||
this.placeholders.add(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull String key, @NotNull Object value) {
|
||||
private Replacer replacePlaceholder(@NotNull String key, @NotNull Object value) {
|
||||
this.placeholders.add(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Replacer replace(@NotNull UnaryOperator<String> replacer) {
|
||||
private Replacer replaceOperator(@NotNull UnaryOperator<String> replacer) {
|
||||
this.replacers.add(replacer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,17 @@ public class Tags {
|
||||
public static final ShortHexColorTag HEX_COLOR_SHORT = new ShortHexColorTag();
|
||||
public static final TranslationTag TRANSLATE = new TranslationTag();
|
||||
|
||||
public static final FontStyleTag BOLD = new FontStyleTag("b", new String[]{"bold"}, FontStyleTag.Style.BOLD);
|
||||
public static final FontStyleTag ITALIC = new FontStyleTag("i", new String[]{"em", "italic"}, FontStyleTag.Style.ITALIC);
|
||||
public static final FontStyleTag OBFUSCATED = new FontStyleTag("o", new String[]{"obfuscated", "obf"}, FontStyleTag.Style.OBFUSCATED);
|
||||
public static final FontStyleTag STRIKETHROUGH = new FontStyleTag("s", new String[]{"strikethrough", "st"}, FontStyleTag.Style.STRIKETHROUGH);
|
||||
public static final FontStyleTag UNDERLINED = new FontStyleTag("u", new String[]{"underlined"}, FontStyleTag.Style.UNDERLINED);
|
||||
public static final FontStyleTag BOLD = new FontStyleTag("b", new String[]{"bold"}, FontStyleTag.Style.BOLD, false);
|
||||
public static final FontStyleTag ITALIC = new FontStyleTag("i", new String[]{"em", "italic"}, FontStyleTag.Style.ITALIC, false);
|
||||
public static final FontStyleTag OBFUSCATED = new FontStyleTag("o", new String[]{"obfuscated", "obf"}, FontStyleTag.Style.OBFUSCATED, false);
|
||||
public static final FontStyleTag STRIKETHROUGH = new FontStyleTag("s", new String[]{"strikethrough", "st"}, FontStyleTag.Style.STRIKETHROUGH, false);
|
||||
public static final FontStyleTag UNDERLINED = new FontStyleTag("u", new String[]{"underlined"}, FontStyleTag.Style.UNDERLINED, false);
|
||||
|
||||
public static final FontStyleTag UNBOLD = BOLD.inverted();
|
||||
public static final FontStyleTag UNITALIC = ITALIC.inverted();
|
||||
public static final FontStyleTag UNOBFUSCATED = OBFUSCATED.inverted();
|
||||
public static final FontStyleTag UNSTRIKETHROUGH = STRIKETHROUGH.inverted();
|
||||
public static final FontStyleTag UNUNDERLINED = UNDERLINED.inverted();
|
||||
|
||||
public static final ColorTag BLACK = new ColorTag("black", "#000000");
|
||||
public static final ColorTag WHITE = new ColorTag("white", "#ffffff");
|
||||
@@ -69,7 +75,10 @@ public class Tags {
|
||||
Tags.LIGHT_BLUE, Tags.LIGHT_CYAN, Tags.LIGHT_PURPLE, Tags.LIGHT_PINK
|
||||
);
|
||||
|
||||
registerTags(Tags.BOLD, Tags.ITALIC, Tags.OBFUSCATED, Tags.STRIKETHROUGH, Tags.UNDERLINED);
|
||||
registerTags(
|
||||
Tags.BOLD, Tags.ITALIC, Tags.OBFUSCATED, Tags.STRIKETHROUGH, Tags.UNDERLINED,
|
||||
Tags.UNBOLD, Tags.UNITALIC, Tags.UNOBFUSCATED, Tags.UNSTRIKETHROUGH, Tags.UNUNDERLINED
|
||||
);
|
||||
|
||||
registerTags(Tags.GRADIENT, Tags.LINE_BREAK, Tags.FONT, Tags.HOVER, Tags.CLICK,
|
||||
Tags.RESET, Tags.HEX_COLOR, Tags.HEX_COLOR_SHORT, Tags.TRANSLATE);
|
||||
|
||||
@@ -7,19 +7,30 @@ import su.nightexpress.nightcore.util.text.tag.decorator.Decorator;
|
||||
|
||||
public class FontStyleTag extends SimpleTag implements Decorator {
|
||||
|
||||
private static final String INVERT_SIGN = "!";
|
||||
|
||||
public enum Style {
|
||||
BOLD, ITALIC, UNDERLINED, STRIKETHROUGH, OBFUSCATED
|
||||
}
|
||||
|
||||
private final Style style;
|
||||
private final boolean inverted;
|
||||
|
||||
public FontStyleTag(@NotNull String name, @NotNull Style style) {
|
||||
this(name, new String[0], style);
|
||||
public FontStyleTag(@NotNull String name, @NotNull Style style, boolean inverted) {
|
||||
this(name, new String[0], style, inverted);
|
||||
}
|
||||
|
||||
public FontStyleTag(@NotNull String name, String[] aliases, @NotNull Style style) {
|
||||
public FontStyleTag(@NotNull String name, String[] aliases, @NotNull Style style, boolean inverted) {
|
||||
super(name, aliases);
|
||||
this.style = style;
|
||||
this.inverted = inverted;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FontStyleTag inverted() {
|
||||
String[] aliases = this.aliases.stream().map(alias -> INVERT_SIGN + alias).toArray(String[]::new);
|
||||
|
||||
return new FontStyleTag(aliases[0], aliases, this.style, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -30,11 +41,11 @@ public class FontStyleTag extends SimpleTag implements Decorator {
|
||||
@Override
|
||||
public void decorate(@NotNull BaseComponent component) {
|
||||
switch (this.style) {
|
||||
case BOLD -> component.setBold(true);
|
||||
case ITALIC -> component.setItalic(true);
|
||||
case OBFUSCATED -> component.setObfuscated(true);
|
||||
case UNDERLINED -> component.setUnderlined(true);
|
||||
case STRIKETHROUGH -> component.setStrikethrough(true);
|
||||
case BOLD -> component.setBold(!this.inverted);
|
||||
case ITALIC -> component.setItalic(!this.inverted);
|
||||
case OBFUSCATED -> component.setObfuscated(!this.inverted);
|
||||
case UNDERLINED -> component.setUnderlined(!this.inverted);
|
||||
case STRIKETHROUGH -> component.setStrikethrough(!this.inverted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ public class HexColorTag extends Tag implements ContentTag {
|
||||
super(NAME, new String[]{"colour", "c"});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String enclose(@NotNull String text, @NotNull String hex) {
|
||||
return brackets(this.name + ":" + hex) + text + closedBrackets(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BaseColorDecorator parse(@NotNull String tagContent) {
|
||||
|
||||
@@ -89,6 +89,9 @@ public class UniParticle {
|
||||
double size = config.getDouble(path + ".Size", 1D);
|
||||
data = new Particle.DustOptions(color, (float) size);
|
||||
}
|
||||
else if (dataType == Color.class) {
|
||||
data = StringUtil.getColor(config.getString(path + ".Color", ""));
|
||||
}
|
||||
else if (dataType == Particle.DustTransition.class) {
|
||||
Color colorStart = StringUtil.getColor(config.getString(path + ".Color_From", ""));
|
||||
Color colorEnd = StringUtil.getColor(config.getString(path + ".Color_To", ""));
|
||||
@@ -129,6 +132,9 @@ public class UniParticle {
|
||||
config.set(path + ".Color", color.getRed() + "," + color.getGreen() + "," + color.getBlue());
|
||||
config.set(path + ".Size", dustOptions.getSize());
|
||||
}
|
||||
else if (data instanceof Color color) {
|
||||
config.set(path + ".Color", color.getRed() + "," + color.getGreen() + "," + color.getBlue());
|
||||
}
|
||||
else if (data instanceof ItemStack item) {
|
||||
config.setItem(path + ".Item", item);
|
||||
}
|
||||
@@ -165,6 +171,9 @@ public class UniParticle {
|
||||
else if (dataType == Particle.DustOptions.class) {
|
||||
this.data = new Particle.DustOptions(Color.WHITE, 1F);
|
||||
}
|
||||
else if (dataType == Color.class) {
|
||||
this.data = Color.WHITE;
|
||||
}
|
||||
else if (dataType == Particle.DustTransition.class) {
|
||||
this.data = new Particle.DustTransition(Color.BLACK, Color.WHITE, 1F);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user