Package me.vudu.Conflict.Handlers

Source Code of me.vudu.Conflict.Handlers.CommandHandler

package me.vudu.Conflict.Handlers;

import me.vudu.Conflict.ConflictPlugin;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.inventory.SpoutItemStack;
import org.getspout.spoutapi.player.SpoutPlayer;

/**
* verwaltet alle eigenen Commands
*
* @author vwendel
*
*/
public class CommandHandler {

  /**
   * Commands definieren
   */
  public static boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    String commandName = command.getName().toLowerCase();

    // Hunger pro Zeiteinheit
    if (commandName.equals("sethunger")) {
      if (args.length > 0) {
        ConflictPlugin.hungerPerTime = Integer.parseInt(args[0]);
        Bukkit.getServer().broadcastMessage("Hunger pro Zeit wurde von admin auf " + args[0] + " gesetzt.");
      } else {
        sender.sendMessage("/" + commandName + " needs one argument (int)");
      }

      return true;
    }
   
    // Hunger pro Zeiteinheit
        if (commandName.equals("setspawn")) {
          if (args.length == 2) {
            ConflictPlugin.spawnX = Integer.parseInt(args[0]);
            ConflictPlugin.spawnZ = Integer.parseInt(args[1]);
            Bukkit.getServer().broadcastMessage("Der SpawnPunkt wurde auf x: " + args[0] +", z: "+args[2] " gesetzt.");
          } else {
            sender.sendMessage("/" + commandName + " needs two arguments if type int (x, z)");
          }

          return true;
        }

    // Erlaube Zerst�ren von BaseBlocks
    if (commandName.equals("allowdbb")) {
      if (args.length > 0) {
        if (args[0].equals("0")) {
          ConflictPlugin.allowDestroyBaseBlock = false;
          Bukkit.getServer().broadcastMessage("BaseBlocks k�nnen jetzt nicht mehr zerst�rt werden.");
        }
        if (args[0].equals("1")) {
          ConflictPlugin.allowDestroyBaseBlock = true;
          Bukkit.getServer().broadcastMessage("BaseBlocks k�nnen jetzt zerst�rt werden.");
        }

      } else {
        sender.sendMessage("/" + commandName + " needs one argument (0/1)");
      }

      return true;
    }

    // generieren von roten BaseBlocks zulassen?
    if (commandName.equals("allowbbr")) {
      if (args.length > 0) {
        if (args[0].equals("0")) {
          ConflictPlugin.allowBBR = false;
          Bukkit.getServer().broadcastMessage("Rote BaseBlocks k�nnen jetzt nicht mehr generiert werden.");
        }
        if (args[0].equals("1")) {
          ConflictPlugin.allowBBR = true;
          Bukkit.getServer().broadcastMessage("Rote BaseBlocks k�nnen jetzt generiert werden.");
        }
      }
      return true;
    }

    // generieren von blauen BaseBlocks zulassen?
    if (commandName.equals("allowbbb")) {
      if (args.length > 0) {
        if (args[0].equals("0")) {
          ConflictPlugin.allowBBB = false;
          Bukkit.getServer().broadcastMessage("Blaue BaseBlocks k�nnen jetzt nicht mehr generiert werden.");
        }
        if (args[0].equals("1")) {
          ConflictPlugin.allowBBB = true;
          Bukkit.getServer().broadcastMessage("Blaue BaseBlocks k�nnen jetzt generiert werden.");
        }
      }
      return true;
    }

    // check if command from ingame
    // ***************** ab hier nur ingame commands*****************
    if (!(sender instanceof Player)) {
      sender.sendMessage("/" + commandName + " can only be run from in game.");
      return true;
    }
    // *****************************************************************

    // TeamChat
    if (commandName.equals("t")) {
      SpoutPlayer player = (SpoutPlayer) sender;
      StringBuilder message = new StringBuilder();
      for (int i = 0; i < args.length; i++) {
        message.append(args[i] + " ");
      }
      if (ConflictPlugin.playerIsInTeam(player).equals("red")) {
        for (SpoutPlayer p : ConflictPlugin.playersRed) {
          p.sendMessage("[" + sender.getName() + "]: " + message.toString());
        }
      } else {
        for (SpoutPlayer p : ConflictPlugin.playersBlue) {
          p.sendMessage("[" + sender.getName() + "]: " + message.toString());
        }
      }

    }

    // BaseBlockRed
    if (commandName.equals("bbr")) {
      if (ConflictPlugin.allowBBR) {
        Player player = (Player) sender;

        if (ConflictPlugin.playersRed.contains((SpoutPlayer) player)) {
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.baseBlockRed, 1));
          ConflictPlugin.allowBBR = false; // nur 1x
          Bukkit.getServer()
              .broadcastMessage("Spieler &c" + player.getName() + " &fhat den roten BaseBlock!");
        } else {
          sender.sendMessage(ChatColor.RED
              + "Du musst im roten Team sein um diesen Befehl ausf�hren zu k�nnen!");
        }

      } else {
        sender.sendMessage(ChatColor.RED + "Roter BaseBlock wurde bereits verteilt!");
      }
      return true;
    }

    // BaseBlockBlue
    if (commandName.equals("bbb")) {
      if (ConflictPlugin.allowBBB) {
        Player player = (Player) sender;
        if (ConflictPlugin.playersBlue.contains((SpoutPlayer) player)) {
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.baseBlockBlue, 1));
          ConflictPlugin.allowBBB = false; // nur 1x
          Bukkit.getServer().broadcastMessage(
              "Spieler &1" + player.getName() + " &fhat den blauen BaseBlock!");
        } else {
          sender.sendMessage(ChatColor.RED
              + "Du musst im blauen Team sein um diesen Befehl ausf�hren zu k�nnen!");
        }

      } else {
        sender.sendMessage(ChatColor.RED + "Blauer BaseBlock wurde bereits verteilt!");
      }
      return true;
    }

    // Artefakt Stufe 1
    if (commandName.equals("art")) {
      try {
        Player player = (Player) sender;
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int amount = Integer.parseInt(args[2]);
        switch (a) {
        case 1:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.artifact1Grow.get(b), amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen ArtefaktBlock ercheatet!");
          break;
        case 2:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.artifact2Grow.get(b), amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen ArtefaktBlock ercheatet!");
          break;
        case 3:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.artifact3Grow.get(b), amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen ArtefaktBlock ercheatet!");
          break;
        }

      } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + "Invalid arguments");
      }
    }

    // basedef Bl�cke generieren
    if (commandName.equals("basedef")) {
      try {
        Player player = (Player) sender;
        int a = Integer.parseInt(args[0]);
        int amount = Integer.parseInt(args[1]);
        switch (a) {
        case 1:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.defenseTower, amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen DefenseTower ercheatet!");
          break;
        case 2:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.damageTower, amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen DamageTower ercheatet!");
          break;
        case 3:
          player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.radarTower, amount));
          Bukkit.getServer().broadcastMessage(
              "Spieler &c" + player.getName() + " &fhat sich einen RadarTower ercheatet!");
          break;
        }

      } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + "Invalid arguments");
      }
    }

    // generiere VuduBrick
    if (commandName.equals("vb")) {
      try {
        Player player = (Player) sender;
        int amount = Integer.parseInt(args[0]);
        player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.vuduBrick, amount));

      } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + "Invalid arguments");
      }
    }

    // show red arrows
    if (commandName.equals("showred")) {
      SpoutPlayer player = (SpoutPlayer) sender;

      if (args.length > 0) {
        if (args[0].equals("0")) {
          ConflictPlugin.showArrowRed.put(player, false);
        }
        if (args[0].equals("1")) {
          ConflictPlugin.showArrowRed.put(player, true);
        }

      } else {
        sender.sendMessage("/" + commandName + " needs one argument (0/1)");
      }
      return true;
    }

    // show blue arrows
    if (commandName.equals("showblue")) {
      SpoutPlayer player = (SpoutPlayer) sender;

      if (args.length > 0) {
        if (args[0].equals("0")) {
          ConflictPlugin.showArrowBlue.put(player, false);
        }
        if (args[0].equals("1")) {
          ConflictPlugin.showArrowBlue.put(player, true);
        }

      } else {
        sender.sendMessage("/" + commandName + " needs one argument (0/1)");
      }
      return true;
    }

    // sonst
    return false;
  }

}
TOP

Related Classes of me.vudu.Conflict.Handlers.CommandHandler

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.