Need help with a world border..

Discussion in 'Plugin Development' started by patey, Aug 4, 2014.

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

    patey

    I'm trying to create a border plugin, the border is supposed to prevent players from leaving but allow them to enter and the border will only affect them if they have a certain permission node.

    everything seems to be in order for the code but it doesn't have any effect, can anyone point out my mistake(s)?

    Code:java
    1. @EventHandler
    2. public void move(PlayerMoveEvent event){
    3. Player p = event.getPlayer();
    4. int fromx = event.getFrom().getBlockX();
    5. int fromz = event.getFrom().getBlockZ();
    6. int tox = event.getTo().getBlockX();
    7. int toz = event.getTo().getBlockZ();
    8.  
    9. if (p.hasPermission("DwarfBorder.border.dwarf1")){
    10. int centerx = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.X");
    11. int centerz = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.Z");
    12. int radius = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.radius");
    13. if (tox > centerx + (radius/2)){
    14. if (fromx < centerx + (radius/2)){
    15. p.setVelocity(new Vector(fromx-1,event.getFrom().getBlockY(),fromz));
    16. p.sendMessage("Border hit");
    17. }
    18. }
    19.  
    20. if (tox < centerx - (radius/2)){
    21. if (fromx > centerx - (radius/2)){
    22. p.setVelocity(new Vector(fromx+1,event.getFrom().getBlockY(),fromz));
    23. p.sendMessage("Border hit");
    24. }
    25. }
    26.  
    27. if (toz > centerz + (radius/2)){
    28. if (fromz < centerz + (radius/2)){
    29. p.setVelocity(new Vector(fromx,event.getFrom().getBlockY(),fromz-1));
    30. p.sendMessage("Border hit");
    31. }
    32. }
    33.  
    34. if (toz < centerz - (radius/2)){
    35. if (fromz > centerz - (radius/2)){
    36. p.setVelocity(new Vector(fromx,event.getFrom().getBlockY(),fromz+1));
    37. p.sendMessage("Border hit");
    38. }
    39. }
    40.  
    41. }
    42.  
    43. }


    bump?

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

    fireblast709

    patey your code applies the border to all players with the permission
     
  3. Offline

    MOMOTHEREAL

    If I didn't misunderstand, it's intended...
     
  4. Offline

    patey

    yeah, it's intentional for multiple borders.

    I should mention I don't get the test message either, so I'm assuming it's something to do with my coordinate check? also there's no error messages.
    is it maybe how I'm retrieving the location variables?
     
  5. Offline

    Necrodoom

    patey make a debug check on event start and permission check as well, please.
     
  6. Offline

    patey

    I've never had to do a debug check, how would I do that?
     
  7. Offline

    Necrodoom

    patey sendMessage or logger, your choice.
    Point of debug is that you know what is happening.
     
  8. Offline

    patey

    ah, thought it was something different lol

    I'll do that now

    the debug works, still no border effect though.

    I'm thinking it's something to do with this part of my code, but it all seems ok to me :/
    Code:java
    1. int centerx = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.X");
    2. int centerz = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.Z");
    3. int radius = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.radius");
    4. if (tox > centerx + (radius/2)){
    5. if (fromx < centerx + (radius/2)){


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

    patey

    I forgot to come back and explain how i made that work, for some reason I couldn't get the radius/2 to work there (I was probably doing it wrong) so I just did all the math in different variables
     
Thread Status:
Not open for further replies.

Share This Page