mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-06 00:18:39 +01:00
Create and save new Quester if not generated on join, fixes #993
This commit is contained in:
parent
488ccc1d5a
commit
f13e07f89b
@ -2717,16 +2717,21 @@ public class Quester {
|
||||
hardDataPut(quest, data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save data of the Quester to file
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public void saveData() {
|
||||
public boolean saveData() {
|
||||
FileConfiguration data = getBaseData();
|
||||
try {
|
||||
data.save(new File(plugin.getDataFolder(), "data" + File.separator + id + ".yml"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3072,6 +3077,11 @@ public class Quester {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data of the Quester from file
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean loadData() {
|
||||
FileConfiguration data = new YamlConfiguration();
|
||||
|
@ -396,9 +396,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String s) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
final Player player = (Player) context.getForWhom();
|
||||
if (s.equalsIgnoreCase(Lang.get(player, "yesWord"))) {
|
||||
String questToTake = getQuester(player.getUniqueId()).questToTake;
|
||||
Quester quester = getQuester(player.getUniqueId());
|
||||
if (quester == null) {
|
||||
// Must be new player
|
||||
quester = new Quester(Quests.this);
|
||||
quester.setUUID(player.getUniqueId());
|
||||
if (quester.saveData()) {
|
||||
getLogger().info("Created new data for player " + player.getName());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + Lang.get(player, "questSaveError"));
|
||||
}
|
||||
}
|
||||
final String questToTake = quester.questToTake;
|
||||
try {
|
||||
if (getQuest(questToTake) == null) {
|
||||
getLogger().info(player.getName() + " attempted to take quest \"" + questToTake
|
||||
|
@ -288,7 +288,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
try {
|
||||
data.save(actionsFile);
|
||||
} catch (IOException e) {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorErrorSaving"));
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("questSaveError"));
|
||||
return;
|
||||
}
|
||||
ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
|
||||
@ -445,7 +445,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
try {
|
||||
data.save(actionsFile);
|
||||
} catch (IOException e) {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorErrorSaving"));
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("questSaveError"));
|
||||
return;
|
||||
}
|
||||
ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
|
||||
|
@ -267,7 +267,6 @@ eventEditorNoneToEdit: "No actions currently exist to be edited!"
|
||||
eventEditorNoneToDelete: "No actions currently exist to be deleted!"
|
||||
eventEditorNotFound: "Action not found!"
|
||||
eventEditorExists: "Action already exists!"
|
||||
eventEditorErrorSaving: "An error occurred while saving."
|
||||
eventEditorDeleted: "Action deleted. Quest and action data reloaded."
|
||||
eventEditorSaved: "Action saved. Quest and action data reloaded."
|
||||
eventEditorEnterEventName: "Enter Action name, <cancel>"
|
||||
|
Loading…
Reference in New Issue
Block a user