@Test @SuppressWarnings("unchecked") public void verifyAchievementMapping() throws Throwable { List<Achievement> achievements = Lists.newArrayList(Achievement.values()); for (net.minecraft.server.Achievement achievement : (List<net.minecraft.server.Achievement>) AchievementList.e) { String name = achievement.name; String message = String.format("org.bukkit.Achievement is missing: '%s'", name); Achievement subject = CraftStatistic.getBukkitAchievement(achievement); assertThat(message, subject, is(not(nullValue()))); assertThat(name, achievements.remove(subject), is(true)); } assertThat("org.bukkit.Achievement has too many achievements", achievements, is(empty())); }
@Override public void awardAchievement(Achievement achievement) { Validate.notNull(achievement, "Achievement cannot be null"); if (achievement.hasParent() && !hasAchievement(achievement.getParent())) { awardAchievement(achievement.getParent()); } getHandle().func_147099_x().func_150873_a(getHandle(), CraftStatistic.getNMSAchievement(achievement), 1); getHandle().func_147099_x().func_150884_b(getHandle()); }
@Override public void removeAchievement(Achievement achievement) { Validate.notNull(achievement, "Achievement cannot be null"); for (Achievement achieve : Achievement.values()) { if (achieve.getParent() == achievement && hasAchievement(achieve)) { removeAchievement(achieve); } } getHandle().func_147099_x().func_150873_a(getHandle(), CraftStatistic.getNMSAchievement(achievement), 0); }
@Override public void setStatistic(Statistic statistic, int newValue) { Validate.notNull(statistic, "Statistic cannot be null"); Validate.isTrue(statistic.getType() == Type.UNTYPED, "Must supply additional paramater for this statistic"); Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getNMSStatistic(statistic); getHandle().func_147099_x().func_150873_a(getHandle(), nmsStatistic, newValue); }
@Override public int getStatistic(Statistic statistic, Material material) { Validate.notNull(statistic, "Statistic cannot be null"); Validate.notNull(material, "Material cannot be null"); Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); return getHandle().func_147099_x().writeStat(nmsStatistic); }
@Override public void setStatistic(Statistic statistic, Material material, int newValue) { Validate.notNull(statistic, "Statistic cannot be null"); Validate.notNull(material, "Material cannot be null"); Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); Validate.isTrue(statistic.getType() == Type.BLOCK || statistic.getType() == Type.ITEM, "This statistic does not take a Material parameter"); net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getMaterialStatistic(statistic, material); Validate.notNull(nmsStatistic, "The supplied Material does not have a corresponding statistic"); getHandle().func_147099_x().func_150873_a(getHandle(), nmsStatistic, newValue); }
@Override public int getStatistic(Statistic statistic, EntityType entityType) { Validate.notNull(statistic, "Statistic cannot be null"); Validate.notNull(entityType, "EntityType cannot be null"); Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); return getHandle().func_147099_x().writeStat(nmsStatistic); }
@Override public void setStatistic(Statistic statistic, EntityType entityType, int newValue) { Validate.notNull(statistic, "Statistic cannot be null"); Validate.notNull(entityType, "EntityType cannot be null"); Validate.isTrue(newValue >= 0, "Value must be greater than or equal to 0"); Validate.isTrue(statistic.getType() == Type.ENTITY, "This statistic does not take an EntityType parameter"); net.minecraft.stats.StatBase nmsStatistic = CraftStatistic.getEntityStatistic(statistic, entityType); Validate.notNull(nmsStatistic, "The supplied EntityType does not have a corresponding statistic"); getHandle().func_147099_x().func_150873_a(getHandle(), nmsStatistic, newValue); }
public static Cancellable handleStatisticsIncrease(EntityPlayer entityHuman, net.minecraft.stats.StatBase statistic, int current, int incrementation) { Player player = ((EntityPlayerMP) entityHuman).getBukkitEntity(); Event event; if (statistic instanceof net.minecraft.stats.Achievement) { if (current != 0) { return null; } event = new PlayerAchievementAwardedEvent(player, CraftStatistic.getBukkitAchievement((net.minecraft.stats.Achievement) statistic)); } else { org.bukkit.Statistic stat = CraftStatistic.getBukkitStatistic(statistic); switch (stat) { case FALL_ONE_CM: case BOAT_ONE_CM: case CLIMB_ONE_CM: case DIVE_ONE_CM: case FLY_ONE_CM: case HORSE_ONE_CM: case MINECART_ONE_CM: case PIG_ONE_CM: case PLAY_ONE_TICK: case SWIM_ONE_CM: case WALK_ONE_CM: // Do not process event for these - too spammy return null; default: } if (stat.getType() == Type.UNTYPED) { event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation); } else if (stat.getType() == Type.ENTITY) { EntityType entityType = CraftStatistic.getEntityTypeFromStatistic(statistic); event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, entityType); } else { Material material = CraftStatistic.getMaterialFromStatistic(statistic); event = new PlayerStatisticIncrementEvent(player, stat, current, current + incrementation, material); } } entityHuman.worldObj.getServer().getPluginManager().callEvent(event); return (Cancellable) event; }