Starting convert command

This commit is contained in:
sekwah 2018-01-25 06:37:33 +00:00 committed by Sekwah
parent 2bbb4444ef
commit ab33362c0e
2 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,66 @@
package com.sekwah.advancedportals.spigot.convertolddata;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
public class ConfigAccessor {
private final String fileName;
private final JavaPlugin plugin;
private File configFile;
private FileConfiguration fileConfiguration;
public ConfigAccessor(JavaPlugin plugin, String fileName) {
this.plugin = plugin;
this.fileName = fileName;
}
public void reloadConfig() {
if (configFile == null) {
File dataFolder = plugin.getDataFolder();
if (dataFolder == null)
throw new IllegalStateException();
configFile = new File(dataFolder, fileName);
}
fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new File(this.getClass()
.getClassLoader().getResource(fileName).getPath()));
fileConfiguration.setDefaults(defConfig);
}
public FileConfiguration getConfig() {
if (fileConfiguration == null) {
this.reloadConfig();
}
return fileConfiguration;
}
public void saveConfig() {
if (fileConfiguration == null || configFile == null) {
return;
} else {
try {
getConfig().save(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
}
public void saveDefaultConfig() {
if (configFile == null) {
configFile = new File(plugin.getDataFolder(), fileName);
}
if (!configFile.exists()) {
plugin.saveResource(fileName, false);
}
}
}

View File

@ -0,0 +1,41 @@
package com.sekwah.advancedportals.spigot.convertolddata;
import com.sekwah.advancedportals.core.api.commands.SubCommand;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer;
import java.util.List;
/**
* TODO this is for spigot only for a few releases
*/
public class ConvertOldSubCommand implements SubCommand {
@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old portal data found."));
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old portal data successfully converted."));
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old desti data found."));
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Old desti data successfully converted."));
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor(" Those were just sample outputs, it doesnt work yet."));
}
@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp();
}
@Override
public List<String> onTabComplete(CommandSenderContainer sender, String[] args) {
return null;
}
@Override
public String getBasicHelpText() {
return null;
}
@Override
public String getDetailedHelpText() {
return null;
}
}