Skip to content

Commit

Permalink
v2.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nulli0n committed Nov 20, 2024
1 parent e9d5acf commit bb5a24a
Show file tree
Hide file tree
Showing 26 changed files with 788 additions and 210 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.7.1</version>
<version>2.7.2</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21.3-R0.1-SNAPSHOT</version>
</dependency>

<!--<dependency>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/su/nightexpress/nightcore/config/FileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.util.*;
import su.nightexpress.nightcore.util.bukkit.NightItem;
import su.nightexpress.nightcore.util.text.NightMessage;

import java.io.File;
Expand Down Expand Up @@ -308,12 +309,24 @@ public Set<FireworkEffect> getFireworkEffects(@NotNull String path) {
}*/

@NotNull
public NightItem getCosmeticItem(@NotNull String path, @NotNull NightItem def) {
return this.contains(path) ? this.getCosmeticItem(path) : def;
}

@NotNull
public NightItem getCosmeticItem(@NotNull String path) {
return NightItem.read(this, path);
}

@NotNull
@Deprecated
public ItemStack getItem(@NotNull String path, @Nullable ItemStack def) {
ItemStack item = this.getItem(path);
return item.getType().isAir() && def != null ? def : item;
}

@NotNull
@Deprecated
public ItemStack getItem(@NotNull String path) {
if (!path.isEmpty() && !path.endsWith(".")) path = path + ".";

Expand Down Expand Up @@ -399,6 +412,7 @@ else if (meta instanceof PotionMeta potionMeta) {
return item;
}

@Deprecated
public void setItem(@NotNull String path, @Nullable ItemStack item) {
if (item == null) {
this.set(path, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CoreConfig {
"IMPORTANT NOTE: You need to use this setting only once! Enable it, reboot the server and re-save all configurations that stores compressed item data: shops, crates, etc."
);

@Deprecated
public static final ConfigValue<Boolean> MODERN_TEXT_PRECOMPILE_LANG = ConfigValue.create("ModernTextFormation.Precompile_Language",
true,
"When enabled, parses (deserializes) language messages to Spigot TextComponent(s) on plugin load.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public <T> List<T> select(@NotNull String table, @NotNull Function<ResultSet, T>

@Nullable
public <T> T selectFirst(@NotNull String table, @NotNull SelectQuery<T> query) {
List<T> list = this.select(table, query);
return list.isEmpty() ? null : list.get(0);
List<T> list = this.select(table, query.limit(1));
return list.isEmpty() ? null : list.getFirst();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ public void manageUserSynchronized(@NotNull UUID playerId, Consumer<U> consumer)
this.manageUserSynchronized(() -> this.getLoaded(playerId), () -> this.getUserDataAsync(playerId), consumer);
}

private void manageUserSynchronized(@NotNull Supplier<U> loadedSupplier, @NotNull Supplier<CompletableFuture<U>> fetchSupplier, @NotNull Consumer<U> consumer) {
this.manageUser(loadedSupplier, fetchSupplier, user -> this.plugin.runTask(task -> consumer.accept(user)));
}

public void manageUser(@NotNull Player player, Consumer<U> consumer) {
this.manageUser(player, consumer, false);
}

public void manageUserWithSave(@NotNull Player player, Consumer<U> consumer) {
this.manageUser(player, consumer, true);
}

private void manageUser(@NotNull Player player, Consumer<U> consumer, boolean save) {
U user = this.getLoaded(player);
if (user == null) return;

consumer.accept(user);
if (save) this.save(user);
}

private void manageUser(@NotNull Supplier<U> loadedSupplier, @NotNull Supplier<CompletableFuture<U>> fetchSupplier, @NotNull Consumer<U> consumer) {
U user = loadedSupplier.get();
if (user != null) {
Expand All @@ -283,10 +303,6 @@ private void manageUser(@NotNull Supplier<U> loadedSupplier, @NotNull Supplier<C
else fetchSupplier.get().thenAccept(consumer);
}

private void manageUserSynchronized(@NotNull Supplier<U> loadedSupplier, @NotNull Supplier<CompletableFuture<U>> fetchSupplier, @NotNull Consumer<U> consumer) {
this.manageUser(loadedSupplier, fetchSupplier, user -> this.plugin.runTask(task -> consumer.accept(user)));
}

/**
* @return Fetches all users from the database and returns them in as a single set.<br>
* Users that are already loaded won't be replaced by ones from the database, however they will be fetched anyway.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/su/nightexpress/nightcore/integration/VaultHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private static void setPermission() {
}
}

@Deprecated
private static void setEconomy() {
economy = getProvider(Economy.class);
if (economy != null) {
Expand Down Expand Up @@ -97,16 +98,19 @@ public static Chat getChat() {
return chat;
}

@Deprecated
public static boolean hasEconomy() {
return economy != null;
}

@Nullable
@Deprecated
public static Economy getEconomy() {
return economy;
}

@NotNull
@Deprecated
public static String getEconomyName() {
return hasEconomy() ? economy.getName() : "null";
}
Expand Down Expand Up @@ -139,10 +143,12 @@ public static String getSuffix(@NotNull Player player) {
return hasChat() ? chat.getPlayerSuffix(player) : "";
}

@Deprecated
public static double getBalance(@NotNull Player player) {
return getBalance((OfflinePlayer) player);
}

@Deprecated
public static double getBalance(@NotNull OfflinePlayer player) {
return economy.getBalance(player);
}
Expand All @@ -157,10 +163,12 @@ public static boolean addMoney(@NotNull OfflinePlayer player, double amount) {
return deposit(player, amount);
}

@Deprecated
public static boolean deposit(@NotNull Player player, double amount) {
return deposit((OfflinePlayer) player, amount);
}

@Deprecated
public static boolean deposit(@NotNull OfflinePlayer player, double amount) {
return economy.depositPlayer(player, Math.abs(amount)).transactionSuccess();
}
Expand All @@ -175,10 +183,12 @@ public static boolean takeMoney(@NotNull OfflinePlayer player, double amount) {
return withdraw(player, Math.abs(amount));
}

@Deprecated
public static boolean withdraw(@NotNull Player player, double amount) {
return withdraw((OfflinePlayer) player, amount);
}

@Deprecated
public static boolean withdraw(@NotNull OfflinePlayer player, double amount) {
return economy.withdrawPlayer(player, Math.abs(amount)).transactionSuccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void load(@NotNull NightCorePlugin plugin) {

@NotNull
public String getLocalized(@NotNull E keyed) {
String namespace = BukkitThing.toString(keyed);
String key = BukkitThing.toString(keyed);

return this.localeMap.getOrDefault(namespace, namespace);
return this.localeMap.getOrDefault(key, key);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package su.nightexpress.nightcore.language.message;

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.core.CoreConfig;
import su.nightexpress.nightcore.language.tag.MessageTag;
import su.nightexpress.nightcore.language.tag.MessageTags;
import su.nightexpress.nightcore.util.NumberUtil;
import su.nightexpress.nightcore.util.Placeholders;
import su.nightexpress.nightcore.util.Players;
import su.nightexpress.nightcore.util.StringUtil;
import su.nightexpress.nightcore.util.*;
import su.nightexpress.nightcore.util.bukkit.NightSound;
import su.nightexpress.nightcore.util.placeholder.Replacer;
import su.nightexpress.nightcore.util.text.NightMessage;
import su.nightexpress.nightcore.util.text.TextRoot;
import su.nightexpress.nightcore.util.text.tag.Tags;
import su.nightexpress.nightcore.util.text.tag.api.Tag;
import su.nightexpress.nightcore.util.wrapper.UniSound;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,7 +26,8 @@ public class LangMessage {
private final NightCorePlugin plugin;
private final String defaultText;
private final MessageOptions options;
private final TextRoot message;

private TextRoot message;

public LangMessage(@NotNull NightCorePlugin plugin, @NotNull String defaultText, @NotNull MessageOptions options) {
this(plugin, defaultText, options, null);
Expand All @@ -41,10 +37,22 @@ public LangMessage(@NotNull NightCorePlugin plugin, @NotNull String defaultText,
this.plugin = plugin;
this.defaultText = defaultText;
this.options = options;

this.setPrefix(prefix);
// this.message = NightMessage.from(prefix == null || !options.hasPrefix() ? defaultText : prefix + defaultText);
// if (CoreConfig.MODERN_TEXT_PRECOMPILE_LANG.get() && options.getOutputType() != OutputType.TITLES) {
// this.message.compile();
// }
}

@NotNull
public LangMessage setPrefix(@Nullable String prefix) {
this.message = NightMessage.from(prefix == null || !options.hasPrefix() ? defaultText : prefix + defaultText);
if (CoreConfig.MODERN_TEXT_PRECOMPILE_LANG.get() && options.getOutputType() != OutputType.TITLES) {

if (this.options.getOutputType() != OutputType.TITLES) {
this.message.compile();
}
return this;
}

@Deprecated
Expand Down Expand Up @@ -96,7 +104,7 @@ else if (typeContent.startsWith("titles")) {
}
}
else if (type.equalsIgnoreCase("sound")) {
StringUtil.getEnum(typeContent, Sound.class).ifPresent(options::setSound);
options.setSound(BukkitThing.getSound(typeContent));
}
else if (type.equalsIgnoreCase("prefix")) {
boolean b = Boolean.parseBoolean(typeContent);
Expand Down Expand Up @@ -162,10 +170,10 @@ else if (type.equalsIgnoreCase("papi")) {
return new LangMessage(plugin, strippedText, options, prefix);
}

@NotNull
public LangMessage setPrefix(@NotNull String prefix) {
return new LangMessage(this.plugin, this.defaultText, this.options, prefix);
}
// @NotNull
// public LangMessage setPrefix(@NotNull String prefix) {
// return new LangMessage(this.plugin, this.defaultText, this.options, prefix);
// }

@NotNull
public String getDefaultText() {
Expand Down Expand Up @@ -227,10 +235,19 @@ public boolean isDisabled() {
}

public void broadcast() {
// if (this.isDisabled()) return;
//
// this.plugin.getServer().getOnlinePlayers().forEach(this::send);
// this.send(this.plugin.getServer().getConsoleSender());
//
this.broadcast(replacer -> {});
}

public void broadcast(@NotNull Consumer<Replacer> consumer) {
if (this.isDisabled()) return;

this.plugin.getServer().getOnlinePlayers().forEach(this::send);
this.send(this.plugin.getServer().getConsoleSender());
Players.getOnline().forEach(player -> this.send(player, consumer));
this.send(plugin.getServer().getConsoleSender(), consumer);
}

public void send(@NotNull CommandSender sender) {
Expand Down Expand Up @@ -266,7 +283,7 @@ public void send(@NotNull CommandSender sender, @NotNull Consumer<Replacer> cons
if (this.isDisabled()) return;

if (this.options.getSound() != null && sender instanceof Player player) {
UniSound.of(this.options.getSound()).play(player);
NightSound.of(this.options.getSound()).play(player);
}

Replacer replacer = new Replacer();
Expand All @@ -275,7 +292,7 @@ public void send(@NotNull CommandSender sender, @NotNull Consumer<Replacer> cons
replacer.replacePlaceholderAPI(player);
}

TextRoot message = replacer.getReplaced(this.message);
TextRoot message = replacer.apply(this.message);

if (this.options.getOutputType() == OutputType.CHAT) {
message.send(sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public void setUsePlaceholderAPI(boolean usePlaceholderAPI) {

@Nullable
public Sound getSound() {
return sound;
return this.sound;
}

public void setSound(Sound sound) {
public void setSound(@Nullable Sound sound) {
this.sound = sound;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.language.message.MessageOptions;
import su.nightexpress.nightcore.language.tag.MessageTag;
import su.nightexpress.nightcore.util.StringUtil;
import su.nightexpress.nightcore.util.BukkitThing;

public class SoundTag extends MessageTag {

Expand All @@ -15,14 +15,13 @@ public SoundTag() {

@NotNull
public String enclose(@NotNull Sound sound) {
return this.enclose(sound.name().toLowerCase());
return this.enclose(BukkitThing.toString(sound));
}

@Override
public void apply(@NotNull MessageOptions options, @Nullable String tagContent) {
if (tagContent == null) return;

Sound sound = StringUtil.getEnum(tagContent, Sound.class).orElse(null);
options.setSound(sound);
options.setSound(BukkitThing.getSound(tagContent));
}
}
14 changes: 13 additions & 1 deletion src/main/java/su/nightexpress/nightcore/menu/MenuViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MenuViewer {
private int page;
private int pages;
private long lastClickTime;
private boolean updateTitle;

public MenuViewer(@NotNull Player player) {
this.player = player;
Expand All @@ -29,7 +30,10 @@ public void openInventory(@NotNull Inventory inventory) {

public void flushInventory(@NotNull MenuOptions options) {
this.inventory.clear();
//this.view.setTitle(options.getTitleFormatted());
if (this.isUpdateTitle()) {
this.view.setTitle(options.getTitleFormatted());
this.setUpdateTitle(false);
}
}

public boolean hasInventory() {
Expand Down Expand Up @@ -78,4 +82,12 @@ public long getLastClickTime() {
public void setLastClickTime(long lastClickTime) {
this.lastClickTime = lastClickTime;
}

public boolean isUpdateTitle() {
return updateTitle;
}

public void setUpdateTitle(boolean updateTitle) {
this.updateTitle = updateTitle;
}
}
Loading

0 comments on commit bb5a24a

Please sign in to comment.