Fixed saving issues

This commit is contained in:
stijnb1234 2020-02-08 10:59:57 +01:00
parent 79f37ee2bc
commit 27bf53aaad
8 changed files with 58 additions and 31 deletions

16
pom.xml
View file

@ -14,7 +14,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<jackson.version>2.10.0</jackson.version>
</properties> </properties>
<build> <build>
@ -53,6 +52,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -105,7 +112,12 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version> <version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.10.2</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -1,6 +1,7 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -8,12 +9,12 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
@Getter @Setter @Getter @Setter @NoArgsConstructor
public class Floor { public class Floor {
private final String world; private String world;
private final int y; private int y;
private final ArrayList<LiftBlock> doorBlocks = new ArrayList<>(); private ArrayList<LiftBlock> doorBlocks = new ArrayList<>();
private final HashSet<UUID> whitelist = new HashSet<>(); private HashSet<UUID> whitelist = new HashSet<>();
public Floor(int y, String world) { public Floor(int y, String world) {
this.y = y; this.y = y;

View file

@ -1,16 +1,18 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser; import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
@NoArgsConstructor
public class Lift { public class Lift {
@Getter @Setter private String worldName; @Getter @Setter private String worldName;
@Getter @Setter private int y; @Getter @Setter private int y;
@Getter private final HashSet<UUID> owners; @Getter private HashSet<UUID> owners;
//@Getter @Setter private ArrayList<String> whitelist; //@Getter @Setter private ArrayList<String> whitelist;
@Getter private final TreeSet<LiftBlock> blocks = new TreeSet<>(); @Getter private final TreeSet<LiftBlock> blocks = new TreeSet<>();
@Getter private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>(); @Getter private final LinkedHashMap<String, Floor> floors = new LinkedHashMap<>();

View file

@ -1,6 +1,7 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -9,22 +10,23 @@ import javax.annotation.Nonnull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
@NoArgsConstructor
public class LiftBlock implements Comparable<LiftBlock> { public class LiftBlock implements Comparable<LiftBlock> {
@Getter @Setter private String world; @Getter @Setter private String world;
@Getter private final int x; @Getter private int x;
@Getter @Setter private int y; @Getter @Setter private int y;
@Getter private final int z; @Getter private int z;
//Only used for cabine blocks, because those need caching! //Only used for cabine blocks, because those need caching!
@Getter private final Material mat; @Getter private Material mat;
@Getter private final byte data; @Getter private byte data;
@Getter private final BlockFace face; @Getter private BlockFace face;
@Getter private final String bisected; @Getter private String bisected;
@Getter private final String[] signLines; @Getter private String[] signLines;
//Only used for inputs! //Only used for inputs!
@Getter private final String floor; @Getter private String floor;
@Getter @Setter private boolean active = false; @Getter @Setter private boolean active = false;
//Only used for chests //Only used for chests

View file

@ -1,21 +1,22 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@Getter @Setter @Getter @Setter @NoArgsConstructor
public class LiftRope { public class LiftRope {
private final Material type; private Material type;
private final BlockFace face; private BlockFace face;
private final String world; private String world;
private final int x; private int x;
private final int minY; private int minY;
private final int maxY; private int maxY;
private final int z; private int z;
private int currently; private int currently;
public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) { public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) {

View file

@ -1,18 +1,19 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@Getter @Setter @Getter @Setter @NoArgsConstructor
public class LiftSign { public class LiftSign {
private String world; private String world;
private int x; private int x;
private int z; private int z;
private int y; private int y;
private String oldText = null; private String oldText = null;
private final byte type; private byte type;
private byte state; private byte state;
public LiftSign(String world, int x, int y, int z, byte type, byte state) { public LiftSign(String world, int x, int y, int z, byte type, byte state) {

View file

@ -1,6 +1,7 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -9,14 +10,14 @@ import org.bukkit.entity.Entity;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.UUID; import java.util.UUID;
@Getter @Getter @NoArgsConstructor
public class V10Entity { public class V10Entity {
private final UUID entityUUID; private UUID entityUUID;
private String world; private String world;
private int locX; private int locX;
private int locY; private int locY;
private int locZ; private int locZ;
private final int y; private int y;
@Setter private short step; @Setter private short step;
public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) { public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) {

View file

@ -1,7 +1,10 @@
package nl.SBDeveloper.V10Lift.Managers; package nl.SBDeveloper.V10Lift.Managers;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
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;
@ -47,7 +50,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(); ObjectMapper mapper = new ObjectMapper()
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
Lift lift = mapper.readValue(json, Lift.class); Lift lift = mapper.readValue(json, Lift.class);
DataManager.addLift(liftSet.getString("liftName"), lift); DataManager.addLift(liftSet.getString("liftName"), lift);
@ -93,7 +98,9 @@ public class DBManager {
public void save() throws JsonProcessingException { public void save() throws JsonProcessingException {
for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) { for (Map.Entry<String, Lift> entry : DataManager.getLifts().entrySet()) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper()
.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes(); byte[] blob = mapper.writeValueAsString(entry.getValue()).getBytes();