summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-04-21 20:56:19 +0100
committerDinnerbone <dinnerbone@dinnerbone.com>2011-04-21 20:56:19 +0100
commit539e822e3343a43f710d9befe410b9b606f35c7b (patch)
tree0b7452b59931b75cc3afe95f1913c2016ef230d6 /src
parent626edb3eb02e0015334306fdce1367eb5346dc85 (diff)
downloadbukkit-539e822e3343a43f710d9befe410b9b606f35c7b.tar
bukkit-539e822e3343a43f710d9befe410b9b606f35c7b.tar.gz
bukkit-539e822e3343a43f710d9befe410b9b606f35c7b.tar.lz
bukkit-539e822e3343a43f710d9befe410b9b606f35c7b.tar.xz
bukkit-539e822e3343a43f710d9befe410b9b606f35c7b.zip
Added Achievement and Statistics
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/Achievement.java67
-rw-r--r--src/main/java/org/bukkit/Statistic.java84
-rw-r--r--src/main/java/org/bukkit/entity/Player.java42
3 files changed, 193 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/Achievement.java b/src/main/java/org/bukkit/Achievement.java
new file mode 100644
index 00000000..38089bae
--- /dev/null
+++ b/src/main/java/org/bukkit/Achievement.java
@@ -0,0 +1,67 @@
+
+package org.bukkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents an achievement, which may be given to players
+ */
+public enum Achievement {
+ OPEN_INVENTORY(0),
+ MINE_WOOD(1),
+ BUILD_WORKBENCH(2),
+ BUILD_PICKAXE(3),
+ BUILD_FURNACE(4),
+ ACQUIRE_IRON(5),
+ BUILD_HOE(6),
+ MAKE_BREAD(7),
+ BAKE_CAKE(8),
+ BUILD_BETTER_PICKAXE(9),
+ COOK_FISH(10),
+ ON_A_RAIL(11),
+ BUILD_SWORD(12),
+ KILL_ENEMY(13),
+ KILL_COW(14),
+ FLY_PIG(15);
+
+ /**
+ * The offset used to distinguish Achievements and Statistics
+ */
+ public final static int STATISTIC_OFFSET = 5242880;
+ private final static Map<Integer, Achievement> achievements = new HashMap<Integer, Achievement>();
+ private final int id;
+
+ private Achievement(int id) {
+ this.id = STATISTIC_OFFSET + id;
+ }
+
+ /**
+ * Gets the ID for this achievement.
+ *
+ * Note that this is offset using {@link #STATISTIC_OFFSET}
+ *
+ * @return ID of this achievement
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Gets the achievement associated with the given ID.
+ *
+ * Note that the ID must already be offset using {@link #STATISTIC_OFFSET}
+ *
+ * @param id ID of the achievement to return
+ * @return Achievement with the given ID
+ */
+ public static Achievement getAchievement(int id) {
+ return achievements.get(id);
+ }
+
+ static {
+ for (Achievement ach : values()) {
+ achievements.put(ach.getId(), ach);
+ }
+ }
+}
diff --git a/src/main/java/org/bukkit/Statistic.java b/src/main/java/org/bukkit/Statistic.java
new file mode 100644
index 00000000..827eade6
--- /dev/null
+++ b/src/main/java/org/bukkit/Statistic.java
@@ -0,0 +1,84 @@
+
+package org.bukkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents a countable statistic, which is collected by the client
+ */
+public enum Statistic {
+ DAMAGE_DEALT(2020),
+ DAMAGE_TAKEN(2021),
+ DEATHS(2022),
+ MOB_KILLS(2023),
+ PLAYER_KILLS(2024),
+ FISH_CAUGHT(2025),
+ MINE_BLOCK(16777216, true),
+ USE_ITEM(6908288, false),
+ BREAK_ITEM(16973824, true);
+
+ private final static Map<Integer, Statistic> statistics = new HashMap<Integer, Statistic>();
+ private final int id;
+ private final boolean isSubstat;
+ private final boolean isBlock;
+
+ private Statistic(int id) {
+ this(id, false, false);
+ }
+
+ private Statistic(int id, boolean isBlock) {
+ this(id, true, isBlock);
+ }
+
+ private Statistic(int id, boolean isSubstat, boolean isBlock) {
+ this.id = id;
+ this.isSubstat = isSubstat;
+ this.isBlock = isBlock;
+ }
+
+ /**
+ * Gets the ID for this statistic.
+ *
+ * @return ID of this statistic
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Checks if this is a substatistic.
+ *
+ * A substatistic exists in mass for each block or item, depending on {@link #isBlock()}
+ *
+ * @return true if this is a substatistic
+ */
+ public boolean isSubstatistic() {
+ return isSubstat;
+ }
+
+ /**
+ * Checks if this is a substatistic dealing with blocks (As opposed to items)
+ *
+ * @return true if this deals with blocks, false if with items
+ */
+ public boolean isBlock() {
+ return isSubstat && isBlock;
+ }
+
+ /**
+ * Gets the statistic associated with the given ID.
+ *
+ * @param id ID of the statistic to return
+ * @return statistic with the given ID
+ */
+ public static Statistic getStatistic(int id) {
+ return statistics.get(id);
+ }
+
+ static {
+ for (Statistic stat : values()) {
+ statistics.put(stat.getId(), stat);
+ }
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index f30d2726..88bf7d1a 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -2,7 +2,10 @@
package org.bukkit.entity;
import java.net.InetSocketAddress;
+import org.bukkit.Achievement;
import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.Statistic;
import org.bukkit.command.CommandSender;
/**
@@ -135,4 +138,43 @@ public interface Player extends HumanEntity, CommandSender {
* @deprecated This method should not be relied upon as it is a temporary work-around for a larger, more complicated issue.
*/
public void updateInventory();
+
+ /**
+ * Awards this player the given achievement
+ *
+ * @param achievement Achievement to award
+ */
+ public void awardAchievement(Achievement achievement);
+
+ /**
+ * Increments the given statistic for this player
+ *
+ * @param statistic Statistic to increment
+ */
+ public void incrementStatistic(Statistic statistic);
+
+ /**
+ * Increments the given statistic for this player
+ *
+ * @param statistic Statistic to increment
+ * @param amount Amount to increment this statistic by
+ */
+ public void incrementStatistic(Statistic statistic, int amount);
+
+ /**
+ * Increments the given statistic for this player for the given material
+ *
+ * @param statistic Statistic to increment
+ * @param material Material to offset the statistic with
+ */
+ public void incrementStatistic(Statistic statistic, Material material);
+
+ /**
+ * Increments the given statistic for this player for the given material
+ *
+ * @param statistic Statistic to increment
+ * @param material Material to offset the statistic with
+ * @param amount Amount to increment this statistic by
+ */
+ public void incrementStatistic(Statistic statistic, Material material, int amount);
}