Advertisement
lelesape

MAIN

Sep 12th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. package lele.SimpleBroadCaster;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.Reader;
  7. import java.io.UnsupportedEncodingException;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12. import org.bukkit.configuration.file.YamlConfiguration;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. import lele.SimpleBroadCaster.comandos.MainCommand;
  17.  
  18. public class SimpleBroadcaster extends JavaPlugin{
  19.  
  20. public String rutaconfig;
  21. PluginDescriptionFile pdffile = getDescription();
  22. public String version = pdffile.getVersion();
  23. public String nombre = "["+ChatColor.GREEN+pdffile.getName()+ChatColor.RESET+"]"+ChatColor.RESET;
  24. private FileConfiguration messages = null;
  25. private File messagesFile = null;
  26.  
  27. //
  28. //MENSAJES PARA ACTIVADO Y DESACTIVADO
  29. //
  30.  
  31. public void onEnable(){
  32. Bukkit.getConsoleSender().sendMessage(nombre+ChatColor.GREEN+"Enabled. Version: "+ChatColor.YELLOW+version);
  33. Bukkit.getConsoleSender().sendMessage(nombre+"Thank you for using my plugin!");
  34. Bukkit.getConsoleSender().sendMessage(nombre+"Please consider subscribing to my yt channel to show your support");
  35. Bukkit.getConsoleSender().sendMessage(nombre+ChatColor.RED+"https://www.youtube.com/channel/UC_S4D7348gQh8BYD1Vxl0Sw");
  36. Bukkit.getConsoleSender().sendMessage(nombre+"SimpleBroadcaster By lelesape");
  37. registrarconfig();
  38. registerMessages();
  39. registercommands();
  40. }
  41.  
  42. public void onDisable(){
  43. Bukkit.getConsoleSender().sendMessage(nombre+ChatColor.RED+"Disabled. Version: "+ChatColor.YELLOW+version);
  44. Bukkit.getConsoleSender().sendMessage(nombre+"Thank you for using my plugin!");
  45. Bukkit.getConsoleSender().sendMessage(nombre+"Please consider subscribing to my yt channel to show your support");
  46. Bukkit.getConsoleSender().sendMessage(nombre+ChatColor.RED+"https://www.youtube.com/channel/UC_S4D7348gQh8BYD1Vxl0Sw");
  47. Bukkit.getConsoleSender().sendMessage(nombre+"SimpleBroadcaster By lelesape");
  48. }
  49.  
  50.  
  51. //
  52. //REGISTRAR COMANDOS
  53. //
  54. //sin argumentos, list, crear sin argumentos, crear
  55.  
  56. public void registercommands() {
  57. this.getCommand("sbc").setExecutor(new MainCommand(this));
  58. }
  59.  
  60. //
  61. //registrar la config
  62. //
  63. public void registrarconfig() {
  64. File config = new File(this.getDataFolder(),"config.yml");
  65. rutaconfig = config.getPath();
  66. if(!config.exists()) {
  67. this.getConfig().options().copyDefaults(true);
  68. saveConfig();
  69. }
  70.  
  71. }
  72.  
  73. //
  74. //OTROS YML
  75. //
  76. //Mensajes yml
  77.  
  78. public FileConfiguration getMessages(){
  79. if(messages == null){
  80. reloadMessages();
  81. }
  82. return messages;
  83. }
  84.  
  85. public void reloadMessages(){
  86. if(messages == null){
  87. messagesFile = new File(getDataFolder(),"messages.yml");
  88. }
  89. messages = YamlConfiguration.loadConfiguration(messagesFile);
  90. Reader defConfigStream;
  91. try{
  92. defConfigStream = new InputStreamReader(this.getResource("messages.yml"),"UTF8");
  93. if(defConfigStream != null){
  94. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  95. messages.setDefaults(defConfig);
  96. }
  97. }catch(UnsupportedEncodingException e){
  98. e.printStackTrace();
  99. }
  100. }
  101.  
  102. public void saveMessages(){
  103. try{
  104. messages.save(messagesFile);
  105. }catch(IOException e){
  106. e.printStackTrace();
  107. }
  108. }
  109.  
  110. public void registerMessages(){
  111. messagesFile = new File(this.getDataFolder(),"messages.yml");
  112. if(!messagesFile.exists()){
  113. this.getMessages().options().copyDefaults(true);
  114. saveMessages();
  115. }
  116. }
  117.  
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement