toggles help

Discussion in 'Spigot Plugin Development' started by rhunter, May 13, 2015.

  1. Im trying to make wither arrows toggleable but it wont work for some reason. When I type /togglewither nothing happens.
    Heres my code:
    Code (Text):

    List<String> witherToggle = new ArrayList<String>();


    public boolean witherToggleCommand(CommandSender sender, Command cmd, String label, String[] args) {

                if(cmd.getName().equalsIgnoreCase("togglewither")){

        Player player = (Player) sender;

                    if (witherToggle.contains(player.getName())){

                    player.sendMessage(ChatColor.GOLD+"Wither arrows are toggled off");

                    witherToggle.remove(player.getName());

                    return true;

                    }

                    player.sendMessage(ChatColor.GOLD+"Wither arrows are toggled on");

                    witherToggle.add(player.getName());

                    return true;

        }

    returnfalse;

    }


    @EventHandler

      public void shootWither(ProjectileLaunchEvent event){

      if(event.getEntity() instanceof Arrow){

      Arrow arrow = (Arrow)event.getEntity();

    if(arrow.getShooter() instanceof Player){

    Player player = (Player)arrow.getShooter();

    if(player.hasPermission("wands.archer")){

                if (witherToggle.contains(player.getName())){

    event.setCancelled(true);

    player.launchProjectile(WitherSkull.class).setVelocity(arrow.getVelocity());

      }

    }}

    }}
     
     
  2. Code (Text):
    public boolean witherToggleCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
    should be
    Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
     
  3. @minecraftkyle457
    Thanks! But how do I have multiple commands in the same plugin now? Everytime i try to make a new one it is just an error except for when i change onCommand to something else, but then the command doesn't work
     
  4. Code (Text):
    return false;
    not
    Code (Text):
    returnfalse;
     
  5. i know thats just an error that happened why i pasted:p
     
  6. check if the sender is a player before you cast it to a player
     
  7. Either put them all in one onCommand and use command.getName() to check which command is executed (and use if-else if-else to add command specific behaviour) or create separate CommandExecutors for each command.