Moved back to GSON, makes jar smaller.

This commit is contained in:
stijnb1234 2020-02-25 13:14:49 +01:00
parent 7d1ae3b5f9
commit 3907de1610
4 changed files with 13 additions and 44 deletions

17
pom.xml
View file

@ -177,23 +177,6 @@
<scope>compile</scope>
</dependency>
<!-- Jackson, used for Object to JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.1</version>
</dependency>
<!-- BStats, used for metrics -->
<dependency>
<groupId>org.bstats</groupId>

View file

@ -1,6 +1,5 @@
package nl.SBDeveloper.V10Lift.Commands;
import com.fasterxml.jackson.core.JsonProcessingException;
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
@ -22,7 +21,6 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
@ -357,7 +355,7 @@ public class V10LiftCommand implements CommandExecutor {
try {
V10LiftPlugin.getDBManager().save();
V10LiftPlugin.getDBManager().load();
} catch (SQLException | IOException e) {
} catch (SQLException e) {
e.printStackTrace();
}
@ -917,11 +915,7 @@ public class V10LiftCommand implements CommandExecutor {
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
DataManager.removeDoorEditPlayer(p.getUniqueId());
try {
V10LiftPlugin.getDBManager().save();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
V10LiftPlugin.getDBManager().save();
BlockState bs;
Sign sign;
@ -1087,7 +1081,7 @@ public class V10LiftCommand implements CommandExecutor {
sender.sendMessage("§6/v10lift speed <New speed>§f: Change the speed of a lift.");
sender.sendMessage("§6/v10lift realistic§f: Toggle realistic mode.");
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");
sender.sendMessage("§6/v10lift whitelist <add/del> <Player> [Floorname]§f: Add/remove someone of the whitelist.");
sender.sendMessage("§6/v10lift whitelist <add/del> <Player/Group> [Floorname]§f: Add/remove someone of the whitelist. Use g:<Groupname> for a group.");
sender.sendMessage("§6/v10lift start [Name] [Floor]§f: Start a lift to a floor.");
sender.sendMessage("§6/v10lift stop [Name]§f: Stop a lift.");
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");

View file

@ -1,12 +1,10 @@
package nl.SBDeveloper.V10Lift.Managers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -32,7 +30,7 @@ public class DBManager {
}
}
public void load() throws SQLException, IOException {
public void load() throws SQLException {
String query = "SELECT * FROM lifts";
PreparedStatement statement = con.prepareStatement(query);
ResultSet liftSet = statement.executeQuery();
@ -48,8 +46,9 @@ public class DBManager {
byte[] blob = liftSet.getBytes("liftData");
String json = new String(blob);
ObjectMapper mapper = new ObjectMapper();
Lift lift = mapper.readValue(json, Lift.class);
Gson gson = new Gson();
Lift lift = gson.fromJson(json, Lift.class);
DataManager.addLift(liftSet.getString("liftName"), lift);
Bukkit.getLogger().info("[V10Lift] Loading lift " + liftSet.getString("liftName") + " from data...");
@ -91,12 +90,11 @@ public class DBManager {
}
}
public void save() throws JsonProcessingException {
public void save() {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
ObjectMapper mapper = new ObjectMapper();
byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes();
Gson gson = new Gson();
byte[] blob = gson.toJson(entry.getValue()).getBytes();
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");

View file

@ -1,6 +1,5 @@
package nl.SBDeveloper.V10Lift;
import com.fasterxml.jackson.core.JsonProcessingException;
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
import nl.SBDeveloper.V10Lift.Commands.V10LiftTabCompleter;
@ -18,7 +17,6 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Objects;
@ -45,7 +43,7 @@ public class V10LiftPlugin extends JavaPlugin {
dbManager = new DBManager("data");
try {
dbManager.load();
} catch (SQLException | IOException e) {
} catch (SQLException e) {
e.printStackTrace();
}
@ -92,11 +90,7 @@ public class V10LiftPlugin extends JavaPlugin {
public void onDisable() {
V10LiftPlugin.getDBManager().removeFromData();
try {
dbManager.save();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
dbManager.save();
dbManager.closeConnection();
instance = null;