Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia Support Using MineLib #3

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.wordBasedSuggestions": "matchingDocuments"
}
31 changes: 31 additions & 0 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,36 @@
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<!-- MineLib -->
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-entity</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-global</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-async</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-canceller</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.projectunified</groupId>
<artifactId>minelib-scheduler-common</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
6 changes: 4 additions & 2 deletions bukkit/src/main/java/net/leaderos/plugin/Bukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import org.bstats.bukkit.Metrics;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

import java.io.File;

Expand Down Expand Up @@ -184,7 +187,7 @@ public void setupFiles() {
}

public void checkUpdate() {
org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {
AsyncScheduler.get(this).run(() -> {
PluginUpdater updater = new PluginUpdater(getDescription().getVersion());
try {
if (updater.checkForUpdates()) {
Expand All @@ -197,7 +200,6 @@ public void checkUpdate() {
} catch (Exception ignored) {}
});
}

/**
* Constructor of Main class
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import net.leaderos.shared.helpers.RequestUtil;
import net.leaderos.shared.modules.auth.AuthHelper;
import org.bukkit.entity.Player;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

/**
* Auth commands
Expand All @@ -20,7 +23,7 @@
@RequiredArgsConstructor
@Command(value = "auth", alias = {"authy", "kayit", "site", "web"})
public class AuthCommand extends BaseCommand {

private static Bukkit instance;
/**
* Default command of auth
* @param player executor
Expand All @@ -35,7 +38,7 @@ public void defaultCommand(Player player) {

RequestUtil.addRequest(player.getUniqueId());

org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {
AsyncScheduler.get(instance).run(() -> {
String link = AuthHelper.getAuthLink(player.getName(), player.getUniqueId());
if (link != null)
player.spigot().sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

import java.net.HttpURLConnection;
import java.text.SimpleDateFormat;
Expand All @@ -41,6 +44,7 @@ public class BazaarAddItemGui {
*/
public BazaarAddItemGui() {}

private static Bukkit instance;

/**
* Opens gui to player
Expand Down Expand Up @@ -113,7 +117,7 @@ public static void showGui(Player player, int itemAmount) {
String modelId = ItemUtil.getModelId(item);
String enchantment = ItemUtil.getEnchantments(item);

org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {
AsyncScheduler.get(instance).run(() -> {
// Sends response
try {
Response postBazaarItem = new AddBazaarItemRequest(userId, name, lore, amount, maxDurability, durability, base64, price, creationDate, modelId, enchantment, serverId, material.name()).getResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import net.leaderos.shared.helpers.RequestUtil;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

import java.util.List;

Expand All @@ -28,6 +31,10 @@ public class BazaarGui {
* Constructor of gui
*/
public BazaarGui() {}
/**
* Instance of plugin
*/
private static Bukkit instance;

/**
* Opens gui to player
Expand All @@ -42,7 +49,7 @@ public static void showGui(Player player) {

RequestUtil.addRequest(player.getUniqueId());

org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {
AsyncScheduler.get(instance).run(() -> {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getBazaar().getGui().getLayout().toArray(new String[0]);
// Inventory object
Expand Down Expand Up @@ -85,7 +92,7 @@ public static void showGui(Player player) {
String subtitleProgress = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getBazaarGui().getWithdrawProgressSubtitle());
player.sendTitle(title, subtitleProgress);

org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {
AsyncScheduler.get(instance).run(() -> {
Error error = playerBazaarItem.withdrawItem(player);
if (error == null)
player.sendTitle(title, subtitleSuccess);
Expand All @@ -105,7 +112,7 @@ else if (error == Error.DELETE_ERROR)
gui.addElement(GuiHelper.createNextPage(Bukkit.getInstance().getModulesFile().getBazaar().getGui().getNextPage().getItem()));
gui.addElement(GuiHelper.createPreviousPage(Bukkit.getInstance().getModulesFile().getBazaar().getGui().getPreviousPage().getItem()));

org.bukkit.Bukkit.getScheduler().runTask(Bukkit.getInstance(), () -> {
GlobalScheduler.get(instance).run(() -> {
gui.show(player);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

/**
* Login listener class
Expand All @@ -13,12 +16,14 @@
*/
public class LoginListener implements Listener {

private static Bukkit instance;

/**
* Login event of player
* @param event LoginEvent
*/
@EventHandler
public void playerLoginEvent(PlayerLoginEvent event) {
org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> User.loadPlayerCache(event.getPlayer()));
AsyncScheduler.get(instance).run(() -> User.loadPlayerCache(event.getPlayer()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

/**
* Quit listener for remove cache
Expand All @@ -19,13 +22,15 @@ public class QuitListener implements Listener {
*/
public QuitListener(){}

private static Bukkit instance;

/**
* QuitListener for remove cache
* @param event QuitEvent
*/
@EventHandler
public void quitListener(PlayerQuitEvent event) {
org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> User.unloadPlayerCache(event.getPlayer().getName()));
AsyncScheduler.get(instance).run(() -> User.unloadPlayerCache(event.getPlayer().getName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -33,6 +36,8 @@ public class User {
@Getter
private static HashMap<String, User> userList = new HashMap<>();

private static Bukkit instance;

/**
* Gets one player @Nullable
* @param name - player name
Expand Down Expand Up @@ -142,7 +147,7 @@ public static boolean isPlayerAuthed(Player player) {
* loads all player data
*/
public static void loadAllPlayers() {
org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () ->
AsyncScheduler.get(instance).run(() ->
org.bukkit.Bukkit.getOnlinePlayers().forEach(User::loadPlayerCache));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.leaderos.shared.modules.connect.socket.SocketClient;
import net.leaderos.shared.modules.connect.data.CommandsQueue;
import org.bukkit.event.HandlerList;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;

import java.net.URISyntaxException;
import java.util.List;
Expand All @@ -22,6 +25,8 @@
@Getter
public class ConnectModule extends LeaderOSModule {

private static Bukkit instance;

/**
* Socket client for connect to leaderos
*/
Expand Down Expand Up @@ -75,7 +80,7 @@ public void executeCommands(List<String> commands, String username) {
});
} else {
// Execute commands
org.bukkit.Bukkit.getScheduler().runTask(Bukkit.getInstance(), () -> {
GlobalScheduler.get(instance).run(() -> {
commands.forEach(command -> {
org.bukkit.Bukkit.dispatchCommand(org.bukkit.Bukkit.getConsoleSender(), command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import io.github.projectunified.minelib.scheduler.async.AsyncScheduler;
import io.github.projectunified.minelib.scheduler.common.task.Task;
import io.github.projectunified.minelib.scheduler.global.GlobalScheduler;
import io.github.projectunified.minelib.scheduler.entity.EntityScheduler;

import java.util.List;

Expand All @@ -18,6 +22,8 @@
* @since 1.0
*/
public class LoginListener implements Listener {

private static Bukkit instance;

/**
* Listens player join event to execute commands
Expand All @@ -34,7 +40,7 @@ public void onJoin(PlayerJoinEvent event) {
if (commands == null || commands.isEmpty()) return;

// Execute commands
org.bukkit.Bukkit.getScheduler().runTaskLater(Bukkit.getInstance(), () -> {
EntityScheduler.get(instance, player).runLater(() -> {
if (!player.isOnline()) return;

commands.forEach(command -> {
Expand Down
Loading