1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-18 09:43:00 +01:00

Compare commits

..

6 Commits

Author SHA1 Message Date
TfT_02
9e04e437e3 Compile with RELEASE 2014-02-28 19:50:20 +01:00
TfT_02
30e1d3fff3 No such thing as cancelled events 2014-02-28 19:49:53 +01:00
TfT_02
bada2f5d0d Remove reflection 2014-02-28 19:15:11 +01:00
GJ
1edc12af3b This is ugly & awful, but may keep us from needing to add Tag-API as a dependency. 2014-02-28 10:46:34 -05:00
TfT_02
f9a73c38d8 Step two 2014-02-27 22:25:54 +01:00
TfT_02
ccdab96650 First step in starting to fix this issue 2014-02-27 22:25:34 +01:00
11 changed files with 123 additions and 553 deletions

View File

@@ -47,5 +47,6 @@ Required Libraries:
* JUnit
* EMetrics
* Bukkit
* TagAPI
http://dev.bukkit.org/server-mods/mcmmo for more up to date information.

10
pom.xml
View File

@@ -116,6 +116,10 @@
<id>Plugin MetricsExtension</id>
<url>http://repo.turt2live.com</url>
</repository>
<repository>
<id>TagAPI</id>
<url>http://repo.kitteh.org/content/repositories/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
@@ -136,6 +140,12 @@
<artifactId>MetricsExtension</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>
<artifactId>tagapi</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>

View File

@@ -61,9 +61,6 @@ public class DatabaseManagerFactory {
case FLATFILE:
return new FlatfileDatabaseManager();
case SERIALIZED:
return new SerializedDatabaseManager();
case SQL:
return new SQLDatabaseManager();

View File

@@ -1,440 +0,0 @@
package com.gmail.nossr50.database;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.OfflinePlayer;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.player.UserData;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
public class SerializedDatabaseManager implements DatabaseManager {
private final HashMap<SkillType, List<PlayerStat>> playerStatHash = new HashMap<SkillType, List<PlayerStat>>();
private final List<PlayerStat> powerLevels = new ArrayList<PlayerStat>();
private long lastUpdate = 0;
private final long UPDATE_WAIT_TIME = 600000L; // 10 minutes
protected SerializedDatabaseManager() {
updateLeaderboards();
}
public void purgePowerlessUsers() {
int purgedUsers = 0;
mcMMO.p.getLogger().info("Purging powerless users...");
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return;
}
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data == null) {
continue;
}
boolean powerless = true;
for (int skill : data.getSkillLevels().values()) {
if (skill != 0) {
powerless = false;
break;
}
}
if (powerless && file.delete()) {
purgedUsers++;
Misc.profileCleanup(data.getName());
}
}
mcMMO.p.getLogger().info("Purged " + purgedUsers + " users from the database.");
}
public void purgeOldUsers() {
int removedPlayers = 0;
long currentTime = System.currentTimeMillis();
mcMMO.p.getLogger().info("Purging old users...");
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return;
}
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data == null) {
continue;
}
boolean rewrite = false;
String name = data.getName();
long lastPlayed = data.getLastPlayed();
if (lastPlayed == 0) {
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(name);
lastPlayed = player.getLastPlayed();
rewrite = true;
}
if (currentTime - lastPlayed > PURGE_TIME) {
if (file.delete()) {
removedPlayers++;
Misc.profileCleanup(name);
}
}
if (rewrite) {
data.setLastPlayed(lastPlayed);
serialize(file, data);
}
}
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
}
public boolean removeUser(String playerName) {
boolean worked = false;
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return worked;
}
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data != null && data.getName().equalsIgnoreCase(playerName)) {
mcMMO.p.getLogger().info("User found, removing...");
worked = file.delete();
break;
}
}
return worked;
}
public boolean saveUser(PlayerProfile profile) {
UserData data = new UserData(profile);
return serialize(new File(mcMMO.getUsersDirectory(), data.getName() + ".mcmmoplayer"), data);
}
public List<PlayerStat> readLeaderboard(SkillType skill, int pageNumber, int statsPerPage) {
updateLeaderboards();
List<PlayerStat> statsList = skill == null ? powerLevels : playerStatHash.get(skill);
int fromIndex = (Math.max(pageNumber, 1) - 1) * statsPerPage;
return statsList.subList(Math.min(fromIndex, statsList.size()), Math.min(fromIndex + statsPerPage, statsList.size()));
}
public Map<SkillType, Integer> readRank(String playerName) {
updateLeaderboards();
Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
for (SkillType skill : SkillType.NON_CHILD_SKILLS) {
skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill)));
}
skills.put(null, getPlayerRank(playerName, powerLevels));
return skills;
}
public void newUser(String playerName) {
serialize(new File(mcMMO.getUsersDirectory(), playerName + ".mcmmoplayer"), new UserData(new PlayerProfile(playerName)));
}
public PlayerProfile loadPlayerProfile(String playerName, boolean createNew) {
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return new PlayerProfile(playerName, createNew);
}
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data != null && data.getName().equalsIgnoreCase(playerName)) {
return loadFromData(data);
}
}
return new PlayerProfile(playerName, createNew);
}
public List<String> getStoredUsers() {
ArrayList<String> users = new ArrayList<String>();
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return users;
}
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data == null) {
continue;
}
users.add(data.getName());
}
return users;
}
public void convertUsers(DatabaseManager destination) {
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
//TODO: log issue
return;
}
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data == null) {
continue;
}
try {
if (destination.saveUser(loadFromData(data))) {
convertedUsers++;
Misc.printProgress(convertedUsers, progressInterval, startMillis);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public DatabaseType getDatabaseType() {
return DatabaseType.SERIALIZED;
}
private UserData deserialize(File file) {
UserData data = null;
try {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
data = (UserData) ois.readObject();
ois.close();
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while reading " + file.getName() + ": " + e.toString());
}
return data;
}
private boolean serialize(File file, UserData data) {
boolean success = true;
try {
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(data);
oos.close();
}
catch (Exception e) {
mcMMO.p.getLogger().severe("Exception while writing " + file.getName() + ": " + e.toString());
success = false;
}
return success;
}
private PlayerProfile loadFromData(UserData data) {
return new PlayerProfile(data.getName(), data.getSkillLevels(), data.getSkillXp(), data.getAbilityData(), data.getMobHealthbarType());
}
/**
* Update the leader boards.
*/
private void updateLeaderboards() {
// Only update leaderboards every 10 minutes.. this puts a lot of strain on the server (depending on the size of the database) and should not be done frequently
if (System.currentTimeMillis() < lastUpdate + UPDATE_WAIT_TIME) {
return;
}
File usersDirectory = new File(mcMMO.getUsersDirectory());
File[] userFiles = usersDirectory.listFiles();
if (userFiles == null) {
return;
}
lastUpdate = System.currentTimeMillis(); // Log when the last update was run
powerLevels.clear(); // Clear old values from the power levels
// Initialize lists
List<PlayerStat> mining = new ArrayList<PlayerStat>();
List<PlayerStat> woodcutting = new ArrayList<PlayerStat>();
List<PlayerStat> herbalism = new ArrayList<PlayerStat>();
List<PlayerStat> excavation = new ArrayList<PlayerStat>();
List<PlayerStat> acrobatics = new ArrayList<PlayerStat>();
List<PlayerStat> repair = new ArrayList<PlayerStat>();
List<PlayerStat> swords = new ArrayList<PlayerStat>();
List<PlayerStat> axes = new ArrayList<PlayerStat>();
List<PlayerStat> archery = new ArrayList<PlayerStat>();
List<PlayerStat> unarmed = new ArrayList<PlayerStat>();
List<PlayerStat> taming = new ArrayList<PlayerStat>();
List<PlayerStat> fishing = new ArrayList<PlayerStat>();
List<PlayerStat> alchemy = new ArrayList<PlayerStat>();
for (File file : userFiles) {
if (!file.isFile() || file.isDirectory()) {
continue;
}
UserData data = deserialize(file);
if (data == null) {
continue;
}
int powerLevel = 0;
String playerName = data.getName();
Map<SkillType, Integer> skills = data.getSkillLevels();
powerLevel += putStat(acrobatics, playerName, skills.get(SkillType.ACROBATICS));
powerLevel += putStat(alchemy, playerName, skills.get(SkillType.ALCHEMY));
powerLevel += putStat(archery, playerName, skills.get(SkillType.ARCHERY));
powerLevel += putStat(axes, playerName, skills.get(SkillType.AXES));
powerLevel += putStat(excavation, playerName, skills.get(SkillType.EXCAVATION));
powerLevel += putStat(fishing, playerName, skills.get(SkillType.FISHING));
powerLevel += putStat(herbalism, playerName, skills.get(SkillType.HERBALISM));
powerLevel += putStat(mining, playerName, skills.get(SkillType.MINING));
powerLevel += putStat(repair, playerName, skills.get(SkillType.REPAIR));
powerLevel += putStat(swords, playerName, skills.get(SkillType.SWORDS));
powerLevel += putStat(taming, playerName, skills.get(SkillType.TAMING));
powerLevel += putStat(unarmed, playerName, skills.get(SkillType.UNARMED));
powerLevel += putStat(woodcutting, playerName, skills.get(SkillType.WOODCUTTING));
putStat(powerLevels, playerName, powerLevel);
}
SkillComparator c = new SkillComparator();
Collections.sort(mining, c);
Collections.sort(woodcutting, c);
Collections.sort(repair, c);
Collections.sort(unarmed, c);
Collections.sort(herbalism, c);
Collections.sort(excavation, c);
Collections.sort(archery, c);
Collections.sort(swords, c);
Collections.sort(axes, c);
Collections.sort(acrobatics, c);
Collections.sort(taming, c);
Collections.sort(fishing, c);
Collections.sort(alchemy, c);
Collections.sort(powerLevels, c);
playerStatHash.put(SkillType.MINING, mining);
playerStatHash.put(SkillType.WOODCUTTING, woodcutting);
playerStatHash.put(SkillType.REPAIR, repair);
playerStatHash.put(SkillType.UNARMED, unarmed);
playerStatHash.put(SkillType.HERBALISM, herbalism);
playerStatHash.put(SkillType.EXCAVATION, excavation);
playerStatHash.put(SkillType.ARCHERY, archery);
playerStatHash.put(SkillType.SWORDS, swords);
playerStatHash.put(SkillType.AXES, axes);
playerStatHash.put(SkillType.ACROBATICS, acrobatics);
playerStatHash.put(SkillType.TAMING, taming);
playerStatHash.put(SkillType.FISHING, fishing);
playerStatHash.put(SkillType.ALCHEMY, alchemy);
}
private int putStat(List<PlayerStat> statList, String playerName, int statValue) {
statList.add(new PlayerStat(playerName, statValue));
return statValue;
}
private Integer getPlayerRank(String playerName, List<PlayerStat> statsList) {
if (statsList == null) {
return null;
}
int currentPos = 1;
for (PlayerStat stat : statsList) {
if (stat.name.equalsIgnoreCase(playerName)) {
return currentPos;
}
currentPos++;
}
return null;
}
private class SkillComparator implements Comparator<PlayerStat> {
@Override
public int compare(PlayerStat o1, PlayerStat o2) {
return (o2.statVal - o1.statVal);
}
}
}

View File

@@ -2,7 +2,6 @@ package com.gmail.nossr50.datatypes.database;
public enum DatabaseType {
FLATFILE,
SERIALIZED,
SQL,
CUSTOM;

View File

@@ -91,6 +91,8 @@ public class McMMOPlayer {
private boolean isUsingUnarmed;
private final FixedMetadataValue playerMetadata;
private String nameTag;
public McMMOPlayer(Player player) {
String playerName = player.getName();
@@ -949,4 +951,12 @@ public class McMMOPlayer {
public FixedMetadataValue getPlayerMetadata() {
return playerMetadata;
}
public String getNameTag() {
return nameTag;
}
public void setNameTag(String nameTag) {
this.nameTag = nameTag;
}
}

View File

@@ -1,98 +0,0 @@
package com.gmail.nossr50.datatypes.player;
import com.gmail.nossr50.datatypes.MobHealthbarType;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.mcMMO;
import org.bukkit.entity.Player;
import java.io.Serializable;
import java.util.HashMap;
import java.util.UUID;
public class UserData implements Serializable {
private static final long serialVersionUID = 1L;
private UUID playerID;
private String name;
private long lastPlayed;
private HashMap<SkillType, Integer> skillLevels = new HashMap<SkillType, Integer>();
private HashMap<SkillType, Float> skillXp = new HashMap<SkillType, Float>();
private HashMap<AbilityType, Integer> abilityData = new HashMap<AbilityType, Integer>();
private MobHealthbarType mobHealthbarType;
public UserData(McMMOPlayer mcMMOPlayer) {
Player player = mcMMOPlayer.getPlayer();
playerID = player.getUniqueId();
name = player.getName();
lastPlayed = player.getLastPlayed();
for (SkillType skill : SkillType.values()) {
skillLevels.put(skill, mcMMOPlayer.getSkillLevel(skill));
skillXp.put(skill, mcMMOPlayer.getSkillXpLevelRaw(skill));
}
PlayerProfile profile = mcMMOPlayer.getProfile();
for (AbilityType ability : AbilityType.values()) {
abilityData.put(ability, (int) profile.getAbilityDATS(ability));
}
mobHealthbarType = profile.getMobHealthbarType();
}
public UserData(PlayerProfile profile) {
name = profile.getPlayerName();
Player player = mcMMO.p.getServer().getPlayerExact(name);
if (player == null) {
playerID = UUID.fromString(name);
lastPlayed = 0L;
}
else {
playerID = player.getUniqueId();
lastPlayed = player.getLastPlayed();
}
for (SkillType skill : SkillType.values()) {
skillLevels.put(skill, profile.getSkillLevel(skill));
skillXp.put(skill, profile.getSkillXpLevelRaw(skill));
}
for (AbilityType ability : AbilityType.values()) {
abilityData.put(ability, (int) profile.getAbilityDATS(ability));
}
mobHealthbarType = profile.getMobHealthbarType();
}
public String getName() {
return name;
}
public long getLastPlayed() {
return lastPlayed;
}
public void setLastPlayed(long lastPlayed) {
this.lastPlayed = lastPlayed;
}
public HashMap<SkillType, Integer> getSkillLevels() {
return skillLevels;
}
public HashMap<SkillType, Float> getSkillXp() {
return skillXp;
}
public HashMap<AbilityType, Integer> getAbilityData() {
return abilityData;
}
public MobHealthbarType getMobHealthbarType() {
return mobHealthbarType;
}
}

View File

@@ -0,0 +1,59 @@
package com.gmail.nossr50.listeners;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
public class TagListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onAsyncPlayerReceiveNameTag(AsyncPlayerReceiveNameTagEvent event) {
Player player = event.getNamedPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player, true);
if (mcMMOPlayer == null) {
return;
}
String tag = event.getTag();
String colorlessTag = ChatColor.stripColor(tag);
if (colorlessTag.equals(tag)) {
mcMMOPlayer.setNameTag(null);
return;
}
if (colorlessTag.equals(player.getName()) && (mcMMOPlayer.getNameTag() == null || !mcMMOPlayer.getNameTag().equals(tag))) {
mcMMOPlayer.setNameTag(tag);
ScoreboardManager.tagUpdate(player);
}
/*
mbax:
With TagAPI, you can set the name tag over anybody's head to any value.
You can have five people with the name 'Notch' (And one named 'notch' for
good measure). That makes it difficult to properly utilize the scoreboard
feature to match a changed name to a score for below name objective display.
Additionally, every single player can be seeing a different username over
the head of the same player. So even if you're just trying to detect colored usernames
you could be encountering 16 different colors before a username (15, generally, who does white?)
and maybe some format codes as well. The Scoreboard API doesn't support per-player setting of names,
so you'd have to add an entry for each.
At best, what you could do is listen to TagAPI's event on MONITOR priority and track all the names.
Check if a set name is the same as their actual name, sans colors. If yes, store that and each time
you update a player's below-name objective, update an OfflinePlayer with that colored version as well.
This is not a good idea if the objective will ever change DisplaySlot, particularly if it goes to the
sidebar, since you'll then need to clear the color ones.
*/
}
}

View File

@@ -5,11 +5,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.config.mods.ArmorConfigManager;
import com.gmail.nossr50.config.mods.BlockConfigManager;
import com.gmail.nossr50.config.mods.EntityConfigManager;
import com.gmail.nossr50.config.mods.ToolConfigManager;
import com.gmail.nossr50.util.ModManager;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue;
@@ -19,6 +14,10 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.mods.ArmorConfigManager;
import com.gmail.nossr50.config.mods.BlockConfigManager;
import com.gmail.nossr50.config.mods.EntityConfigManager;
import com.gmail.nossr50.config.mods.ToolConfigManager;
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
import com.gmail.nossr50.config.skills.repair.RepairConfigManager;
import com.gmail.nossr50.config.treasure.TreasureConfig;
@@ -29,6 +28,7 @@ import com.gmail.nossr50.listeners.EntityListener;
import com.gmail.nossr50.listeners.InventoryListener;
import com.gmail.nossr50.listeners.PlayerListener;
import com.gmail.nossr50.listeners.SelfListener;
import com.gmail.nossr50.listeners.TagListener;
import com.gmail.nossr50.listeners.WorldListener;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.metrics.MetricsManager;
@@ -48,6 +48,7 @@ import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.HolidayManager;
import com.gmail.nossr50.util.LogFilter;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager;
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
@@ -73,7 +74,6 @@ public class mcMMO extends JavaPlugin {
/* File Paths */
private static String mainDirectory;
private static String flatFileDirectory;
private static String usersDirectory;
private static String usersFile;
private static String modDirectory;
@@ -90,6 +90,7 @@ public class mcMMO extends JavaPlugin {
private static boolean healthBarPluginEnabled;
private static boolean noCheatPlusPluginEnabled;
private static boolean compatNoCheatPlusPluginEnabled;
private static boolean tagapiPluginEnabled;
private static boolean mcpcEnabled;
// Config Validation Check
@@ -131,6 +132,7 @@ public class mcMMO extends JavaPlugin {
healthBarPluginEnabled = getServer().getPluginManager().getPlugin("HealthBar") != null;
noCheatPlusPluginEnabled = getServer().getPluginManager().getPlugin("NoCheatPlus") != null;
compatNoCheatPlusPluginEnabled = getServer().getPluginManager().getPlugin("CompatNoCheatPlus") != null;
tagapiPluginEnabled = getServer().getPluginManager().getPlugin("TagAPI") != null && checkTagVersion();
setupFilePaths();
@@ -251,10 +253,6 @@ public class mcMMO extends JavaPlugin {
return flatFileDirectory;
}
public static String getUsersDirectory() {
return usersDirectory;
}
public static String getUsersFilePath() {
return usersFile;
}
@@ -331,7 +329,6 @@ public class mcMMO extends JavaPlugin {
mcmmo = getFile();
mainDirectory = getDataFolder().getPath() + File.separator;
flatFileDirectory = mainDirectory + "flatfile" + File.separator;
usersDirectory = flatFileDirectory + "users" + File.separator;
usersFile = flatFileDirectory + "mcmmo.users";
modDirectory = mainDirectory + "mods" + File.separator;
fixFilePaths();
@@ -451,6 +448,10 @@ public class mcMMO extends JavaPlugin {
pluginManager.registerEvents(new InventoryListener(this), this);
pluginManager.registerEvents(new SelfListener(), this);
pluginManager.registerEvents(new WorldListener(this), this);
if (tagapiPluginEnabled) {
pluginManager.registerEvents(new TagListener(), this);
}
}
private void registerCustomRecipes() {
@@ -515,4 +516,17 @@ public class mcMMO extends JavaPlugin {
getLogger().info("To enable, set Mods.Entity_Mods_Enabled to TRUE in config.yml.");
}
}
private boolean checkTagVersion() {
try {
Class.forName("org.kitteh.tag.AsyncPlayerReceiveNameTagEvent");
}
catch (final ClassNotFoundException e) {
getLogger().info("This TagAPI version does not have AsyncPlayerReceiveNameTagEvent");
getLogger().info("Please update TagAPI to ensure full compatibility with mcMMO");
return false;
}
return true;
}
}

View File

@@ -224,6 +224,15 @@ public class ScoreboardManager {
}
}
// Called by internal TagAPI event listener
public static void tagUpdate(Player player) {
String playerName = player.getName();
if (Config.getInstance().getPowerLevelTagsEnabled() && !dirtyPowerLevels.contains(playerName)) {
dirtyPowerLevels.add(playerName);
}
}
// **** Setup methods **** //
public static void enablePlayerSkillScoreboard(Player player, SkillType skill) {
@@ -342,6 +351,10 @@ public class ScoreboardManager {
for (ScoreboardWrapper wrapper : PLAYER_SCOREBOARDS.values()) {
wrapper.updatePowerLevel(player, power);
if (mcMMOPlayer.getNameTag() != null) {
wrapper.updatePowerLevel(mcMMO.p.getServer().getOfflinePlayer(mcMMOPlayer.getNameTag()), power);
}
}
}

View File

@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
@@ -558,4 +559,8 @@ public class ScoreboardWrapper {
public void updatePowerLevel(Player player, int newPowerLevel) {
powerObjective.getScore(player).setScore(newPowerLevel);
}
public void updatePowerLevel(OfflinePlayer offlinePlayer, int newPowerLevel) {
powerObjective.getScore(offlinePlayer).setScore(newPowerLevel);
}
}