mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 02:25:42 +01:00
Move storage files to nested folder
This commit is contained in:
parent
5c5d4dd0b3
commit
45a64a05ed
@ -173,10 +173,13 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
||||
// 6 - Load soft-depends
|
||||
depends.init();
|
||||
|
||||
// 7 - Save resources from jar
|
||||
saveResourceAs("quests.yml", "quests.yml", false);
|
||||
saveResourceAs("actions.yml", "actions.yml", false);
|
||||
saveResourceAs("conditions.yml", "conditions.yml", false);
|
||||
// 7 - Transfer resources from jar
|
||||
moveStorageResource("quests.yml");
|
||||
moveStorageResource("actions.yml");
|
||||
moveStorageResource("conditions.yml");
|
||||
saveResourceAs("quests.yml", "storage/quests.yml", false);
|
||||
saveResourceAs("actions.yml", "storage/actions.yml", false);
|
||||
saveResourceAs("conditions.yml", "storage/conditions.yml", false);
|
||||
|
||||
// 8 - Save config with any new options
|
||||
getConfig().options().copyDefaults(true);
|
||||
@ -553,6 +556,33 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a storage file from legacy location, if present
|
||||
*
|
||||
* @param fileName Name of file to attempt move
|
||||
*/
|
||||
private void moveStorageResource(String fileName) {
|
||||
File storageFile = new File(getDataFolder(), fileName);
|
||||
if (!storageFile.isFile()) {
|
||||
return;
|
||||
}
|
||||
final File outFile = new File(getDataFolder(), "storage" + File.separatorChar + fileName);
|
||||
final File outDir = new File(outFile.getPath().replace(fileName, ""));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
if (!outDir.mkdirs()) {
|
||||
getLogger().log(Level.SEVERE, "Failed to make directories for " + fileName + " (canWrite= "
|
||||
+ outDir.canWrite() + ")");
|
||||
}
|
||||
}
|
||||
boolean q = storageFile.renameTo(outFile);
|
||||
if (!q) {
|
||||
getLogger().severe("Unable to move " + fileName + " file. Check folder permissions and restart.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a Quests plugin resource to a specific path in the filesystem
|
||||
*
|
||||
|
@ -268,7 +268,7 @@ public class BukkitActionFactory implements ActionFactory, ConversationAbandoned
|
||||
|
||||
public void deleteAction(final ConversationContext context) {
|
||||
final YamlConfiguration data = new YamlConfiguration();
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "actions.yml");
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "actions.yml");
|
||||
try {
|
||||
data.load(actionsFile);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
@ -316,7 +316,7 @@ public class BukkitActionFactory implements ActionFactory, ConversationAbandoned
|
||||
@SuppressWarnings("unchecked")
|
||||
public void saveAction(final ConversationContext context) {
|
||||
final YamlConfiguration data = new YamlConfiguration();
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "actions.yml");
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "actions.yml");
|
||||
try {
|
||||
data.load(actionsFile);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
|
@ -162,7 +162,7 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
|
||||
|
||||
public void deleteCondition(final ConversationContext context) {
|
||||
final YamlConfiguration data = new YamlConfiguration();
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "conditions.yml");
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "conditions.yml");
|
||||
try {
|
||||
data.load(conditionsFile);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
@ -204,7 +204,7 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
|
||||
|
||||
public void saveCondition(final ConversationContext context) {
|
||||
final YamlConfiguration data = new YamlConfiguration();
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "conditions.yml");
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "conditions.yml");
|
||||
try {
|
||||
data.load(conditionsFile);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
|
@ -858,7 +858,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
try {
|
||||
data.load(new File(plugin.getDataFolder(), "quests.yml"));
|
||||
data.load(new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml"));
|
||||
ConfigurationSection questSection = data.getConfigurationSection("quests");
|
||||
if (questSection == null) {
|
||||
questSection = data.createSection("quests");
|
||||
@ -884,7 +884,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
if (newSection != null) {
|
||||
plugin.getQuestFactory().saveQuest(context, newSection);
|
||||
data.save(new File(plugin.getDataFolder(), "quests.yml"));
|
||||
data.save(new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml"));
|
||||
context.getForWhom().sendRawMessage(ChatColor.GREEN
|
||||
+ BukkitLang.get("questEditorSaved").replace("<command>", "/questadmin "
|
||||
+ BukkitLang.get("COMMAND_QUESTADMIN_RELOAD")));
|
||||
|
@ -539,7 +539,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
|
||||
|
||||
public void deleteQuest(final ConversationContext context) {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
final File questsFile = new File(plugin.getDataFolder(), "quests.yml");
|
||||
final File questsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml");
|
||||
try {
|
||||
data.load(questsFile);
|
||||
} catch (final IOException | InvalidConfigurationException e) {
|
||||
|
@ -54,7 +54,7 @@ public class BukkitActionYamlStorage implements ActionStorageImpl {
|
||||
public void init() {
|
||||
final YamlConfiguration config = new YamlConfiguration();
|
||||
final File legacyFile = new File(plugin.getDataFolder(), "events.yml");
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "actions.yml");
|
||||
final File actionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "actions.yml");
|
||||
// Using #isFile because #exists and #renameTo can return false positives
|
||||
if (legacyFile.isFile()) {
|
||||
try {
|
||||
@ -123,7 +123,7 @@ public class BukkitActionYamlStorage implements ActionStorageImpl {
|
||||
return null;
|
||||
}
|
||||
final File legacy = new File(plugin.getDataFolder(), "events.yml");
|
||||
final File actions = new File(plugin.getDataFolder(), "actions.yml");
|
||||
final File actions = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "actions.yml");
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
try {
|
||||
if (actions.isFile()) {
|
||||
|
@ -48,7 +48,7 @@ public class BukkitConditionYamlStorage implements ConditionStorageImpl {
|
||||
@Override
|
||||
public void init() {
|
||||
final YamlConfiguration config = new YamlConfiguration();
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "conditions.yml");
|
||||
final File conditionsFile = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "conditions.yml");
|
||||
// Using #isFile because #exists and #renameTo can return false positives
|
||||
if (conditionsFile.length() != 0) {
|
||||
try {
|
||||
@ -92,7 +92,7 @@ public class BukkitConditionYamlStorage implements ConditionStorageImpl {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
final File conditions = new File(plugin.getDataFolder(), "conditions.yml");
|
||||
final File conditions = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "conditions.yml");
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
try {
|
||||
if (conditions.isFile()) {
|
||||
|
@ -73,7 +73,7 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
public void init() {
|
||||
boolean needsSaving = false;
|
||||
FileConfiguration config = null;
|
||||
final File file = new File(plugin.getDataFolder(), "quests.yml");
|
||||
final File file = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml");
|
||||
try {
|
||||
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file),
|
||||
StandardCharsets.UTF_8));
|
||||
@ -139,7 +139,7 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
|
||||
return null;
|
||||
}
|
||||
FileConfiguration config = null;
|
||||
final File file = new File(plugin.getDataFolder(), "quests.yml");
|
||||
final File file = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml");
|
||||
try {
|
||||
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file),
|
||||
StandardCharsets.UTF_8));
|
||||
|
@ -70,7 +70,7 @@ public class BukkitModuleJarStorage implements ModuleStorageImpl {
|
||||
plugin.getLogger().warning("Unable to create module directory");
|
||||
}
|
||||
FileConfiguration config = null;
|
||||
final File file = new File(plugin.getDataFolder(), "quests.yml");
|
||||
final File file = new File(plugin.getDataFolder(), "storage" + File.separatorChar + "quests.yml");
|
||||
try {
|
||||
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file),
|
||||
StandardCharsets.UTF_8));
|
||||
|
Loading…
Reference in New Issue
Block a user