mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-01 22:16:36 +00:00
patches and additions
This commit is contained in:
1 parent
972acb7979
commit
407f3ccf0b
17 files changed
+151
-43
No files matched your search
@@ -8,7 +8,6 @@ import su.nightexpress.nightcore.command.api.NightPluginCommand;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
import su.nightexpress.nightcore.config.PluginDetails;
|
||||
import su.nightexpress.nightcore.language.LangManager;
|
||||
import su.nightexpress.nightcore.menu.api.Menu;
|
||||
import su.nightexpress.nightcore.menu.impl.AbstractMenu;
|
||||
import su.nightexpress.nightcore.util.Lists;
|
||||
import su.nightexpress.nightcore.util.Plugins;
|
||||
@@ -161,7 +160,7 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
this.disable();
|
||||
|
||||
HandlerList.unregisterAll(this); // Unregister all plugin listeners.
|
||||
AbstractMenu.PLAYER_MENUS.values().forEach(Menu::close); // Close all GUIs.
|
||||
AbstractMenu.closeAll(); // Close all GUIs.
|
||||
|
||||
this.getCommandManager().shutdown();
|
||||
this.getLangManager().shutdown();
|
||||
|
||||
@@ -77,5 +77,6 @@ public class CoreConfig {
|
||||
UniFormatter.of("#,###.##", RoundingMode.HALF_EVEN),
|
||||
"Control over how numerical data is formatted and rounded.",
|
||||
"Allowed modes: " + Arrays.stream(RoundingMode.values()).map(RoundingMode::name).map(String::toLowerCase).collect(Collectors.joining(", ")),
|
||||
"A tutorial can be found here: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html");
|
||||
"A tutorial can be found here: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html"
|
||||
);
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface DialogHandler {
|
||||
|
||||
boolean onInput(@NotNull WrappedInput input);
|
||||
boolean onInput(@NotNull Dialog dialog, @NotNull WrappedInput input);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class DialogListener extends AbstractListener<NightCore> {
|
||||
WrappedInput input = new WrappedInput(event);
|
||||
|
||||
this.plugin.runTask(task -> {
|
||||
if (input.getTextRaw().equalsIgnoreCase(Dialog.EXIT) || dialog.getHandler().onInput(input)) {
|
||||
if (input.getTextRaw().equalsIgnoreCase(Dialog.EXIT) || dialog.getHandler().onInput(dialog, input)) {
|
||||
Dialog.stop(player);
|
||||
}
|
||||
});
|
||||
@@ -65,7 +65,7 @@ public class DialogListener extends AbstractListener<NightCore> {
|
||||
WrappedInput input = new WrappedInput(chatEvent);
|
||||
|
||||
this.plugin.runTask(task -> {
|
||||
if (input.getTextRaw().equalsIgnoreCase(Dialog.EXIT) || dialog.getHandler().onInput(input)) {
|
||||
if (input.getTextRaw().equalsIgnoreCase(Dialog.EXIT) || dialog.getHandler().onInput(dialog, input)) {
|
||||
Dialog.stop(player);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -106,13 +106,13 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
||||
return wrappedLore;
|
||||
}
|
||||
|
||||
protected static final String LMB = "Left-Click";
|
||||
protected static final String RMB = "Right-Click";
|
||||
protected static final String DROP_KEY = "[Q] Drop Key";
|
||||
protected static final String SWAP_KEY = "[F] Swap Key";
|
||||
protected static final String SHIFT_LMB = "Shift-Left";
|
||||
protected static final String SHIFT_RMB = "Shift-Right";
|
||||
protected static final String DRAG_DROP = "Drag & Drop";
|
||||
public static final String LMB = "Left-Click";
|
||||
public static final String RMB = "Right-Click";
|
||||
public static final String DROP_KEY = "[Q] Drop Key";
|
||||
public static final String SWAP_KEY = "[F] Swap Key";
|
||||
public static final String SHIFT_LMB = "Shift-Left";
|
||||
public static final String SHIFT_RMB = "Shift-Right";
|
||||
public static final String DRAG_DROP = "Drag & Drop";
|
||||
|
||||
@NotNull
|
||||
public static Builder builder(@NotNull String key) {
|
||||
@@ -162,7 +162,7 @@ public class LangItem extends LangEntry<Pair<String, List<String>>> {
|
||||
|
||||
@NotNull
|
||||
public Builder current(@NotNull String type, @NotNull String value) {
|
||||
return this.addLore(Tags.YELLOW.enclose("▪ " + Tags.GRAY.enclose(type) + ": " + value));
|
||||
return this.addLore(Tags.YELLOW.enclose("▪ " + Tags.GRAY.enclose(type + ": ") + value));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.util.Colorizer;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@@ -35,12 +35,11 @@ public class MenuOptions {
|
||||
|
||||
@NotNull
|
||||
public Inventory createInventory() {
|
||||
String title = this.getTitle();
|
||||
if (this.getType() == InventoryType.CHEST) {
|
||||
return Bukkit.getServer().createInventory(null, this.getSize(), title);
|
||||
return Bukkit.getServer().createInventory(null, this.getSize(), this.getTitleFormatted());
|
||||
}
|
||||
else {
|
||||
return Bukkit.getServer().createInventory(null, this.getType(), title);
|
||||
return Bukkit.getServer().createInventory(null, this.getType(), this.getTitleFormatted());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +48,13 @@ public class MenuOptions {
|
||||
return title;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTitleFormatted() {
|
||||
return NightMessage.asLegacy(this.getTitle());
|
||||
}
|
||||
|
||||
public void setTitle(@NotNull String title) {
|
||||
this.title = Colorizer.apply(title);
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void editTitle(@NotNull UnaryOperator<String> function) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MenuViewer {
|
||||
this.inventory.clear();
|
||||
|
||||
if (Version.isAtLeast(Version.V1_19_R3)) {
|
||||
this.view.setTitle(options.getTitle());
|
||||
this.view.setTitle(options.getTitleFormatted());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ public abstract class AbstractMenu<P extends NightCorePlugin> implements Menu {
|
||||
|
||||
public static final Map<UUID, Menu> PLAYER_MENUS = new HashMap<>();
|
||||
|
||||
public static void closeAll() {
|
||||
new HashSet<>(PLAYER_MENUS.values()).forEach(Menu::close);
|
||||
}
|
||||
|
||||
protected final P plugin;
|
||||
protected final UUID id;
|
||||
protected final MenuOptions options;
|
||||
|
||||
@@ -2,7 +2,6 @@ package su.nightexpress.nightcore.menu.impl;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.NightCorePlugin;
|
||||
@@ -17,9 +16,12 @@ import su.nightexpress.nightcore.menu.item.ItemHandler;
|
||||
import su.nightexpress.nightcore.menu.item.MenuItem;
|
||||
import su.nightexpress.nightcore.menu.link.Linked;
|
||||
import su.nightexpress.nightcore.menu.link.ViewLink;
|
||||
import su.nightexpress.nightcore.util.ItemReplacer;
|
||||
import su.nightexpress.nightcore.util.ItemUtil;
|
||||
import su.nightexpress.nightcore.util.text.WrappedMessage;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractMenu<P> implements Linked<T> {
|
||||
|
||||
protected final ViewLink<T> link;
|
||||
@@ -77,12 +79,7 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
|
||||
@NotNull
|
||||
public MenuItem addItem(@NotNull ItemStack item, @NotNull LangItem locale, int... slots) {
|
||||
ItemUtil.editMeta(item, meta -> {
|
||||
meta.setDisplayName(locale.getLocalizedName());
|
||||
meta.setLore(locale.getLocalizedLore());
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
});
|
||||
|
||||
ItemReplacer.create(item).trimmed().hideFlags().readLocale(locale).writeMeta();
|
||||
MenuItem menuItem = new MenuItem(item).setPriority(100).setSlots(slots);
|
||||
this.addItem(menuItem);
|
||||
return menuItem;
|
||||
@@ -98,12 +95,14 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
this.handleInput(player, prompt.getString(), handler);
|
||||
}
|
||||
|
||||
public void handleInput(@NotNull MenuViewer viewer, @NotNull LangString prompt, @NotNull DialogHandler handler) {
|
||||
this.handleInput(viewer.getPlayer(), prompt, handler);
|
||||
@NotNull
|
||||
public Dialog handleInput(@NotNull MenuViewer viewer, @NotNull LangString prompt, @NotNull DialogHandler handler) {
|
||||
return this.handleInput(viewer.getPlayer(), prompt, handler);
|
||||
}
|
||||
|
||||
public void handleInput(@NotNull Player player, @NotNull LangString prompt, @NotNull DialogHandler handler) {
|
||||
this.handleInput(player, prompt.getString(), handler);
|
||||
@NotNull
|
||||
public Dialog handleInput(@NotNull Player player, @NotNull LangString prompt, @NotNull DialogHandler handler) {
|
||||
return this.handleInput(player, prompt.getMessage(), handler);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -124,8 +123,21 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void editObject(@NotNull MenuViewer viewer, @NotNull Consumer<T> consumer) {
|
||||
this.editObject(viewer.getPlayer(), consumer);
|
||||
}
|
||||
|
||||
public void editObject(@NotNull Player player, @NotNull Consumer<T> consumer) {
|
||||
consumer.accept(this.getObject(player));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getObject(@NotNull MenuViewer viewer) {
|
||||
return this.getLink().get(viewer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getObject(@NotNull Player player) {
|
||||
return this.getLink().get(player);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import su.nightexpress.nightcore.util.Placeholders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ItemHandler {
|
||||
@@ -44,6 +45,18 @@ public class ItemHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main purpose of this method is to quickly created ItemHandler object for non-configurable GUIs.
|
||||
* <br><br>
|
||||
* Do NOT use this for items requires specific handler name.
|
||||
* @param action Click action
|
||||
* @return ItemHandler with random UUID as a name.
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemHandler forClick(@NotNull ClickAction action) {
|
||||
return new ItemHandler(UUID.randomUUID().toString(), action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ItemHandler forNextPage(@NotNull Menu menu) {
|
||||
return new ItemHandler(NEXT_PAGE,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package su.nightexpress.nightcore.util;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BukkitThing {
|
||||
|
||||
@Nullable
|
||||
public static <T extends Keyed> T fromRegistry(@NotNull Registry<T> registry, @NotNull String key) {
|
||||
key = StringUtil.lowerCaseUnderscoreStrict(key);
|
||||
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
return registry.get(namespacedKey);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Material getMaterial(@NotNull String name) {
|
||||
return fromRegistry(Registry.MATERIAL, name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Enchantment getEnchantment(@NotNull String name) {
|
||||
if (Version.isBehind(Version.V1_19_R3)) {
|
||||
return Enchantment.getByKey(NamespacedKey.minecraft(StringUtil.lowerCaseUnderscoreStrict(name)));
|
||||
}
|
||||
return fromRegistry(Registry.ENCHANTMENT, name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static EntityType getEntityType(@NotNull String name) {
|
||||
return fromRegistry(Registry.ENTITY_TYPE, name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Attribute getAttribute(@NotNull String name) {
|
||||
return fromRegistry(Registry.ATTRIBUTE, name);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.util.placeholder.PlaceholderMap;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
import su.nightexpress.nightcore.util.text.tag.Tags;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -67,7 +68,7 @@ public class ItemReplacer {
|
||||
this.replace(this.placeholderMap.replacer());
|
||||
|
||||
this.meta.setDisplayName(this.getDisplayName() == null ? null : NightMessage.asLegacy(this.getDisplayName()));
|
||||
this.meta.setLore(NightMessage.asLegacy(this.packTrimmedLore()));
|
||||
this.meta.setLore(this.packTrimmedLore());
|
||||
|
||||
if (this.isHideFlags()) {
|
||||
this.meta.addItemFlags(ItemFlag.values());
|
||||
@@ -179,7 +180,17 @@ public class ItemReplacer {
|
||||
public ItemReplacer replaceLoreExact(@NotNull String placeholder, @NotNull List<String> replacer) {
|
||||
if (this.getLore() == null) return this;
|
||||
|
||||
this.setLore(Lists.replace(this.packLore(), placeholder, replacer));
|
||||
this.replace(placeholder, () -> String.join(Tags.LINE_BREAK.getFullName(), replacer));
|
||||
//this.setLore(Lists.replace(this.packLore(), placeholder, replacer));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemReplacer replaceLore(@NotNull String placeholder, @NotNull Supplier<List<String>> replacer) {
|
||||
//if (this.getLore() == null) return this;
|
||||
|
||||
this.replace(placeholder, () -> String.join(Tags.LINE_BREAK.getFullName(), replacer.get()));
|
||||
//this.setLore(Lists.replace(this.packLore(), placeholder, replacer));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -210,7 +221,7 @@ public class ItemReplacer {
|
||||
|
||||
@NotNull
|
||||
public List<String> packTrimmedLore() {
|
||||
List<String> lore = this.packLore();
|
||||
List<String> lore = NightMessage.asLegacy(this.packLore());
|
||||
if (this.isTrimLore()) {
|
||||
lore = Lists.stripEmpty(lore);
|
||||
}
|
||||
|
||||
@@ -167,8 +167,9 @@ public class Lists {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static String getEnums(@NotNull Class<? extends Enum<?>> clazz, @NotNull String delimiter) {
|
||||
return String.join(delimiter, getEnums(clazz));
|
||||
return StringUtil.inlineEnum(clazz, delimiter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -99,7 +99,8 @@ public class NumberUtil {
|
||||
if (!Double.isNaN(amount) && !Double.isInfinite(amount)) {
|
||||
return amount;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
catch (NumberFormatException ignored) {}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -115,7 +116,8 @@ public class NumberUtil {
|
||||
public static int getAnyInteger(@NotNull String input, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(input);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
catch (NumberFormatException ignored) {}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -63,14 +63,22 @@ public class RankMap<T extends Number> {
|
||||
cfg.remove(path);
|
||||
}
|
||||
|
||||
Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK).read(cfg);
|
||||
String permissionPrefix = ConfigValue.create(path + ".Permission_Prefix", "sample.prefix.").read(cfg);
|
||||
Mode mode = ConfigValue.create(path + ".Mode", Mode.class, Mode.RANK,
|
||||
"Available values: " + StringUtil.inlineEnum(Mode.class, ", "),
|
||||
"RANK = Get value by player's permission group. All 'Values' keys will represent permission group names.",
|
||||
"PERMISSION = Get value by player's permissions. All 'Values' keys will become as suffix for 'Permission_Prefix' setting."
|
||||
).read(cfg);
|
||||
|
||||
String permissionPrefix = ConfigValue.create(path + ".Permission_Prefix", "sample.prefix.",
|
||||
"Sets permission prefix for the 'PERMISSION' mode.",
|
||||
"All 'Values' keys will be used to check if player has permission: <permission_prefix> + <key>."
|
||||
).read(cfg);
|
||||
|
||||
T defaultValue;
|
||||
if (clazz == Double.class) {
|
||||
defaultValue = clazz.cast(cfg.getDouble(path + ".Default_Value"));
|
||||
defaultValue = clazz.cast(ConfigValue.create(path + ".Default_Value", -1).read(cfg));
|
||||
}
|
||||
else defaultValue = clazz.cast(cfg.getInt(path + ".Default_Value"));
|
||||
else defaultValue = clazz.cast(ConfigValue.create(path + ".Default_Value", -1).read(cfg));
|
||||
|
||||
Map<String, T> values = new HashMap<>();
|
||||
for (String rank : cfg.getSection(path + ".Values")) {
|
||||
@@ -89,6 +97,7 @@ public class RankMap<T extends Number> {
|
||||
public void write(@NotNull FileConfig cfg, @NotNull String path) {
|
||||
cfg.set(path + ".Mode", this.getMode().name());
|
||||
cfg.set(path + ".Permission_Prefix", this.getPermissionPrefix());
|
||||
cfg.set(path + ".Default_Value", this.getDefaultValue());
|
||||
this.values.forEach((rank, number) -> {
|
||||
cfg.set(path + ".Values." + rank, number);
|
||||
});
|
||||
@@ -97,7 +106,7 @@ public class RankMap<T extends Number> {
|
||||
@NotNull
|
||||
public T getRankValue(@NotNull Player player) {
|
||||
String group = Players.getPermissionGroup(player);
|
||||
return this.values.getOrDefault(group, this.getDefaultValue());
|
||||
return this.values.getOrDefault(group, this.values.getOrDefault(Placeholders.DEFAULT, this.getDefaultValue()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -111,6 +111,11 @@ public class StringUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String inlineEnum(@NotNull Class<? extends Enum<?>> clazz, @NotNull String delimiter) {
|
||||
return String.join(delimiter, Lists.getEnums(clazz));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Color getColor(@NotNull String str) {
|
||||
String[] rgb = str.split(",");
|
||||
|
||||
@@ -23,7 +23,7 @@ public class NightMessage {
|
||||
|
||||
static {
|
||||
registerTags(
|
||||
Tags.WHITE, Tags.GRAY, Tags.GREEN,
|
||||
Tags.BLACK, Tags.WHITE, Tags.GRAY, Tags.GREEN,
|
||||
Tags.YELLOW, Tags.ORANGE, Tags.RED,
|
||||
Tags.BLUE, Tags.CYAN, Tags.PURPLE, Tags.PINK,
|
||||
|
||||
@@ -230,6 +230,8 @@ public class NightMessage {
|
||||
|
||||
//System.out.println("parsedTexts = " + parts);
|
||||
|
||||
parts.removeIf(wrappedText -> wrappedText.getText().isEmpty());
|
||||
|
||||
fixGradients(parts);
|
||||
|
||||
ComponentBuilder builder = new ComponentBuilder();
|
||||
|
||||
Reference in new issue
Block a user