/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
- package me.TheWiseman.TreeFeller;
-
- import com.gmail.nossr50.mcMMO;
- import java.io.File;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import de.diddiz.LogBlock.Consumer;
- import de.diddiz.LogBlock.LogBlock;
-
- public class TreeFeller extends JavaPlugin {
- public final Logger log = Logger.getLogger("Minecraft");
- public static mcMMO mcMMO;
- public static TreeFeller plugin;
- private FileConfiguration playerSettings = null;
- private File playerSettingsFile = new File("plugins/TreeFeller/playerSettings.yml");
- Consumer lbconsumer;
-
- public void onEnable() {
- loadConfiguration();
-
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvents(new TreeFellerBlockListener(this), this);
- pm.registerEvents(new TreeFellerPlayerListener(this), this);
-
- if(logBlockEnabled()) {
- final Plugin LogBlock2 = pm.getPlugin("LogBlock");
- lbconsumer = ((LogBlock) LogBlock2).getConsumer();
- }
-
- PluginDescriptionFile pdfFile = this.getDescription();
- log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
- }
-
- public void onDisable() {
- PluginDescriptionFile pdfFile = this.getDescription();
- log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
- }
-
- public void loadConfiguration() {
- getConfig().addDefault("CanChop", true);
- getConfig().addDefault("SupportMcMMOIfAvailable", true);
- getConfig().addDefault("TreeFellerOnByDefault", true);
- getConfig().options().copyDefaults(true);
- saveConfig();
-
- getPlayerSettings();
- getPlayerSettings().options().copyDefaults(true);
- savePlayerSettings();
- }
-
- public FileConfiguration getPlayerSettings() {
- if(playerSettings == null) {
- reloadPlayerSettings();
- }
-
- return playerSettings;
- }
-
- public void reloadPlayerSettings() {
- playerSettings = YamlConfiguration.loadConfiguration(playerSettingsFile);
- }
-
- public void savePlayerSettings() {
- try {
- playerSettings.save(playerSettingsFile);
- } catch(IOException ex) {
- Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + playerSettingsFile, ex);
- }
- }
-
- public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
- if(cmd.getName().equalsIgnoreCase("treefeller") || cmd.getName().equalsIgnoreCase("tf")) {
- Player player = (Player)sender;
- String playerName = player.getDisplayName();
-
- if(args.length == 0) {
- if(getPlayerSettings().getInt("player.settings." + playerName, -1) == 1) {
- getPlayerSettings().set("player.settings." + playerName, 0);
- savePlayerSettings();
-
- sender.sendMessage("TreeFeller has been disabled.");
- } else if(getPlayerSettings().getInt("player.settings." + playerName, -1) == 0) {
- getPlayerSettings().set("player.settings." + playerName, 1);
- savePlayerSettings();
-
- sender.sendMessage("TreeFeller has been enabled.");
- }
-
- return true;
- } else if(args[0].equalsIgnoreCase("on")) {
- getPlayerSettings().set("player.settings." + playerName, 1);
- savePlayerSettings();
-
- sender.sendMessage("TreeFeller has been enabled.");
-
- return true;
- } else if(args[0].equalsIgnoreCase("off")) {
- getPlayerSettings().set("player.settings." + playerName, 0);
- savePlayerSettings();
-
- sender.sendMessage("TreeFeller has been disabled.");
-
- return true;
- } else {
- sender.sendMessage("You must enter /treefeller or /tf [on | off].");
- return false;
- }
- } else {
- return false;
- }
- }
-
- public boolean activemcMMO() {
- if(getConfig().getBoolean("SupportMcMMOIfAvailable")) {
- boolean isMcMMOEnabled = getServer().getPluginManager().isPluginEnabled("mcMMO");
- if(isMcMMOEnabled) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- public boolean worldGuardEnabled() {
- if(getServer().getPluginManager().isPluginEnabled("WorldGuard") == true) {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean logBlockEnabled() {
- if(getServer().getPluginManager().isPluginEnabled("LogBlock") == true) {
- return true;
- } else {
- return false;
- }
- }
- }