mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-03 22:16:57 +00:00
v2.6.4
This commit is contained in:
1 parent
454c1c92db
commit
6a88a81a24
28 files changed
+462
-215
No files matched your search
@@ -57,6 +57,7 @@ public class NightCore extends NightPlugin implements ImprovedCommands {
|
||||
VaultHook.shutdown();
|
||||
}
|
||||
PlayerBlockTracker.shutdown();
|
||||
LangAssets.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@ import su.nightexpress.nightcore.util.*;
|
||||
import su.nightexpress.nightcore.util.wrapper.UniPermission;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin {
|
||||
|
||||
@@ -40,18 +39,28 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
|
||||
Version version = Version.getCurrent();
|
||||
if (version == Version.UNKNOWN) {
|
||||
this.warn("=".repeat(35));
|
||||
this.warn("WARNING: You're running an unsupported server version!");
|
||||
this.warn("WARNING: The plugin is not yet compatible with your server version!");
|
||||
this.warn("Expect bugs and broken features.");
|
||||
this.warn("! NO DISCORD SUPPORT WILL BE GIVEN !");
|
||||
this.warn("ABSOLUTELY NO DISCORD SUPPORT WILL BE PROVIDED!");
|
||||
this.warn("=".repeat(35));
|
||||
}
|
||||
else if (version.isDeprecated()) {
|
||||
this.warn("=".repeat(35));
|
||||
this.warn("WARNING: You're running an outdated/deprecated server version (" + Version.getCurrent().getLocalized() + ")!");
|
||||
this.warn("Support for this version will be dropped soon.");
|
||||
this.warn("Please, upgrade your server to at least " + Lists.next(Version.getCurrent(), Predicate.not(Version::isDeprecated)).getLocalized() + ".");
|
||||
this.warn("WARNING: You're running an outdated server version (" + Version.getCurrent().getLocalized() + ")!");
|
||||
this.warn("This version will no longer be supported in future relases.");
|
||||
this.warn("Please upgrade your server to " + Lists.next(Version.getCurrent(), (Version::isSupported)).getLocalized() + ".");
|
||||
this.warn("NO DISCORD SUPPORT WILL BE PROVIDED!");
|
||||
this.warn("=".repeat(35));
|
||||
}
|
||||
else if (version.isDropped()) {
|
||||
this.error("=".repeat(35));
|
||||
this.error("ERROR: You're running an unsupported server version (" + Version.getCurrent().getLocalized() + ")!");
|
||||
this.error("Please upgrade your server to " + Lists.next(Version.getCurrent(), (Version::isSupported)).getLocalized() + ".");
|
||||
this.error("ABSOLUTELY NO DISCORD SUPPORT WILL BE PROVIDED!");
|
||||
this.error("=".repeat(35));
|
||||
this.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadManagers();
|
||||
this.info("Plugin loaded in " + (System.currentTimeMillis() - loadTook) + " ms!");
|
||||
|
||||
+1
-13
@@ -26,18 +26,6 @@ public class CommandArgument<T> {
|
||||
private final Function<TabContext, List<String>> samples;
|
||||
private final LangMessage failureMessage;
|
||||
|
||||
// @Deprecated
|
||||
// public CommandArgument(@NotNull String name,
|
||||
// @NotNull Function<String, T> parser,
|
||||
// boolean required,
|
||||
// boolean complex,
|
||||
// @Nullable String localized,
|
||||
// @Nullable String permission,
|
||||
// @Nullable LangMessage failureMessage,
|
||||
// @Nullable Function<TabContext, List<String>> samples) {
|
||||
// this(name, ((string, context) -> parser.apply(string)), required, complex, localized, permission, failureMessage, samples);
|
||||
// }
|
||||
|
||||
public CommandArgument(@NotNull String name,
|
||||
@NotNull ArgumentParser<T> parser,
|
||||
boolean required,
|
||||
@@ -80,7 +68,7 @@ public class CommandArgument<T> {
|
||||
|
||||
@NotNull
|
||||
public List<String> getSamples(@NotNull TabContext context) {
|
||||
return this.samples == null ? Lists.newList(NightMessage.asLegacy(this.getLocalized())) : this.samples.apply(context);
|
||||
return this.samples == null ? Lists.newList(NightMessage.stripAll(this.getLocalized())) : this.samples.apply(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CoreConfig {
|
||||
"[Default is false]");
|
||||
|
||||
public static final ConfigValue<UniFormatter> NUMBER_FORMAT = ConfigValue.create("Engine.Number_Format",
|
||||
UniFormatter.of("#,###.##", RoundingMode.HALF_EVEN),
|
||||
UniFormatter.of("#,###.###", RoundingMode.HALF_EVEN),
|
||||
"Control over how numerical data is formatted and rounded.",
|
||||
"Allowed modes: " + StringUtil.inlineEnum(RoundingMode.class, ", "),
|
||||
"A tutorial can be found here: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html"
|
||||
|
||||
@@ -37,8 +37,8 @@ public abstract class AbstractUser<P extends NightCorePlugin> implements DataUse
|
||||
|
||||
}
|
||||
|
||||
private long getTimestamp(int seconds) {
|
||||
return seconds < 0 ? -1L : System.currentTimeMillis() + 1000L * seconds;
|
||||
private long getTimestamp(double seconds) {
|
||||
return seconds < 0 ? -1L : System.currentTimeMillis() + (long) (1000D * seconds);
|
||||
}
|
||||
|
||||
public boolean isCacheExpired() {
|
||||
@@ -81,7 +81,7 @@ public abstract class AbstractUser<P extends NightCorePlugin> implements DataUse
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoSaveIn(int seconds) {
|
||||
public void setAutoSaveIn(double seconds) {
|
||||
this.autoSaveIn = this.getTimestamp(seconds);
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +240,11 @@ public abstract class AbstractUserManager<P extends NightDataPlugin<U>, U extend
|
||||
user.setName(player.getName());
|
||||
user.setLastOnline(System.currentTimeMillis());
|
||||
}
|
||||
this.scheduleSave(user);
|
||||
if (this.isScheduledToSave(user)) {
|
||||
this.scheduledSaves.remove(user.getId());
|
||||
}
|
||||
this.plugin.runTaskAsync(task -> this.save(user));
|
||||
//this.scheduleSave(user);
|
||||
this.cacheTemporary(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface DataUser {
|
||||
|
||||
void setCachedUntil(long cachedUntil);
|
||||
|
||||
void setAutoSaveIn(int seconds);
|
||||
void setAutoSaveIn(double seconds);
|
||||
|
||||
void setNextSyncIn(int seconds);
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import su.nightexpress.nightcore.config.FileConfig;
|
||||
public class UserdataConfig {
|
||||
|
||||
private final long scheduledSaveInterval;
|
||||
private final int scheduledSaveDelay;
|
||||
private final double scheduledSaveDelay;
|
||||
private final int scheduledSaveSyncPause;
|
||||
|
||||
public UserdataConfig(long scheduledSaveInterval, int scheduledSaveDelay, int scheduledSaveSyncPause) {
|
||||
public UserdataConfig(long scheduledSaveInterval, double scheduledSaveDelay, int scheduledSaveSyncPause) {
|
||||
this.scheduledSaveInterval = scheduledSaveInterval;
|
||||
this.scheduledSaveDelay = scheduledSaveDelay;
|
||||
this.scheduledSaveSyncPause = scheduledSaveSyncPause;
|
||||
@@ -30,8 +30,8 @@ public class UserdataConfig {
|
||||
"[Default is 20]"
|
||||
).read(config);
|
||||
|
||||
int scheduledSaveDelay = ConfigValue.create("Database.UserData.Scheduled_Save_Delay",
|
||||
1,
|
||||
double scheduledSaveDelay = ConfigValue.create("Database.UserData.Scheduled_Save_Delay",
|
||||
1D,
|
||||
"Sets scheduled save delay (in seconds) for a user when marked to be saved.",
|
||||
"This means that a user will be saved X seconds later after being marked.",
|
||||
"Generally, you should keep this value less than 'Scheduled_Save_Interval' for best results,",
|
||||
@@ -42,6 +42,7 @@ public class UserdataConfig {
|
||||
"",
|
||||
"Users marked for save when their data has been changed/affected in some way.",
|
||||
"However this is higly depends on the plugin.",
|
||||
"[Decimals allowed]",
|
||||
"[Default is 1]"
|
||||
).read(config);
|
||||
|
||||
@@ -61,7 +62,7 @@ public class UserdataConfig {
|
||||
return scheduledSaveInterval;
|
||||
}
|
||||
|
||||
public int getScheduledSaveDelay() {
|
||||
public double getScheduledSaveDelay() {
|
||||
return scheduledSaveDelay;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public class Dialog {
|
||||
String hoverHint = GRAY.enclose("Click me to select " + CYAN.enclose(element) + ".");
|
||||
String clickCommand = element.charAt(0) == '/' ? element : '/' + element;
|
||||
|
||||
builder.append(DARK_GRAY.enclose("> ")).append(GREEN.enclose(HOVER.encloseHint(CLICK.encloseRun(element, clickCommand), hoverHint)));
|
||||
builder.append(DARK_GRAY.enclose("> ")).append(GREEN.enclose(HOVER.encloseHint(CLICK.enclose(element, action, clickCommand), hoverHint)));
|
||||
builder.append(Placeholders.TAG_LINE_BREAK);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package su.nightexpress.nightcore.language;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -28,6 +30,18 @@ public class LangAssets {
|
||||
|
||||
String assetsCode = downloadAssets(core, langCode);
|
||||
config = FileConfig.loadOrExtract(core, LangManager.DIR_LANG, getFileName(assetsCode));
|
||||
|
||||
loadDamageTypes();
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
config.saveChanges();
|
||||
config = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private static void loadDamageTypes() {
|
||||
BukkitThing.allFromRegistry(Registry.DAMAGE_TYPE).forEach(damageType -> getOrCreate("DamageType", damageType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -90,6 +104,12 @@ public class LangAssets {
|
||||
return getOrCreate("Enchantment", enchantment);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@NotNull
|
||||
public static String get(@NotNull DamageType damageType) {
|
||||
return getOrCreate("DamageType", damageType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getAsset(@NotNull String path, @NotNull Keyed keyed) {
|
||||
return getAsset(path, BukkitThing.toString(keyed));
|
||||
@@ -113,7 +133,7 @@ public class LangAssets {
|
||||
@NotNull
|
||||
public static String getOrCreate(@NotNull String path, @NotNull String nameRaw) {
|
||||
config.addMissing(path + "." + nameRaw, StringUtil.capitalizeUnderscored(nameRaw));
|
||||
config.saveChanges();
|
||||
//config.saveChanges();
|
||||
|
||||
return getAsset(path, nameRaw);
|
||||
}
|
||||
|
||||
@@ -59,16 +59,18 @@ public abstract class EditorMenu<P extends NightCorePlugin, T> extends AbstractM
|
||||
@NotNull
|
||||
@Deprecated
|
||||
protected MenuItem addReturn(int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM4NTJiZjYxNmYzMWVkNjdjMzdkZTRiMGJhYTJjNWY4ZDhmY2E4MmU3MmRiY2FmY2JhNjY5NTZhODFjNCJ9fX0=");
|
||||
ItemStack item = ItemUtil.getSkinHead("be9ae7a4be65fcbaee65181389a2f7d47e2e326db59ea3eb789a92c85ea46");
|
||||
//ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
//ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM4NTJiZjYxNmYzMWVkNjdjMzdkZTRiMGJhYTJjNWY4ZDhmY2E4MmU3MmRiY2FmY2JhNjY5NTZhODFjNCJ9fX0=");
|
||||
return this.addItem(item, CoreLang.EDITOR_ITEM_RETURN, slots);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
protected MenuItem addCreation(@NotNull LangItem locale, int... slots) {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWZmMzE0MzFkNjQ1ODdmZjZlZjk4YzA2NzU4MTA2ODFmOGMxM2JmOTZmNTFkOWNiMDdlZDc4NTJiMmZmZDEifX19");
|
||||
ItemStack item = ItemUtil.getSkinHead("5ff31431d64587ff6ef98c0675810681f8c13bf96f51d9cb07ed7852b2ffd1");
|
||||
//ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
//ItemUtil.setSkullTexture(item, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWZmMzE0MzFkNjQ1ODdmZjZlZjk4YzA2NzU4MTA2ODFmOGMxM2JmOTZmNTFkOWNiMDdlZDc4NTJiMmZmZDEifX19");
|
||||
return this.addItem(item, locale, slots);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,16 +3,17 @@ package su.nightexpress.nightcore.util;
|
||||
import com.google.common.base.Splitter;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.language.entry.LangItem;
|
||||
import su.nightexpress.nightcore.util.placeholder.Placeholder;
|
||||
import su.nightexpress.nightcore.util.placeholder.PlaceholderMap;
|
||||
import su.nightexpress.nightcore.util.text.NightMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.UnaryOperator;
|
||||
@@ -26,11 +27,11 @@ public class ItemReplacer {
|
||||
private final List<UnaryOperator<String>> operatorCache;
|
||||
|
||||
private String displayName;
|
||||
private String lore;
|
||||
private List<String> lore;
|
||||
|
||||
private boolean trimLore;
|
||||
private boolean hideFlags;
|
||||
private Player papi;
|
||||
//private Player papi;
|
||||
|
||||
public ItemReplacer(@NotNull ItemStack item) {
|
||||
this(item, item.getItemMeta());
|
||||
@@ -82,21 +83,19 @@ public class ItemReplacer {
|
||||
operators.add(this.placeholderCache.replacer());
|
||||
|
||||
boolean hasDisplayName = this.displayName != null;
|
||||
boolean hasLore = this.lore != null;
|
||||
//boolean hasLore = this.lore != null;
|
||||
|
||||
operators.forEach(operator -> {
|
||||
if (hasDisplayName) this.setDisplayName(operator.apply(this.displayName));
|
||||
if (hasLore) this.setLore(operator.apply(this.lore));
|
||||
this.replaceLore(operator);
|
||||
//if (hasLore) this.setLore(operator.apply(this.lore));
|
||||
});
|
||||
|
||||
//this.replace(this.placeholderCache.replacer());
|
||||
// this.injectPlaceholderAPI(this.papi);
|
||||
|
||||
this.meta.setDisplayName(this.getDisplayName() == null ? null : NightMessage.asLegacy(this.getDisplayName()));
|
||||
this.meta.setLore(this.packTrimmedLore());
|
||||
|
||||
if (this.isHideFlags()) {
|
||||
this.meta.addItemFlags(ItemFlag.values());
|
||||
ItemUtil.hideAttributes(this.meta, this.item.getType());
|
||||
}
|
||||
|
||||
if (this.hasItem()) {
|
||||
@@ -211,23 +210,11 @@ public class ItemReplacer {
|
||||
|
||||
@NotNull
|
||||
public ItemReplacer replace(@NotNull UnaryOperator<String> replacer) {
|
||||
// this.operatorCache.add(replacer);
|
||||
//
|
||||
// if (this.getDisplayName() != null) {
|
||||
// this.setDisplayName(replacer.apply(this.getDisplayName()));
|
||||
// }
|
||||
//
|
||||
// if (this.getLore() != null) {
|
||||
// this.setLore(replacer.apply(this.getLore()));
|
||||
// }
|
||||
return cacheOperator(replacer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemReplacer replacePlaceholderAPI(@NotNull Player player) {
|
||||
// if (Plugins.hasPlaceholderAPI()) {
|
||||
// this.papi = player;
|
||||
// }
|
||||
if (Plugins.hasPlaceholderAPI()) {
|
||||
this.cacheOperator(str -> PlaceholderAPI.setPlaceholders(player, str));
|
||||
}
|
||||
@@ -237,39 +224,24 @@ public class ItemReplacer {
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public ItemReplacer replaceLoreExact(@NotNull String placeholder, @NotNull List<String> replacer) {
|
||||
// this.replace(placeholder, () -> String.join(Tags.LINE_BREAK.getBracketsName(), replacer));
|
||||
// return this;
|
||||
return this.replace(placeholder, replacer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public ItemReplacer replaceLore(@NotNull String placeholder, @NotNull Supplier<List<String>> replacer) {
|
||||
// this.replace(placeholder, () -> String.join(Tags.LINE_BREAK.getBracketsName(), replacer.get()));
|
||||
// return this;
|
||||
return this.replace(placeholder, replacer.get());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public ItemReplacer injectLore(@NotNull String placeholder, @NotNull List<String> replacer) {
|
||||
// this.injectLoreCache.put(placeholder, replacer);
|
||||
// if (this.getLore() == null) return this;
|
||||
//
|
||||
// this.setLore(Lists.replace(this.packLore(), placeholder, replacer));
|
||||
// return this;
|
||||
return this.replace(placeholder, replacer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public ItemReplacer injectPlaceholderAPI(@NotNull Player player) {
|
||||
//// if (player != null) {
|
||||
// this.replace(str -> PlaceholderAPI.setPlaceholders(player, str));
|
||||
//// }
|
||||
// return this;
|
||||
return this.replacePlaceholderAPI(player);
|
||||
}
|
||||
|
||||
@@ -294,9 +266,26 @@ public class ItemReplacer {
|
||||
|
||||
@NotNull
|
||||
public List<String> packLore() {
|
||||
if (this.lore == null) return new ArrayList<>();
|
||||
// if (this.lore == null) return new ArrayList<>();
|
||||
//
|
||||
// return Splitter.on("\n").splitToList(this.lore);
|
||||
return this.lore == null ? new ArrayList<>() : this.lore;
|
||||
}
|
||||
|
||||
return Splitter.on("\n").splitToList(this.lore);
|
||||
private void replaceLore(@NotNull UnaryOperator<String> operator) {
|
||||
if (this.lore == null) return;
|
||||
|
||||
List<String> replaced = new ArrayList<>();
|
||||
for (String line : this.lore) {
|
||||
if (!line.isBlank()) {
|
||||
line = operator.apply(line);
|
||||
if (line.isBlank()) continue;
|
||||
|
||||
replaced.addAll(Arrays.asList(line.split("\n")));
|
||||
}
|
||||
else replaced.add(line);
|
||||
}
|
||||
this.setLore(replaced);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -305,7 +294,39 @@ public class ItemReplacer {
|
||||
if (this.isTrimLore()) {
|
||||
lore = Lists.stripEmpty(lore);
|
||||
}
|
||||
return NightMessage.asLegacy(lore);
|
||||
|
||||
List<String> fixed = fixLore(lore);
|
||||
|
||||
return NightMessage.asLegacy(fixed);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<String> fixLore(@NotNull List<String> lore) {
|
||||
for (int index = 0; index < lore.size(); index++) {
|
||||
String line = lore.get(index);
|
||||
if (line.equalsIgnoreCase(Placeholders.EMPTY_IF_ABOVE)) {
|
||||
if (index == 0 || !this.isNotEmpty(lore.get(index - 1))) {
|
||||
lore.remove(index);
|
||||
}
|
||||
else lore.set(index, "");
|
||||
|
||||
return fixLore(lore);
|
||||
}
|
||||
else if (line.equalsIgnoreCase(Placeholders.EMPTY_IF_BELOW)) {
|
||||
if (index == lore.size() - 1 || !this.isNotEmpty(lore.get(index + 1))) {
|
||||
lore.remove(index);
|
||||
}
|
||||
else lore.set(index, "");
|
||||
|
||||
return fixLore(lore);
|
||||
}
|
||||
}
|
||||
|
||||
return lore;
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(@NotNull String line) {
|
||||
return !line.isBlank() && !line.equalsIgnoreCase(Placeholders.EMPTY_IF_ABOVE) && !line.equalsIgnoreCase(Placeholders.EMPTY_IF_BELOW);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -320,18 +341,21 @@ public class ItemReplacer {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLore() {
|
||||
public List<String> getLore() {
|
||||
return this.lore;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemReplacer setLore(@Nullable List<String> lore) {
|
||||
return this.setLore(lore == null ? null : String.join("\n", lore));
|
||||
this.lore = lore;
|
||||
return this;
|
||||
//return this.setLore(lore == null ? null : String.join("\n", lore));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemReplacer setLore(@Nullable String lore) {
|
||||
this.lore = lore;
|
||||
this.lore = lore == null ? null : Lists.newList(lore.split("\n"));
|
||||
//this.lore = lore;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package su.nightexpress.nightcore.util;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
@@ -15,8 +18,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.language.LangAssets;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -38,6 +41,20 @@ public class ItemUtil {
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public static void hideAttributes(@NotNull ItemStack itemStack) {
|
||||
editMeta(itemStack, meta -> hideAttributes(meta, itemStack.getType()));
|
||||
}
|
||||
|
||||
public static void hideAttributes(@NotNull ItemMeta meta, @NotNull Material material) {
|
||||
if (Version.isAtLeast(Version.MC_1_20_6)) {
|
||||
EquipmentSlot slot = material.getEquipmentSlot();
|
||||
material.getDefaultAttributeModifiers(slot).forEach((meta::addAttributeModifier));
|
||||
//meta.addAttributeModifier(Attribute.GENERIC_MAX_HEALTH, new AttributeModifier("veryNiceItemChanges", 1, AttributeModifier.Operation.ADD_NUMBER));
|
||||
}
|
||||
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getLore(@NotNull ItemStack item) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@@ -106,21 +123,35 @@ public class ItemUtil {
|
||||
@Deprecated
|
||||
public static void setSkullTexture(@NotNull ItemStack item, @NotNull String value) {
|
||||
if (item.getType() != Material.PLAYER_HEAD) return;
|
||||
if (!(item.getItemMeta() instanceof SkullMeta meta)) return;
|
||||
//if (!(item.getItemMeta() instanceof SkullMeta meta)) return;
|
||||
|
||||
UUID uuid = UUID.nameUUIDFromBytes(value.getBytes());
|
||||
GameProfile profile = new GameProfile(uuid, "null");
|
||||
profile.getProperties().put("textures", new Property("textures", value));
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(value);
|
||||
String decodedStr = new String(decoded, StandardCharsets.UTF_8);
|
||||
JsonElement element = JsonParser.parseString(decodedStr);
|
||||
|
||||
Method method = Reflex.getMethod(meta.getClass(), "setProfile", GameProfile.class);
|
||||
if (method != null) {
|
||||
Reflex.invokeMethod(method, meta, profile);
|
||||
String url = element.getAsJsonObject().getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString();
|
||||
url = url.substring(ItemUtil.TEXTURES_HOST.length());
|
||||
|
||||
setHeadSkin(item, url);
|
||||
}
|
||||
else {
|
||||
Reflex.setFieldValue(meta, "profile", profile);
|
||||
catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
// UUID uuid = UUID.nameUUIDFromBytes(value.getBytes());
|
||||
// GameProfile profile = new GameProfile(uuid, "null");
|
||||
// profile.getProperties().put("textures", new Property("textures", value));
|
||||
//
|
||||
// Method method = Reflex.getMethod(meta.getClass(), "setProfile", GameProfile.class);
|
||||
// if (method != null) {
|
||||
// Reflex.invokeMethod(method, meta, profile);
|
||||
// }
|
||||
// else {
|
||||
// Reflex.setFieldValue(meta, "profile", profile);
|
||||
// }
|
||||
//
|
||||
// item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -126,16 +126,16 @@ public class Lists {
|
||||
public static List<String> getSequentialMatches(@NotNull List<String> results, @NotNull String input) {
|
||||
if (input.isBlank()) return results;
|
||||
|
||||
char[] chars = input.toCharArray();
|
||||
char[] inputChars = input.toCharArray();
|
||||
List<String> goods = new ArrayList<>();
|
||||
|
||||
Result:
|
||||
for (String item : results) {
|
||||
int itemLength = item.length();
|
||||
for (String resultItem : results) {
|
||||
int itemLength = resultItem.length();
|
||||
if (input.length() > itemLength) continue;
|
||||
|
||||
int lastIndex = -1;
|
||||
for (char letter : chars) {
|
||||
for (char letter : inputChars) {
|
||||
int nextIndex = lastIndex;
|
||||
|
||||
if (nextIndex < 0) {
|
||||
@@ -145,14 +145,15 @@ public class Lists {
|
||||
nextIndex++; // This fixes an issue, where method fails for similar characters in a row, like 'oo'.
|
||||
}
|
||||
|
||||
int index = item.indexOf(letter, nextIndex);
|
||||
letter = Character.toLowerCase(letter);
|
||||
int index = resultItem.toLowerCase().indexOf(letter, nextIndex);
|
||||
if (index <= lastIndex) {
|
||||
continue Result;
|
||||
}
|
||||
|
||||
lastIndex = index;
|
||||
}
|
||||
goods.add(item);
|
||||
goods.add(resultItem);
|
||||
}
|
||||
return goods;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ public class Placeholders {
|
||||
public static final String SKIN_ARROW_RIGHT = "f32ca66056b72863e98f7f32bd7d94c7a0d796af691c9ac3a9136331352288f9";
|
||||
public static final String SKIN_ARROW_DOWN = "be9ae7a4be65fcbaee65181389a2f7d47e2e326db59ea3eb789a92c85ea46";
|
||||
|
||||
public static final String EMPTY_IF_ABOVE = "%empty-if-above%";
|
||||
public static final String EMPTY_IF_BELOW = "%empty-if-below%";
|
||||
public static final String EMPTY_IF_BOTH = "%empty-if-both%";
|
||||
|
||||
public static final String COMMAND_USAGE = "%command_usage%";
|
||||
public static final String COMMAND_DESCRIPTION = "%command_description%";
|
||||
public static final String COMMAND_LABEL = "%command_label%";
|
||||
|
||||
@@ -8,13 +8,14 @@ import java.util.stream.Stream;
|
||||
|
||||
public enum Version {
|
||||
|
||||
V1_18_R2("1.18.2", true),
|
||||
V1_18_R2("1.18.2", Status.DROPPED),
|
||||
V1_19_R3("1.19.4"),
|
||||
V1_20_R1("1.20.1", true),
|
||||
V1_20_R2("1.20.2", true),
|
||||
V1_20_R1("1.20.1", Status.OUTDATED),
|
||||
V1_20_R2("1.20.2", Status.OUTDATED),
|
||||
V1_20_R3("1.20.4"),
|
||||
MC_1_20_6("1.20.6"),
|
||||
MC_1_21("1.21"),
|
||||
MC_1_20_6("1.20.6", Status.DROPPED),
|
||||
MC_1_21_0("1.21", Status.OUTDATED),
|
||||
MC_1_21("1.21.1"),
|
||||
UNKNOWN("Unknown"),
|
||||
;
|
||||
|
||||
@@ -22,16 +23,16 @@ public enum Version {
|
||||
|
||||
private static Version current;
|
||||
|
||||
private final boolean deprecated;
|
||||
private final Status status;
|
||||
private final String localized;
|
||||
|
||||
Version(@NotNull String localized) {
|
||||
this(localized, false);
|
||||
this(localized, Status.SUPPORTED);
|
||||
}
|
||||
|
||||
Version(@NotNull String localized, boolean deprecated) {
|
||||
Version(@NotNull String localized, @NotNull Status status) {
|
||||
this.localized = localized;
|
||||
this.deprecated = deprecated;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -40,17 +41,38 @@ public enum Version {
|
||||
return Bukkit.getServer().getBukkitVersion();
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
SUPPORTED,
|
||||
OUTDATED,
|
||||
DROPPED
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Version getCurrent() {
|
||||
if (current == null) {
|
||||
String protocol = Bukkit.getServer().getBukkitVersion();
|
||||
current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> protocol.startsWith(version.getLocalized())).findFirst().orElse(UNKNOWN);
|
||||
String exact = protocol.split("-")[0];
|
||||
|
||||
current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> exact.equalsIgnoreCase(version.getLocalized())).findFirst().orElse(UNKNOWN);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public boolean isDeprecated() {
|
||||
return deprecated;
|
||||
return this.status == Status.OUTDATED;
|
||||
}
|
||||
|
||||
public boolean isDropped() {
|
||||
return this.status == Status.DROPPED;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return this.status == Status.SUPPORTED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Tags {
|
||||
|
||||
public static final ColorTag DARK_GRAY = new ColorTag("dgray", new String[]{"dark_gray"}, "#6c6c62");
|
||||
public static final ColorTag LIGHT_GRAY = new ColorTag("lgray", new String[]{"light_gray"}, "#d4d9d8");
|
||||
public static final ColorTag LIGHT_GREEN = new ColorTag("lgreen", new String[]{"light_green"}, "#aefd5e");
|
||||
public static final ColorTag LIGHT_GREEN = new ColorTag("lgreen", new String[]{"light_green"}, "#91f251");
|
||||
public static final ColorTag LIGHT_YELLOW = new ColorTag("lyellow", new String[]{"light_yellow"}, "#ffeea2");
|
||||
public static final ColorTag LIGHT_ORANGE = new ColorTag("lorange", new String[]{"light_orange"}, "#fdba5e");
|
||||
public static final ColorTag LIGHT_RED = new ColorTag("lred", new String[]{"light_red"}, "#fd5e5e");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package su.nightexpress.nightcore.util.wrapper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nightexpress.nightcore.config.ConfigValue;
|
||||
import su.nightexpress.nightcore.config.FileConfig;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
@@ -15,7 +16,7 @@ public class UniFormatter {
|
||||
private final String format;
|
||||
private final RoundingMode rounding;
|
||||
|
||||
private UniFormatter(String format, RoundingMode rounding) {
|
||||
private UniFormatter(@NotNull String format, @NotNull RoundingMode rounding) {
|
||||
this.format = format;
|
||||
this.rounding = rounding;
|
||||
this.formatter = new DecimalFormat(format, new DecimalFormatSymbols(Locale.US));
|
||||
@@ -23,20 +24,21 @@ public class UniFormatter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UniFormatter of(String format, RoundingMode rounding) {
|
||||
public static UniFormatter of(@NotNull String format, @NotNull RoundingMode rounding) {
|
||||
return new UniFormatter(format, rounding);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UniFormatter read(@NotNull FileConfig cfg, @NotNull String path) {
|
||||
String format = cfg.getString(path + ".Format_Pattern", "#,###.##");
|
||||
RoundingMode rounding = RoundingMode.valueOf(cfg.getString(path + ".Rounding_Mode", "half_even").toUpperCase());
|
||||
public static UniFormatter read(@NotNull FileConfig config, @NotNull String path) {
|
||||
String format = ConfigValue.create(path + ".Format", "#,###.##").read(config);
|
||||
RoundingMode rounding = ConfigValue.create(path + ".Rounding", RoundingMode.class, RoundingMode.HALF_EVEN).read(config);
|
||||
|
||||
return of(format, rounding);
|
||||
}
|
||||
|
||||
public void write(@NotNull FileConfig cfg, @NotNull String path) {
|
||||
cfg.set(path + ".Format", this.getFormat());
|
||||
cfg.set(path + ".Rounding", this.getRounding().name().toLowerCase());
|
||||
public void write(@NotNull FileConfig config, @NotNull String path) {
|
||||
config.set(path + ".Format", this.getFormat());
|
||||
config.set(path + ".Rounding", this.getRounding().name().toLowerCase());
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
Command:
|
||||
Help:
|
||||
List:
|
||||
- <noprefix>
|
||||
- ' <yellow><b>%name%</b></yellow><gray> - </gray><yellow><b>指令:</b></yellow>'
|
||||
- ' '
|
||||
- <gray> <red><b><></b></red> - 必填, <green><b>[]</b></green> - 選填。</gray>
|
||||
- ' '
|
||||
- '%entry%'
|
||||
- ' '
|
||||
Entry: ' <yellow>/%command_label%</yellow> <orange>%command_usage%</orange><gray> - %command_description%</gray>'
|
||||
Desc: 顯示幫助頁面。
|
||||
CheckPerm:
|
||||
Desc: 顯示玩家權限資訊。
|
||||
Usage: <player>
|
||||
Reload:
|
||||
Desc: 重新加載插件。
|
||||
Done: 插件 <green>已重新加載</green>!
|
||||
Argument:
|
||||
Type:
|
||||
Required: <lred><%name%></lred>
|
||||
Optional: <lyellow>[%name%]</lyellow>
|
||||
Name:
|
||||
Generic: 數值
|
||||
Type: 類型
|
||||
Name: 名稱
|
||||
Player: 玩家
|
||||
World: 世界
|
||||
Amount: 數量
|
||||
Material: 材料
|
||||
ItemMaterial: 物品類型
|
||||
BlockMaterial: 方塊類型
|
||||
Enchantment: 附魔
|
||||
Flag:
|
||||
Format: <lgray>[%name%]</lgray>
|
||||
Time:
|
||||
Day: '%amount%天.'
|
||||
Hour: '%amount%小時.'
|
||||
Min: '%amount%分鐘.'
|
||||
Sec: '%amount%秒.'
|
||||
Delimiter: ' '
|
||||
Other:
|
||||
'Yes': <green>是</green>
|
||||
'No': <red>否</red>
|
||||
Enabled: <green>啟用</green>
|
||||
Disabled: <red>停用</red>
|
||||
Any: 任意
|
||||
None: 無
|
||||
Never: 從不
|
||||
OneTimed: 單次
|
||||
Unlimited: 無限
|
||||
Infinity: ∞
|
||||
Error:
|
||||
Invalid_Player: <red>找不到玩家。</red>
|
||||
Invalid_World: <red>無效的世界。</red>
|
||||
Invalid_Number: <red>%value% 不是有效的數字。</red>
|
||||
NoPermission: <red>您沒有權限執行此操作!</red>
|
||||
Command:
|
||||
NotYourself: <red>此命令無法用於自己。</red>
|
||||
PlayerOnly: <red>此命令僅適用於玩家。</red>
|
||||
Usage:
|
||||
- <noprefix>
|
||||
- '<red>錯誤: </red><gray>參數錯誤!</gray>'
|
||||
- '<red>用法: </red><yellow>/%command_label%</yellow> <orange>%command_usage%</orange>'
|
||||
- ' '
|
||||
ParseFlag: <lgray>無效的值 <lred>%value%</lred> 用於 <lred>%name%</lred> 標誌。</lgray>
|
||||
ParseArgument: <lgray>無效的值 <lred>%value%</lred> 用於 <lred>%name%</lred> 參數。</lgray>
|
||||
Argument:
|
||||
InvalidPlayer: <lgray><lred>找不到玩家 %value%</lred>!</lgray>
|
||||
InvalidWorld: <lgray><lred>找不到世界 %value%</lred>!</lgray>
|
||||
InvalidNumber: <lgray><lred>%value%</lred> 不是有效的數字!</lgray>
|
||||
InvalidMaterial: <lgray><lred>%value%</lred> 不是有效的材料!</lgray>
|
||||
InvalidEnchantment: <lgray><lred>%value%</lred> 不是有效的附魔!</lgray>
|
||||
InvalidMaterial: <red>無效的材料!</red>
|
||||
InvalidEnchantment: <red>無效的附魔!</red>
|
||||
Editor:
|
||||
Action:
|
||||
Exit:
|
||||
- <noprefix>
|
||||
- <gray>點擊 <click:run_command:'/#exit'><hover:show_text:'<gray>點擊以取消</gray>'><green>[此處]</green></hover></click> 退出輸入模式。</gray>
|
||||
- ' '
|
||||
Input:
|
||||
Header:
|
||||
Main: <green><b>輸入模式</b></green>
|
||||
Error: <red><b>錯誤</b></red>
|
||||
Error:
|
||||
NotInteger: <gray>預期的 <red>整數</red>!</gray>
|
||||
Generic: <gray>無效的值!</gray>
|
||||
Generic:
|
||||
Close:
|
||||
Name: <red>(✕) 退出</red>
|
||||
Lore: []
|
||||
Return:
|
||||
Name: <gray>() </gray><white>返回</white>
|
||||
Lore: []
|
||||
NextPage:
|
||||
Name: <white>下一頁</white><gray> (→)</gray>
|
||||
Lore: []
|
||||
PreviousPage:
|
||||
Name: <gray>(←) </gray><white>上一頁</white>
|
||||
Lore: []
|
||||
Number:
|
||||
Thousand: 千
|
||||
Million: 百萬
|
||||
Billion: 十億
|
||||
Trillion: 兆
|
||||
Quadrillion: 千兆
|
||||
Entry:
|
||||
Good: <green>✔</green> <gray>%entry%</gray>
|
||||
Bad: <red>✘</red> <gray>%entry%</gray>
|
||||
Warn: <orange>[❗]</orange> <gray>%entry%</gray>
|
||||
Reference in new issue
Block a user