Skip to content

Commit

Permalink
Fix lag when fake players are created repeatedly (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts authored Jun 10, 2024
1 parent 8d19f18 commit 86ad4aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import serverutils.lib.math.BlockDimPos;
import serverutils.lib.math.TeleporterDimPos;
import serverutils.lib.util.NBTUtils;
import serverutils.lib.util.ServerUtils;
import serverutils.lib.util.StringUtils;
import serverutils.lib.util.misc.IScheduledTask;
import serverutils.lib.util.misc.TimeType;
Expand Down Expand Up @@ -299,7 +300,7 @@ public void checkTeleportCooldown(ICommandSender sender, Timer timer) throws Com
@Override
public void clearCache() {
cachedNameForChat = null;

if (player.isFake()) return;
EntityPlayerMP p = player.getNullablePlayer();

if (p != null) {
Expand All @@ -308,6 +309,10 @@ public void clearCache() {
}

public IChatComponent getNameForChat(EntityPlayerMP playerMP) {
if (ServerUtils.isFake(playerMP)) {
return new ChatComponentText(player.getName());
}

if (cachedNameForChat != null) {
return cachedNameForChat.createCopy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ public void onBlockPlace(BlockEvent.PlaceEvent event) {

@SubscribeEvent(priority = EventPriority.LOW)
public void onNameFormat(PlayerEvent.NameFormat event) {
if (ServerUtilitiesConfig.commands.nick && Universe.loaded() && event.entityPlayer instanceof EntityPlayerMP) {
ForgePlayer p = Universe.get().getPlayer(event.entityPlayer.getGameProfile());
if (!(event.entityPlayer instanceof EntityPlayerMP player) || ServerUtils.isFake(player)) return;
if (ServerUtilitiesConfig.commands.nick && Universe.loaded()) {
ForgePlayer p = Universe.get().getPlayer(player);

if (p != null) {
ServerUtilitiesPlayerData data = ServerUtilitiesPlayerData.get(p);

if (!data.getNickname().isEmpty() && PermissionAPI
.hasPermission(event.entityPlayer, ServerUtilitiesPermissions.CHAT_NICKNAME_SET)) {
if (!data.getNickname().isEmpty()
&& PermissionAPI.hasPermission(player, ServerUtilitiesPermissions.CHAT_NICKNAME_SET)) {
String name = StringUtils.addFormatting(data.getNickname());

if (!p.hasPermission(ServerUtilitiesPermissions.CHAT_NICKNAME_COLORS)) {
Expand Down

0 comments on commit 86ad4aa

Please sign in to comment.