Created
March 19, 2016 13:54
-
-
Save MrPowerGamerBR/98e700037e475ec65ea5 to your computer and use it in GitHub Desktop.
PowerConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File; | |
| import java.io.IOException; | |
| import org.bukkit.Bukkit; | |
| import org.bukkit.configuration.file.FileConfiguration; | |
| import org.bukkit.configuration.file.YamlConfiguration; | |
| import org.bukkit.plugin.Plugin; | |
| import org.bukkit.plugin.java.JavaPlugin; | |
| public class PowerConfig { | |
| JavaPlugin m = null; | |
| String configName; | |
| public PowerConfig(JavaPlugin m, String configName) { | |
| this.m = m; | |
| this.configName = configName; | |
| setupConfig(); | |
| } | |
| public FileConfiguration userfile; | |
| private File userfiled; | |
| public Plugin getPlugin() | |
| { | |
| return m; | |
| } | |
| public void reloadConfig() | |
| { | |
| getPlugin().reloadConfig(); | |
| return; | |
| } | |
| public File getDataFolder() | |
| { | |
| return getPlugin().getDataFolder(); | |
| } | |
| public void updateConfig() { | |
| saveConfig(); | |
| } | |
| public void reloadMe() | |
| { | |
| reloadConfig(); | |
| } | |
| public void setupConfig() { | |
| if (!m.getDataFolder().exists()) { | |
| m.getDataFolder().mkdir(); | |
| } | |
| this.userfiled = new File(m.getDataFolder(), configName); | |
| if (!this.userfiled.exists()) { | |
| try { | |
| this.userfiled.createNewFile(); | |
| } catch (IOException e) { | |
| Bukkit.getConsoleSender().sendMessage("§cNão foi possível criar o " + configName + "!"); | |
| } | |
| } | |
| this.userfile = YamlConfiguration.loadConfiguration(this.userfiled); | |
| } | |
| public FileConfiguration getConfig() | |
| { | |
| return this.userfile; | |
| } | |
| public void saveConfig() | |
| { | |
| try | |
| { | |
| this.userfile.save(this.userfiled); | |
| } | |
| catch (Exception e) | |
| { | |
| Bukkit.getConsoleSender().sendMessage("§cNão foi possível salvar o " + configName + ".yml!"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Quebrei um pouco o propósito do código, mas tomai a versão que eu fiz em Singleton que não é um singleton)
`
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.master.Main;
public class Config {
JavaPlugin m;
String configName;
}`