Use scoreboard for display names

This commit is contained in:
libraryaddict 2017-08-06 12:23:47 +12:00
parent 833ea9531e
commit d5913354e4
6 changed files with 35 additions and 30 deletions

View File

@ -8,7 +8,10 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
@ -17,7 +20,6 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsMsg;
import me.libraryaddict.disguise.utilities.UpdateChecker;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@ -37,6 +39,7 @@ import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@ -450,7 +453,11 @@ public class DisguiseListener implements Listener {
} else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName());
disguise.getWatcher().setCustomName(
(team == null ? "" : team.getPrefix()) + entity.getName() + (team == null ? "" :
team.getSuffix()));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);

View File

@ -6,11 +6,15 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
/**
* @author libraryaddict
@ -36,6 +40,12 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
return new ArrayList<>(new HashSet<>(list));
}
protected String getDisplayName(CommandSender player) {
Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName());
return (team == null ? "" : team.getPrefix()) + player.getName() + (team == null ? "" : team.getSuffix());
}
protected ArrayList<String> getAllowedDisguises(
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> hashMap) {
ArrayList<String> allowedDisguises = new ArrayList<>();

View File

@ -61,7 +61,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
disguise.getWatcher().setCustomName(getDisplayName(sender));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);

View File

@ -86,7 +86,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(player.getDisplayName());
disguise.getWatcher().setCustomName(getDisplayName(sender));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);

View File

@ -172,7 +172,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
disguise.getWatcher().setCustomName(getDisplayName(entity));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}

View File

@ -23,22 +23,17 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
public class PacketListenerClientInteract extends PacketAdapter
{
public PacketListenerClientInteract(LibsDisguises plugin)
{
public class PacketListenerClientInteract extends PacketAdapter {
public PacketListenerClientInteract(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY);
}
@Override
public void onPacketReceiving(PacketEvent event)
{
public void onPacketReceiving(PacketEvent event) {
if (event.isCancelled())
return;
try
{
try {
Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
@ -48,42 +43,35 @@ public class PacketListenerClientInteract extends PacketAdapter
Entity entity = entityModifer.read(0);
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || entity == observer)
{
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow || entity == observer) {
event.setCancelled(true);
}
for (ItemStack item : new ItemStack[]
{
observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()
})
{
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(),
observer.getInventory().getItemInOffHand()}) {
if (item == null || item.getType() != Material.INK_SACK)
continue;
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null || (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF))
if (disguise == null || (disguise.getType() != DisguiseType.SHEEP && disguise
.getType() != DisguiseType.WOLF))
continue;
AnimalColor color = AnimalColor.getColor(item.getDurability());
if (disguise.getType() == DisguiseType.SHEEP)
{
if (disguise.getType() == DisguiseType.SHEEP) {
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
}
else
{
} else {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
}
}
}
catch (Exception e)
{
catch (Exception e) {
e.printStackTrace();
}
}