Package org.cattech.bukkit.bigdig

Source Code of org.cattech.bukkit.bigdig.Main

package org.cattech.bukkit.bigdig;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.cattech.bukkit.Common;

public class Main extends JavaPlugin {
  Logger  log;

  int    digSize  = 1;

  @Override
  public void onEnable() {
    log = this.getLogger();

    FileConfiguration config = getConfig();
    DigSettings.setConfig(config);

    List<String> modesEnabled = Arrays.asList(config.getString("modesEnabled").split(","));

    if (modesEnabled.contains("digging")) {
      getServer().getPluginManager().registerEvents(new DigEventListener(), this);
      //      System.out.println("Digging enabled");
    }
    if (modesEnabled.contains("track")) {
      getServer().getPluginManager().registerEvents(new BlockEventListener(), this);
      //      System.out.println("Track placing enabled");
    }
  }

  @Override
  public void onDisable() {}

  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    Player player = null;
    Boolean commandValid = false;

    if (sender instanceof Player) {
      player = (Player) sender;
    }

    FileConfiguration config = getConfig();

    List<String> sizeList = Arrays.asList(config.getString("sizeList").split(","));
    int maxDepth = config.getInt("maxDepth");
    int maxTrackLength = config.getInt("maxTrackLength");

    if (cmd.getName().equalsIgnoreCase("bigdig")) {
      if (args.length > 0) {

        // ====================Dig Settings====================
        if (args[0].equalsIgnoreCase("size")) {
          if (player.hasPermission("bigdig.dig")) {
            if (args.length > 1) {
              int newSize = Integer.parseInt(args[1]);
              if (sizeList.contains(String.valueOf(newSize))) {
                DigSettings.setSize(player, newSize);
                player.sendMessage("BigDig size set to " + String.valueOf(newSize));
              } else {
                player.sendMessage("BigDig size not set, must be one of " + sizeList.toString());
              }
            }else{
              player.sendMessage("BigDig size not set, must be one of " + sizeList.toString());
            }
          } else {
            player.sendMessage("You do not have bigdig.dig permission.");
          }
          commandValid = true;
        }
        if (args[0].equalsIgnoreCase("depth")) {
          if (player.hasPermission("bigdig.dig")) {
            if (args.length > 1) {
              int newDepth = Integer.parseInt(args[1]);
              if (newDepth > 0 && newDepth <= maxDepth) {
                DigSettings.setDepth(player, newDepth);
                player.sendMessage("BigDig depth set to " + String.valueOf(newDepth));
              } else{
                player.sendMessage("BigDig depth not set, must be 1.." + String.valueOf(maxDepth));
              }
            } else {
              player.sendMessage("BigDig depth not set, must be 1.." + String.valueOf(maxDepth));
            }
            commandValid = true;
          } else {
            player.sendMessage("You do not have bigdig.dig permission.");
          }
        }
        if (args[0].equalsIgnoreCase("autolight")) {
          if (player.hasPermission("bigdig.dig")) {
            if (args.length > 1) {
              if (args[1].equalsIgnoreCase("torch")) {
                DigSettings.setAutoLamp(player, Material.TORCH.getId());
                player.sendMessage("BigDig will auto-place : "+ DigSettings.getAutoLampName(player));
              } else if (args[1].equalsIgnoreCase("glowstone")) {
                DigSettings.setAutoLamp(player, Material.GLOWSTONE.getId());
                player.sendMessage("BigDig will auto-place : "+ DigSettings.getAutoLampName(player));
              } else if (args[1].equalsIgnoreCase("none")) {
                DigSettings.setAutoLamp(player, 0);
                player.sendMessage("BigDig will not place any lightsource");

              } else {
                player.sendMessage("autolight value must be either none, torch or glowstone");
              }
            }
          } else {
            player.sendMessage("You do not have bigdig.dig permission.");
          }
          commandValid = true;
        }
        if (args[0].equalsIgnoreCase("dropall")) {
          if (player.hasPermission("bigdig.dig")) {
            if (args.length > 1) {
              if (args[1].equalsIgnoreCase("on")) {
                DigSettings.setDropAll(player, true);
                player.sendMessage("BigDig will drop all blocks");

              } else if (args[1].equalsIgnoreCase("off")) {
                DigSettings.setDropAll(player, false);
                player.sendMessage("BigDig will not drop common blocks");

              } else {
                player.sendMessage("dropall value must be either on or off");
              }
            }
          } else {
            player.sendMessage("You do not have bigdig.dig permission.");
          }
          commandValid = true;
        }
        // ====================Track Settings====================
        if (args[0].equalsIgnoreCase("track")) {
          if (player.hasPermission("bigdig.track")) {
            if (args.length > 1) {
              if (args[1].equalsIgnoreCase("none")) {
                DigSettings.setTrackMode(player, Common.TRACK_MODE_NONE);
                player.sendMessage("BigDig will not place tracks");
              } else if (args[1].equalsIgnoreCase("follow")) {
                DigSettings.setTrackMode(player, Common.TRACK_MODE_FOLLOW);
                player.sendMessage("BigDig will place tracks to follow the terrain");
              } else if (args[1].equalsIgnoreCase("bridge")) {
                DigSettings.setTrackMode(player, Common.TRACK_MODE_BRIDGE);
                player.sendMessage("BigDig will place tracks and create bridges to cross gaps");
              } else if (args[1].equalsIgnoreCase("flat")) {
                DigSettings.setTrackMode(player, Common.TRACK_MODE_FLAT);
                player.sendMessage("BigDig will place tracks on flat surfaces and stop if there is a gap");
              } else {
                player.sendMessage("track value can be : none, follow, bridge, flat");
              }
            }
          } else {
            player.sendMessage("You do not have bigdig.track permission.");
          }
          commandValid = true;
        }
        if (args[0].equalsIgnoreCase("tracklength")) {
          if (player.hasPermission("bigdig.track")) {
            if (args.length > 1) {
              int trackLen = Integer.parseInt(args[1]);
              if (trackLen > 0 && trackLen <= maxTrackLength) {
                DigSettings.setTrackLength(player, trackLen);
                player.sendMessage("BigDig tracklength set to " + String.valueOf(trackLen));
              } else {
                player.sendMessage("BigDig tracklength not set, must be 1.."
                    + String.valueOf(maxTrackLength));
              }
            }
          } else {
            player.sendMessage("You do not have bigdig.track permission.");
          }
          commandValid = true;
        }
        if (args[0].equalsIgnoreCase("boostlength")) {
          if (player.hasPermission("bigdig.track")) {
            if (args.length > 1) {
              int boostLen = Integer.parseInt(args[1]);
              if (boostLen > 0 && boostLen <= maxTrackLength) {
                DigSettings.setBoostLength(player, boostLen);
                player.sendMessage("BigDig boostlength set to " + String.valueOf(boostLen));
              } else {
                player.sendMessage("BigDig boostlength not set, must be 1.."
                    + String.valueOf(maxTrackLength));
              }
            }
          } else {
            player.sendMessage("You do not have bigdig.track permission.");
          }
          commandValid = true;
        }
        // =====================Debug Mode =====================
        if (args[0].equalsIgnoreCase("debug")) {
          if (player.hasPermission("bigdig.debug")) {
            DigSettings.setSize(player, 3);
            DigSettings.setDepth(player, 3);
            DigSettings.setAutoLamp(player, Material.GLOWSTONE.getId());
            DigSettings.setDropAll(player, false);
            DigSettings.setTrackLength(player, 16);
            DigSettings.setBoostLength(player, 8);
            DigSettings.setTrackMode(player, Common.TRACK_MODE_FLAT);
            player.sendMessage("BigDig set to 3x3 auto-glowstone !dropall tracklen 16 flat");
            commandValid = true;
          } else {
            player.sendMessage("You do not have bigdig.debug permission.");
          }
          commandValid = true;
        }
      }
    }
    return commandValid;
  }
}
TOP

Related Classes of org.cattech.bukkit.bigdig.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.