All pastes #2065747 Raw Edit

Miscellany

public text v1 · immutable
#2065747 ·published 2011-05-20 14:28 UTC
rendered paste body
package netherrackdamage;

import java.util.HashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.*;
import org.bukkit.event.*;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import org.bukkit.plugin.Plugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;

public class NetherrackDamage extends JavaPlugin {
    private final NDprops props = new NDprops(this);
    private final NDcommands cmdHandle = new NDcommands(this, props);
    private final NetherrackDamagePlayerListener playerListener = new NetherrackDamagePlayerListener(this, props, cmdHandle);
    private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    public static PermissionHandler permissionHandler;
    String permiss;
    
    private void setupPermissions() {
      Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");

      if (this.permissionHandler == null) {
          if (permissionsPlugin != null) {
              this.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
              System.out.println("[Netherrack-Damage] hooked into Permissions.");
              permiss = "Yes";
          } else {
              // TODO: read ops.txt file if Permissions isn't found.
              System.out.println("[Netherrack-Damage] Permissions not found! Using ops.txt file.");
              permiss = "No";
          }
      }
    }

    public void onDisable() {
        System.out.println("[Netherrack-Damage] has been safely disabled.");
    }

    public void onEnable() {
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
        pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
        setupPermissions();
        setupCommands();
        props.doConfig(permiss);
        PluginDescriptionFile pdfFile = this.getDescription();
        System.out.println( "[Netherrack-Damage] version v" + pdfFile.getVersion() + " is enabled." );
    }

    private void setupCommands() {
        PluginCommand dmgdealt = getCommand("dmgdealt");
        PluginCommand dmgdelay = getCommand("dmgdelay");
        PluginCommand bootmod = getCommand("bootmod");
        CommandExecutor commandExecutor = new CommandExecutor() {
            public boolean onCommand( CommandSender sender, Command command, String label, String[] args ) {
                if (props.perm.equals("Yes")) {
                 if ((this).permissionHandler.has(event.getPlayer(), "nd.admin.dmgdealt")) {
                        if (label.equals("dmgdealt")) {
                            cmdHandle.chngDmgDealt(sender, args[0]);
                        }
                 }
                }
                        if (label.equals("dmgdelay")) {
                            cmdHandle.chngDmgDelay(sender, args[0]);
                        }
                        if (label.equals("bootmod")) {
                            cmdHandle.chngBootMod(sender, args[0]);
                        }
                return true;
                    }
            };
        if (dmgdealt != null) {
            dmgdealt.setExecutor(commandExecutor);
        }
        if (dmgdelay != null) {
            dmgdelay.setExecutor(commandExecutor);
        }
        if (bootmod != null) {
            bootmod.setExecutor(commandExecutor);
        }
        }
    
    public boolean isDebugging(final Player player) {
        if (debugees.containsKey(player)) {
            return debugees.get(player);
        } else {
            return false;
        }
    }

    public void setDebugging(final Player player, final boolean value) {
        debugees.put(player, value);
    }
}