Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package it.fw.smistamento;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.util.logging.Level;
  7.  
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.configuration.file.FileConfiguration;
  12. import org.bukkit.configuration.file.YamlConfiguration;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14.  
  15. public class main extends JavaPlugin{
  16. private FileConfiguration statistica = null;
  17. private File statisticaFile = null;
  18. public static main plugin;
  19.  
  20. @Override
  21. public void onEnable(){
  22. getLogger().info("onEnable has been invoked!");
  23. this.saveDefaultConfig();
  24. }//end onEnable
  25.  
  26. @Override
  27. public void onDisable(){
  28. getLogger().info("onDisable has been invoked!");
  29. }//end onDisable
  30.  
  31.  
  32. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  33. if (cmd.getName().equalsIgnoreCase("smista")) {
  34.  
  35. //comando help
  36. if (args.length > 0 && args[1].equalsIgnoreCase("help")) {
  37. sender.sendMessage("------ " + ChatColor.YELLOW + "Smista Help " + ChatColor.RESET +" ------");
  38. sender.sendMessage(ChatColor.RED + "/smista help:" + ChatColor.GRAY + " Ti da tutti i comandi disponibili di questo plugin.");
  39. sender.sendMessage(ChatColor.RED + "/smista squadre:" + ChatColor.GRAY + " Smista le squadre.");
  40. return true;
  41. }//end if
  42.  
  43. //comando squadre
  44. if (args.length > 0 && args[1].equalsIgnoreCase("squadre")) {
  45. this.getServer().getOnlinePlayers();
  46. }//end if
  47. return true;
  48. }//end if
  49. return false;
  50. }//end onCommand
  51.  
  52.  
  53. public void reloadStatistica ( ) {
  54. if ( statisticaFile == null ) {
  55. statisticaFile = new File ( getDataFolder ( ) , "customConfig.yml" ) ;
  56. }
  57. statistica = YamlConfiguration. loadConfiguration ( statisticaFile ) ;
  58.  
  59. // Cercare inadempienze nella jar
  60. InputStream defConfigStream = this.getResource("statisticaFile.yml");
  61. if ( defConfigStream != null ) {
  62. YamlConfiguration defConfig = YamlConfiguration. loadConfiguration ( defConfigStream ) ;
  63. statistica. setDefaults ( defConfig ) ;
  64. }
  65. }
  66.  
  67. public FileConfiguration getCustomConfig() {
  68. if (statistica == null) {
  69. reloadStatistica();
  70. }
  71. return statistica;
  72. }
  73.  
  74. public void saveCustomConfig() {
  75. if (statistica == null || statisticaFile == null) {
  76. return;
  77. }
  78. try {
  79. getCustomConfig().save(statisticaFile);
  80. } catch (IOException ex) {
  81. getLogger().log(Level.SEVERE, "Could not save config to " + statisticaFile, ex);
  82. }
  83. }
  84.  
  85. public void saveDefaultConfig() {
  86. if (statisticaFile == null) {
  87. statisticaFile = new File(getDataFolder(), "customConfig.yml");
  88. }
  89. if (!statisticaFile.exists()) {
  90. plugin.saveResource("customConfig.yml", false);
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement