2014-01-15 05:42:40 +01:00
|
|
|
package org.bukkit.craftbukkit;
|
|
|
|
|
|
|
|
import net.minecraft.server.EntityTypes;
|
2015-02-26 23:41:06 +01:00
|
|
|
import net.minecraft.server.EntityTypes.MonsterEggInfo;
|
2014-01-15 05:42:40 +01:00
|
|
|
import net.minecraft.server.StatisticList;
|
|
|
|
|
|
|
|
import org.bukkit.Achievement;
|
|
|
|
import org.bukkit.Statistic;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
|
|
|
|
import com.google.common.base.CaseFormat;
|
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
2014-11-25 22:32:16 +01:00
|
|
|
import net.minecraft.server.Block;
|
|
|
|
import net.minecraft.server.Item;
|
|
|
|
import net.minecraft.server.MinecraftKey;
|
2016-02-29 22:32:46 +01:00
|
|
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
2014-01-15 05:42:40 +01:00
|
|
|
|
|
|
|
public class CraftStatistic {
|
|
|
|
private static final BiMap<String, org.bukkit.Statistic> statistics;
|
|
|
|
private static final BiMap<String, org.bukkit.Achievement> achievements;
|
|
|
|
|
|
|
|
static {
|
|
|
|
ImmutableMap<String, org.bukkit.Achievement> specialCases = ImmutableMap.<String, org.bukkit.Achievement> builder()
|
|
|
|
.put("achievement.buildWorkBench", Achievement.BUILD_WORKBENCH)
|
|
|
|
.put("achievement.diamonds", Achievement.GET_DIAMONDS)
|
|
|
|
.put("achievement.portal", Achievement.NETHER_PORTAL)
|
|
|
|
.put("achievement.ghast", Achievement.GHAST_RETURN)
|
|
|
|
.put("achievement.theEnd", Achievement.END_PORTAL)
|
|
|
|
.put("achievement.theEnd2", Achievement.THE_END)
|
|
|
|
.put("achievement.blazeRod", Achievement.GET_BLAZE_ROD)
|
|
|
|
.put("achievement.potion", Achievement.BREW_POTION)
|
|
|
|
.build();
|
|
|
|
ImmutableBiMap.Builder<String, org.bukkit.Statistic> statisticBuilder = ImmutableBiMap.<String, org.bukkit.Statistic>builder();
|
|
|
|
ImmutableBiMap.Builder<String, org.bukkit.Achievement> achievementBuilder = ImmutableBiMap.<String, org.bukkit.Achievement>builder();
|
|
|
|
for (Statistic statistic : Statistic.values()) {
|
|
|
|
if (statistic == Statistic.PLAY_ONE_TICK) {
|
|
|
|
statisticBuilder.put("stat.playOneMinute", statistic);
|
|
|
|
} else {
|
|
|
|
statisticBuilder.put("stat." + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, statistic.name()), statistic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Achievement achievement : Achievement.values()) {
|
|
|
|
if (specialCases.values().contains(achievement)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
achievementBuilder.put("achievement." + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, achievement.name()), achievement);
|
|
|
|
}
|
|
|
|
|
|
|
|
achievementBuilder.putAll(specialCases);
|
|
|
|
|
|
|
|
statistics = statisticBuilder.build();
|
|
|
|
achievements = achievementBuilder.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
private CraftStatistic() {}
|
|
|
|
|
|
|
|
public static org.bukkit.Achievement getBukkitAchievement(net.minecraft.server.Achievement achievement) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return getBukkitAchievementByName(achievement.name);
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static org.bukkit.Achievement getBukkitAchievementByName(String name) {
|
|
|
|
return achievements.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static org.bukkit.Statistic getBukkitStatistic(net.minecraft.server.Statistic statistic) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return getBukkitStatisticByName(statistic.name);
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static org.bukkit.Statistic getBukkitStatisticByName(String name) {
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.killEntity.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.killEntity";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.entityKilledBy.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.entityKilledBy";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.breakItem.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.breakItem";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.useItem.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.useItem";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.mineBlock.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.mineBlock";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.craftItem.")) {
|
2014-01-15 05:42:40 +01:00
|
|
|
name = "stat.craftItem";
|
|
|
|
}
|
2016-02-29 22:32:46 +01:00
|
|
|
if (name.startsWith("stat.drop.")) {
|
|
|
|
name = "stat.drop";
|
|
|
|
}
|
|
|
|
if (name.startsWith("stat.pickup.")) {
|
|
|
|
name = "stat.pickup";
|
|
|
|
}
|
2014-01-15 05:42:40 +01:00
|
|
|
return statistics.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static net.minecraft.server.Statistic getNMSStatistic(org.bukkit.Statistic statistic) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return StatisticList.getStatistic(statistics.inverse().get(statistic));
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static net.minecraft.server.Achievement getNMSAchievement(org.bukkit.Achievement achievement) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return (net.minecraft.server.Achievement) StatisticList.getStatistic(achievements.inverse().get(achievement));
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static net.minecraft.server.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
|
|
|
|
try {
|
|
|
|
if (stat == Statistic.MINE_BLOCK) {
|
2016-02-29 22:32:46 +01:00
|
|
|
return StatisticList.a(CraftMagicNumbers.getBlock(material)); // PAIL: getMineBlockStatistic
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
if (stat == Statistic.CRAFT_ITEM) {
|
2016-02-29 22:32:46 +01:00
|
|
|
return StatisticList.a(CraftMagicNumbers.getItem(material)); // PAIL: getCraftItemStatistic
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
if (stat == Statistic.USE_ITEM) {
|
2016-02-29 22:32:46 +01:00
|
|
|
return StatisticList.b(CraftMagicNumbers.getItem(material)); // PAIL: getUseItemStatistic
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
if (stat == Statistic.BREAK_ITEM) {
|
2016-02-29 22:32:46 +01:00
|
|
|
return StatisticList.c(CraftMagicNumbers.getItem(material)); // PAIL: getBreakItemStatistic
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static net.minecraft.server.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
|
2014-03-21 05:26:30 +01:00
|
|
|
MonsterEggInfo monsteregginfo = (MonsterEggInfo) EntityTypes.eggInfo.get(Integer.valueOf(entity.getTypeId()));
|
2014-01-15 05:42:40 +01:00
|
|
|
|
|
|
|
if (monsteregginfo != null) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return monsteregginfo.killEntityStatistic;
|
2014-01-15 05:42:40 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityType getEntityTypeFromStatistic(net.minecraft.server.Statistic statistic) {
|
2014-03-21 05:26:30 +01:00
|
|
|
String statisticString = statistic.name;
|
2014-01-15 05:42:40 +01:00
|
|
|
return EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Material getMaterialFromStatistic(net.minecraft.server.Statistic statistic) {
|
2014-03-21 05:26:30 +01:00
|
|
|
String statisticString = statistic.name;
|
2014-11-25 22:32:16 +01:00
|
|
|
String val = statisticString.substring(statisticString.lastIndexOf(".") + 1);
|
|
|
|
Item item = (Item) Item.REGISTRY.get(new MinecraftKey(val));
|
|
|
|
if (item != null) {
|
|
|
|
return Material.getMaterial(Item.getId(item));
|
|
|
|
}
|
|
|
|
Block block = (Block) Block.REGISTRY.get(new MinecraftKey(val));
|
|
|
|
if (block != null) {
|
|
|
|
return Material.getMaterial(Block.getId(block));
|
|
|
|
}
|
2014-01-15 05:42:40 +01:00
|
|
|
try {
|
2014-11-25 22:32:16 +01:00
|
|
|
return Material.getMaterial(Integer.parseInt(val));
|
2014-01-15 05:42:40 +01:00
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|