mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-21 18:15:17 +01:00
feat: make sure old data is not lost!
Now, I was thinking if there is a way to directly convert it but there isn't because of the way it was structured. This *ISN'T* the best way around things but if someone can find a better way around it, be my guest.
This commit is contained in:
parent
0a343219bc
commit
64f8a4899a
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
@ -16,8 +17,12 @@ public class WarpsData implements DataObject {
|
||||
|
||||
@Expose
|
||||
private String uniqueId = "warps";
|
||||
|
||||
@Deprecated @Expose
|
||||
private Map<Location, UUID> warpSigns = new HashMap<>();
|
||||
|
||||
@Expose
|
||||
private Map<PlayerWarp, UUID> warpSigns = new HashMap<>();
|
||||
private Map<PlayerWarp, UUID> newWarpSigns = new HashMap<>();
|
||||
|
||||
public WarpsData() {
|
||||
// Required by YAML database
|
||||
@ -34,13 +39,28 @@ public class WarpsData implements DataObject {
|
||||
}
|
||||
|
||||
public Map<PlayerWarp, UUID> getWarpSigns() {
|
||||
if (warpSigns == null)
|
||||
convertOldWarpSigns();
|
||||
if (newWarpSigns == null)
|
||||
return new HashMap<>();
|
||||
return warpSigns;
|
||||
return newWarpSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for converting old warp signs to new warp signs
|
||||
*/
|
||||
public void convertOldWarpSigns() {
|
||||
if (warpSigns == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<Location, UUID> entry : warpSigns.entrySet()) {
|
||||
PlayerWarp playerWarp = new PlayerWarp(entry.getKey(), true);
|
||||
newWarpSigns.put(playerWarp, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void setWarpSigns(Map<PlayerWarp, UUID> warpSigns) {
|
||||
this.warpSigns = warpSigns;
|
||||
this.newWarpSigns = warpSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +70,7 @@ public class WarpsData implements DataObject {
|
||||
*/
|
||||
public WarpsData save(Map<World, Map<UUID, PlayerWarp>> worldsWarpList) {
|
||||
getWarpSigns().clear();
|
||||
worldsWarpList.values().forEach(world -> world.forEach((uuid,playerWarp) -> warpSigns.put(playerWarp, uuid)));
|
||||
worldsWarpList.values().forEach(world -> world.forEach((uuid,playerWarp) -> newWarpSigns.put(playerWarp, uuid)));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user