Solved Get Sign in a ProtectedRegion (WorldGuard)

Discussion in 'Plugin Development' started by zaza97, May 19, 2014.

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

    zaza97

    Hello Guys,

    I have a Problem with my Plugin depends on WorldGuard (WorldEdit).

    I want to get a Sign in a Region, but i don't have an idea how i get it.

    First i want to go through the levels of the Region from 0,0,0 to the end of the Region (16,16,256).

    I create a Plugin which can create CuboidRegions i works fine. But now i want that the Sign, which was Placed before to create the region, will be reset if i sell the Region.

    Example Code:
    Code:java
    1. private void removeSign(String regionID, WorldGuardPlugin wg, Player p)
    2. {
    3. ProtectedRegion region = wg.getRegionManager(p.getWorld()).getRegion(regionID);
    4. //World world = p.getWorld();
    5.  
    6. int xMin = region.getMinimumPoint().getBlockX();
    7. int yMin = region.getMinimumPoint().getBlockY();
    8. int zMin = region.getMinimumPoint().getBlockZ();
    9.  
    10. int xMax = region.getMaximumPoint().getBlockX();
    11. int yMax = region.getMaximumPoint().getBlockY();
    12. int zMax = region.getMaximumPoint().getBlockZ();
    13.  
    14. for(;xMin < xMax; xMin++)
    15. {
    16. for(;yMin < yMax; yMin++)
    17. {
    18. for(;zMin < zMax; zMin++)
    19. {
    20. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    21.  
    22. if(loc.getState() instanceof Sign)
    23. {
    24. Sign sc = (Sign) loc.getState();
    25. if(sc.getLine(1).equalsIgnoreCase("Besitzer: "))
    26. {
    27. sc.setLine(0, "§3[Kaufen]");
    28. sc.setLine(1, "");
    29. sc.setLine(2, "");
    30. sc.setLine(3, "");
    31. }
    32. }
    33. }
    34. }
    35. }


    Here the Method Calling:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args)
    3. {
    4. if(sender instanceof Player)
    5. {
    6. Player p = (Player) sender;
    7. if(cmd.getName().equalsIgnoreCase("verkaufen") && p.hasPermission("SignBuy.Owner.verkaufen"))
    8. {
    9. if(args.length == 1)
    10. {
    11. String regionID = args[0];
    12. String plNa = p.getName();
    13. if(wg.getGlobalRegionManager().get(p.getWorld()).getRegion(regionID) != null)
    14. {
    15. ProtectedRegion region = wg.getGlobalRegionManager().get(p.getWorld()).getRegion(regionID);
    16. DefaultDomain domain = new DefaultDomain();
    17. domain = region.getOwners();
    18. if(domain.contains(plNa))
    19. {
    20. domain = region.getOwners();
    21. domain.removePlayer(plNa);
    22. try {
    23. removeSign(regionID, wg, p);//Here is the Calling for the Method
    24. wg.getGlobalRegionManager().get(p.getWorld()).removeRegion(regionID);
    25. wg.getGlobalRegionManager().get(p.getWorld()).save();
    26. } catch (ProtectionDatabaseException e)
    27. {
    28. return false;
    29. }
    30. p.sendMessage("§3[SignBuy] §c Du hast dein Grundstück verkauft!");
    31. }
    32. else
    33. {
    34. p.sendMessage("§3[SignBuy] §cDu bist nicht der Besitzer dieser Region!");
    35. }
    36. }else
    37. {
    38. p.sendMessage("§3[SignBuy] §cDiese Region existiert nicht!");
    39. }
    40. }
    41. else
    42. {
    43. p.sendMessage("§3[SignBuy] §c/verkaufen <RegionID>");
    44. return true;
    45. }
    46. }
    47. }else
    48. {
    49. System.out.println("Nur im Spiel! Sorry!");
    50. return true;
    51. }
    52. return true;
    53. }


    Please Help me what have i do wrong?
    i think i do wrong to get the first block (0,0,0) in the Chunk(Region).
    Or i change the Dimensions(x,y,z) or something like this.

    Best Regards,

    Christopher Ludwig
    PS: (Sorry for my bad English)
     
  2. Offline

    RawCode

    sign is tileentity
     
  3. Offline

    TGRHavoc

    zaza97
    Maybe you should do: "Sign sign = (Sign)loc"..
     
  4. Offline

    !Phoenix!

    Are you sure the entire line is supposed to be "Besitzer: " or only the beginning of the line? It looks like something is supposed to follow that because of the whitespace. In this case, check if the String only starts like that.

    Notice that the call if(loc.getState() instanceof Sign) for each single block is very inefficient. Rather check if the block type is SIGN_POST or WALL_SIGN instead.

    Despite that: It looks like you are about to create a plugin that allows players to buy WorldGuard regions. There are already multiple available on BukkitDev if you want to save some time.
     
  5. Offline

    zaza97

    Yeah i know that they are many Plugins on Bukkit, but i do this Plugin for a Server.

    OK but with SIGN_POST or WALL_SIGN works also as instanceof so hmm.
    And Starts with i check it out .

    Ty

    if i do this, there is a Exception, cause not every Block is a Sign. The code want to take the Block and change it to the object Sign. So it don't work fine and is a bad programming style.

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

    TGRHavoc

    zaza97
    I am seriously facepalming right now... So hard.... Put it after you have checked whether the block is an instace of a sign.... Seriously, you thought I was telling you to put that anywhere.... Please...
     
  7. Offline

    zaza97

    ^^ yes that's right if you have told me the Line Number of the Code i don't have wrote it!

    I tried it out previously, but it doesn't matter! I think i have to get the position of the first blocks and go trough it. Level for Level, Block for Block. I think there's is my fail.
    And that you are Facepalming than you have to explain what you want to tell me better :p
     
  8. Offline

    !Phoenix!

    TGRHavoc I think you are the one to get a facepalm:

    Code:
    /* 22 */ if(loc.getState() instanceof Sign)
    /* 23 */ {
    /* 24 */     Sign sc = (Sign) loc.getState();
    
    He is checking if the block is a sign before. Even tough it is not the best way to do it.
     
  9. Offline

    zaza97

    Sign sc = (Sign) loc.getState();

    And I do this already :p

    Have you any idea what have i done wrong in the three for() blocks?

    I think i changed the dimensions(x,y,z) or something like that you know?
    Or i get wrong coordinates?

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

    !Phoenix!

    Like I said I am pretty sure your problem has something to do with that whitespace after "Besitzer:". I guess either this is only the beginning of the line (in this case you cannot check it using equals / equalsIgnoreCase) or the whitespace is not supposed to be there at all. Tell me if I am wrong.
     
  11. Offline

    zaza97

    Code:java
    1. private void removeSign(String regionID, WorldGuardPlugin wg, Player p)
    2. {
    3. ProtectedRegion region = wg.getRegionManager(p.getWorld()).getRegion(regionID);
    4. //World world = p.getWorld();
    5.  
    6. int xMin = region.getMinimumPoint().getBlockX();
    7. int yMin = region.getMinimumPoint().getBlockY();
    8. int zMin = region.getMinimumPoint().getBlockZ();
    9.  
    10. int xMax = region.getMaximumPoint().getBlockX();
    11. int yMax = region.getMaximumPoint().getBlockY();
    12. int zMax = region.getMaximumPoint().getBlockZ();
    13.  
    14. for(;xMin < xMax; xMin++)
    15. {
    16. for(;yMin < yMax; yMin++)
    17. {
    18. for(;zMin < zMax; zMin++)
    19. {
    20. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    21.  
    22. if(loc.getState().equals(Material.WALL_SIGN) || loc.getState().equals(Material.SIGN_POST) || loc.getState().equals(Material.SIGN))
    23. {
    24. Sign sc = (Sign) loc.getState();
    25. if(sc.getLine(1).startsWith("Besitzer:"))
    26. {
    27. sc.setLine(0, "§3[Kaufen]");
    28. sc.setLine(1, "");
    29. sc.setLine(2, "");
    30. sc.setLine(3, "");
    31. }
    32. }
    33. }
    34. }
    35. }
    36. }


    Now the code is something like that, but i don't work -.-
     
  12. Offline

    TGRHavoc

    zaza97
    Put some debug code in a see what code isn't being executed...
     
  13. Offline

    zaza97

    Nope you're wrong. :p

    It's not the error.

    I think over all the dimension are wrong or I have forgot any error-checking.
    Or i have an issues in
    Code:java
    1. */20*/Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();

    Don't know..

    Code:java
    1. private void removeSign(String regionID, WorldGuardPlugin wg, Player p)
    2. {
    3. ProtectedRegion region = wg.getRegionManager(p.getWorld()).getRegion(regionID);
    4. //World world = p.getWorld();
    5.  
    6. int xMin = region.getMinimumPoint().getBlockX();
    7. int yMin = region.getMinimumPoint().getBlockY();
    8. int zMin = region.getMinimumPoint().getBlockZ();
    9.  
    10. int xMax = region.getMaximumPoint().getBlockX();
    11. int yMax = region.getMaximumPoint().getBlockY();
    12. int zMax = region.getMaximumPoint().getBlockZ();
    13.  
    14. for(;xMin < xMax; xMin++)
    15. {
    16. for(;yMin < yMax; yMin++)
    17. {
    18. for(;zMin < zMax; zMin++)
    19. {
    20. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    21. p.sendMessage("HELLO");
    22.  
    23. if(loc.getState().equals(Material.WALL_SIGN) || loc.getState().equals(Material.SIGN_POST) || loc.getState().equals(Material.SIGN))
    24. {
    25.  
    26. Sign sc = (Sign) loc.getState();
    27. if(sc.getLine(1).startsWith("Besitzer:"))
    28. {
    29. sc.setLine(0, "§3[Kaufen]");
    30. sc.setLine(1, "");
    31. sc.setLine(2, "");
    32. sc.setLine(3, "");
    33. }
    34. }
    35. }
    36. }
    37. }
    38. }


    now i done this and it worked only 15 times i get the Message HELLO hmm. if i do this there:
    Code:java
    1. [syntax=java] private void removeSign(String regionID, WorldGuardPlugin wg, Player p)
    2.  
    3. {
    4.  
    5. ProtectedRegion region = wg.getRegionManager(p.getWorld()).getRegion(regionID);
    6.  
    7. //World world = p.getWorld();
    8.  
    9. int xMin = region.getMinimumPoint().getBlockX();
    10.  
    11. int yMin = region.getMinimumPoint().getBlockY();
    12.  
    13. int zMin = region.getMinimumPoint().getBlockZ();
    14.  
    15.  
    16.  
    17. int xMax = region.getMaximumPoint().getBlockX();
    18.  
    19. int yMax = region.getMaximumPoint().getBlockY();
    20.  
    21. int zMax = region.getMaximumPoint().getBlockZ();
    22.  
    23.  
    24.  
    25. for(;xMin < xMax; xMin++)
    26.  
    27. {
    28.  
    29. for(;yMin < yMax; yMin++)
    30.  
    31. {
    32.  
    33. for(;zMin < zMax; zMin++)
    34.  
    35. {
    36.  
    37. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    38.  
    39.  
    40.  
    41.  
    42.  
    43. if(loc.getState().equals(Material.WALL_SIGN) || loc.getState().equals(Material.SIGN_POST) || loc.getState().equals(Material.SIGN))
    44.  
    45. {
    46.  
    47. p.sendMessage("HELLO");
    48.  
    49. Sign sc = (Sign) loc.getState();
    50.  
    51. if(sc.getLine(1).startsWith("Besitzer:"))
    52.  
    53. {
    54.  
    55. sc.setLine(0, "§3[Kaufen]");
    56.  
    57. sc.setLine(1, "");
    58.  
    59. sc.setLine(2, "");
    60.  
    61. sc.setLine(3, "");
    62.  
    63. }
    64.  
    65. }
    66.  
    67. }
    68.  
    69. }
    70.  
    71. }
    72.  
    73. }[/syntax]
    74.  
    75. Nothing Happends
    76.  
    77. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  14. Offline

    !Phoenix!

    Print all min and max coordinates.

    Instead of for(;xMin < xMax; xMin++) go for for(;xMin <= xMax; xMin++).


    Ouch. block.getType().


    - - - - - - - - - - - - - -
    Edit:
    Also notice that if(sc.getLine(1).startsWith("Besitzer:")) refers to line number 2.
     
  15. Offline

    zaza97

    Ty i check it.

    Also notice that if(sc.getLine(1).startsWith("Besitzer:")) refers to line number 2 = Yeah i know in line(0) it starts with("§3[Verkauft])


    OK i try it and on the console:

    Code:
    INFO]: x 80y 0z 288
    INFO]: x 80y 0z 289
    INFO]: x 80y 0z 290
    INFO]: x 80y 0z 291
    INFO]: x 80y 0z 292
    INFO]: x 80y 0z 293
    INFO]: x 80y 0z 294
    INFO]: x 80y 0z 295
    INFO]: x 80y 0z 296
    INFO]: x 80y 0z 297
    INFO]: x 80y 0z 298
    INFO]: x 80y 0z 299
    INFO]: x 80y 0z 300
    INFO]: x 80y 0z 301
    INFO]: x 80y 0z 302
    i place it at:
    Code:java
    1. for(;xMin < xMax; xMin++)
    2. {
    3. for(;yMin < yMax; yMin++)
    4. {
    5. for(;zMin < zMax; zMin++)
    6. {
    7. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    8.  
    9. System.out.println("x " + xMin + "y " + yMin + "z " + zMin);
    10.  
    11. if(loc.getType().equals(Material.WALL_SIGN) || loc.getType().equals(Material.SIGN_POST) || loc.getType().equals(Material.SIGN))
    12. {
    13. p.sendMessage("HELLO");
    14. Sign sc = (Sign) loc.getState();
    15. if(sc.getLine(1).startsWith("Besitzer:"))
    16. {
    17. sc.setLine(0, "§3[Kaufen]");
    18. sc.setLine(1, "");
    19. sc.setLine(2, "");
    20. sc.setLine(3, "");
    21. }
    22. }
    23. }
    24. }
    25. }


    So the for() dosen't works how they should.

    Better Format:
    Code:
    [11:51:17 INFO]: x = 80 y = 0 z = 288
    [11:51:17 INFO]: x = 80 y = 0 z = 289
    [11:51:17 INFO]: x = 80 y = 0 z = 290
    [11:51:17 INFO]: x = 80 y = 0 z = 291
    [11:51:17 INFO]: x = 80 y = 0 z = 292
    [11:51:17 INFO]: x = 80 y = 0 z = 293
    [11:51:17 INFO]: x = 80 y = 0 z = 294
    [11:51:17 INFO]: x = 80 y = 0 z = 295
    [11:51:17 INFO]: x = 80 y = 0 z = 296
    [11:51:17 INFO]: x = 80 y = 0 z = 297
    [11:51:17 INFO]: x = 80 y = 0 z = 298
    [11:51:17 INFO]: x = 80 y = 0 z = 299
    [11:51:17 INFO]: x = 80 y = 0 z = 300
    [11:51:17 INFO]: x = 80 y = 0 z = 301
    [11:51:17 INFO]: x = 80 y = 0 z = 302
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  16. Offline

    TGRHavoc

    zaza97
    Try replacing all the start ";" with the variable declaration E.g.:
    Code:
    for(double xMin=region.getMinimunPoint().getBlockX();xMin < xMax; xMin++)
     
  17. Offline

    !Phoenix!

    Why do you think so? It is looking fine to me. Z is increasing.

    Do it like this:

    Code:java
    1.  
    2. int xMin = region.getMinimumPoint().getBlockX();
    3. int yMin = region.getMinimumPoint().getBlockY();
    4. int zMin = region.getMinimumPoint().getBlockZ();
    5.  
    6. int xMax = region.getMaximumPoint().getBlockX();
    7. int yMax = region.getMaximumPoint().getBlockY();
    8. int zMax = region.getMaximumPoint().getBlockZ();
    9.  
    10. System.out.println("xMin: " + xMin);
    11. System.out.println("yMin: " + yMin);
    12. // ...
    13. // TODO
    14.  
    15. // [...]
    16.  
    17. if (isSign) {
    18. // PRINT second line (index 1)
    19.  
    20. if(sc.getLine(1).startsWith("Besitzer:")) {
    21. // ...
    22. }
    23.  



    - - - - - - - - - - - - -
    Edit: Nobody really cares about the format you use to print. If you change it please just edit your previous post and, in general, try to avoid quoting a whole post. If you need to quote something then only quote the relevant part.
     
  18. Offline

    zaza97

    Its the same, but i check it and no it doesn't work :confused:.





    Just this write the Console at point:
    INFO]: x = 80 y = 0 z = 288

    Code:java
    1. private void removeSign(String regionID, WorldGuardPlugin wg, Player p)
    2. {
    3. ProtectedRegion region = wg.getRegionManager(p.getWorld()).getRegion(regionID);
    4. //World world = p.getWorld();
    5. int xMin = region.getMinimumPoint().getBlockX();
    6. int yMin = region.getMinimumPoint().getBlockY();
    7. int zMin = region.getMinimumPoint().getBlockZ();
    8.  
    9. int xMax = region.getMaximumPoint().getBlockX();
    10. int yMax = region.getMaximumPoint().getBlockY();
    11. int zMax = region.getMaximumPoint().getBlockZ();
    12.  
    13. System.out.println("x = " + xMin + " y = " + yMin + " z = " + zMin); // here is the console output you want
    14.  
    15. for(;xMin < xMax; xMin++)
    16. {
    17. for(;yMin < yMax; yMin++)
    18. {
    19. for(;zMin < zMax; zMin++)
    20. {
    21. Block loc= (Block) new Location(p.getWorld(), xMin, yMin, zMin).getBlock();
    22.  
    23. if(loc.getType().equals(Material.WALL_SIGN) || loc.getType().equals(Material.SIGN_POST) || loc.getType().equals(Material.SIGN))
    24. {
    25. p.sendMessage("HELLO"); // dont write to me
    26. Sign sc = (Sign) loc.getState();
    27. System.out.println(sc.getLine(1)); // dont print too
    28. if(sc.getLine(1).startsWith("Besitzer:"))
    29. {
    30. sc.setLine(0, "§3[Kaufen]");
    31. sc.setLine(1, "");
    32. sc.setLine(2, "");
    33. sc.setLine(3, "");
    34. }
    35. }
    36. }
    37. }
    38. }
    39. }
    40. }


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

    !Phoenix!

    NEVER QUOTE AN ENTIRE POST!!!

    Why? Is there a sign supposed to be at this location? This statement does not help.

    Please try what I have suggested in my last post.

    Have to go now, will be unavailable for help the next 10h.
     
  20. Offline

    zaza97

    Can someone else help me? pls

    I want to get a Sign in a region i need 3 For()'s :D
     
  21. Offline

    TGRHavoc

     
    !Phoenix! likes this.
  22. Offline

    zaza97

    done solved!
     
  23. Offline

    !Phoenix!

    Good to hear. It would be very interesting for us to know how you did that ;)
     
Thread Status:
Not open for further replies.

Share This Page