Plugin Help Help with checking variables

Discussion in 'Plugin Help/Development/Requests' started by iseemtobelost, Apr 20, 2017.

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

    iseemtobelost

    I am relatively new to bukkit and I was trying to make dodge feature however there is one problem, I don't know how to check for the 'dir' variable that shows the player's direction. And then teleport them accordingly. Am I missing something obvious?

    1. @EventHandler
    2. public void onPlayerDamage1(EntityDamageByEntityEvent event) {
    3. if (event.getEntity() instanceof Player) {
    4. Player player = (Player) event.getEntity();
    5. String dir = getPlayerDirection(event);
    6. Location playerLoc = player.getLocation();
    7. //Here I don't know how to test for 'dir'
    8. player.teleport(playerLoc.add(-5, 0, 0));
    9. }
    10. }
    11. String getPlayerDirection (EntityDamageByEntityEvent event) {
    12. Player player = (Player) event.getEntity();
    13. String dir = "west";
    14. float y = player.getLocation().getYaw();
    15. int i = (int)((y+8) / 22.5);
    16. if (i == 0) {dir = "west";}
    17. else if(i == 1){dir = "west northwest";}
    18. else if(i == 2){dir = "northwest";}
    19. else if(i == 3){dir = "north northwest";}
    20. else if(i == 4){dir = "north";}
    21. else if(i == 5){dir = "north northeast";}
    22. else if(i == 6){dir = "northeast";}
    23. else if(i == 7){dir = "east northeast";}
    24. else if(i == 8){dir = "east";}
    25. else if(i == 9){dir = "east southeast";}
    26. else if(i == 10){dir = "southeast";}
    27. else if(i == 11){dir = "south southeast";}
    28. else if(i == 12){dir = "south";}
    29. else if(i == 13){dir = "south southwest";}
    30. else if(i == 14){dir = "southwest";}
    31. else if(i == 15){dir = "west southwest";}
    32. else {dir = "west";}
    33. return dir;
    34. }
     
  2. Offline

    yPedx

    @iseemtobelost
    try Player.getLocation().getDirection()
    EDIT: Read wrong. :p
    Something like this?
    Code:
    public static String getCardinalDirection(Player player) {
            double rotation = (player.getLocation().getYaw() - 90) % 360;
            if (rotation < 0) {
                rotation += 360.0;
            }
             if (0 <= rotation && rotation < 22.5) {
                return "N";
            } else if (22.5 <= rotation && rotation < 67.5) {
                return "NE";
            } else if (67.5 <= rotation && rotation < 112.5) {
                return "E";
            } else if (112.5 <= rotation && rotation < 157.5) {
                return "SE";
            } else if (157.5 <= rotation && rotation < 202.5) {
                return "S";
            } else if (202.5 <= rotation && rotation < 247.5) {
                return "SW";
            } else if (247.5 <= rotation && rotation < 292.5) {
                return "W";
            } else if (292.5 <= rotation && rotation < 337.5) {
                return "NW";
            } else if (337.5 <= rotation && rotation < 360.0) {
                return "N";
            } else {
                return null;
            }
     
  3. Offline

    iseemtobelost

    Well the problem wasn't I need a detection system, I have one, but rather I need a way for the plugin to teleport me accordingly. See line 10.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @iseemtobelost Get the location.
    Get an angle (like the yaw)
    Add 90 or -90.
    Turn it into a vector using math.
    setVelocity(vector)
     
Thread Status:
Not open for further replies.

Share This Page