Add CustomStatistic as fallback for custom or unimplemented statistic IDs.

This commit is contained in:
Steveice10 2017-11-26 18:05:45 -08:00
parent 299efaf248
commit 6de0593ca1
2 changed files with 42 additions and 1 deletions

View file

@ -0,0 +1,36 @@
package com.github.steveice10.mc.protocol.data.game.statistic;
import com.github.steveice10.mc.protocol.util.ObjectUtil;
import java.util.Objects;
public class CustomStatistic implements Statistic {
private String name;
public CustomStatistic(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(!(o instanceof CustomStatistic)) return false;
CustomStatistic that = (CustomStatistic) o;
return Objects.equals(this.name, that.name);
}
@Override
public int hashCode() {
return ObjectUtil.hashCode(this.name);
}
@Override
public String toString() {
return ObjectUtil.toString(this);
}
}

View file

@ -4,6 +4,7 @@ import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.statistic.BreakBlockStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.BreakItemStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.CraftItemStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.CustomStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.DropItemStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.GenericStatistic;
import com.github.steveice10.mc.protocol.data.game.statistic.KillEntityStatistic;
@ -66,7 +67,11 @@ public class ServerStatisticsPacket extends MinecraftPacket {
} else if(value.startsWith(PICKUP_ITEM_PREFIX)) {
statistic = new PickupItemStatistic(value.substring(PICKUP_ITEM_PREFIX.length()));
} else {
statistic = MagicValues.key(GenericStatistic.class, value);
try {
statistic = MagicValues.key(GenericStatistic.class, value);
} catch(IllegalArgumentException e) {
statistic = new CustomStatistic(value);
}
}
this.statistics.put(statistic, in.readVarInt());