diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index af970741b..edf50ed10 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -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 { 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; diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 20f9ad667..4bec79412 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -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 { updateJournal(); } }; - protected LinkedList completedQuests = new LinkedList() { + protected ConcurrentSkipListSet completedQuests = new ConcurrentSkipListSet() { private static final long serialVersionUID = -269110128568487000L; @@ -119,12 +120,12 @@ public class Quester implements Comparable { return b; } - @Override + /*@Override public void add(final int index, final Quest element) { super.add(index, element); updateJournal(); - } - + }*/ + @Override public boolean addAll(final Collection c) { final boolean b = super.addAll(c); @@ -132,12 +133,12 @@ public class Quester implements Comparable { return b; } - @Override + /*@Override public boolean addAll(final int index, final Collection c) { final boolean b = super.addAll(index, c); updateJournal(); return b; - } + }*/ @Override public void clear() { @@ -151,8 +152,15 @@ public class Quester implements Comparable { 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 { final Quest s = super.set(index, element); updateJournal(); return s; - } + }*/ }; protected ConcurrentHashMap completedTimes = new ConcurrentHashMap(); protected ConcurrentHashMap amountsCompleted = new ConcurrentHashMap() { @@ -321,11 +329,11 @@ public class Quester implements Comparable { this.currentQuests = currentQuests; } - public LinkedList getCompletedQuests() { + public ConcurrentSkipListSet getCompletedQuests() { return completedQuests; } - public void setCompletedQuests(final LinkedList completedQuests) { + public void setCompletedQuests(final ConcurrentSkipListSet completedQuests) { this.completedQuests = completedQuests; } diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 1a880df61..4c6ae3c3d 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -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()); } diff --git a/main/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java b/main/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java index 6feb121ad..3aecf96e8 100644 --- a/main/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java +++ b/main/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java @@ -118,7 +118,7 @@ public class SeparatedYamlStorage implements StorageImplementation { } quester.setLastKnownName(data.getString("lastKnownName")); quester.setQuestPoints(data.getInt("quest-points")); - final LinkedList completedQuests = quester.getCompletedQuests(); + final ConcurrentSkipListSet completedQuests = quester.getCompletedQuests(); if (data.isList("completed-Quests")) { for (final String s : data.getStringList("completed-Quests")) { for (final Quest q : plugin.getQuests()) { diff --git a/main/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java b/main/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java index 582bff735..249a7fc45 100644 --- a/main/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java +++ b/main/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java @@ -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 getQuesterCompletedQuests(final UUID uniqueId) throws Exception { - final LinkedList completedQuests = new LinkedList(); + public ConcurrentSkipListSet getQuesterCompletedQuests(final UUID uniqueId) throws Exception { + final ConcurrentSkipListSet completedQuests = new ConcurrentSkipListSet(); try (Connection c = connectionFactory.getConnection()) { try (PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_COMPLETED_QUESTS_SELECT_BY_UUID))) { ps.setString(1, uniqueId.toString());