Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Map<UUID, String> playerColor = new HashMap<UUID, String>();
- private static Map<UUID, String> playerTag = new HashMap<UUID, String>();
- private final static File storageDirectory = new File(DynamicGui.get().getPlugin().getDataFolder() + File.separator + "storage");
- private static void initDir() {
- if(!storageDirectory.exists() || storageDirectory == null) {
- storageDirectory.mkdirs();
- }
- }
- public void deSerializeMap(String fileName, Map<?, ?> map) {
- initDir();
- try {
- File file = new File(storageDirectory, fileName);
- if(!file.exists() || file == null) {
- return;
- }
- FileInputStream stream = new FileInputStream(file);
- ObjectInputStream object = new ObjectInputStream(stream);
- /*
- * Basically, the map saves to the file. It gets loaded here.
- * It does register here as map, but will not replace the map
- * specified.
- *
- * Ex:
- * MapSerializer.get().deSerializeMap("color.txt", MapSerializer.get().getColorMap());
- * When getColorMap() is called, it will not give the outputs
- * defined below.
- */
- map = (Map<?, ?>) object.readObject());
- object.close();
- stream.close();
- Bukkit.getLogger().info("Loading data from: " + file.getPath());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void serializerMap(String fileName, Map<?, ?> map) {
- initDir();
- try {
- File file = new File(storageDirectory, fileName);
- if(!file.exists() || file == null) {
- file.createNewFile();
- }
- FileOutputStream stream = new FileOutputStream(file);
- ObjectOutputStream object = new ObjectOutputStream(stream);
- object.writeObject(map);
- object.close();
- stream.close();
- Bukkit.getLogger().info("Saving data to: " + file.getPath());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public Map<UUID, String> getColorMap() {
- return playerColor;
- }
- public Map<UUID, String> getTagMap() {
- return playerTag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement