could some help me get this to work

Discussion in 'Plugin Development' started by cannopener, Feb 1, 2017.

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

    cannopener

    i'm trying to add another permission to the /blablabla when i use the /blablabla <player> command it has a separate permission which i added for it which is blablabla.others but when you have no permission the message doesn't show saying no permission to teleport others

    Code:
    package me.blabla.main;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
        public void onEnable(){
         
            saveDefaultConfig();
         
            Bukkit.getServer().getLogger().info("blablabla has been enabled!");
         
        }
        public void onDisable(){
         
         
            Bukkit.getServer().getLogger().info("blablabla has been disabled!");
         
        }
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
    
            if(!(sender instanceof Player)){
              
                 sender.sendMessage("§4You must be a player to use this command!");
              
                 return true;
             }
         
            Player player = (Player) sender;
         
            if (command.getName().equalsIgnoreCase("blablabla")) {
         
                if (!(player.hasPermission("blablabla.use"))){
                        player.sendMessage("You have no permission to do that");
                    } else{
                    if (args.length == 0) {
             
             
                Location originalLocation = player.getLocation();
             
                Random random = new Random();
            
                Location teleportLocation = null;
            
                int x = random.nextInt(getConfig().getInt("randomx")) + 1;
                int y = 150;
                int z = random.nextInt(getConfig().getInt("randomz")) + 1;
            
                boolean isOnLand = false;
            
                while (isOnLand == false) {
    
                        teleportLocation = new Location(player.getWorld(), x, y, z);
                    
                        if (teleportLocation.getBlock().getType() != Material.AIR) {
                                isOnLand = true;
                        } else y--;
            
                }
            
                player.teleport(new Location(player.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 1, teleportLocation.getZ()));
            
                player.sendMessage("§aYou have been teleported §e" + (int)teleportLocation.distance(originalLocation) + "§a blocks away!");
                    }
                    }
                }else{
                    if (!(player.hasPermission("blablabla.others"))){
                            player.sendMessage("§4You have no permission to teleport others");
                        } else{
             
            Player target = Bukkit.getPlayerExact(args[0]);
         
            if (target == null) {
             
             
            player.sendMessage(args[0] + " is not online!");
         
            } else
             
                {
             
                Location originalLocation = target.getLocation();
             
                Random random = new Random();
            
                Location teleportLocation = null;
            
                int x = random.nextInt(getConfig().getInt("randomx")) + 1;
                int y = 150;
                int z = random.nextInt(getConfig().getInt("randomz")) + 1;
            
                boolean isOnLand = false;
            
                while (isOnLand == false) {
    
                        teleportLocation = new Location(player.getWorld(), x, y, z);
                    
                        if (teleportLocation.getBlock().getType() != Material.AIR) {
                                isOnLand = true;
                        } else y--;
            
                }
            
                target.teleport(new Location(target.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 1, teleportLocation.getZ()));
            
                target.sendMessage("§aYou have been teleported §e" + (int)teleportLocation.distance(originalLocation) + "§a blocks away by §b" + sender.getName());
                player.sendMessage("§eYou random teleported §b" + target.getDisplayName());
            }
            }
         
    }
            return false;
    }
    }
     
    Last edited: Feb 1, 2017
  2. Offline

    dodiaraculus

    I can help you
     
  3. Offline

    cannopener

    that would be great if you could :D
     
  4. Offline

    dodiaraculus

    if (!(player.hasPermission("blablabla.use"))){

    just do this

    if (!(player.hasPermission("blablabla.use")) || player.hasPermission("blablabla.use2"))){
     
  5. Offline

    Drkmaster83

    Your boolean logic is flawed; The statement you gave evaluates to "if the player doesn't have "blablabla.use" or the player does have "blablabla.use2", which means it won't let the people who have the second permission do the command, only people with the first permission.

    @cannopener Here's what you would replace your if statement with:
    Code:
    if (!(player.hasPermission("blablabla.use") || player.hasPermission("blablabla.others))) {
    }
    
    @cannopener Also, your command won't work for the "others" portion. Currently, that code is only accessed if the command.getName() isn't "blablabla" (it's in the else of that if check). You must move it around and check the args, only when the args.length is sufficiently long can you parse out the player and all.

    Let me know if you're lost.
     
  6. Offline

    cannopener

  7. Offline

    Drkmaster83

    [​IMG]
    I could rewrite your code and post the difference if you need more than this.
     
Thread Status:
Not open for further replies.

Share This Page