mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-26 04:25:30 +01:00
Starting convert command
This commit is contained in:
parent
2bbb4444ef
commit
ab33362c0e
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user