Address concurrent modification of quester list, fixes #1439

This commit is contained in:
PikaMug 2020-11-04 16:11:47 -05:00
parent 42815bdaec
commit c512261fb7
2 changed files with 36 additions and 16 deletions

View File

@ -233,6 +233,11 @@ public class Quester {
public Quester(final Quests plugin) {
this.plugin = plugin;
}
public Quester(final Quests plugin, final UUID uuid) {
this.plugin = plugin;
this.id = uuid;
}
public UUID getUUID() {
return id;
@ -3189,6 +3194,23 @@ public class Quester {
return data;
}
/**
* Check whether data file for this Quester exists
*
* @return file if exists, otherwise null
*/
public File getDataFile() {
File dataFile = new File(plugin.getDataFolder(), "data" + File.separator + id.toString() + ".yml");
if (!dataFile.exists()) {
final OfflinePlayer p = getOfflinePlayer();
dataFile = new File(plugin.getDataFolder(), "data" + File.separator + p.getName() + ".yml");
if (!dataFile.exists()) {
return null;
}
}
return dataFile;
}
/**
* Load data of the Quester from file
*
@ -3198,15 +3220,12 @@ public class Quester {
public boolean loadData() {
final FileConfiguration data = new YamlConfiguration();
try {
File dataFile = new File(plugin.getDataFolder(), "data" + File.separator + id.toString() + ".yml");
if (dataFile.exists() == false) {
final OfflinePlayer p = getOfflinePlayer();
dataFile = new File(plugin.getDataFolder(), "data" + File.separator + p.getName() + ".yml");
if (dataFile.exists() == false) {
return false;
}
final File dataFile = getDataFile();
if (dataFile != null) {
data.load(dataFile);
} else {
return false;
}
data.load(dataFile);
} catch (final IOException e) {
return false;
} catch (final InvalidConfigurationException e) {

View File

@ -1304,22 +1304,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (id == null) {
return null;
}
for (final Quester q: questers) {
final ConcurrentSkipListSet<Quester> set = (ConcurrentSkipListSet<Quester>) questers;
for (final Quester q: set) {
if (q != null && q.getUUID().equals(id)) {
return q;
}
}
final Quester quester = new Quester(this);
quester.setUUID(id);
final Quester quester = new Quester(this, id);
if (depends.getCitizens() != null) {
if (depends.getCitizens().getNPCRegistry().getByUniqueId(id) != null) {
return quester;
}
}
questers.add(quester);
if (!quester.loadData()) {
questers.remove(quester);
set.add(quester);
} else {
set.remove(quester);
}
setOfflineQuesters(set);
return quester;
}
@ -1333,9 +1335,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
public LinkedList<Quester> getOnlineQuesters() {
final LinkedList<Quester> qs = new LinkedList<Quester>();
for (final Player p : getServer().getOnlinePlayers()) {
final Quester quester = new Quester(this);
quester.setUUID(p.getUniqueId());
if (quester.loadData() == false) {
final Quester quester = new Quester(this, p.getUniqueId());
if (!quester.loadData()) {
quester.saveData();
}
qs.add(quester);