Skip to content

Commit

Permalink
Merge pull request #4 from CraptiCraft-Development/fix/folialib-update
Browse files Browse the repository at this point in the history
FoliaLib Update & New PAPI Placeholder
  • Loading branch information
Loving11ish authored Sep 14, 2024
2 parents 9cb876f + 31e60ec commit 040ecb3
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 98 deletions.
6 changes: 6 additions & 0 deletions .idea/scala_compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.loving11ish</groupId>
<artifactId>EpicHomes</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>

<name>EpicHomes</name>
Expand Down Expand Up @@ -161,7 +161,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<version>3.15.0</version>
<scope>compile</scope>
</dependency>

Expand All @@ -187,9 +187,9 @@
</dependency>

<dependency>
<groupId>com.tcoded</groupId>
<groupId>com.github.technicallycoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.3.4</version>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>

Expand Down
50 changes: 35 additions & 15 deletions src/main/java/me/loving11ish/epichomes/EpicHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void onLoad() {

// Server version compatibility check
if (versionCheckerUtils.getVersion() < 16 || versionCheckerUtils.getVersion() > 21
|| !versionCheckerUtils.isVersionCheckedSuccessfully()) {
|| !versionCheckerUtils.isVersionCheckedSuccessfully()
&& !serverVersion.serverVersionEqual(ServerVersion.Other)) {
MessageUtils.sendConsole("&4-------------------------------------------");
MessageUtils.sendConsole("&4Your server version is: &d" + Bukkit.getVersion());
MessageUtils.sendConsole("&4This plugin is only supported on the Minecraft versions listed below:");
Expand All @@ -102,7 +103,6 @@ public void onLoad() {
MessageUtils.sendConsole("&41.21.x");
MessageUtils.sendConsole("&4Is now disabling!");
MessageUtils.sendConsole("&4-------------------------------------------");
Bukkit.getPluginManager().disablePlugin(this);
setPluginEnabled(false);
return;
} else {
Expand All @@ -119,7 +119,6 @@ public void onLoad() {
MessageUtils.sendConsole("&4This plugin uses features that your server most likely doesn't have!");
MessageUtils.sendConsole("&4Is now disabling!");
MessageUtils.sendConsole("&4-------------------------------------------");
Bukkit.getPluginManager().disablePlugin(this);
setPluginEnabled(false);
return;
}
Expand All @@ -137,6 +136,19 @@ public void onLoad() {

@Override
public void onEnable() {
// Plugin startup logic

// Check plugin was not disabled during onLoad
if (!isPluginEnabled()) {
MessageUtils.sendConsole("&4-------------------------------------------");
MessageUtils.sendConsole("&4Plugin has been disabled during onLoad!");
MessageUtils.sendConsole("&4See above for details!");
MessageUtils.sendConsole("&4Disabling plugin!");
MessageUtils.sendConsole("&4-------------------------------------------");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

// Load internal plugin objects
setUsermapStorageUtil(new UsermapStorageUtil());

Expand Down Expand Up @@ -243,7 +255,7 @@ public void onEnable() {
setPluginEnabled(true);

// Start auto save task
getFoliaLib().getImpl().runLaterAsync(() -> {
getFoliaLib().getScheduler().runLaterAsync(() -> {
AutoSaveTaskUtils.runAutoSaveTask();
MessageUtils.sendConsole(getMessagesManager().getAutoSaveStart());
}, 5L, TimeUnit.SECONDS);
Expand Down Expand Up @@ -281,7 +293,7 @@ public void onDisable() {
MessageUtils.sendDebugConsole( "&aAuto save timed task canceled successfully");
AutoSaveTaskUtils.getAutoSaveTask().cancel();
}
getFoliaLib().getImpl().cancelAllTasks();
getFoliaLib().getScheduler().cancelAllTasks();
if (getFoliaLib().isUnsupported()) {
Bukkit.getScheduler().cancelTasks(this);
MessageUtils.sendDebugConsole( "&aBukkit scheduler tasks canceled successfully");
Expand Down Expand Up @@ -343,17 +355,25 @@ public static PlayerMenuUtility getPlayerMenuUtility(Player player) {
}

private void setVersion() {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
if (bukkitVersion.contains("1.20.5")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.20.6")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.21")) {
serverVersion = ServerVersion.v1_21_R1;
} else {
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
try {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
if (bukkitVersion.contains("1.20.5")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.20.6")) {
serverVersion = ServerVersion.v1_20_R5;
} else if (bukkitVersion.contains("1.21")) {
serverVersion = ServerVersion.v1_21_R1;
} else if (bukkitVersion.contains("1.21.1")) {
serverVersion = ServerVersion.v1_21_R2;
}else {
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
}
} catch (Exception e) {
serverVersion = ServerVersion.Other;
MessageUtils.sendDebugConsole("Failed to detect server version, defaulting to: " + serverVersion);
}
MessageUtils.sendDebugConsole("Set server version: " + serverVersion);
}

public static EpicHomes getPlugin() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/loving11ish/epichomes/api/EpicHomesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static void teleportPlayerToHomeLocation(Player player, Location homeLoca
User user = EpicHomes.getPlugin().getUsermapStorageUtil().getUserByOnlinePlayer(player);
TeleportationUtils teleportationUtils = new TeleportationUtils();

getFoliaLib().getImpl().runAsync((task) -> {
getFoliaLib().getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, homeName, homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand All @@ -181,7 +181,7 @@ public static void teleportPlayerToHomeLocationTimed(Player player, Location hom
User user = EpicHomes.getPlugin().getUsermapStorageUtil().getUserByOnlinePlayer(player);
TeleportationUtils teleportationUtils = new TeleportationUtils();

getFoliaLib().getImpl().runAsync((task) -> {
getFoliaLib().getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, homeName, homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,11 @@ else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("list")

case "delete":
if (args.length == 3) {
if (args[1] != null && args[2] != null) {

if (player.hasPermission("epichomes.command.deleteothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new DeleteSubCommand().adminDeleteHomeSubCommand(sender, args);
}

else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}

else {
MessageUtils.sendPlayerNoPrefix(player, sendUsageMessage());
if (player.hasPermission("epichomes.command.deleteothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new DeleteSubCommand().adminDeleteHomeSubCommand(sender, args);
} else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}
Expand All @@ -66,21 +56,11 @@ else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("list")

case "visit":
if (args.length == 3) {
if (args[1] != null && args[2] != null) {

if (player.hasPermission("epichomes.command.visitothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new HomeAdminVisitSubCommand().homeAdminVisitSubCommand(sender, args);
}

else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}

else {
MessageUtils.sendPlayerNoPrefix(player, sendUsageMessage());
if (player.hasPermission("epichomes.command.visitothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new HomeAdminVisitSubCommand().homeAdminVisitSubCommand(sender, args);
} else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}
Expand All @@ -93,21 +73,11 @@ else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("list")

case "list":
if (args.length == 2) {
if (args[1] != null) {

if (player.hasPermission("epichomes.command.listothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new ListSubCommand().adminListSubCommand(sender, args);
}

else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}

else {
MessageUtils.sendPlayerNoPrefix(player, sendUsageMessage());
if (player.hasPermission("epichomes.command.listothers") || player.hasPermission("epichomes.command.*")
|| player.hasPermission("epichomes.admin") || player.hasPermission("epichomes.*") || player.isOp()) {
return new ListSubCommand().adminListSubCommand(sender, args);
} else {
MessageUtils.sendPlayer(player, EpicHomes.getPlugin().getMessagesManager().getNoPermission());
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HomeCommand implements CommandExecutor, TabCompleter {
private final UsermapStorageUtil usermapStorageUtil = EpicHomes.getPlugin().getUsermapStorageUtil();

public static void updateBannedNamesList() {
foliaLib.getImpl().runLaterAsync(() ->
foliaLib.getScheduler().runLaterAsync(() ->
bannedNames = EpicHomes.getPlugin().getConfigManager().getBannedHomeNames(), 50L, TimeUnit.MILLISECONDS);
}

Expand Down Expand Up @@ -130,7 +130,7 @@ else if (args[0].equalsIgnoreCase("set")
TeleportationUtils teleportationUtils = new TeleportationUtils();

if (EpicHomes.getPlugin().getConfigManager().isUseDelayBeforeHomeTP()) {
foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, args[0], homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand All @@ -139,7 +139,7 @@ else if (args[0].equalsIgnoreCase("set")
}

else {
foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, args[0], homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -19,12 +20,12 @@ public class SetHomeCommand implements CommandExecutor {
private static List<String> bannedNames;

public static void updateBannedNamesList() {
foliaLib.getImpl().runLaterAsync(() ->
foliaLib.getScheduler().runLaterAsync(() ->
bannedNames = EpicHomes.getPlugin().getConfigManager().getBannedHomeNames(), 50L, TimeUnit.MILLISECONDS);
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean deleteSubCommand(CommandSender sender, String[] args) {
try {
if (usermapStorageUtil.removeHomeFromUser(user, homeName)) {

foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomeDeleteEvent(player, user, homeName);
MessageUtils.sendDebugConsole("&aFired AsyncHomeDeleteEvent");
});
Expand Down Expand Up @@ -80,7 +80,7 @@ public boolean deleteHomeSubCommand(CommandSender sender, String[] args) {
try {
if (usermapStorageUtil.removeHomeFromUser(user, homeName)) {

foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomeDeleteEvent(player, user, homeName);
MessageUtils.sendDebugConsole("&aFired AsyncHomeDeleteEvent");
});
Expand Down Expand Up @@ -120,7 +120,7 @@ public boolean adminDeleteHomeSubCommand(CommandSender sender, String[] args) {
try {
if (usermapStorageUtil.removeHomeFromUser(targetUser, homeName)) {

foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomeDeleteEvent(offlineTarget.getPlayer(), targetUser, homeName);
MessageUtils.sendDebugConsole("&aFired AsyncHomeDeleteEvent");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean homeAdminVisitSubCommand(CommandSender sender, String[] args) {
TeleportationUtils teleportationUtils = new TeleportationUtils();
if (EpicHomes.getPlugin().getConfigManager().isUseDelayBeforeHomeTP()) {

foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, args[2], homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand All @@ -56,7 +56,7 @@ public boolean homeAdminVisitSubCommand(CommandSender sender, String[] args) {
}

else {
foliaLib.getImpl().runAsync((task) -> {
foliaLib.getScheduler().runAsync((task) -> {
fireHomePreTeleportEvent(player, user, args[2], homeLocation, player.getLocation());
MessageUtils.sendDebugConsole("&aFired AsyncHomePreTeleportEvent");
});
Expand Down
Loading

0 comments on commit 040ecb3

Please sign in to comment.