Solved Second class

Discussion in 'Plugin Development' started by Threehundredcc2, Jan 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Threehundredcc2

    This may seem like a really nooby, I'm having a problem with my second class. I have my main class which works perfectly fine, I recently created a second class for some new commands(I don't really do that) and the commands in my second class don't work. If I run then it doesn't give me any errors or anything it just does nothing, and my main class is called Main. Second class:

    Note: If you think its the constructors that are misplaced, it's not, I had to cut some code to make it shorter sooo..


    Code:
    package mc.threehundredcctwo.kit;
     
    import java.io.PrintStream;
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import mc.threehundredcctwo.kit.Main;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class PotionPerk extends Main {
     
      {}
     
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Player player = null;
        if ((sender instanceof Player)) {
          player = (Player)sender;
        }
        if (cmd.getName().equalsIgnoreCase("perk") || (cmd.getName().equalsIgnoreCase("perks"))) {
            if (player == null) {
              sender.sendMessage("This command can only be run by a player.");
            }
       
       
            else if (args.length == 0) {
              player.sendMessage(ChatColor.DARK_AQUA + " ++ Perks ++ ");
              player.sendMessage(ChatColor.AQUA + "Please use:" + ChatColor.YELLOW + " /<perkname name>");
              player.sendMessage(ChatColor.YELLOW + "You can choose a perk AFTER you choose a class!");
              if (player.hasPermission("pvpmc.perk.speed"))
                player.sendMessage(ChatColor.GOLD + "Speed " + ChatColor.AQUA + "- Ready to use!");
              else player.sendMessage(ChatColor.GOLD + "Speed " + ChatColor.GRAY + "- Can't use :(");
     
         
              if (player.hasPermission("pvpmc.perk.strength"))
                player.sendMessage(ChatColor.GOLD + "Strength (You can also do /str" + ChatColor.AQUA + "- Ready to use");
              else player.sendMessage(ChatColor.GOLD + "Strength " + ChatColor.GRAY + "- Can't use :(");
     
         
              if (player.hasPermission("pvpmc.perk.invisibilty"))
                player.sendMessage(ChatColor.GOLD + "Invisibilty (You can also do /inv" + ChatColor.AQUA + "- Ready to use");
              else player.sendMessage(ChatColor.GOLD + "Invisibilty " + ChatColor.GRAY + "- Can't use :(");
     
     
            }
            else if (args.length == 0) {
              player.sendMessage(ChatColor.RED + "Error: Too many arguments. Please use " + ChatColor.WHITE + "/mchelp");
         
          }
        }
        if (cmd.getName().equalsIgnoreCase("speed")) {
            if (player == null) {
              sender.sendMessage("This command can only be run by a player.");
             
            }
            else if (args.length == 0) {
              if ((player.hasPermission("pvpmc.perk.speed")) || (player.isOp()))
                if (Strength.containsKey(player) || Speed.containsKey(player) || Invisibilty.containsKey(player)) {
                player.sendMessage(ChatColor.RED + "You have already choosen a perk! Try agian next life!");
           
                } else {
                  if (swordsman.containsKey(player) || tank.containsKey(player) || battlerifle.containsKey(player) || SpawnKit.containsKey(player)) {
                 
                  }
                try {
                  Speed.put(player, null);
                  Strength.put(player, null);
                  Invisibilty.put(player, null);
                  Thread.sleep(100L);
                } catch (InterruptedException localInterruptedException) {
                }
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 24000, 1));
                player.sendMessage(ChatColor.DARK_AQUA + "You have recived perk " + ChatColor.ITALIC + "" + ChatColor.AQUA + "Speed");
              } else if (args.length == 1) {
                player.sendMessage(ChatColor.DARK_AQUA + "Error: Not too many arguments. Please use " + ChatColor.RED + "/perks"); } else {
                    player.sendMessage(ChatColor.RED + "Can't do this! Umadbro?");
               
      }
      }
    }
        return false;
      }
    } 
      
    Thanks if anyone can help!
     
  2. Offline

    caseif

    It hasn't been too long, but I'd like to know this as well, so I suppose this is sort of a bump, seeing as no one is answering.
     
  3. Offline

    Johnzeh

    Have you tried using a command executor for commands?

    In the onEnable:
    getCommand("speed").setExecutor(new CommandExecutor(this));
    getCommand("command2").setExecutor(new CommandExecutor(this));

    In the CommandExecutor Class:

    private pluginname plugin;

    public MyExecutorClassName(MyPluginName plugin) {
    this.plugin = plugin;

    @Override
    public boolean onCommand(...) {

    }

    And then just write the commands in the Command Executor.
     
  4. Offline

    RainoBoy97

    In the PotionPerk class do
    Code:java
    1. Main plugin;
    2. public PotionPerk(Main instance){
    3. plugin = instance;
    4. }
    5.  

    Then in the onEnable in the Main class do
    Code:java
    1.  
    2. getCommand("perk").setExecutor(new PotionPerk(this));
    3. getCommand("perks").setExecutor(new PotionPerk(this));
    4. getCommand("speed").setExecutor(new PotionPerk(this));
     
    Threehundredcc2 likes this.
  5. Offline

    stickeric

  6. Offline

    Threehundredcc2


    Thanks, it works perfectly.
     
Thread Status:
Not open for further replies.

Share This Page