replace folialib with morepaperlib
This commit is contained in:
parent
77ff0a8921
commit
d547628a55
18
pom.xml
18
pom.xml
@ -41,10 +41,6 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.tcoded.folialib</pattern>
|
||||
<shadedPattern>me.xginko.villageroptimizer.libs.folialib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.benmanes.caffeine</pattern>
|
||||
<shadedPattern>me.xginko.villageroptimizer.libs.caffeine</shadedPattern>
|
||||
@ -69,6 +65,10 @@
|
||||
<pattern>com.cryptomorin.xseries</pattern>
|
||||
<shadedPattern>me.xginko.villageroptimizer.libs.xseries</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>space.arim.morepaperlib</pattern>
|
||||
<shadedPattern>me.xginko.villageroptimizer.libs.morepaperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
@ -112,8 +112,8 @@
|
||||
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>folialib-repo</id>
|
||||
<url>https://nexuslite.gcnt.net/repos/other/</url>
|
||||
<id>morepaperlib-repo</id>
|
||||
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@ -179,9 +179,9 @@
|
||||
</dependency>
|
||||
<!-- Folia Support -->
|
||||
<dependency>
|
||||
<groupId>com.tcoded</groupId>
|
||||
<artifactId>FoliaLib</artifactId>
|
||||
<version>0.3.1</version>
|
||||
<groupId>space.arim.morepaperlib</groupId>
|
||||
<artifactId>morepaperlib</artifactId>
|
||||
<version>0.4.3</version>
|
||||
</dependency>
|
||||
<!-- Cross-Version Support -->
|
||||
<dependency>
|
||||
|
@ -1,6 +1,5 @@
|
||||
package me.xginko.villageroptimizer;
|
||||
|
||||
import com.tcoded.folialib.FoliaLib;
|
||||
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
|
||||
import me.xginko.villageroptimizer.config.Config;
|
||||
import me.xginko.villageroptimizer.config.LanguageCache;
|
||||
@ -19,6 +18,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -40,7 +41,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
|
||||
private static VillagerOptimizer instance;
|
||||
private static VillagerCache villagerCache;
|
||||
private static FoliaLib foliaLib;
|
||||
private static GracefulScheduling scheduling;
|
||||
private static Map<String, LanguageCache> languageCacheMap;
|
||||
private static Config config;
|
||||
private static BukkitAudiences audiences;
|
||||
@ -57,7 +58,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
foliaLib = new FoliaLib(this);
|
||||
scheduling = new MorePaperLib(this).scheduling();
|
||||
audiences = BukkitAudiences.create(this);
|
||||
logger = ComponentLogger.logger(getLogger().getName());
|
||||
bStats = new Metrics(this, 19954);
|
||||
@ -112,9 +113,9 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
VillagerOptimizerModule.ENABLED_MODULES.forEach(VillagerOptimizerModule::disable);
|
||||
VillagerOptimizerModule.ENABLED_MODULES.clear();
|
||||
if (foliaLib != null) {
|
||||
foliaLib.getImpl().cancelAllTasks();
|
||||
foliaLib = null;
|
||||
if (scheduling != null) {
|
||||
scheduling.cancelGlobalTasks();
|
||||
scheduling = null;
|
||||
}
|
||||
if (villagerCache != null) {
|
||||
villagerCache.clear();
|
||||
@ -143,8 +144,8 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
public static @NotNull VillagerCache getCache() {
|
||||
return villagerCache;
|
||||
}
|
||||
public static @NotNull FoliaLib getFoliaLib() {
|
||||
return foliaLib;
|
||||
public static @NotNull GracefulScheduling scheduling() {
|
||||
return scheduling;
|
||||
}
|
||||
public static @NotNull ComponentLogger logger() {
|
||||
return logger;
|
||||
|
@ -35,7 +35,7 @@ public class ReloadSubCmd extends SubCommand {
|
||||
}
|
||||
|
||||
KyoriUtil.sendMessage(sender, Component.text("Reloading VillagerOptimizer...").color(NamedTextColor.WHITE));
|
||||
VillagerOptimizer.getFoliaLib().getImpl().runNextTick(reload -> { // Reload in sync with the server
|
||||
VillagerOptimizer.scheduling().asyncScheduler().run(reload -> {
|
||||
VillagerOptimizer.getInstance().reloadPlugin();
|
||||
KyoriUtil.sendMessage(sender, Component.text("Reload complete.").color(NamedTextColor.GREEN));
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.xginko.villageroptimizer.modules;
|
||||
|
||||
import com.cryptomorin.xseries.XEntityType;
|
||||
import com.tcoded.folialib.wrapper.task.WrappedTask;
|
||||
import me.xginko.villageroptimizer.utils.LocationUtil;
|
||||
import me.xginko.villageroptimizer.utils.Util;
|
||||
import org.bukkit.Chunk;
|
||||
@ -15,6 +14,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import space.arim.morepaperlib.scheduling.ScheduledTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -25,7 +25,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class VillagerChunkLimit extends VillagerOptimizerModule implements Runnable, Listener {
|
||||
|
||||
private WrappedTask periodic_chunk_check;
|
||||
private ScheduledTask periodic_chunk_check;
|
||||
private final List<Villager.Profession> non_optimized_removal_priority, optimized_removal_priority;
|
||||
private final long check_period;
|
||||
private final int non_optimized_max_per_chunk, optimized_max_per_chunk;
|
||||
@ -93,7 +93,7 @@ public class VillagerChunkLimit extends VillagerOptimizerModule implements Runna
|
||||
@Override
|
||||
public void enable() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
periodic_chunk_check = scheduler.runTimer(this, check_period, check_period);
|
||||
periodic_chunk_check = scheduling.globalRegionalScheduler().runAtFixedRate(this, check_period, check_period);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -160,11 +160,11 @@ public class VillagerChunkLimit extends VillagerOptimizerModule implements Runna
|
||||
// Remove prioritized villagers that are too many
|
||||
for (int i = 0; i < not_optimized_villagers_too_many; i++) {
|
||||
Villager villager = not_optimized_villagers.get(i);
|
||||
scheduler.runAtEntity(villager, kill -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(kill -> {
|
||||
villager.remove();
|
||||
if (log_enabled) info("Removed unoptimized villager with profession '" +
|
||||
Util.formatEnum(villager.getProfession()) + "' at " + LocationUtil.toString(villager.getLocation()));
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,11 +179,11 @@ public class VillagerChunkLimit extends VillagerOptimizerModule implements Runna
|
||||
// Remove prioritized villagers that are too many
|
||||
for (int i = 0; i < optimized_villagers_too_many; i++) {
|
||||
Villager villager = optimized_villagers.get(i);
|
||||
scheduler.runAtEntity(villager, kill -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(kill -> {
|
||||
villager.remove();
|
||||
if (log_enabled) info("Removed optimized villager with profession '" +
|
||||
if (log_enabled) info("Removed unoptimized villager with profession '" +
|
||||
Util.formatEnum(villager.getProfession()) + "' at " + LocationUtil.toString(villager.getLocation()));
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package me.xginko.villageroptimizer.modules;
|
||||
|
||||
import com.tcoded.folialib.impl.ServerImplementation;
|
||||
import me.xginko.villageroptimizer.VillagerCache;
|
||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||
import me.xginko.villageroptimizer.config.Config;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
@ -23,7 +23,7 @@ public abstract class VillagerOptimizerModule {
|
||||
protected final VillagerOptimizer plugin;
|
||||
protected final Config config;
|
||||
protected final VillagerCache villagerCache;
|
||||
protected final ServerImplementation scheduler;
|
||||
protected final GracefulScheduling scheduling;
|
||||
public final String configPath;
|
||||
private final String logFormat;
|
||||
|
||||
@ -31,7 +31,7 @@ public abstract class VillagerOptimizerModule {
|
||||
this.plugin = VillagerOptimizer.getInstance();
|
||||
this.config = VillagerOptimizer.config();
|
||||
this.villagerCache = VillagerOptimizer.getCache();
|
||||
this.scheduler = VillagerOptimizer.getFoliaLib().getImpl();
|
||||
this.scheduling = VillagerOptimizer.scheduling();
|
||||
this.configPath = configPath;
|
||||
shouldEnable(); // Ensure enable option is always first
|
||||
String[] paths = configPath.split("\\.");
|
||||
|
@ -68,7 +68,7 @@ public class EnableLeashingVillagers extends VillagerOptimizerModule implements
|
||||
// If canceled by any plugin, do nothing
|
||||
if (!leashEvent.callEvent()) return;
|
||||
|
||||
scheduler.runAtEntity(villager, leash -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(leash -> {
|
||||
// Legitimate to not use entities from the event object since they are final in PlayerLeashEntityEvent
|
||||
if (!villager.setLeashHolder(player)) return;
|
||||
if (player.getGameMode().equals(GameMode.SURVIVAL))
|
||||
@ -77,6 +77,6 @@ public class EnableLeashingVillagers extends VillagerOptimizerModule implements
|
||||
if (log_enabled) {
|
||||
info(player.getName() + " leashed a villager at " + LocationUtil.toString(villager.getLocation()));
|
||||
}
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTransformEvent;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FixOptimisationAfterCure extends VillagerOptimizerModule implements Listener {
|
||||
|
||||
public FixOptimisationAfterCure() {
|
||||
@ -40,10 +38,10 @@ public class FixOptimisationAfterCure extends VillagerOptimizerModule implements
|
||||
&& event.getTransformedEntity().getType() == XEntityType.VILLAGER.get()
|
||||
) {
|
||||
Villager villager = (Villager) event.getTransformedEntity();
|
||||
scheduler.runAtEntityLater(villager, () -> {
|
||||
scheduling.entitySpecificScheduler(villager).runDelayed(() -> {
|
||||
WrappedVillager wVillager = villagerCache.createIfAbsent(villager);
|
||||
wVillager.setOptimizationType(wVillager.getOptimizationType());
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}, null, 40L);
|
||||
}
|
||||
}
|
||||
}
|
@ -71,14 +71,14 @@ public class LevelOptimizedProfession extends VillagerOptimizerModule implements
|
||||
if (wVillager.canLevelUp(cooldown_millis)) {
|
||||
if (wVillager.calculateLevel() <= villager.getVillagerLevel()) return;
|
||||
|
||||
scheduler.runAtEntity(villager, enableAI -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(enableAI -> {
|
||||
villager.addPotionEffect(SUPER_SLOWNESS);
|
||||
villager.setAware(true);
|
||||
scheduler.runAtEntityLater(villager, disableAI -> {
|
||||
scheduling.entitySpecificScheduler(villager).runDelayed(disableAI -> {
|
||||
villager.setAware(false);
|
||||
wVillager.saveLastLevelUp();
|
||||
}, 5, TimeUnit.SECONDS);
|
||||
});
|
||||
}, null, 100L);
|
||||
}, null);
|
||||
} else {
|
||||
if (notify_player) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
|
@ -35,16 +35,16 @@ public class VisuallyHighlightOptimized extends VillagerOptimizerModule implemen
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onOptimize(VillagerOptimizeEvent event) {
|
||||
Villager villager = event.getWrappedVillager().villager();
|
||||
scheduler.runAtEntity(villager, glow -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(glow -> {
|
||||
if (!villager.isGlowing()) villager.setGlowing(true);
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
private void onUnOptimize(VillagerUnoptimizeEvent event) {
|
||||
Villager villager = event.getWrappedVillager().villager();
|
||||
scheduler.runAtEntity(villager, unGlow -> {
|
||||
scheduling.entitySpecificScheduler(villager).run(unGlow -> {
|
||||
if (villager.isGlowing()) villager.setGlowing(false);
|
||||
});
|
||||
}, null);
|
||||
}
|
||||
}
|
@ -85,7 +85,7 @@ public class OptimizeByWorkstation extends VillagerOptimizerModule implements Li
|
||||
final AtomicBoolean taskComplete = new AtomicBoolean();
|
||||
final AtomicInteger taskAliveTicks = new AtomicInteger();
|
||||
|
||||
scheduler.runAtLocationTimer(workstationLoc, repeatingTask -> {
|
||||
scheduling.regionSpecificScheduler(workstationLoc).runAtFixedRate(repeatingTask -> {
|
||||
if (taskComplete.get() || taskAliveTicks.getAndAdd(10) > check_duration_ticks) {
|
||||
repeatingTask.cancel();
|
||||
return;
|
||||
|
@ -40,7 +40,7 @@ public class AVLVillagerDataHandlerImpl implements VillagerDataHandler {
|
||||
|
||||
@Override
|
||||
public void setOptimizationType(OptimizationType type) {
|
||||
VillagerOptimizer.getFoliaLib().getImpl().runAtEntityTimer(villager, setOptimization -> {
|
||||
VillagerOptimizer.scheduling().entitySpecificScheduler(villager).runAtFixedRate(setOptimization -> {
|
||||
// Keep repeating task until villager is no longer trading with a player
|
||||
if (villager.isTrading()) return;
|
||||
|
||||
@ -73,7 +73,7 @@ public class AVLVillagerDataHandlerImpl implements VillagerDataHandler {
|
||||
|
||||
// End repeating task once logic is finished
|
||||
setOptimization.cancel();
|
||||
}, 1L, 1L, TimeUnit.SECONDS);
|
||||
}, null, 1L, 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,8 +8,6 @@ import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MainVillagerDataHandlerImpl implements VillagerDataHandler {
|
||||
|
||||
private final @NotNull Villager villager;
|
||||
@ -37,7 +35,7 @@ public class MainVillagerDataHandlerImpl implements VillagerDataHandler {
|
||||
|
||||
@Override
|
||||
public void setOptimizationType(OptimizationType type) {
|
||||
VillagerOptimizer.getFoliaLib().getImpl().runAtEntityTimer(villager, setOptimization -> {
|
||||
VillagerOptimizer.scheduling().entitySpecificScheduler(villager).runAtFixedRate(setOptimization -> {
|
||||
// Keep repeating task until villager is no longer trading with a player
|
||||
if (villager.isTrading()) return;
|
||||
|
||||
@ -53,7 +51,7 @@ public class MainVillagerDataHandlerImpl implements VillagerDataHandler {
|
||||
|
||||
// End repeating task once logic is finished
|
||||
setOptimization.cancel();
|
||||
}, 1L, 1L, TimeUnit.SECONDS);
|
||||
}, null, 1L, 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user