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
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.
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 if (cmd.getName().equalsIgnoreCase("zone")) { Player p = (Player) sender; UUID uuid = p.getUniqueId(); Location l1 = S1.get(uuid); Location l2 = S2.get(uuid); if (sender.hasPermission("relocatedgaming.help")) { if (args.length >= 1) { if (args[0].equalsIgnoreCase("new")) { if (l1 != null) { if (l2 != null) { Location start = getMin(l1,l2); Location end = getMax(l1,l2); String world = end.getWorld().getName(); int startX = start.getBlockX(); int startY = start.getBlockY(); int startZ = start.getBlockZ(); int endX = end.getBlockX(); int endY = end.getBlockY(); int endZ = end.getBlockZ(); int newX = endX - startX + 1; int newZ = endZ - startZ + 1; int merp = newX * newZ *5; if (Money.hasEnough(p, merp)) { Money.takeMoney(p, merp); sender.sendMessage("New " + newX + " x " + newZ + " Zone Created. -" + merp + " coins."); Zone zerp = new Zone(); zerp.setOwner(p.getUniqueId()); zerp.setId(zerp.getId()+1); //or get all the zones and add then + 1 zerp.setName("(None)"); zerp.setWorld(world); zerp.setX1(startX); zerp.setY1(startY); zerp.setZ1(startZ); zerp.setX2(endX); zerp.setY2(endY); zerp.setZ2(endZ); zerp.setPvp(false); zerp.setMobs(false); zerp.setDoors(false); return true; } else { p.sendMessage("This zone costs " + merp + "coins. You do not have enough."); } } else { p.sendMessage("No area selected1."); } } else { p.sendMessage("No area selected2."); } } if (args[0].equalsIgnoreCase("info")) { Zone zerp = new Zone(); String name = zerp.getName(); p.sendMessage(name); } } else { p.sendMessage("help"); } } } Then my class Zone. Code:java package com.relocatedgaming; import java.util.ArrayList;import java.util.UUID; public class Zone { private int id; private String name; private int x1; private int y1; private int z1; private int x2; private int y2; private int z2; private int price; private String world; private boolean pvp; private boolean doors; private boolean noTP; private boolean mobs; private UUID owner; private ArrayList<String> allowedList = new ArrayList<String>(); public UUID getOwner() { return owner; } public void setOwner(UUID owner) { this.owner = owner; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getX1() { return x1; } public void setX1(int x1) { this.x1 = x1; } public int getY1() { return y1; } public void setY1(int y1) { this.y1 = y1; } public int getZ1() { return z1; } public void setZ1(int z1) { this.z1 = z1; } public int getX2() { return x2; } public void setX2(int x2) { this.x2 = x2; } public int getY2() { return y2; } public void setY2(int y2) { this.y2 = y2; } public int getZ2() { return z2; } public void setZ2(int z2) { this.z2 = z2; } public String getWorld() { return world; } public void setWorld(String world) { this.world = world; } public boolean isPvp() { return pvp; } public void setPvp(boolean pvp) { this.pvp = pvp; } public boolean isMobs() { return mobs; } public void setMobs(boolean mobs) { this.mobs = mobs; } public boolean isDoors() { return doors; } public void setDoors(boolean doors) { this.doors = doors; } public boolean isnoTP() { return noTP; } public void setnoTP(boolean noTP) { this.noTP = noTP; }} 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.
Chew When implementing ConfigurationSerializable, there are methods that you must have. There is the serialize() method, and there are the various ways of deserializing the Map that serialize() returns. http://forums.bukkit.org/threads/configurationserializable-and-how-to-use-it.271862/ Read through that, it'll help.
xTigerRebornx Thanks but I knew how to do the serialization for it, I just need help putting/getting the class info- before reboots.
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.
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.
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?
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.
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.
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?