Add setNameVisible to player disguises
This commit is contained in:
parent
ce292302fe
commit
ead5a23d65
@ -334,6 +334,17 @@ public class DisguiseListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!event.getPlayer().isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DisguiseUtilities.registerNoName(event.getPlayer().getScoreboard());
|
||||
}
|
||||
}.runTaskLater(LibsDisguises.getInstance(), 20);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,6 +28,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
private WrappedGameProfile gameProfile;
|
||||
private String playerName;
|
||||
private String skinToUse;
|
||||
private boolean nameVisible = true;
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
|
||||
private PlayerDisguise() {
|
||||
@ -86,6 +87,32 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isNameVisible() {
|
||||
return nameVisible;
|
||||
}
|
||||
|
||||
public PlayerDisguise setNameVisible(boolean nameVisible) {
|
||||
if (isNameVisible() == nameVisible) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
if (stopDisguise()) {
|
||||
this.nameVisible = nameVisible;
|
||||
|
||||
if (!startDisguise()) {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
this.nameVisible = nameVisible;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise addPlayer(Player player) {
|
||||
return (PlayerDisguise) super.addPlayer(player);
|
||||
@ -110,6 +137,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
disguise.setSkin(getSkin());
|
||||
}
|
||||
|
||||
disguise.setNameVisible(isNameVisible());
|
||||
disguise.setReplaceSounds(isSoundsReplaced());
|
||||
disguise.setViewSelfDisguise(isSelfDisguiseVisible());
|
||||
disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
|
||||
@ -215,12 +243,28 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
public void setName(String name) {
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
|
||||
playerName = name;
|
||||
if (name.equals(playerName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDisguiseInUse()) {
|
||||
if (stopDisguise()) {
|
||||
playerName = name;
|
||||
|
||||
if (!startDisguise()) {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to restart disguise");
|
||||
}
|
||||
} else {
|
||||
playerName = name;
|
||||
}
|
||||
|
||||
// Scare monger for the pirates of a certain site.
|
||||
if (LibsPremium.getUserID().equals("12345")) {
|
||||
|
@ -855,7 +855,7 @@ public class DisguiseUtilities {
|
||||
return gson;
|
||||
}
|
||||
|
||||
public static void init(LibsDisguises disguises) {
|
||||
public static void init() {
|
||||
try {
|
||||
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
|
||||
}
|
||||
@ -904,6 +904,12 @@ public class DisguiseUtilities {
|
||||
getLogger().warning("The file '" + key + "' does not belong in " + savedDisguises.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
registerNoName(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
registerNoName(player.getScoreboard());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||
@ -1208,6 +1214,18 @@ public class DisguiseUtilities {
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public static void registerNoName(Scoreboard scoreboard) {
|
||||
Team mainTeam = scoreboard.getTeam("LD_NoName");
|
||||
|
||||
if (mainTeam == null) {
|
||||
mainTeam = scoreboard.registerNewTeam("LD_NoName");
|
||||
mainTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
|
||||
mainTeam.addEntry("");
|
||||
} else if (!mainTeam.hasEntry("")) {
|
||||
mainTeam.addEntry("");
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeSelfDisguiseScoreboard(Player player) {
|
||||
String originalTeam = preDisguiseTeam.remove(player.getUniqueId());
|
||||
String teamDisguise = disguiseTeam.remove(player.getUniqueId());
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
@ -9,11 +8,9 @@ import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||
@ -28,7 +25,6 @@ import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -36,6 +32,7 @@ import org.bukkit.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 3/01/2019.
|
||||
@ -159,29 +156,40 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||
|
||||
String name = playerDisguise.getName();
|
||||
WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
|
||||
WrappedGameProfile spawnProfile = playerDisguise.isNameVisible() ? playerDisguise.getGameProfile() :
|
||||
ReflectionManager.getGameProfileWithThisSkin(UUID.randomUUID(), "",
|
||||
playerDisguise.getGameProfile());
|
||||
|
||||
int entityId = disguisedEntity.getEntityId();
|
||||
|
||||
// Send player info along with the disguise
|
||||
PacketContainer sendTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
if (!playerDisguise.isDisplayedInTab() || !playerDisguise.isNameVisible()) {
|
||||
// Send player info along with the disguise
|
||||
PacketContainer sendTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
||||
// Add player to the list, necessary to spawn them
|
||||
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
||||
|
||||
List playerList = Collections
|
||||
.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), gameProfile));
|
||||
.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), spawnProfile));
|
||||
sendTab.getModifier().write(1, playerList);
|
||||
|
||||
packets.addPacket(sendTab);
|
||||
|
||||
// Remove player from the list
|
||||
PacketContainer deleteTab = sendTab.shallowClone();
|
||||
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||
|
||||
if (LibsPremium.getPaidInformation() == null ||
|
||||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
packets.addDelayedPacket(deleteTab, DisguiseConfig.getPlayerDisguisesTablistExpires());
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn the player
|
||||
PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||
|
||||
spawnPlayer.getIntegers().write(0, entityId); // Id
|
||||
spawnPlayer.getModifier().write(1, gameProfile.getUUID());
|
||||
spawnPlayer.getModifier().write(1, spawnProfile.getUUID());
|
||||
|
||||
Location spawnAt = disguisedEntity.getLocation();
|
||||
|
||||
@ -256,17 +264,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
packets.addDelayedPacket(metaPacket, 7);
|
||||
packets.setRemoveMetaAt(7);
|
||||
}
|
||||
|
||||
// Remove player from the list
|
||||
PacketContainer deleteTab = sendTab.shallowClone();
|
||||
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||
|
||||
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
||||
if (LibsPremium.getPaidInformation() == null ||
|
||||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
packets.addDelayedPacket(deleteTab, DisguiseConfig.getPlayerDisguisesTablistExpires());
|
||||
}
|
||||
}
|
||||
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||
Vector vec = disguisedEntity.getVelocity();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user