diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-04-21 20:57:09 +0100 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-04-21 20:57:34 +0100 |
commit | 3afe2df2415b6c4b5b2f52756c3ff7ec8615be22 (patch) | |
tree | f9cf47f6442b391c480ca0faa1351e7e28634aff /src/main/java | |
parent | 212ec7f33dd020d3135b4f8881f52900c0328b6c (diff) | |
download | craftbukkit-3afe2df2415b6c4b5b2f52756c3ff7ec8615be22.tar craftbukkit-3afe2df2415b6c4b5b2f52756c3ff7ec8615be22.tar.gz craftbukkit-3afe2df2415b6c4b5b2f52756c3ff7ec8615be22.tar.lz craftbukkit-3afe2df2415b6c4b5b2f52756c3ff7ec8615be22.tar.xz craftbukkit-3afe2df2415b6c4b5b2f52756c3ff7ec8615be22.zip |
Implemented stats/achievement giving
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 16495db3..694c14b3 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -6,11 +6,15 @@ import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityPlayer; import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.Packet; +import net.minecraft.server.Packet200Statistic; import net.minecraft.server.Packet3Chat; import net.minecraft.server.Packet6SpawnPosition; import net.minecraft.server.ServerConfigurationManager; import net.minecraft.server.WorldServer; +import org.bukkit.Achievement; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Statistic; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.TextWrapper; @@ -222,4 +226,46 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public boolean isSleepingIgnored() { return getHandle().fauxSleeping; } + + public void awardAchievement(Achievement achievement) { + sendStatistic(achievement.getId(), 1); + } + + public void incrementStatistic(Statistic statistic) { + incrementStatistic(statistic, 1); + } + + public void incrementStatistic(Statistic statistic, int amount) { + sendStatistic(statistic.getId(), amount); + } + + public void incrementStatistic(Statistic statistic, Material material) { + incrementStatistic(statistic, material, 1); + } + + public void incrementStatistic(Statistic statistic, Material material, int amount) { + if (!statistic.isSubstatistic()) { + throw new IllegalArgumentException("Given statistic is not a substatistic"); + } + if (statistic.isBlock() != material.isBlock()) { + throw new IllegalArgumentException("Given material is not valid for this substatistic"); + } + + int mat = material.getId(); + + if (!material.isBlock()) { + mat -= 255; + } + + sendStatistic(statistic.getId() + mat, amount); + } + + private void sendStatistic(int id, int amount) { + while (amount > Byte.MAX_VALUE) { + sendStatistic(id, Byte.MAX_VALUE); + amount -= Byte.MAX_VALUE; + } + + getHandle().netServerHandler.sendPacket(new Packet200Statistic(id, amount)); + } } |