Map organization

Discussion in 'Plugin Development' started by Chew, Jun 29, 2014.

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

    Chew

    I have a plugin that I'm working on, in which I am allowing players to create they're own zones, I'm confused on how I would organize the HashMaps and whatnot in which order etc. I plan to save the maps to a binary dump. It would be splendid if someone could point out what maps and lists I need to use.

    Here is how I would do it in a config file.
    Code:
    Zones:
      1:
        Nick: Home
        Startlocation: Location1
        Endlocation: Location2
        Owner: 7abfc826-af20-4c79-b725-e0d96344cc6e
        Allowed: Example_UUID, anotherexampleUUID
        Date:
          join: 1403844720
        Type: 0
        Pvp:false
        Doors:true
        noTP:false
        Teleport: Location3
      2:
        Nick: Home
        Startlocation: Location1
        Endlocation: Location2
        Owner: 7abfc826-af20-4c79-b725-e0d96344cc6e
        Allowed: Example_UUID, anotherexampleUUID
        Date:
          join: 1403844720
        Type: 0
        Pvp:false
        Doors:true
        noTP:false
        Teleport: Location3
    
     
  2. Offline

    monster860

    I don't know. What have you attempted so far? I would personally define a class to represent a zone, including world names, coordinates, owner, and other stuff. Then, have a HashMap<String,HashSet<zone>> where "zone" is the name of the class for the zone, that has all the zone. String is for world name. Then, have seperate files for each world. That's pretty much what I would do here.
     
  3. Offline

    Chew

    monster860 Sorry if this has been a couple days, but so instead I decided that I'm going to do Configuration Serialization,
    anyway say I have my zone creation command (it's not finished). If you could tell me the method for putting and getting data from the class that would be helpful (or give me link to documentation) that would be extremely helpful. -this isn't concerning the configuration serialization.
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("zone")) {
    2. Player p = (Player) sender;
    3. UUID uuid = p.getUniqueId();
    4. Location l1 = S1.get(uuid);
    5. Location l2 = S2.get(uuid);
    6. if (sender.hasPermission("relocatedgaming.help")) {
    7. if (args.length >= 1) {
    8. if (args[0].equalsIgnoreCase("new")) {
    9. if (l1 != null) {
    10. if (l2 != null) {
    11. Location start = getMin(l1,l2);
    12. Location end = getMax(l1,l2);
    13. String world = end.getWorld().getName();
    14. int startX = start.getBlockX();
    15. int startY = start.getBlockY();
    16. int startZ = start.getBlockZ();
    17. int endX = end.getBlockX();
    18. int endY = end.getBlockY();
    19. int endZ = end.getBlockZ();
    20. int newX = endX - startX + 1;
    21. int newZ = endZ - startZ + 1;
    22. int merp = newX * newZ *5;
    23. if (Money.hasEnough(p, merp)) {
    24. Money.takeMoney(p, merp);
    25. sender.sendMessage("New " + newX + " x " + newZ + " Zone Created. -" + merp + " coins.");
    26. Zone zerp = new Zone();
    27. zerp.setOwner(p.getUniqueId());
    28. zerp.setId(zerp.getId()+1); //or get all the zones and add then + 1
    29. zerp.setName("(None)");
    30. zerp.setWorld(world);
    31. zerp.setX1(startX);
    32. zerp.setY1(startY);
    33. zerp.setZ1(startZ);
    34. zerp.setX2(endX);
    35. zerp.setY2(endY);
    36. zerp.setZ2(endZ);
    37. zerp.setPvp(false);
    38. zerp.setMobs(false);
    39. zerp.setDoors(false);
    40.  
    41. return true;
    42. } else {
    43. p.sendMessage("This zone costs " + merp + "coins. You do not have enough.");
    44. }
    45. } else {
    46. p.sendMessage("No area selected1.");
    47. }
    48. } else {
    49. p.sendMessage("No area selected2.");
    50. }
    51. }
    52. if (args[0].equalsIgnoreCase("info")) {
    53. Zone zerp = new Zone();
    54. String name = zerp.getName();
    55. p.sendMessage(name);
    56. }
    57. } else {
    58. p.sendMessage("help");
    59. }
    60. }
    61. }

    Then my class Zone.
    Code:java
    1. package com.relocatedgaming;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.UUID;
    5.  
    6. public class Zone {
    7.  
    8. private int id;
    9.  
    10. private String name;
    11.  
    12. private int x1;
    13. private int y1;
    14. private int z1;
    15.  
    16. private int x2;
    17. private int y2;
    18. private int z2;
    19.  
    20. private int price;
    21.  
    22. private String world;
    23.  
    24. private boolean pvp;
    25. private boolean doors;
    26. private boolean noTP;
    27. private boolean mobs;
    28.  
    29. private UUID owner;
    30.  
    31. private ArrayList<String> allowedList = new ArrayList<String>();
    32.  
    33. public UUID getOwner() {
    34. return owner;
    35. }
    36.  
    37. public void setOwner(UUID owner) {
    38. this.owner = owner;
    39. }
    40.  
    41. public int getId() {
    42. return id;
    43. }
    44.  
    45. public void setId(int id) {
    46. this.id = id;
    47. }
    48.  
    49. public int getPrice() {
    50. return price;
    51. }
    52.  
    53. public void setPrice(int price) {
    54. this.price = price;
    55. }
    56.  
    57. public String getName() {
    58. return name;
    59. }
    60.  
    61. public void setName(String name) {
    62. this.name = name;
    63. }
    64.  
    65. public int getX1() {
    66. return x1;
    67. }
    68.  
    69. public void setX1(int x1) {
    70. this.x1 = x1;
    71. }
    72.  
    73. public int getY1() {
    74. return y1;
    75. }
    76.  
    77. public void setY1(int y1) {
    78. this.y1 = y1;
    79. }
    80.  
    81. public int getZ1() {
    82. return z1;
    83. }
    84.  
    85. public void setZ1(int z1) {
    86. this.z1 = z1;
    87. }
    88.  
    89. public int getX2() {
    90. return x2;
    91. }
    92.  
    93. public void setX2(int x2) {
    94. this.x2 = x2;
    95. }
    96.  
    97. public int getY2() {
    98. return y2;
    99. }
    100.  
    101. public void setY2(int y2) {
    102. this.y2 = y2;
    103. }
    104.  
    105. public int getZ2() {
    106. return z2;
    107. }
    108.  
    109. public void setZ2(int z2) {
    110. this.z2 = z2;
    111. }
    112.  
    113. public String getWorld() {
    114. return world;
    115. }
    116.  
    117. public void setWorld(String world) {
    118. this.world = world;
    119. }
    120.  
    121. public boolean isPvp() {
    122. return pvp;
    123. }
    124.  
    125. public void setPvp(boolean pvp) {
    126. this.pvp = pvp;
    127. }
    128.  
    129. public boolean isMobs() {
    130. return mobs;
    131. }
    132.  
    133. public void setMobs(boolean mobs) {
    134. this.mobs = mobs;
    135. }
    136. public boolean isDoors() {
    137. return doors;
    138. }
    139.  
    140. public void setDoors(boolean doors) {
    141. this.doors = doors;
    142. }
    143. public boolean isnoTP() {
    144. return noTP;
    145. }
    146.  
    147. public void setnoTP(boolean noTP) {
    148. this.noTP = noTP;
    149. }
    150. }
    151.  


    If anyone else could tell me as well that would be nice.

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

    xTigerRebornx

  5. Offline

    Chew

    xTigerRebornx Thanks but I knew how to do the serialization for it, I just need help putting/getting the class info- before reboots.
     
  6. Offline

    xTigerRebornx

    Chew I am confused as to what you need help with?
    Once you have properly implemented ConfigurationSerializable, you can simply use any FileConfiguration's set/get method to store it.
     
  7. Offline

    Chew

    xTigerRebornx I'm not talking about Serialization here. I'm talking purely about sending data from one class to another, then getting that data from that class again. NOT storing data.
     
  8. Offline

    xTigerRebornx

    Chew Not sure if I am following you correctly, but here is what I got from what you said.
    You want to send data from class A to class B, let class B handle that data, then send it back to class A?
     
  9. Offline

    Chew

    xTigerRebornx Essentially yes, all the zone data. like Lines 26-39 sending all the selection data to the class Zone, ~I'm not even sure if I'm doing it correctly, but anyway eventually I need to make a /zone info cmd to iterate though all the Zones to find out which one the player is in. This requires to get the data from the Zone class, to get the coords etc.
     
  10. Offline

    xTigerRebornx

    Chew Ah, I see. Look into making another class that follows a Manager-like design, where it manages all instances of the Zone class and will save/load those instances when your plugin is enabled/disabled.
    General concept is something where it has a List/Set that stores your Zone instances, and some ease-of-access methods. Also, look into the Singleton design pattern, following something like that in order to keep one instance of this manager may be useful.
     
  11. Offline

    Chew

    xTigerRebornx So say I make my public static HashSet<Zone> zones; in my main class, what two methods would I use to put the data into the class, then to get all the Zone instances from the HashSet?
     
Thread Status:
Not open for further replies.

Share This Page