Fixed loading boosters on bukkit

This commit is contained in:
Teriuihi 2022-08-07 20:35:25 +02:00
parent c023531e85
commit 5e7897bb50

View File

@ -26,48 +26,56 @@ public class ServerBoosterStorage extends BoosterStorage {
@Override @Override
public Booster loadBooster(JsonParser parser) throws IOException { public Booster loadBooster(JsonParser parser) throws IOException {
JsonToken jsonToken = parser.currentToken(); JsonToken jsonToken = parser.getCurrentToken();
if (!jsonToken.isStructStart()) if (!jsonToken.isStructStart())
return error("Didn't find struct start"); return error("Didn't find struct start");
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"uuid".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"uuid".equals(parser.getCurrentName()))
return error("Didn't find uuid at expected location"); return error("Didn't find uuid at expected location");
parser.nextValue();
UUID uuid = UUID.fromString(parser.getValueAsString()); UUID uuid = UUID.fromString(parser.getValueAsString());
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"activator".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"activator".equals(parser.getCurrentName()))
return error("Didn't find activator at expected location"); return error("Didn't find activator at expected location");
parser.nextValue();
String activator = parser.getValueAsString(); String activator = parser.getValueAsString();
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"type".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"type".equals(parser.getCurrentName()))
return error("Didn't find type at expected location"); return error("Didn't find type at expected location");
parser.nextValue();
BoosterType boosterType = BoosterType.getByName(parser.getValueAsString()); BoosterType boosterType = BoosterType.getByName(parser.getValueAsString());
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"startingTime".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"startingTime".equals(parser.getCurrentName()))
return error("Didn't find startingTime at expected location"); return error("Didn't find startingTime at expected location");
parser.nextValue();
long startingTime = parser.getValueAsLong(); long startingTime = parser.getValueAsLong();
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"duration".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"duration".equals(parser.getCurrentName()))
return error("Didn't find duration at expected location"); return error("Didn't find duration at expected location");
parser.nextValue();
long duration = parser.getValueAsLong(); long duration = parser.getValueAsLong();
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"multiplier".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"multiplier".equals(parser.getCurrentName()))
return error("Didn't find multiplier at expected location"); return error("Didn't find multiplier at expected location");
parser.nextValue();
double multiplier = parser.getValueAsDouble(); double multiplier = parser.getValueAsDouble();
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"active".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"active".equals(parser.getCurrentName()))
return error("Didn't find active at expected location"); return error("Didn't find active at expected location");
parser.nextValue();
boolean active = parser.getValueAsBoolean(); boolean active = parser.getValueAsBoolean();
jsonToken = parser.nextToken(); jsonToken = parser.nextToken();
if (jsonToken != JsonToken.FIELD_NAME || !"finished".equals(parser.getCurrentName())) if (jsonToken != JsonToken.FIELD_NAME || !"finished".equals(parser.getCurrentName()))
return error("Didn't find finished at expected location"); return error("Didn't find finished at expected location");
parser.nextValue();
boolean finished = parser.getValueAsBoolean(); boolean finished = parser.getValueAsBoolean();
return new com.alttd.boosters.data.Booster(uuid, activator, boosterType, startingTime, duration, multiplier, active, finished); return new com.alttd.boosters.data.Booster(uuid, activator, boosterType, startingTime, duration, multiplier, active, finished);
} }