mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
fix some problems with gson, use hashCode in Enchantment and Statistic
This commit is contained in:
parent
d7bf4f527a
commit
ec1a7b3465
@ -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());
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user