diff --git a/README.md b/README.md
index 094581106..560f5cf9e 100644
--- a/README.md
+++ b/README.md
@@ -47,5 +47,6 @@ Required Libraries:
* JUnit
* EMetrics
* Bukkit
+* TagAPI
http://dev.bukkit.org/server-mods/mcmmo for more up to date information.
diff --git a/pom.xml b/pom.xml
index 34d451fe4..6e24ce369 100755
--- a/pom.xml
+++ b/pom.xml
@@ -116,6 +116,10 @@
Plugin MetricsExtension
http://repo.turt2live.com
+
+ TagAPI
+ http://repo.kitteh.org/content/repositories/public/
+
@@ -136,6 +140,12 @@
MetricsExtension
0.0.5-SNAPSHOT
+
+ org.kitteh
+ tagapi
+ LATEST
+ compile
+
diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java
index 9bcdb3e0e..d4bc6499f 100644
--- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java
+++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java
@@ -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;
+ }
}
diff --git a/src/main/java/com/gmail/nossr50/listeners/TagListener.java b/src/main/java/com/gmail/nossr50/listeners/TagListener.java
new file mode 100644
index 000000000..76fdb9dbf
--- /dev/null
+++ b/src/main/java/com/gmail/nossr50/listeners/TagListener.java
@@ -0,0 +1,57 @@
+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 org.kitteh.tag.AsyncPlayerReceiveNameTagEvent;
+
+public class TagListener implements Listener {
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onAsyncPlayerReceiveNameTag(AsyncPlayerReceiveNameTagEvent event) {
+ Player player = event.getNamedPlayer();
+ McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
+
+ 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);
+ }
+
+ /*
+ 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.
+ */
+ }
+}
diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java
index 4cbee75a0..2647db6b2 100644
--- a/src/main/java/com/gmail/nossr50/mcMMO.java
+++ b/src/main/java/com/gmail/nossr50/mcMMO.java
@@ -29,6 +29,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;
@@ -89,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
@@ -130,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();
@@ -445,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() {
@@ -509,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;
+ }
}
diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java
index 155952705..e4c34e560 100644
--- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java
+++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java
@@ -342,6 +342,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);
+ }
}
}
diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java
index 7c39d066b..0a5e9fd59 100644
--- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java
+++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java
@@ -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);
+ }
}