diff --git a/build.gradle.kts b/build.gradle.kts index e6638a6..693b817 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,6 +18,7 @@ repositories { maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://repo.extendedclip.com/releases/") + maven("https://repo.tcoded.com/releases") } dependencies { @@ -25,6 +26,7 @@ dependencies { compileOnly("me.clip:placeholderapi:2.11.6") implementation("com.github.cryptomorin:XSeries:13.7.0") + implementation("com.tcoded:FoliaLib:0.5.1") } tasks { @@ -47,6 +49,7 @@ tasks { withType { relocate("com.cryptomorin.xseries", "me.clip.deluxetags.libs.xseries") + relocate("com.tcoded.folialib", "me.clip.deluxetags.libs.folialib") archiveFileName.set("DeluxeTags-${project.version}.jar") } } diff --git a/src/main/java/me/clip/deluxetags/DeluxeTags.java b/src/main/java/me/clip/deluxetags/DeluxeTags.java index 158e4a0..d49514c 100644 --- a/src/main/java/me/clip/deluxetags/DeluxeTags.java +++ b/src/main/java/me/clip/deluxetags/DeluxeTags.java @@ -3,6 +3,8 @@ import java.util.List; import java.util.UUID; +import com.tcoded.folialib.FoliaLib; +import com.tcoded.folialib.wrapper.task.WrappedTask; import me.clip.deluxetags.commands.TagCommand; import me.clip.deluxetags.config.ConfigWrapper; import me.clip.deluxetags.config.Lang; @@ -26,11 +28,10 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; /** * DeluxeTags plugin - * + * * @author Ryan McCarthy */ public class DeluxeTags extends JavaPlugin { @@ -43,12 +44,15 @@ public class DeluxeTags extends JavaPlugin { private ConfigWrapper playerFile; private GUIHandler guiHandler; private GUIOptions guiOptions; - private BukkitTask cleanupTask = null; + private FoliaLib foliaLib; + private WrappedTask cleanupTask = null; private static boolean papi; @Override public void onEnable() { + foliaLib = new FoliaLib(this); + tagsHandler = new DeluxeTagsHandler(this); cfg = new TagConfig(this); @@ -70,33 +74,33 @@ public void onEnable() { } playerFile = new ConfigWrapper(this, "userdata", "player_tags.yml"); - - playerFile.createNewFile(null, "DeluxeTags player_tags.yml\nDo not edit this file!"); - - cleanupTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new CleanupTask(this), 20L*300, 20L*300); - + + playerFile.createNewFile(null, "DeluxeTags player_tags.yml\nDo not edit this file!"); + + cleanupTask = foliaLib.getScheduler().runTimerAsync(new CleanupTask(this), 20L * 300, 20L * 300); + guiOptions = new GUIOptions(this); - + guiHandler = new GUIHandler(this); - + Bukkit.getPluginManager().registerEvents(guiHandler, this); PluginCommand command = getCommand("tags"); if (command != null) command.setExecutor(new TagCommand(this)); - + Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this); - + if (cfg.loadTagOnJoin()) { Bukkit.getPluginManager().registerEvents(new JoinListener(this), this); } - + messages = new ConfigWrapper(this, null, "messages.yml"); messages.createNewFile("Loading DeluxeTags messages.yml", "DeluxeTags messages.yml\nEdit the plugin messages to your liking!"); loadMessages(); - + papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null; if (cfg.papiChat()) { @@ -115,11 +119,11 @@ public void onEnable() { if (papi) { new TagPlaceholders(this).register(); } - + if (cfg.checkUpdates()) { UpdateChecker updater = new UpdateChecker(this); updater.fetch(); - + if (updater.hasUpdateAvailable()) { getLogger().info("----------------------------"); getLogger().info(" DeluxeTags Updater"); @@ -140,23 +144,31 @@ public void onEnable() { getLogger().info("of DeluxeTags!"); getLogger().info(" "); getLogger().info("----------------------------"); - } + } } } - + @Override public void onDisable() { if (cleanupTask != null) { cleanupTask.cancel(); - cleanupTask = null; + cleanupTask = null; + } + + if (foliaLib != null) { + foliaLib.getScheduler().cancelAllTasks(); } - + this.getTagsHandler().unloadData(); TagGUI.unload(); - + guiOptions = null; } + public FoliaLib getFoliaLib() { + return foliaLib; + } + public DeluxeTagsHandler getTagsHandler() { return tagsHandler; } @@ -196,13 +208,13 @@ public String getSavedTagIdentifier(String uuid) { } return null; } - + public void saveTagIdentifier(String uuid, String tagIdentifier) { FileConfiguration c = playerFile.getConfig(); c.set(uuid, tagIdentifier); playerFile.saveConfig(); } - + public void removeSavedTag(String uuid) { FileConfiguration c = playerFile.getConfig(); if (c.contains(uuid)) { @@ -210,7 +222,7 @@ public void removeSavedTag(String uuid) { playerFile.saveConfig(); } } - + public void removeSavedTags(List uuids) { boolean requiresSave = false; FileConfiguration config = playerFile.getConfig(); @@ -230,7 +242,7 @@ public void removeSavedTags(List uuids) { playerFile.saveConfig(); } } - + public void loadMessages() { Lang.setFile(messages.getConfig()); @@ -250,7 +262,7 @@ public String setPlaceholders(Player p, String s, DeluxeTag tag) { if (tag == null) { tag = this.getTagsHandler().getPlayerActiveTag(p); } - + if (tag == null) { tag = DUMMY_TAG; } @@ -259,25 +271,25 @@ public String setPlaceholders(Player p, String s, DeluxeTag tag) { String tagId = tag.getIdentifier() != null ? tag.getIdentifier() : ""; String amount = tags != null ? String.valueOf(tags.size()) : "0"; String availability = tag.hasPermissionToUse(p) - ? Lang.GUI_PLACEHOLDERS_TAG_AVAILABLE.getConfigValue(null) - : Lang.GUI_PLACEHOLDERS_TAG_UNAVAILABLE.getConfigValue(null); + ? Lang.GUI_PLACEHOLDERS_TAG_AVAILABLE.getConfigValue(null) + : Lang.GUI_PLACEHOLDERS_TAG_UNAVAILABLE.getConfigValue(null); s = s - .replace("%player%", p.getName()) - .replace("{player}", p.getName()) - .replace("%displayname%", p.getDisplayName()) - .replace("{displayname}", p.getDisplayName()) - .replace("%deluxetags_tag%", tag.getDisplayTag(p)) - .replace("{deluxetags_tag}", tag.getDisplayTag(p)) - .replace("%deluxetags_identifier%", tagId) - .replace("{deluxetags_identifier}", tagId) - .replace("%deluxetags_description%", tag.getDescription(p)) - .replace("{deluxetags_description}", tag.getDescription(p)) - .replace("%deluxetags_amount%", amount) - .replace("{deluxetags_amount}", amount) - .replace("%deluxetags_available%", availability) - .replace("{deluxetags_available}", availability); - + .replace("%player%", p.getName()) + .replace("{player}", p.getName()) + .replace("%displayname%", p.getDisplayName()) + .replace("{displayname}", p.getDisplayName()) + .replace("%deluxetags_tag%", tag.getDisplayTag(p)) + .replace("{deluxetags_tag}", tag.getDisplayTag(p)) + .replace("%deluxetags_identifier%", tagId) + .replace("{deluxetags_identifier}", tagId) + .replace("%deluxetags_description%", tag.getDescription(p)) + .replace("{deluxetags_description}", tag.getDescription(p)) + .replace("%deluxetags_amount%", amount) + .replace("{deluxetags_amount}", amount) + .replace("%deluxetags_available%", availability) + .replace("{deluxetags_available}", availability); + if (papi) { s = PlaceholderAPI.setPlaceholders(p, s); } diff --git a/src/main/java/me/clip/deluxetags/tasks/CleanupTask.java b/src/main/java/me/clip/deluxetags/tasks/CleanupTask.java index e79ca38..15a6a10 100644 --- a/src/main/java/me/clip/deluxetags/tasks/CleanupTask.java +++ b/src/main/java/me/clip/deluxetags/tasks/CleanupTask.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; public class CleanupTask implements Runnable { - + DeluxeTags plugin; /** @@ -18,18 +18,18 @@ public class CleanupTask implements Runnable { public CleanupTask(DeluxeTags instance) { plugin = instance; } - + @Override public void run() { final Set playersWithActiveTags = plugin.getTagsHandler().getPlayersWithActiveTags(); - if (playersWithActiveTags.isEmpty()) { + if (playersWithActiveTags.isEmpty()) { return; } - final List toRemove = new ArrayList<>(); + plugin.getFoliaLib().getScheduler().runNextTick(t -> { + final List toRemove = new ArrayList<>(); - Bukkit.getScheduler().runTask(plugin, () -> { - for (final UUID uuid: playersWithActiveTags) { + for (final UUID uuid : playersWithActiveTags) { final Player player = Bukkit.getPlayer(uuid); if (player == null) { toRemove.add(uuid); @@ -45,4 +45,4 @@ public void run() { } }); } -} +} \ No newline at end of file diff --git a/src/main/java/me/clip/deluxetags/updater/UpdateChecker.java b/src/main/java/me/clip/deluxetags/updater/UpdateChecker.java index 92bb082..3d8ad0b 100644 --- a/src/main/java/me/clip/deluxetags/updater/UpdateChecker.java +++ b/src/main/java/me/clip/deluxetags/updater/UpdateChecker.java @@ -4,22 +4,23 @@ import java.io.InputStreamReader; import java.net.URL; import javax.net.ssl.HttpsURLConnection; +import me.clip.deluxetags.DeluxeTags; import me.clip.placeholderapi.util.Msg; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.plugin.Plugin; public class UpdateChecker implements Listener { private final int RESOURCE_ID = 4390; - private Plugin plugin; - private String spigotVersion, pluginVersion; + private final DeluxeTags plugin; + private String spigotVersion; + private final String pluginVersion; private boolean updateAvailable; - public UpdateChecker(Plugin instance) { + public UpdateChecker(DeluxeTags instance) { plugin = instance; pluginVersion = instance.getDescription().getVersion(); } @@ -33,10 +34,10 @@ public String getSpigotVersion() { } public void fetch() { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getFoliaLib().getScheduler().runAsync(asyncTask -> { try { HttpsURLConnection con = (HttpsURLConnection) new URL( - "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); + "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); con.setRequestMethod("GET"); spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); } catch (Exception ex) { @@ -54,20 +55,20 @@ public void fetch() { return; } - Bukkit.getScheduler().runTask(plugin, () -> { + plugin.getFoliaLib().getScheduler().runNextTick(syncTask -> { plugin.getLogger() - .info("An update for DeluxeTags (v" + getSpigotVersion() + ") is available at:"); + .info("An update for DeluxeTags (v" + getSpigotVersion() + ") is available at:"); plugin.getLogger() - .info("https://www.spigotmc.org/resources/deluxetags." + RESOURCE_ID + "/"); + .info("https://www.spigotmc.org/resources/deluxetags." + RESOURCE_ID + "/"); Bukkit.getPluginManager().registerEvents(this, plugin); }); }); } private boolean spigotIsNewer() { - if (spigotVersion == null || spigotVersion.isEmpty()) { - return false; - } + if (spigotVersion == null || spigotVersion.isEmpty()) { + return false; + } String plV = toReadable(pluginVersion); String spV = toReadable(spigotVersion); return plV.compareTo(spV) < 0; @@ -84,10 +85,10 @@ private String toReadable(String version) { public void onJoin(PlayerJoinEvent e) { if (e.getPlayer().hasPermission("deluxetags.updates")) { Msg.msg(e.getPlayer(), - "&bAn update for &5&lDeluxeTags &e(&5&lDeluxeTags &fv" + getSpigotVersion() - + "&e)" - , "&bis available at &ehttps://www.spigotmc.org/resources/deluxetags." + RESOURCE_ID - + "/"); + "&bAn update for &5&lDeluxeTags &e(&5&lDeluxeTags &fv" + getSpigotVersion() + + "&e)" + , "&bis available at &ehttps://www.spigotmc.org/resources/deluxetags." + RESOURCE_ID + + "/"); } } -} +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8608b13..e2b44dd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,6 +5,7 @@ api-version: "1.13" author: extended_clip description: DeluxeChat add on to allow players to select a custom tag softdepend: [PlaceholderAPI] +folia-supported: true commands: tags: description: DeluxeTags command