Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. package net.WMisiedjan.Infchests;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Hashtable;
  7. import java.util.List;
  8. import org.bukkit.Server;
  9. import org.bukkit.World;
  10. import org.bukkit.util.config.Configuration;
  11.  
  12. public class InfChestConfiguration {
  13.  
  14. private File pluginfolder;
  15. private File pluginconfig;
  16. private StackableLogger log = new StackableLogger("InfChests");
  17. private Hashtable<String, Object> configtable;
  18. private List<String> allowedWorlds;
  19. public Configuration ConfY;
  20. private Server BServer;
  21.  
  22. public InfChestConfiguration(Server server) {
  23. this.pluginfolder = new File("plugins\\InfChests");
  24. this.pluginconfig = new File("plugins\\InfChests\\config.yml");
  25. this.configtable = new Hashtable<String, Object>();
  26. this.allowedWorlds = new ArrayList<String>();
  27. this.BServer = server;
  28. }
  29.  
  30. public boolean isFirstrun() {
  31. if (this.getPluginFolder().exists()) {
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. }
  37.  
  38. public boolean CreatePluginFiles() {
  39. if (!this.getPluginFolder().mkdir()) {
  40. log.warning("Error Creating plugin folder.");
  41. return false;
  42. } else {
  43. try {
  44. if (!this.getConfigFile().createNewFile()) {
  45. log.warning("Error Creating plugin Configuration.");
  46. return false;
  47. } else {
  48. return true;
  49. }
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. return false;
  53. }
  54. }
  55. }
  56.  
  57. public boolean CreateConfiguration() {
  58.  
  59. //Load Worlds
  60. ConfY = new Configuration(pluginconfig);
  61. List<String> worlds = new ArrayList<String>();
  62.  
  63. for(World world : BServer.getWorlds())
  64. {
  65. worlds.add(world.getName());
  66. }
  67.  
  68. ConfY.setProperty("AllowedWorlds", worlds);
  69.  
  70. if (ConfY.save())
  71. return true;
  72. else
  73. return false;
  74. }
  75.  
  76. public boolean LoadConfiguration()
  77. {
  78. ConfY = new Configuration(pluginconfig);
  79. Object list = ConfY.getProperty("AllowedWorlds");
  80. if(list instanceof List<?>)
  81. {
  82. this.allowedWorlds = (List<String>)list;
  83. }
  84. else
  85. {
  86. return false;
  87. }
  88. return true;
  89. }
  90.  
  91. public File getPluginFolder() {
  92. return pluginfolder;
  93. }
  94.  
  95. public File getConfigFile() {
  96. return pluginconfig;
  97. }
  98.  
  99. public List<String> getAllowedWorlds()
  100. {
  101. return this.allowedWorlds;
  102. }
  103.  
  104. public boolean AddAllowedWorld(String name)
  105. {
  106. return this.allowedWorlds.add(name);
  107. }
  108.  
  109. public Hashtable<String, Object> getConfigTable() {
  110. return configtable;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement