org.bukkit.craftbukkit.scoreboard.CraftCriteria Maven / Gradle / Ivy
package org.bukkit.craftbukkit.scoreboard;
import com.google.common.collect.ImmutableMap;
import net.minecraft.server.IScoreboardCriteria;
import net.minecraft.server.ScoreboardObjective;
import java.util.Map;
final class CraftCriteria {
static final Map DEFAULTS;
static final CraftCriteria DUMMY;
static {
ImmutableMap.Builder defaults = ImmutableMap.builder();
for (Map.Entry, ?> entry : ((Map, ?>) IScoreboardCriteria.criteria).entrySet()) {
String name = entry.getKey().toString();
IScoreboardCriteria criteria = (IScoreboardCriteria) entry.getValue();
defaults.put(name, new CraftCriteria(criteria));
}
DEFAULTS = defaults.build();
DUMMY = DEFAULTS.get("dummy");
}
final IScoreboardCriteria criteria;
final String bukkitName;
private CraftCriteria(String bukkitName) {
this.bukkitName = bukkitName;
this.criteria = DUMMY.criteria;
}
private CraftCriteria(IScoreboardCriteria criteria) {
this.criteria = criteria;
this.bukkitName = criteria.getName();
}
static CraftCriteria getFromNMS(ScoreboardObjective objective) {
return DEFAULTS.get(objective.getCriteria().getName());
}
static CraftCriteria getFromBukkit(String name) {
final CraftCriteria criteria = DEFAULTS.get(name);
if (criteria != null) {
return criteria;
}
return new CraftCriteria(name);
}
@Override
public boolean equals(Object that) {
if (!(that instanceof CraftCriteria)) {
return false;
}
return ((CraftCriteria) that).bukkitName.equals(this.bukkitName);
}
@Override
public int hashCode() {
return this.bukkitName.hashCode() ^ CraftCriteria.class.hashCode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy