Solved World Permissions

Discussion in 'Plugin Development' started by Kaskadeking, Aug 26, 2014.

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

    Kaskadeking

    Hey guys, i try to create world permissions but it seems to doesn't work.
    My current code:
    Code:java
    1. @EventHandler
    2. public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
    3. Player player = event.getPlayer();
    4. World world = Bukkit.getPlayer(player.getUniqueId()).getWorld();
    5. if(player.getGameMode()==GameMode.CREATIVE) {
    6. return;
    7. }
    8. if(!player.hasPermission("doublejump.use")) {
    9. player.setAllowFlight(false);
    10. player.setFlying(false);
    11. return;
    12. } else if (!player.hasPermission("doublejump.worlds." + world)) {
    13. player.setAllowFlight(false);
    14. player.setFlying(false);
    15. return;
    16. }
    17. event.setCancelled(true);
    18. player.setAllowFlight(false);
    19. player.setFlying(false);
    20. player.setVelocity(player.getLocation().getDirection().multiply(1.5).setY(1));
    21.  
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerMove(PlayerMoveEvent event) {
    26. Player player = event.getPlayer();
    27. World world = Bukkit.getPlayer(player.getUniqueId()).getWorld();
    28. if((player.getGameMode()!=GameMode.CREATIVE)&&(player.getLocation().subtract(0, 1, 0).getBlock().getType()!=Material.AIR)&&(!player.isFlying())) {
    29. if(!player.hasPermission("doublejump.use")) {
    30. player.setAllowFlight(false);
    31. player.setFlying(false);
    32. return;
    33. } else if (!player.hasPermission("doublejump.worlds." + world)) {
    34. player.setAllowFlight(false);
    35. player.setFlying(false);
    36. return;
    37. }
    38. player.setAllowFlight(true);
    39. }
    40. }


    I have all permissions but i can't doublejump.
     
  2. Offline

    Totom3

    Kaskadeking Did you try testing for the permission "doublejump.worlds."+world.getName() ?
     
    Kaskadeking likes this.
  3. Offline

    TheMcScavenger

    The problem is that you're getting whether the player has a World in their permission node. A World isn't a string, therefor when you convert it to a string, it won't work. Try "Bukkit.broadcastMessage("World: " + world);" to see what it expects you to give the player as permission.

    To solve your problem, simply get the name of the world, and use that instead of the World.
    Code:java
    1. String worldName = world.getName();
     
    Kaskadeking likes this.
  4. Also, you could create a method for all those "player.setAlowFlight and player.setFlying".
     
    Kaskadeking likes this.
  5. Offline

    Kaskadeking

    Thanks. world.getName() is working :3
    and thanks for the tip XXLuigiMario :)
     
Thread Status:
Not open for further replies.

Share This Page