Added Achievement and Statistics
This commit is contained in:
parent
626edb3eb0
commit
539e822e33
67
src/main/java/org/bukkit/Achievement.java
Normal file
67
src/main/java/org/bukkit/Achievement.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
84
src/main/java/org/bukkit/Statistic.java
Normal file
84
src/main/java/org/bukkit/Statistic.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,10 @@
|
|||||||
package org.bukkit.entity;
|
package org.bukkit.entity;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import org.bukkit.Achievement;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.command.CommandSender;
|
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.
|
* @deprecated This method should not be relied upon as it is a temporary work-around for a larger, more complicated issue.
|
||||||
*/
|
*/
|
||||||
public void updateInventory();
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user