mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-07 17:07:48 +01:00
Quest class shall implement Comparable, fixes #1499
This commit is contained in:
parent
e78a6733f4
commit
b7a8d25f60
@ -53,7 +53,7 @@ import me.blackvein.quests.util.Lang;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class Quest {
|
||||
public class Quest implements Comparable<Quest> {
|
||||
|
||||
protected Quests plugin;
|
||||
protected String id;
|
||||
@ -70,6 +70,11 @@ public class Quest {
|
||||
private final Planner pln = new Planner();
|
||||
private final Rewards rews = new Rewards();
|
||||
private final Options opts = new Options();
|
||||
|
||||
@Override
|
||||
public int compareTo(final Quest quest) {
|
||||
return id.compareTo(quest.getId());
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -23,6 +23,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -108,7 +109,7 @@ public class Quester implements Comparable<Quester> {
|
||||
updateJournal();
|
||||
}
|
||||
};
|
||||
protected LinkedList<Quest> completedQuests = new LinkedList<Quest>() {
|
||||
protected ConcurrentSkipListSet<Quest> completedQuests = new ConcurrentSkipListSet<Quest>() {
|
||||
|
||||
private static final long serialVersionUID = -269110128568487000L;
|
||||
|
||||
@ -119,12 +120,12 @@ public class Quester implements Comparable<Quester> {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public void add(final int index, final Quest element) {
|
||||
super.add(index, element);
|
||||
updateJournal();
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean addAll(final Collection<? extends Quest> c) {
|
||||
final boolean b = super.addAll(c);
|
||||
@ -132,12 +133,12 @@ public class Quester implements Comparable<Quester> {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public boolean addAll(final int index, final Collection<? extends Quest> c) {
|
||||
final boolean b = super.addAll(index, c);
|
||||
updateJournal();
|
||||
return b;
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
@ -151,8 +152,15 @@ public class Quester implements Comparable<Quester> {
|
||||
updateJournal();
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeAll(final Collection<?> c) {
|
||||
final boolean b = super.removeAll(c);
|
||||
updateJournal();
|
||||
return b;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public Quest remove(final int index) {
|
||||
final Quest s = super.remove(index);
|
||||
updateJournal();
|
||||
@ -164,7 +172,7 @@ public class Quester implements Comparable<Quester> {
|
||||
final Quest s = super.set(index, element);
|
||||
updateJournal();
|
||||
return s;
|
||||
}
|
||||
}*/
|
||||
};
|
||||
protected ConcurrentHashMap<Quest, Long> completedTimes = new ConcurrentHashMap<Quest, Long>();
|
||||
protected ConcurrentHashMap<Quest, Integer> amountsCompleted = new ConcurrentHashMap<Quest, Integer>() {
|
||||
@ -321,11 +329,11 @@ public class Quester implements Comparable<Quester> {
|
||||
this.currentQuests = currentQuests;
|
||||
}
|
||||
|
||||
public LinkedList<Quest> getCompletedQuests() {
|
||||
public ConcurrentSkipListSet<Quest> getCompletedQuests() {
|
||||
return completedQuests;
|
||||
}
|
||||
|
||||
public void setCompletedQuests(final LinkedList<Quest> completedQuests) {
|
||||
public void setCompletedQuests(final ConcurrentSkipListSet<Quest> completedQuests) {
|
||||
this.completedQuests = completedQuests;
|
||||
}
|
||||
|
||||
|
@ -653,15 +653,17 @@ public class CmdExecutor implements CommandExecutor {
|
||||
cs.sendMessage(ChatColor.DARK_PURPLE + Lang.get("none"));
|
||||
} else {
|
||||
final StringBuilder completed = new StringBuilder(" ");
|
||||
int index = 1;
|
||||
for (final Quest q : quester.getCompletedQuests()) {
|
||||
|
||||
completed.append(ChatColor.DARK_PURPLE + q.getName());
|
||||
if (quester.getAmountsCompleted().containsKey(q) && quester.getAmountsCompleted().get(q) > 1) {
|
||||
completed.append(ChatColor.LIGHT_PURPLE + " (x" + quester.getAmountsCompleted().get(q) + ")");
|
||||
}
|
||||
if (quester.getCompletedQuests().indexOf(q) < (quester.getCompletedQuests().size() - 1)) {
|
||||
if (index < (quester.getCompletedQuests().size())) {
|
||||
completed.append(", ");
|
||||
}
|
||||
index++;
|
||||
}
|
||||
cs.sendMessage(completed.toString());
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
}
|
||||
quester.setLastKnownName(data.getString("lastKnownName"));
|
||||
quester.setQuestPoints(data.getInt("quest-points"));
|
||||
final LinkedList<Quest> completedQuests = quester.getCompletedQuests();
|
||||
final ConcurrentSkipListSet<Quest> completedQuests = quester.getCompletedQuests();
|
||||
if (data.isList("completed-Quests")) {
|
||||
for (final String s : data.getStringList("completed-Quests")) {
|
||||
for (final Quest q : plugin.getQuests()) {
|
||||
|
@ -18,7 +18,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -322,8 +321,8 @@ public class SqlStorage implements StorageImplementation {
|
||||
return currentQuests;
|
||||
}
|
||||
|
||||
public LinkedList<Quest> getQuesterCompletedQuests(final UUID uniqueId) throws Exception {
|
||||
final LinkedList<Quest> completedQuests = new LinkedList<Quest>();
|
||||
public ConcurrentSkipListSet<Quest> getQuesterCompletedQuests(final UUID uniqueId) throws Exception {
|
||||
final ConcurrentSkipListSet<Quest> completedQuests = new ConcurrentSkipListSet<Quest>();
|
||||
try (Connection c = connectionFactory.getConnection()) {
|
||||
try (PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_COMPLETED_QUESTS_SELECT_BY_UUID))) {
|
||||
ps.setString(1, uniqueId.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user