mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
First step in starting to fix this issue
This commit is contained in:
parent
8deac175d1
commit
ccdab96650
@ -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
10
pom.xml
@ -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>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
57
src/main/java/com/gmail/nossr50/listeners/TagListener.java
Normal file
57
src/main/java/com/gmail/nossr50/listeners/TagListener.java
Normal file
@ -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.
|
||||
*/
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user