diff --git a/src/main/java/com/gmail/picono435/picojobs/api/JobPlayer.java b/src/main/java/com/gmail/picono435/picojobs/api/JobPlayer.java index 0d54e8da..8cb1fe34 100644 --- a/src/main/java/com/gmail/picono435/picojobs/api/JobPlayer.java +++ b/src/main/java/com/gmail/picono435/picojobs/api/JobPlayer.java @@ -28,8 +28,8 @@ public class JobPlayer { private double salary; private String errorMessage; - public JobPlayer(Job job, double method, double level, double salary, boolean isWorking, UUID uuid) { - this.job = job; + public JobPlayer(String job, double method, double level, double salary, boolean isWorking, UUID uuid) { + this.job = PicoJobsAPI.getJobsManager().getJob(job); this.method = method; this.level = level; this.salary = salary; diff --git a/src/main/java/com/gmail/picono435/picojobs/api/managers/PlayersManager.java b/src/main/java/com/gmail/picono435/picojobs/api/managers/PlayersManager.java index e8d2a391..fe55e335 100644 --- a/src/main/java/com/gmail/picono435/picojobs/api/managers/PlayersManager.java +++ b/src/main/java/com/gmail/picono435/picojobs/api/managers/PlayersManager.java @@ -101,7 +101,7 @@ public CompletableFuture getJobPlayerFromStorage(UUID uuid) { if(!factory.playerExists(uuid)) { factory.createPlayer(uuid); } - JobPlayer jp = new JobPlayer(PicoJobsAPI.getJobsManager().getJob(factory.getJob(uuid)), + JobPlayer jp = new JobPlayer(factory.getJob(uuid), factory.getMethod(uuid), factory.getMethodLevel(uuid), factory.getSalary(uuid), diff --git a/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java b/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java index 242468d1..0921c282 100644 --- a/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java +++ b/src/main/java/com/gmail/picono435/picojobs/commands/JobsAdminCommand.java @@ -8,6 +8,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.logging.Level; import org.apache.commons.lang3.StringUtils; @@ -93,6 +94,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String } PicoJobsAPI.getStorageManager().destroyStorageFactory(); PicoJobsAPI.getStorageManager().initializeStorageFactory(); + for(UUID uuid : PicoJobsAPI.getStorageManager().getCacheManager().getAllFromCache()) { + PicoJobsAPI.getPlayersManager().getJobPlayer(uuid).setJob(PicoJobsAPI.getJobsManager().getJob(PicoJobsAPI.getPlayersManager().getJobPlayer(uuid).getJob().getID())); + } p.sendMessage(LanguageManager.getMessage("reload-command", pl)); return true; } diff --git a/src/main/java/com/gmail/picono435/picojobs/storage/cache/CacheManager.java b/src/main/java/com/gmail/picono435/picojobs/storage/cache/CacheManager.java index 5ead0016..32eb3fe9 100644 --- a/src/main/java/com/gmail/picono435/picojobs/storage/cache/CacheManager.java +++ b/src/main/java/com/gmail/picono435/picojobs/storage/cache/CacheManager.java @@ -1,8 +1,6 @@ package com.gmail.picono435.picojobs.storage.cache; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; import com.gmail.picono435.picojobs.PicoJobsPlugin; import com.gmail.picono435.picojobs.api.JobPlayer; @@ -52,4 +50,20 @@ public void removeFromCache(UUID uuid) { cache.remove(uuid); } + /** + * Gets all players from the cache system + * + * @return the job player uuid list of all jobplayers cached + */ + public List getAllFromCache() { + return new ArrayList<>(cache.keySet()); + } + + /** + * Clears all the cache saved in the plugin, make sure you know what you doing before calling this + */ + public void clearCache() { + cache.clear(); + } + }