/TreeFeller/src/me/TheWiseman/TreeFeller/TreeFeller.java

https://bitbucket.org/Waizujin/treefeller · Java · 151 lines · 126 code · 25 blank · 0 comment · 28 complexity · 26a513c04fbeb11a44c6b3c6994c711e MD5 · raw file

  1. package me.TheWiseman.TreeFeller;
  2. import com.gmail.nossr50.mcMMO;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.configuration.file.YamlConfiguration;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.plugin.Plugin;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.PluginManager;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16. import de.diddiz.LogBlock.Consumer;
  17. import de.diddiz.LogBlock.LogBlock;
  18. public class TreeFeller extends JavaPlugin {
  19. public final Logger log = Logger.getLogger("Minecraft");
  20. public static mcMMO mcMMO;
  21. public static TreeFeller plugin;
  22. private FileConfiguration playerSettings = null;
  23. private File playerSettingsFile = new File("plugins/TreeFeller/playerSettings.yml");
  24. Consumer lbconsumer;
  25. public void onEnable() {
  26. loadConfiguration();
  27. PluginManager pm = getServer().getPluginManager();
  28. pm.registerEvents(new TreeFellerBlockListener(this), this);
  29. pm.registerEvents(new TreeFellerPlayerListener(this), this);
  30. if(logBlockEnabled()) {
  31. final Plugin LogBlock2 = pm.getPlugin("LogBlock");
  32. lbconsumer = ((LogBlock) LogBlock2).getConsumer();
  33. }
  34. PluginDescriptionFile pdfFile = this.getDescription();
  35. log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
  36. }
  37. public void onDisable() {
  38. PluginDescriptionFile pdfFile = this.getDescription();
  39. log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
  40. }
  41. public void loadConfiguration() {
  42. getConfig().addDefault("CanChop", true);
  43. getConfig().addDefault("SupportMcMMOIfAvailable", true);
  44. getConfig().addDefault("TreeFellerOnByDefault", true);
  45. getConfig().options().copyDefaults(true);
  46. saveConfig();
  47. getPlayerSettings();
  48. getPlayerSettings().options().copyDefaults(true);
  49. savePlayerSettings();
  50. }
  51. public FileConfiguration getPlayerSettings() {
  52. if(playerSettings == null) {
  53. reloadPlayerSettings();
  54. }
  55. return playerSettings;
  56. }
  57. public void reloadPlayerSettings() {
  58. playerSettings = YamlConfiguration.loadConfiguration(playerSettingsFile);
  59. }
  60. public void savePlayerSettings() {
  61. try {
  62. playerSettings.save(playerSettingsFile);
  63. } catch(IOException ex) {
  64. Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + playerSettingsFile, ex);
  65. }
  66. }
  67. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
  68. if(cmd.getName().equalsIgnoreCase("treefeller") || cmd.getName().equalsIgnoreCase("tf")) {
  69. Player player = (Player)sender;
  70. String playerName = player.getDisplayName();
  71. if(args.length == 0) {
  72. if(getPlayerSettings().getInt("player.settings." + playerName, -1) == 1) {
  73. getPlayerSettings().set("player.settings." + playerName, 0);
  74. savePlayerSettings();
  75. sender.sendMessage("TreeFeller has been disabled.");
  76. } else if(getPlayerSettings().getInt("player.settings." + playerName, -1) == 0) {
  77. getPlayerSettings().set("player.settings." + playerName, 1);
  78. savePlayerSettings();
  79. sender.sendMessage("TreeFeller has been enabled.");
  80. }
  81. return true;
  82. } else if(args[0].equalsIgnoreCase("on")) {
  83. getPlayerSettings().set("player.settings." + playerName, 1);
  84. savePlayerSettings();
  85. sender.sendMessage("TreeFeller has been enabled.");
  86. return true;
  87. } else if(args[0].equalsIgnoreCase("off")) {
  88. getPlayerSettings().set("player.settings." + playerName, 0);
  89. savePlayerSettings();
  90. sender.sendMessage("TreeFeller has been disabled.");
  91. return true;
  92. } else {
  93. sender.sendMessage("You must enter /treefeller or /tf [on | off].");
  94. return false;
  95. }
  96. } else {
  97. return false;
  98. }
  99. }
  100. public boolean activemcMMO() {
  101. if(getConfig().getBoolean("SupportMcMMOIfAvailable")) {
  102. boolean isMcMMOEnabled = getServer().getPluginManager().isPluginEnabled("mcMMO");
  103. if(isMcMMOEnabled) {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. } else {
  109. return false;
  110. }
  111. }
  112. public boolean worldGuardEnabled() {
  113. if(getServer().getPluginManager().isPluginEnabled("WorldGuard") == true) {
  114. return true;
  115. } else {
  116. return false;
  117. }
  118. }
  119. public boolean logBlockEnabled() {
  120. if(getServer().getPluginManager().isPluginEnabled("LogBlock") == true) {
  121. return true;
  122. } else {
  123. return false;
  124. }
  125. }
  126. }