Solved Genuinely have no clue whats wrong.

Discussion in 'Plugin Help/Development/Requests' started by OTF Catastrophe, Aug 16, 2015.

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

    OTF Catastrophe

    Well I've been working on this incredibly simple plugin... to which I thought.. Anyways, I was working on it and I've had to remove and re-add so many things. I'm having an issue with p.addPotionEffect. It isn't working for me. This sounds like such an amateur thing, but can anyone tell me what I'm doing wrong here?

    Code:
    package me.SirApathy.ToggleEffects;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class MainClass extends JavaPlugin{
       
        @Override
        public void onDisable(){
            getLogger().info("ToggleEffects has been disabled!");
               
        }
       
        @Override
        public void onEnable(){
            getLogger().info("ToggleEffects has been enabled!");
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player p = (Player) sender;
           
            if (cmd.getName().equalsIgnoreCase("toggleeffects") && p.hasPermission("toggleeffects.effects.*")) {
               
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 1)) ; //Adds Speed I to player.
               
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 99999, 1)) ; //Adds Jump Boost I to player.
                   
            }
                   
            if (cmd.getName().equalsIgnoreCase("toggleeffect jump") && p.hasPermission("toggleeffects.effects.jump")) {
                       
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 99999, 1)) ; //Adds Jump Boost I to player.
                   
            }
           
            if (cmd.getName().equalsIgnoreCase("toggleeffect speed") && p.hasPermission("toggleeffects.effects.speed")) {
                       
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 1)) ; //Adds Speed I to player.
    
            }
           
            return false;
           
        }
    
    }
    
     
  2. Offline

    Lolmewn Retired Staff

    A couple of things are wrong:
    no @Override for onCommand (not breaking though)
    Immediate casting to Player in onCommand (What if it's the console or a commandblock performing the command?)
    cmd.getName() will always return the name in your plugin.yml, and therefore cannot have arguments. Instead, use the String[] args for this. You can see if any arguments were given using args.length == 0.
    Also, I would recommend sending a message when you do something. This way you know exactly which piece of code gets executed.
     
  3. Offline

    OTF Catastrophe

    I added the @Override to the top of the onCommand, but the commands that are to be executed are for players and aren't supposed to be console or command block compatible. The plugin is strictly for giving players effects from in game. And if the args are, lets say args.length == 1, how would I specify each separate arg? What I mean is, how would I specify JUMP from SPEED?

    I deleted the commands that have two args and left the toggleeffect command. The 2 commands are gone but the 1 command doesn't even work. I have it set so it's like this now:


    Code:
    package me.SirApathy.ToggleEffects;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class MainClass extends JavaPlugin{
     
        @Override
        public void onDisable(){
            getLogger().info("ToggleEffects has been disabled!");
             
        }
     
        @Override
        public void onEnable(){
            getLogger().info("ToggleEffects has been enabled!");
         
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            Player p = (Player) sender;
         
            if (cmd.getName().equalsIgnoreCase("toggleeffects") && p.hasPermission("toggleeffects.effects.*")) {
             
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 99999, 1)) ;
             
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 99999, 1)) ;
    
            }
         
            return false;
         
        }
    
    }
    
    @timtower Can you merge these two posts? I forgot to just edit the previous one instead.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  4. Offline

    lubbs31

    Try

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("toggleeffects")) {
                if(player.hasPermission("toggleeffects.effects.*")) {
                    //whatever potion effects you desire
                }
            }
            return false;
        }
     
  5. Offline

    OTF Catastrophe

    I was changing around some of my code earlier and re-wrote most of it. I fixed some of my issues already but for the rest of my issues I will try to figure out myself. thank you for your response! ^-^
     
    lubbs31 likes this.
Thread Status:
Not open for further replies.

Share This Page