Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ repositories {

maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.extendedclip.com/releases/")
maven("https://repo.tcoded.com/releases")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.21.9-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.6")

implementation("com.github.cryptomorin:XSeries:13.7.0")
implementation("com.tcoded:FoliaLib:0.5.1")
}

tasks {
Expand All @@ -47,6 +49,7 @@ tasks {

withType<ShadowJar> {
relocate("com.cryptomorin.xseries", "me.clip.deluxetags.libs.xseries")
relocate("com.tcoded.folialib", "me.clip.deluxetags.libs.folialib")
archiveFileName.set("DeluxeTags-${project.version}.jar")
}
}
Expand Down
98 changes: 55 additions & 43 deletions src/main/java/me/clip/deluxetags/DeluxeTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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()) {
Expand All @@ -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");
Expand All @@ -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;
}
Expand Down Expand Up @@ -196,21 +208,21 @@ 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)) {
c.set(uuid, null);
playerFile.saveConfig();
}
}

public void removeSavedTags(List<UUID> uuids) {
boolean requiresSave = false;
FileConfiguration config = playerFile.getConfig();
Expand All @@ -230,7 +242,7 @@ public void removeSavedTags(List<UUID> uuids) {
playerFile.saveConfig();
}
}

public void loadMessages() {
Lang.setFile(messages.getConfig());

Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/me/clip/deluxetags/tasks/CleanupTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.bukkit.entity.Player;

public class CleanupTask implements Runnable {

DeluxeTags plugin;

/**
Expand All @@ -18,18 +18,18 @@ public class CleanupTask implements Runnable {
public CleanupTask(DeluxeTags instance) {
plugin = instance;
}

@Override
public void run() {
final Set<UUID> playersWithActiveTags = plugin.getTagsHandler().getPlayersWithActiveTags();
if (playersWithActiveTags.isEmpty()) {
if (playersWithActiveTags.isEmpty()) {
return;
}

final List<UUID> toRemove = new ArrayList<>();
plugin.getFoliaLib().getScheduler().runNextTick(t -> {
final List<UUID> 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);
Expand All @@ -45,4 +45,4 @@ public void run() {
}
});
}
}
}
35 changes: 18 additions & 17 deletions src/main/java/me/clip/deluxetags/updater/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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
+ "/");
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down