Skip to content
Merged
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
1 change: 1 addition & 0 deletions EpicHomes.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
Expand Down
6 changes: 5 additions & 1 deletion 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.3</version>
<version>1.1.4-BETA-04</version>
<packaging>jar</packaging>

<name>EpicHomes</name>
Expand Down Expand Up @@ -129,6 +129,10 @@
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>paper-mc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
Expand Down
40 changes: 27 additions & 13 deletions src/main/java/me/loving11ish/epichomes/EpicHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import me.loving11ish.epichomes.menusystem.PlayerMenuUtility;
import me.loving11ish.epichomes.updatesystem.JoinEvent;
import me.loving11ish.epichomes.updatesystem.UpdateChecker;
import me.loving11ish.epichomes.utils.AutoSaveTaskUtils;
import me.loving11ish.epichomes.utils.MessageUtils;
import me.loving11ish.epichomes.utils.UsermapStorageUtil;
import me.loving11ish.epichomes.utils.VersionCheckerUtils;
import me.loving11ish.epichomes.utils.*;
import me.loving11ish.epichomes.versionsystems.ServerVersion;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -58,7 +55,7 @@ public final class EpicHomes extends JavaPlugin {
private TeleportationManager teleportationManager;

private final List<String> pluginCommands = new ArrayList<>();
private static final HashMap<Player, PlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();
private final HashMap<Player, PlayerMenuUtility> playerMenuUtilityMap = new HashMap<>();

@Override
public void onLoad() {
Expand Down Expand Up @@ -90,23 +87,30 @@ public void onLoad() {
versionCheckerUtils.getServerVersion();
versionCheckerUtils.setVersion();

ServerVersion detectedServerVersion = getServerVersion();

// Server version compatibility check
if (versionCheckerUtils.getVersion() < 16 || versionCheckerUtils.getVersion() > 21
|| !versionCheckerUtils.isVersionCheckedSuccessfully()
&& !serverVersion.serverVersionEqual(ServerVersion.Other)) {
boolean versionDetectionFailed = !versionCheckerUtils.isVersionCheckedSuccessfully()
|| detectedServerVersion == null
|| detectedServerVersion.serverVersionEqual(ServerVersion.Other);

boolean unsupportedLegacyVersion = !versionDetectionFailed
&& detectedServerVersion.isLegacyVersionScheme()
&& detectedServerVersion.serverVersionLessThan(ServerVersion.v1_16_R3);

if (versionDetectionFailed || unsupportedLegacyVersion) {
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:");
MessageUtils.sendConsole("&4This plugin is only tested on the Minecraft versions listed below:");
MessageUtils.sendConsole("&41.16.x");
MessageUtils.sendConsole("&41.17.x");
MessageUtils.sendConsole("&41.18.x");
MessageUtils.sendConsole("&41.19.x");
MessageUtils.sendConsole("&41.20.x");
MessageUtils.sendConsole("&41.21.x");
MessageUtils.sendConsole("&4Is now disabling!");
MessageUtils.sendConsole("&426.x.x");
MessageUtils.sendConsole("&4NO SUPPORT OR DEVELOPMENT HELP IS GUARANTEED FOR OTHER VERSIONS!");
MessageUtils.sendConsole("&4-------------------------------------------");
setPluginEnabled(false);
return;
} else {
MessageUtils.sendConsole("&a-------------------------------------------");
MessageUtils.sendConsole("&aA supported Minecraft version has been detected");
Expand Down Expand Up @@ -279,6 +283,12 @@ public void onEnable() {
AutoSaveTaskUtils.runAutoSaveTask();
MessageUtils.sendConsole(getMessagesManager().getAutoSaveStart());
}, 5L, TimeUnit.SECONDS);

// Start auto cleanup task
getFoliaLib().getScheduler().runLaterAsync(() -> {
AutoCleanupTaskUtils.runAutoCleanupTask();
MessageUtils.sendDebugConsole("Auto cleanup task started successfully");
}, 6L, TimeUnit.SECONDS);
}

@Override
Expand Down Expand Up @@ -369,7 +379,7 @@ public void onDisable() {
plugin = null;
}

public static PlayerMenuUtility getPlayerMenuUtility(Player player) {
public PlayerMenuUtility getPlayerMenuUtility(Player player) {
PlayerMenuUtility playerMenuUtility;
if (!(playerMenuUtilityMap.containsKey(player))) {
playerMenuUtility = new PlayerMenuUtility(player);
Expand Down Expand Up @@ -483,4 +493,8 @@ public TeleportationManager getTeleportationManager() {
public void setTeleportationManager(TeleportationManager teleportationManager) {
this.teleportationManager = teleportationManager;
}

public HashMap<Player, PlayerMenuUtility> getRawPlayerMenuUtilityMap() {
return playerMenuUtilityMap;
}
}
77 changes: 74 additions & 3 deletions src/main/java/me/loving11ish/epichomes/api/EpicHomesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import me.loving11ish.epichomes.models.User;
import me.loving11ish.epichomes.utils.MessageUtils;
import me.loving11ish.epichomes.utils.TeleportationUtils;
import me.loving11ish.epichomes.versionsystems.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;

/**
* EpicHomesAPI is a class that provides a set of methods for developers to use when interacting with EpicHomes.
Expand Down Expand Up @@ -65,6 +64,62 @@ public static int getMajorServerVersion() {
return EpicHomes.getPlugin().getVersionCheckerUtils().getVersion();
}

/**
* @return Returns an integer that is the first version number in the version enum.
*/
public static int getFirstVersionNumber() {
return EpicHomes.getPlugin().getVersionCheckerUtils().getFirstVersionNumber();
}

/**
* @return Returns an integer that is the second version number in the version enum
*/
public static int getSecondVersionNumber() {
return EpicHomes.getPlugin().getVersionCheckerUtils().getSecondVersionNumber();
}

/**
* @return Returns an integer that is the current patch version of the current version enum.
* For old versions like 1.21.4, this returns 4. For new versions like 26.1, this returns 0.
*/
public static int getPatchVersionNumber() {
return EpicHomes.getPlugin().getVersionCheckerUtils().getPatchVersionNumber();
}

/**
* @return Returns `true` if the server is running an old server version like `1.21.11`.
* Returns `false` if the server is running a new server version like `26.1.x`.
*/
public static boolean isLegacyVersionScheme() {
return EpicHomes.getPlugin().getVersionCheckerUtils().isLegacyVersionScheme();
}

/**
* @return Returns `true` if the server is running a new server version like `26.1.x`.
* Returns `false` if the server is running an old server version like `1.21.11`.
*/
public static boolean isNewVersionScheme() {
return EpicHomes.getPlugin().getVersionCheckerUtils().isNewVersionScheme();
}

/**
* This is very useful if you need a quick way to check that the server is at `1.21.0 or higher`,
* without needing to do a version check yourself.
* @return Returns `true` if the current server version is at least `1.21.0`+.
*/
public static boolean isAtLeastMinecraft1_21() {
return EpicHomes.getPlugin().getVersionCheckerUtils().isAtLeastMinecraft1_21();
}

/**
* Generic helper if you want to compare the current version against a specific enum version.
* @param requiredVersion Version enum to compare the current server version against.
* @return Returns `true` if the provided enum equals or is higher than the current server version.
*/
public static boolean isAtLeast(ServerVersion requiredVersion) {
return EpicHomes.getPlugin().getVersionCheckerUtils().isAtLeast(requiredVersion);
}

/**
* @return Returns `true` if the server or network is able to connect to the Mojang auth servers. Otherwise, returns `false`.
*/
Expand Down Expand Up @@ -141,6 +196,22 @@ public static Location getPlayerHomeLocationByHomeName(User user, String homeNam
return EpicHomes.getPlugin().getUsermapStorageUtil().getHomeLocationByHomeName(user, homeName);
}

/**
* @param player The Bukkit Player object to get the home locations from.
* @return Returns a Set of Map Entries containing the home name and location for the provided player.
*/
public static Set<Map.Entry<String, Location>> getHomeLocationsListByPlayer(Player player) {
return EpicHomes.getPlugin().getUsermapStorageUtil().getHomeLocationsListByPlayer(player);
}

/**
* @param offlinePlayer The Bukkit OfflinePlayer object to get the home locations from.
* @return Returns a Set of Map Entries containing the home name and location for the provided offline player.
*/
public static Set<Map.Entry<String, Location>> getHomeLocationsListByOfflinePlayer(OfflinePlayer offlinePlayer) {
return EpicHomes.getPlugin().getUsermapStorageUtil().getHomeLocationsListByOfflinePlayer(offlinePlayer);
}

/**
* @param uuid The UUID object of the player to get.
* @return Returns a WrappedTask object of the players pending teleport, or null if none found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (args.length < 1) {

if (EpicHomes.getPlugin().isGUIEnabled()) {
new DeleteHomesListGUI(EpicHomes.getPlayerMenuUtility(player)).open();
new DeleteHomesListGUI(EpicHomes.getPlugin().getPlayerMenuUtility(player)).open();
}

else {
Expand All @@ -47,7 +47,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (args[0] != null) {
if (EpicHomes.getPlugin().isGUIEnabled()) {

PlayerMenuUtility playerMenuUtility = EpicHomes.getPlayerMenuUtility(player);
PlayerMenuUtility playerMenuUtility = EpicHomes.getPlugin().getPlayerMenuUtility(player);
playerMenuUtility.setUser(user);
playerMenuUtility.setHomeName(args[0]);
Location location = usermapStorageUtil.getHomeLocationByHomeName(user, args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

if (args.length < 1) {
if (EpicHomes.getPlugin().isGUIEnabled()) {
new HomeListGUI(EpicHomes.getPlayerMenuUtility(player)).open();
new HomeListGUI(EpicHomes.getPlugin().getPlayerMenuUtility(player)).open();
}

else {
Expand Down Expand Up @@ -83,7 +83,7 @@ else if (args[0].equalsIgnoreCase("set")
if (args[1] != null) {
if (EpicHomes.getPlugin().isGUIEnabled()) {

PlayerMenuUtility playerMenuUtility = EpicHomes.getPlayerMenuUtility(player);
PlayerMenuUtility playerMenuUtility = EpicHomes.getPlugin().getPlayerMenuUtility(player);
playerMenuUtility.setUser(user);
playerMenuUtility.setHomeName(args[1]);
playerMenuUtility.setHomeLocation(usermapStorageUtil.getHomeLocationByHomeName(user, args[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import me.loving11ish.epichomes.managers.filemanagers.ConfigManager;
import me.loving11ish.epichomes.managers.filemanagers.MessagesManager;
import me.loving11ish.epichomes.updatesystem.UpdateChecker;
import me.loving11ish.epichomes.utils.AutoCleanupTaskUtils;
import me.loving11ish.epichomes.utils.AutoSaveTaskUtils;
import me.loving11ish.epichomes.utils.MessageUtils;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -87,6 +88,11 @@ private void handleReload() {
MessageUtils.sendDebugConsole( "&aAuto save timed task canceled successfully");
AutoSaveTaskUtils.getAutoSaveTask().cancel();
}
if (!AutoCleanupTaskUtils.getAutoCleanupTask().isCancelled()) {
MessageUtils.sendDebugConsole( "&aWrapped task: " + AutoCleanupTaskUtils.getAutoCleanupTask().toString());
MessageUtils.sendDebugConsole( "&aAuto cleanup timed task canceled successfully");
AutoCleanupTaskUtils.getAutoCleanupTask().cancel();
}
foliaLib.getScheduler().cancelAllTasks();
if (foliaLib.isUnsupported()) {
Bukkit.getScheduler().cancelTasks(EpicHomes.getPlugin());
Expand Down Expand Up @@ -147,6 +153,12 @@ private void handleReload() {
AutoSaveTaskUtils.runAutoSaveTask();
MessageUtils.sendConsole(EpicHomes.getPlugin().getMessagesManager().getAutoSaveStart());
}, 5L, TimeUnit.SECONDS);

// Restart auto cleanup task
foliaLib.getScheduler().runLaterAsync(() -> {
AutoCleanupTaskUtils.runAutoCleanupTask();
MessageUtils.sendDebugConsole("Auto cleanup task started successfully");
}, 6L, TimeUnit.SECONDS);
}, 6L, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public void onPlayerDisconnect(PlayerQuitEvent event) {
MessageUtils.sendConsole("error", "Failed to remove timed teleport for player " + player.getName() + "!");
}
}

EpicHomes.getPlugin().getRawPlayerMenuUtilityMap().remove(player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.loving11ish.epichomes.utils;

import com.tcoded.folialib.FoliaLib;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import me.loving11ish.epichomes.EpicHomes;

import java.util.concurrent.TimeUnit;

public class AutoCleanupTaskUtils {

private static final FoliaLib foliaLib = EpicHomes.getFoliaLib();

public static WrappedTask autoCleanupTask;

public static void runAutoCleanupTask() {
autoCleanupTask = foliaLib.getScheduler().runTimerAsync(() -> {
EpicHomes.getPlugin().getRawPlayerMenuUtilityMap().clear();
MessageUtils.sendDebugConsole("Player menu utility map cleared by auto-cleanup task.");
}, 1L, 3600L, TimeUnit.SECONDS); // Runs every hour
}

public static WrappedTask getAutoCleanupTask() {
return autoCleanupTask;
}
}
Loading