Skip to content

Commit

Permalink
Fixed issue with persistent jobs after reload (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Picono435 committed Mar 12, 2022
1 parent 94b7606 commit eb905cb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/gmail/picono435/picojobs/api/JobPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public CompletableFuture<JobPlayer> 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<UUID> 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();
}

}

0 comments on commit eb905cb

Please sign in to comment.