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
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-01</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
19 changes: 13 additions & 6 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 @@ -279,6 +276,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 +372,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 +486,8 @@ public TeleportationManager getTeleportationManager() {
public void setTeleportationManager(TeleportationManager teleportationManager) {
this.teleportationManager = teleportationManager;
}

public HashMap<Player, PlayerMenuUtility> getRawPlayerMenuUtilityMap() {
return playerMenuUtilityMap;
}
}
20 changes: 17 additions & 3 deletions src/main/java/me/loving11ish/epichomes/api/EpicHomesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
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 @@ -141,6 +139,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
@@ -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;
}
}