Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

Commit

Permalink
💎 Added Waypoint Saving.
Browse files Browse the repository at this point in the history
🐛 Fixed Notification Alignment.
🐛 Fixed Mods from saving.
  • Loading branch information
Hexeption committed Apr 24, 2017
1 parent 81f0e22 commit 9e00108
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void execute(String input, String[] args) throws Exception {
if (args[0].equalsIgnoreCase("clear")) {
DarkForge.INSTANCE.addNotification(Notification.Type.INFO, "Waypoint", "Waypoints Cleared", 5000);
DarkForge.INSTANCE.waypointManager.getWaypoints().clear();
DarkForge.INSTANCE.fileManager.saveWaypoints();
}
}
}
Expand Down
71 changes: 67 additions & 4 deletions src/main/java/uk/co/hexeption/darkforge/managers/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import uk.co.hexeption.darkforge.value.DoubleValue;
import uk.co.hexeption.darkforge.value.FloatValue;
import uk.co.hexeption.darkforge.value.Value;
import uk.co.hexeption.darkforge.waypoint.Waypoint;

import javax.vecmath.Vector3d;
import java.io.*;
import java.util.Map;

Expand All @@ -44,18 +46,20 @@ public class FileManager {

public final File DARKFORGE_DIR = new File(String.format("%s%sdarkforge%s", Minecraft.getMinecraft().mcDataDir, File.separator, File.separator));

private final File MODULE = new File(DARKFORGE_DIR, "mods.json");
private final File MODS = new File(DARKFORGE_DIR, "mods.json");

private final File ALTS = new File(DARKFORGE_DIR, "alts.json");

private final File FRIENDS = new File(DARKFORGE_DIR, "friends.json");

private final File WAYPOINTS = new File(DARKFORGE_DIR, "waypoints.json");

public void Initialization() {

if (!DARKFORGE_DIR.exists())
DARKFORGE_DIR.mkdir();

if (!MODULE.exists())
if (!MODS.exists())
saveModules();
else
loadModules();
Expand All @@ -69,13 +73,19 @@ public void Initialization() {
saveFriends();
else
loadFriends();

if (!WAYPOINTS.exists())
saveWaypoints();
else
loadWaypoints();

}


public void loadModules() {

try {
BufferedReader loadJson = new BufferedReader(new FileReader(MODULE));
BufferedReader loadJson = new BufferedReader(new FileReader(MODS));
JsonObject moduleJason = (JsonObject) jsonParser.parse(loadJson);
loadJson.close();

Expand Down Expand Up @@ -146,7 +156,7 @@ public void saveModules() {
json.add(mod.getName(), jsonModules);
}

PrintWriter saveJson = new PrintWriter(new FileWriter(MODULE));
PrintWriter saveJson = new PrintWriter(new FileWriter(MODS));
saveJson.println(gsonPretty.toJson(json));
saveJson.close();
} catch (IOException e) {
Expand Down Expand Up @@ -241,5 +251,58 @@ public void loadFriends() {
}
}

public void saveWaypoints() {

try {
JsonObject jsonObject = new JsonObject();
for (Waypoint waypoint : DarkForge.INSTANCE.waypointManager.getWaypoints()) {
JsonObject object = new JsonObject();
if (waypoint.server == null)
object.addProperty("server", "localhost");
else
object.addProperty("server", waypoint.server);

object.addProperty("x", waypoint.position.getX());
object.addProperty("y", waypoint.position.getY());
object.addProperty("z", waypoint.position.getZ());
object.addProperty("dimension", waypoint.dimension);
object.addProperty("color", waypoint.color);
jsonObject.add(waypoint.name, object);
}

PrintWriter savedJson = new PrintWriter(new FileWriter(WAYPOINTS));
savedJson.println(gsonPretty.toJson(jsonObject));
savedJson.close();
} catch (Exception e) {
e.printStackTrace();
}

}

public void loadWaypoints() {

try {
BufferedReader loadJson = new BufferedReader(new FileReader(WAYPOINTS));
JsonObject wayPointJson = (JsonObject) jsonParser.parse(loadJson);
DarkForge.INSTANCE.waypointManager.getWaypoints().clear();

for (Map.Entry<String, JsonElement> entry : wayPointJson.entrySet()) {
JsonObject waypoint = entry.getValue().getAsJsonObject();

String name = entry.getKey();
String server = waypoint.get("server").getAsString();
double x = waypoint.get("x").getAsDouble();
double y = waypoint.get("y").getAsDouble();
double z = waypoint.get("z").getAsDouble();
int dimension = waypoint.get("dimension").getAsInt();
int color = waypoint.get("color").getAsInt();
DarkForge.INSTANCE.waypointManager.addWaypoint(new Waypoint(name, new Vector3d(x, y, z), server, dimension, color));
}

} catch (Exception e) {
e.printStackTrace();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/
package uk.co.hexeption.darkforge.managers;

import uk.co.hexeption.darkforge.DarkForge;
import uk.co.hexeption.darkforge.waypoint.Waypoint;

import java.util.ArrayList;
Expand All @@ -33,7 +34,7 @@ public boolean addWaypoint(Waypoint waypoint) {

boolean added = waypoints.add(waypoint);
if (added) {
//TODO: Save
DarkForge.INSTANCE.fileManager.saveWaypoints();
}
return added;

Expand All @@ -43,7 +44,8 @@ public boolean removeWaypoint(Waypoint waypoint) {

boolean removed = waypoints.remove(waypoint);
if (removed) {
//TODO:Save
DarkForge.INSTANCE.fileManager.saveWaypoints();

}

return removed;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/uk/co/hexeption/darkforge/mod/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ public void setState(boolean state) {
onDisable();
}

//TODO: File save

DarkForge.INSTANCE.fileManager.saveModules();

}

public boolean isVisable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void drawNotifications(ScaledResolution scaledResolution) {
break;
}

DarkForge.INSTANCE.fontManager.arraylist.drawStringWithShadow(notification.getMessage(), scaledResolution.getScaledWidth() - DarkForge.INSTANCE.fontManager.arraylist.getStringWidth(notification.getMessage()) - 10, scaledResolution.getScaledHeight() - 20 - ycount, Color.white.hashCode());
DarkForge.INSTANCE.fontManager.arraylist.drawStringWithShadow(notification.getMessage(), scaledResolution.getScaledWidth() - DarkForge.INSTANCE.fontManager.arraylist.getStringWidth(notification.getMessage()) - 10, scaledResolution.getScaledHeight() - 18 - ycount, Color.white.hashCode());
}
ycount += 15;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public Waypoint(String name, Vector3d position, ServerData server, int dimension
setName(name).setPosition(position).setServer(server).setDimension(dimension).setColor(color);
}

public Waypoint(String name, Vector3d position, String server, int dimension, int color) {

setName(name).setPosition(position).setServer(server).setDimension(dimension).setColor(color);
}

public Waypoint(String name, Vector3d position, ServerData server) {

this(name, position, server, mc.player.dimension, GLUtils.getRandomColor().hashCode());
Expand Down

0 comments on commit 9e00108

Please sign in to comment.