Add optional MySQL implementation, part 8

This commit is contained in:
PikaMug 2020-11-26 23:30:12 -05:00
parent 00a6c50c5f
commit b9205ab94c
3 changed files with 14 additions and 6 deletions

View File

@ -73,6 +73,7 @@ public class Quester implements Comparable<Quester> {
private final Quests plugin;
private UUID id;
protected String questIdToTake;
private String lastKnownName;
protected int questPoints = 0;
private String compassTargetQuestId;
protected ConcurrentHashMap<Integer, Quest> timers = new ConcurrentHashMap<Integer, Quest>();
@ -255,7 +256,15 @@ public class Quester implements Comparable<Quester> {
public void setQuestIdToTake(final String questIdToTake) {
this.questIdToTake = questIdToTake;
}
public String getLastKnownName() {
return lastKnownName;
}
public void setLastKnownName(final String lastKnownName) {
this.lastKnownName = lastKnownName;
}
public int getQuestPoints() {
return questPoints;
}

View File

@ -112,9 +112,8 @@ public class SeparatedYamlStorage implements StorageImplementation {
quester.setAmountsCompleted(amountsCompleted);
}
}
int questPoints = quester.getQuestPoints();
questPoints = data.getInt("quest-points");
quester.setQuestPoints(questPoints);
quester.setLastKnownName(data.getString("lastKnownName"));
quester.setQuestPoints(data.getInt("quest-points"));
if (data.isList("completed-Quests")) {
for (final String s : data.getStringList("completed-Quests")) {
for (final Quest q : plugin.getQuests()) {
@ -482,14 +481,13 @@ public class SeparatedYamlStorage implements StorageImplementation {
@Override
public String getQuesterLastKnownName(final UUID uniqueId) throws Exception {
final FileConfiguration data = new YamlConfiguration();
Quester quester = plugin.getQuester(uniqueId);
if (quester != null) {
quester.hardClear();
} else {
quester = new Quester(plugin, uniqueId);
}
return data.getString("lastKnownName");
return quester.getLastKnownName();
}
@Override

View File

@ -162,6 +162,7 @@ public class SqlStorage implements StorageImplementation {
ps.setString(1, uniqueId.toString());
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
quester.setLastKnownName(rs.getString("lastKnownName"));
quester.setQuestPoints(rs.getInt("questpoints"));
}
}
@ -178,7 +179,7 @@ public class SqlStorage implements StorageImplementation {
@Override
public void saveQuesterData(final Quester quester) throws Exception {
final UUID uniqueId = quester.getUUID();
final String lastknownname = quester.getOfflinePlayer().getName();
final String lastknownname = quester.getLastKnownName();
final String oldlastknownname = getQuesterLastKnownName(uniqueId);
final Set<String> currentQuests = quester.getCurrentQuests().keySet().stream().map(Quest::getId).collect(Collectors.toSet());
final Set<String> oldCurrentQuests = getQuesterCurrentQuests(uniqueId).keySet().stream().map(Quest::getId).collect(Collectors.toSet());