Moved back to GSON, makes jar smaller.
This commit is contained in:
parent
7d1ae3b5f9
commit
3907de1610
4 changed files with 13 additions and 44 deletions
17
pom.xml
17
pom.xml
|
@ -177,23 +177,6 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</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 -->
|
<!-- BStats, used for metrics -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package nl.SBDeveloper.V10Lift.Commands;
|
package nl.SBDeveloper.V10Lift.Commands;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
||||||
|
@ -22,7 +21,6 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -357,7 +355,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
try {
|
try {
|
||||||
V10LiftPlugin.getDBManager().save();
|
V10LiftPlugin.getDBManager().save();
|
||||||
V10LiftPlugin.getDBManager().load();
|
V10LiftPlugin.getDBManager().load();
|
||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,11 +915,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
DataManager.removeRopeRemovesPlayer(p.getUniqueId());
|
||||||
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
DataManager.removeDoorEditPlayer(p.getUniqueId());
|
||||||
|
|
||||||
try {
|
V10LiftPlugin.getDBManager().save();
|
||||||
V10LiftPlugin.getDBManager().save();
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockState bs;
|
BlockState bs;
|
||||||
Sign sign;
|
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 speed <New speed>§f: Change the speed of a lift.");
|
||||||
sender.sendMessage("§6/v10lift realistic§f: Toggle realistic mode.");
|
sender.sendMessage("§6/v10lift realistic§f: Toggle realistic mode.");
|
||||||
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");
|
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 start [Name] [Floor]§f: Start a lift to a floor.");
|
||||||
sender.sendMessage("§6/v10lift stop [Name]§f: Stop a lift.");
|
sender.sendMessage("§6/v10lift stop [Name]§f: Stop a lift.");
|
||||||
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");
|
sender.sendMessage("§6/v10lift repair§f: Repair a lift.");
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package nl.SBDeveloper.V10Lift.Managers;
|
package nl.SBDeveloper.V10Lift.Managers;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.google.gson.Gson;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
import nl.SBDeveloper.V10Lift.API.Objects.Lift;
|
||||||
import nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
|
import nl.SBDevelopment.SBUtilities.Data.SQLiteDB;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
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";
|
String query = "SELECT * FROM lifts";
|
||||||
PreparedStatement statement = con.prepareStatement(query);
|
PreparedStatement statement = con.prepareStatement(query);
|
||||||
ResultSet liftSet = statement.executeQuery();
|
ResultSet liftSet = statement.executeQuery();
|
||||||
|
@ -48,8 +46,9 @@ public class DBManager {
|
||||||
|
|
||||||
byte[] blob = liftSet.getBytes("liftData");
|
byte[] blob = liftSet.getBytes("liftData");
|
||||||
String json = new String(blob);
|
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);
|
DataManager.addLift(liftSet.getString("liftName"), lift);
|
||||||
|
|
||||||
Bukkit.getLogger().info("[V10Lift] Loading lift " + liftSet.getString("liftName") + " from data...");
|
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()) {
|
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
Gson gson = new Gson();
|
||||||
|
byte[] blob = gson.toJson(entry.getValue()).getBytes();
|
||||||
byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes();
|
|
||||||
|
|
||||||
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
|
Bukkit.getLogger().info("[V10Lift] Saving lift " + entry.getKey() + " to data...");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package nl.SBDeveloper.V10Lift;
|
package nl.SBDeveloper.V10Lift;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
|
import nl.SBDeveloper.V10Lift.API.V10LiftAPI;
|
||||||
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
|
import nl.SBDeveloper.V10Lift.Commands.V10LiftCommand;
|
||||||
import nl.SBDeveloper.V10Lift.Commands.V10LiftTabCompleter;
|
import nl.SBDeveloper.V10Lift.Commands.V10LiftTabCompleter;
|
||||||
|
@ -18,7 +17,6 @@ import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
dbManager = new DBManager("data");
|
dbManager = new DBManager("data");
|
||||||
try {
|
try {
|
||||||
dbManager.load();
|
dbManager.load();
|
||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,11 +90,7 @@ public class V10LiftPlugin extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
V10LiftPlugin.getDBManager().removeFromData();
|
V10LiftPlugin.getDBManager().removeFromData();
|
||||||
|
|
||||||
try {
|
dbManager.save();
|
||||||
dbManager.save();
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
dbManager.closeConnection();
|
dbManager.closeConnection();
|
||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
|
|
Loading…
Reference in a new issue