Border plugin issue

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

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

    patey

    I'm working on a border plugin, nothing out of the ordinary, and when inside the border it works but I'm running into problems when trying to allow users outside the border to move around.

    say the border is a 20x20 around 0x and 0z, when the user is at 20x -9z and attempts to move past the z border it should allow them to continue because they are outside one of the border walls already but it still enforces the border.

    here is my code so far, it all seems to be in order

    playerEvents.class
    Code:java
    1. public class playerEvents implements Listener{
    2.  
    3. @EventHandler(priority = EventPriority.HIGHEST)
    4. public void move(PlayerMoveEvent event){
    5. Player p = event.getPlayer();
    6. int fromx = event.getFrom().getBlockX();
    7. int fromz = event.getFrom().getBlockZ();
    8. int tox = event.getTo().getBlockX();
    9. int toz = event.getTo().getBlockZ();
    10. int counter = 0;
    11.  
    12. if (p.hasPermission("DwarfBorder.border.dwarf1")){
    13. if (! p.isOp()) {
    14. String bmsg = DwarfBorder.getInstance().getConfig().getString("Borders.Border1.BarrierMessage");
    15. int centerx = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.X");
    16. int centerz = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Center.Z");
    17. int fradius = DwarfBorder.getInstance().getConfig().getInt("Borders.Border1.Radius");
    18. int radius = fradius/2;
    19. int pcenterx = centerx + radius;
    20. int ncenterx = centerx - radius;
    21. int pcenterz = centerz + radius;
    22. int ncenterz = centerz - radius;
    23.  
    24. if ((fromx <= pcenterx) && (fromz <= pcenterz)){
    25. if (tox >= pcenterx){
    26. p.setVelocity(new Vector(-1,-1,0));
    27. if (counter == 0){
    28. p.sendMessage(bmsg);
    29. counter = 10;
    30. }else{
    31. counter--;
    32. }
    33. }
    34. if (toz >= pcenterz){
    35. p.setVelocity(new Vector(0,-1,-1));
    36. if (counter == 0){
    37. p.sendMessage(bmsg);
    38. counter = 10;
    39. }else{
    40. counter--;
    41. }
    42. }
    43. }
    44.  
    45. if ((fromx >= ncenterx) && (fromz >= ncenterz)){
    46. if (tox <= ncenterx){
    47. p.setVelocity(new Vector(1,-1,0));
    48. if (counter == 0){
    49. p.sendMessage(bmsg);
    50. counter = 10;
    51. }else{
    52. counter--;
    53. }
    54. }
    55. if (toz <= ncenterz){
    56. p.setVelocity(new Vector(0,-1,1));
    57. if (counter == 0){
    58. p.sendMessage(bmsg);
    59. counter = 10;
    60. }else{
    61. counter--;
    62. }
    63. }
    64. }
    65.  
    66. if ((fromx >= ncenterx) && (fromz <= pcenterz)){
    67. if (tox <= ncenterx){
    68. p.setVelocity(new Vector(1,-1,0));
    69. if (counter == 0){
    70. p.sendMessage(bmsg);
    71. counter = 10;
    72. }else{
    73. counter--;
    74. }
    75. }
    76. if (toz >= pcenterz){
    77. p.setVelocity(new Vector(0,-1,-1));
    78. if (counter == 0){
    79. p.sendMessage(bmsg);
    80. counter = 10;
    81. }else{
    82. counter--;
    83. }
    84. }
    85. }
    86. if ((fromx <= pcenterx) && (fromz >= ncenterz)){
    87. if (tox >= pcenterx){
    88. p.setVelocity(new Vector(-1,-1,0));
    89. if (counter == 0){
    90. p.sendMessage(bmsg);
    91. counter = 10;
    92. }else{
    93. counter--;
    94. }
    95. }
    96. if (toz <= ncenterz){
    97. p.setVelocity(new Vector(0,-1,1));
    98. if (counter == 0){
    99. p.sendMessage(bmsg);
    100. counter = 10;
    101. }else{
    102. counter--;
    103. }
    104. }
    105. }
    106.  
    107. }
    108. }
    109. }
    110. }
     
  2. Offline

    The Fancy Whale

    I'm on a tablet and don't have time to completely read through the code, but a simple way to find the issue is to add debug statements after all the if/else statements. That way you can check where the event is cancelled and fiugre out why the if statement returns false.
     
  3. Offline

    xXMaTTHDXx

    I couldn't spot anything due to not being on a computer, but just as a general tip class names should be capitalized
    PlayerEvents
     
  4. Offline

    patey

    after adding some debug statements it seems that the second of every double if condition is being ignored, I've searched everything I can think of and this is definitely how the statement should be written so it's something bukkit is doing :S
     
  5. Offline

    joeygallegos

    Did you register the event? patey
     
  6. Offline

    patey

    yup, it's enforcing the border when the user is already outside the border. (example on OP)
     
Thread Status:
Not open for further replies.

Share This Page