Solved how to add admin bypass

Discussion in 'Plugin Development' started by Rick221, Jan 19, 2015.

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

    Rick221

    I made a launch plugin with a cooldown and I want to add an admin bypass so it doesnt have a cooldown. I'm kind of a noob and don't know how I would go about it

    Heres my code

    Code:
    package me.rick221133;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ArrowShoot extends JavaPlugin implements Listener {
       
        private List<Player> cantDoCommand = new ArrayList<Player>();
       
        Countdown d = new Countdown();
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("launch")) {
                       
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if(player.hasPermission("launch.use"));
                    if(!cantDoCommand.contains(player)) {
                        player.sendMessage(ChatColor.GREEN + "You have been launched, prepare for landing!");
                    player.setVelocity(player.getLocation().getDirection().multiply(8));
                    cantDoCommand.add(player);
                    d.setList(cantDoCommand);
                    d.setPlayer(player);
                    new Thread(d).start();
                    if(cantDoCommand.contains(player));
                            player.sendMessage(ChatColor.RED + "Please wait 4 seconds before using launch again!");
                       
                    }
        }
            return false;
           
               
            }
            return false;
           
        }   
       
    }
     
  2. Offline

    Avery246813579

    @Rick221
    Well, this line of code does not do anything:
    Code:
                    if(player.hasPermission("launch.use"));
    
    Just check if the player is op, or check if they have permission to use the command(http://wiki.bukkit.org/Plugin_Tutorial):
    Code:
    if(player.isOp()){
    doSomething
    }
     
  3. Offline

    1Rogue

    He should still use the perm node approach, just add the braces instead of a semicolon.
     
  4. Offline

    Avery246813579

    @1Rogue Yes of course, I was just telling him that, the line of code did not do anything at the moment xD
     
  5. Offline

    Rick221

    @Avery246813579 Worked, thanks mate!

    Also @Avery246813579 for a permission should I replace if(player.hasPermission("launch.use")); with if(player.hasPermission["launch.use"]); instead?
     
    Last edited by a moderator: Jan 19, 2015
  6. Offline

    mythbusterma

    @Rick221

    Why would a String be an array index? I think you need to go learn some more Java if you're that unclear on the syntax.
     
  7. Offline

    Rick221

  8. Offline

    leon3001

    @Rick221 Meh, just because something works, it doesn't mean it's perfect. :p
     
  9. Offline

    xXMaTTHDXx

    False... The syntax is simple. Please learn it before you make those inquiries.
     
  10. Offline

    1Rogue

    Then if it doesn't work at all can we assume it's stupid? Because that doesn't work.
     
  11. Offline

    Rick221

    Sorry guys! I am bit of a noob to java and plugin developing, I am learning :D
     
  12. @Rick221 That's fine, keep learning and you'll eventually know everything about Java. Make sure that you set this thread to "Solved" under "Thread Tools". :)
     
  13. Offline

    Avery246813579

    @Rick221
    So many useless comments on this thread, and he still has a question that everyone neglected to answer.

    Rick when you do the following code, nothing happens because you just check if the player has the permission, you do not do anything if the player does have permission:
    Code:
    if(player.hasPermission("launch.use");
    I suggest checking if the player does NOT have permission to use the command right after you check the command name. I suggest putting something like this at the line you have your old permission statement:
    Code:
                if (!((Player) sender).hasPermission(""launch.use"")) { //You only need to cast player to sender if you have not already.
                    player.sendMessage(ChatColor.RED + "You don't have the permission to use this command!");
                    return false;
                }
    I am sorry for the rude comments people gave you above, this forum should be more welcoming and less people bragging and trying to show off. If you need more help just tag me :D
     
    Last edited: Jan 20, 2015
    1Rogue likes this.
  14. Offline

    1Rogue

    Interesting, for some reason I read his second posting as an answer to the question rather than a further question. (People posting misinformation as fact has definitely been a problem here before).


    @Rick221

    [] is a form of a dereference operator, it's exclusively used in java for arrays (which are int-indexed only, there are no string indexes for arrays).

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

    When I stated to "use braces" earlier, I meant to create a code block with your statement:

    Code:java
    1. if (player.hasPermission("launch.use")) {
    2. //conditional code
    3. }


    This will cause the conditional code to only be executed if "hasPermission" returns a value of true.

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
     
    Avery246813579 likes this.
Thread Status:
Not open for further replies.

Share This Page