fix some problems with gson, use hashCode in Enchantment and Statistic

This commit is contained in:
Bixilon 2020-07-25 17:35:32 +02:00
parent d7bf4f527a
commit ec1a7b3465
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 18 additions and 3 deletions

View File

@ -14,7 +14,6 @@
package de.bixilon.minosoft;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import de.bixilon.minosoft.game.datatypes.TextComponent;
public class ServerListPing {
final JsonObject raw;
@ -46,7 +45,7 @@ public class ServerListPing {
public TextComponent getMotd() {
try {
return new TextComponent(raw.getAsJsonObject("description"));
} catch (JsonParseException ignored) {
} catch (Exception ignored) {
}
return new TextComponent(raw.get("description").getAsString());
}

View File

@ -30,7 +30,7 @@ public class TextComponent {
}
try {
this.json = JsonParser.parseString(raw).getAsJsonObject();
} catch (IllegalStateException e) {
} catch (Exception e) {
// not a text component, is a legacy string
this.json = new JsonObject();
JsonArray extra = new JsonArray();

View File

@ -35,11 +35,19 @@ public class Enchantment {
return String.format("%s:%s", getMod(), getIdentifier());
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (hashCode() != obj.hashCode()) {
return false;
}
Enchantment their = (Enchantment) obj;
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());
}

View File

@ -35,11 +35,19 @@ public class Statistic {
return String.format("%s:%s", getMod(), getIdentifier());
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (hashCode() != obj.hashCode()) {
return false;
}
return toString().equals(obj.toString());
}
}