Skip to content

Commit

Permalink
Merge pull request #105 from ewof/folia
Browse files Browse the repository at this point in the history
folia support
  • Loading branch information
Majekdor authored Aug 2, 2023
2 parents 86d70ab + b405506 commit a6e85e6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,12 @@
<version>5.0.1</version>
<scope>compile</scope>
</dependency>
<!-- Universal Scheduler -->
<dependency>
<groupId>com.github.Anon8281</groupId>
<artifactId>UniversalScheduler</artifactId>
<version>0.1.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
13 changes: 10 additions & 3 deletions src/main/java/dev/majek/hexnicks/HexNicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package dev.majek.hexnicks;

import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand All @@ -38,7 +40,6 @@
import dev.majek.hexnicks.util.LoggingManager;
import dev.majek.hexnicks.util.UpdateChecker;
import java.io.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -48,7 +49,6 @@
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -71,6 +71,7 @@ public final class HexNicks extends JavaPlugin {
private final Map<UUID, Component> nickMap;
private final Metrics metrics;
private final UpdateChecker updateChecker;
private static TaskScheduler scheduler;

/**
* Initialize plugin.
Expand Down Expand Up @@ -103,6 +104,8 @@ public void onEnable() {
this.getPluginLoader().disablePlugin(this);
}

scheduler = UniversalScheduler.getScheduler(core);

// Make sure nickname storage file exists
boolean dataFolderExists = this.getDataFolder().exists();
if (!dataFolderExists) {
Expand Down Expand Up @@ -137,7 +140,7 @@ public void onEnable() {
storage = new SqlStorage();
storage.updateNicks();
logging.log("Successfully connected to MySQL database.");
Bukkit.getScheduler().scheduleSyncRepeatingTask(HexNicks.core(), () -> HexNicks.storage().updateNicks(),
HexNicks.getScheduler().runTaskTimer(() -> HexNicks.storage().updateNicks(),
200L, this.getConfig().getInt("update-interval", 300) * 20L);
} catch (final SQLException ex) {
logging.error("Failed to connect to MySQL database", ex);
Expand Down Expand Up @@ -173,6 +176,10 @@ public void onEnable() {
}
}

public static TaskScheduler getScheduler() {
return scheduler;
}

private void loadNicknamesFromJson() {
try {
storage = new JsonStorage();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/majek/hexnicks/command/CommandNick.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
Messages.WORKING.send(player);

// Asynchronously check to make sure the nickname isn't taken
HexNicks.core().getServer().getScheduler().runTaskAsynchronously(HexNicks.core(), () -> {
HexNicks.getScheduler().runTaskAsynchronously(() -> {
// Make sure the nickname isn't taken
if (!MiscUtils.preventDuplicates(finalNick, player)) {
// Set nick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
Messages.WORKING.send(player);

// Asynchronously check to make sure the nickname isn't taken
HexNicks.core().getServer().getScheduler().runTaskAsynchronously(HexNicks.core(), () -> {
HexNicks.getScheduler().runTaskAsynchronously(() -> {
// Make sure the nickname isn't taken
if (!MiscUtils.preventDuplicates(finalNick, player)) {
// Set nick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
Messages.WORKING.send(sender);

// Asynchronously check to make sure the nickname isn't taken
HexNicks.core().getServer().getScheduler().runTaskAsynchronously(HexNicks.core(), () -> {
HexNicks.getScheduler().runTaskAsynchronously(() -> {
// Make sure the nickname isn't taken
if (!MiscUtils.preventDuplicates(finalNick, target)) {
// Set nick
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/majek/hexnicks/event/PlayerChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.jetbrains.annotations.NotNull;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/majek/hexnicks/storage/SqlStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public CompletableFuture<Component> getNick(@NotNull UUID uuid) {
@Override
public void removeNick(@NotNull UUID uuid) {
HexNicks.logging().debug("Firing SqlStorage#removeNick...");
Bukkit.getScheduler().runTaskAsynchronously(HexNicks.core(), () -> {
HexNicks.getScheduler().runTaskAsynchronously(() -> {
try (Connection connection = HikariManager.getConnection()) {
PreparedStatement ps = connection.prepareStatement("DELETE FROM nicknameTable WHERE uniqueId=?");
ps.setString(1, uuid.toString());
Expand All @@ -114,7 +114,7 @@ public void removeNick(@NotNull UUID uuid) {
@Override
public void saveNick(@NotNull Player player, @NotNull Component nickname) {
HexNicks.logging().debug("Firing SqlStorage#saveNick...");
Bukkit.getScheduler().runTaskAsynchronously(HexNicks.core(), () ->
HexNicks.getScheduler().runTaskAsynchronously(() ->
hasNick(player.getUniqueId()).whenCompleteAsync((hasNick, throwable) -> {
try (Connection connection = HikariManager.getConnection()) {
PreparedStatement update;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: HexNicks
version: ${project.version}
main: dev.majek.hexnicks.HexNicks
api-version: 1.13
folia-supported: true
authors: [Majekdor]
description: ${project.description}
softdepend: [PlaceholderAPI, Vault, Essentials]
Expand Down Expand Up @@ -113,4 +114,4 @@ permissions:
hexnicks.decoration.strikethrough:
default: true
hexnicks.decoration.obfuscated:
default: true
default: true

0 comments on commit a6e85e6

Please sign in to comment.