1.16 compatibility fixes

This commit is contained in:
xGinko 2024-02-08 23:32:28 +01:00
parent 105c4591a8
commit c72ebcf628
5 changed files with 31 additions and 10 deletions

View File

@ -103,13 +103,18 @@
<version>1.20.4-R0.1-SNAPSHOT</version> <version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Needed for 1.16 as it's not in Paper on that version -->
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId> <artifactId>adventure-text-minimessage</artifactId>
<version>4.15.0</version> <version>4.15.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-logger-slf4j</artifactId>
<version>4.15.0</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId> <artifactId>adventure-text-serializer-plain</artifactId>

View File

@ -1,7 +1,6 @@
package me.xginko.villageroptimizer; package me.xginko.villageroptimizer;
import com.tcoded.folialib.FoliaLib; import com.tcoded.folialib.FoliaLib;
import com.tcoded.folialib.impl.ServerImplementation;
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand; import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.config.Config;
import me.xginko.villageroptimizer.config.LanguageCache; import me.xginko.villageroptimizer.config.LanguageCache;
@ -20,7 +19,10 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.*; import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Set;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -40,7 +42,7 @@ public final class VillagerOptimizer extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
logger = getComponentLogger(); logger = ComponentLogger.logger();
foliaLib = new FoliaLib(this); foliaLib = new FoliaLib(this);
logger.info(Component.text("╭────────────────────────────────────────────────────────────╮").style(plugin_style)); logger.info(Component.text("╭────────────────────────────────────────────────────────────╮").style(plugin_style));

View File

@ -1,11 +1,11 @@
package me.xginko.villageroptimizer.enums; package me.xginko.villageroptimizer.enums;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.key.Namespaced; import net.kyori.adventure.key.Namespaced;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Locale; import java.util.Locale;
@ -13,18 +13,19 @@ import java.util.Locale;
public class Keyring { public class Keyring {
public enum Spaces implements Namespaced { public enum Spaces implements Namespaced {
VillagerOptimizer("VillagerOptimizer"), VillagerOptimizer("VillagerOptimizer"),
AntiVillagerLag("AntiVillagerLag"); AntiVillagerLag("AntiVillagerLag");
@KeyPattern.Namespace @Pattern("[a-z0-9_\\-.]+")
private final @NotNull String namespace; private final @NotNull String namespace;
Spaces(@NotNull @KeyPattern.Namespace String pluginName) { Spaces(@NotNull @Pattern("[a-z0-9_\\-.]+") String pluginName) {
this.namespace = pluginName.toLowerCase(Locale.ROOT); this.namespace = pluginName.toLowerCase(Locale.ROOT);
} }
@Override @Override
@KeyPattern.Namespace @Pattern("[a-z0-9_\\-.]+")
public @NotNull String namespace() { public @NotNull String namespace() {
return namespace; return namespace;
} }
@ -42,11 +43,13 @@ public class Keyring {
* @return a {@link NamespacedKey} that can be used to test for and read data stored by plugins * @return a {@link NamespacedKey} that can be used to test for and read data stored by plugins
* from a {@link PersistentDataContainer} * from a {@link PersistentDataContainer}
*/ */
@SuppressWarnings("deprecation")
public static NamespacedKey getKey(@NotNull String pluginName, @NotNull String key) { public static NamespacedKey getKey(@NotNull String pluginName, @NotNull String key) {
return new NamespacedKey(pluginName.toLowerCase(Locale.ROOT), key); return new NamespacedKey(pluginName.toLowerCase(Locale.ROOT), key);
} }
public enum VillagerOptimizer implements Keyed { public enum VillagerOptimizer implements Keyed {
OPTIMIZATION_TYPE("optimization-type"), OPTIMIZATION_TYPE("optimization-type"),
LAST_OPTIMIZE("last-optimize"), LAST_OPTIMIZE("last-optimize"),
LAST_LEVELUP("last-levelup"), LAST_LEVELUP("last-levelup"),
@ -55,6 +58,7 @@ public class Keyring {
private final @NotNull NamespacedKey key; private final @NotNull NamespacedKey key;
@SuppressWarnings("deprecation")
VillagerOptimizer(@NotNull String key) { VillagerOptimizer(@NotNull String key) {
this.key = new NamespacedKey(Spaces.VillagerOptimizer.namespace(), key); this.key = new NamespacedKey(Spaces.VillagerOptimizer.namespace(), key);
} }
@ -66,6 +70,7 @@ public class Keyring {
} }
public enum AntiVillagerLag implements Keyed { public enum AntiVillagerLag implements Keyed {
NEXT_OPTIMIZATION_SYSTIME_SECONDS("cooldown"), // Returns LONG -> (System.currentTimeMillis() / 1000) + cooldown seconds NEXT_OPTIMIZATION_SYSTIME_SECONDS("cooldown"), // Returns LONG -> (System.currentTimeMillis() / 1000) + cooldown seconds
LAST_RESTOCK_WORLDFULLTIME("time"), // Returns LONG -> villager.getWorld().getFullTime() LAST_RESTOCK_WORLDFULLTIME("time"), // Returns LONG -> villager.getWorld().getFullTime()
NEXT_LEVELUP_SYSTIME_SECONDS("levelCooldown"), // Returns LONG -> (System.currentTimeMillis() / 1000) + cooldown seconds NEXT_LEVELUP_SYSTIME_SECONDS("levelCooldown"), // Returns LONG -> (System.currentTimeMillis() / 1000) + cooldown seconds
@ -75,6 +80,7 @@ public class Keyring {
private final @NotNull NamespacedKey key; private final @NotNull NamespacedKey key;
@SuppressWarnings("deprecation")
AntiVillagerLag(@NotNull String avlKey) { AntiVillagerLag(@NotNull String avlKey) {
this.key = new NamespacedKey(Spaces.AntiVillagerLag.namespace(), avlKey); this.key = new NamespacedKey(Spaces.AntiVillagerLag.namespace(), avlKey);
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerLeashEntityEvent; import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
public class EnableLeashingVillagers implements VillagerOptimizerModule, Listener { public class EnableLeashingVillagers implements VillagerOptimizerModule, Listener {
@ -54,7 +55,8 @@ public class EnableLeashingVillagers implements VillagerOptimizerModule, Listene
private void onLeash(PlayerInteractEntityEvent event) { private void onLeash(PlayerInteractEntityEvent event) {
if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return; if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return;
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (!player.getInventory().getItem(event.getHand()).getType().equals(Material.LEAD)) return; final ItemStack handItem = player.getInventory().getItem(event.getHand());
if (handItem == null || !handItem.getType().equals(Material.LEAD)) return;
event.setCancelled(true); // Cancel the event, so we don't interact with the villager event.setCancelled(true); // Cancel the event, so we don't interact with the villager
Villager villager = (Villager) event.getRightClicked(); Villager villager = (Villager) event.getRightClicked();

View File

@ -7,7 +7,13 @@ import org.slf4j.event.Level;
public class LogUtil { public class LogUtil {
public static void moduleLog(Level logLevel, String path, String logMessage) { public static void moduleLog(Level logLevel, String path, String logMessage) {
VillagerOptimizer.getLog().atLevel(logLevel).log("(" + path + ") " + logMessage); switch (logLevel) { // This is the safest way to do it while staying version compatible
case ERROR -> VillagerOptimizer.getLog().error("(" + path + ") " + logMessage);
case WARN -> VillagerOptimizer.getLog().warn("(" + path + ") " + logMessage);
case INFO -> VillagerOptimizer.getLog().info("(" + path + ") " + logMessage);
case DEBUG -> VillagerOptimizer.getLog().debug("(" + path + ") " + logMessage);
case TRACE -> VillagerOptimizer.getLog().trace("(" + path + ") " + logMessage);
}
} }
public static void materialNotRecognized(String path, String material) { public static void materialNotRecognized(String path, String material) {