Skip to content

Commit

Permalink
fixed flickering icons in layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguygab committed Mar 14, 2021
1 parent 2bc0b2c commit 83339c1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.tanguygab.tabadditions.shared.features.layouts;

import com.mojang.authlib.properties.PropertyMap;
import io.github.tanguygab.tabadditions.shared.ConfigType;
import io.github.tanguygab.tabadditions.shared.PlatformType;
import io.github.tanguygab.tabadditions.shared.TABAdditions;
Expand Down Expand Up @@ -27,8 +28,8 @@ public class Layout {
private final Map<Object, List<Integer>> playersets = new HashMap<>();
private final Map<Object,Sorting> sorting = new HashMap<>();

Map<TabPlayer, Map<Integer, Object>> skinsp = new HashMap<>();
Map<TabPlayer, Map<Integer, Object>> skinss = new HashMap<>();
Map<TabPlayer, Map<Integer, String>> skinsp = new HashMap<>();
Map<TabPlayer, Map<Integer, String>> skinss = new HashMap<>();

public Layout(String name) {
this.name = name;
Expand All @@ -54,9 +55,9 @@ protected boolean isConditionMet(TabPlayer p) {

protected void refreshPlaceholders() {
if(!created) return;
Map<Integer, Object> skins = new HashMap<>();
ArrayList<TabPlayer> list = new ArrayList<>(players);
for (TabPlayer p : list) {
Map<Integer, String> skins = new HashMap<>();
for (Integer i : placeholders.keySet()) {
PacketPlayOutPlayerInfo.PlayerInfoData fp = fakeplayers.get(i);
Map<String, Object> slot = placeholders.get(i);
Expand All @@ -71,14 +72,17 @@ protected void refreshPlaceholders() {
}

Object skin = null;
if (slot.containsKey("icon"))
String icon = "";
if (slot.containsKey("icon")) {
skin = TABAdditions.getInstance().getSkins().getIcon(slot.get("icon")+"", p);
if (!skinsp.containsKey(p) || (skin != null && skinsp.get(p).get(i) != skin)) {
icon = TABAdditions.getInstance().parsePlaceholders(slot.get("icon")+"",p);
}
if (!skinsp.containsKey(p) || (skin != null && !skinsp.get(p).get(i).equals(icon))) {
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId)));
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.name, fp.uniqueId, skin, 0, PacketPlayOutPlayerInfo.EnumGamemode.CREATIVE, IChatBaseComponent.fromColoredText(text))));
} else
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId, IChatBaseComponent.fromColoredText(text))));
skins.put(i, skin);
skins.put(i, icon);
p.sendCustomPacket(new PacketPlayOutScoreboardScore(PacketPlayOutScoreboardScore.Action.CHANGE, "TAB-YellowNumber", fp.name, 0));
}
skinsp.put(p, skins);
Expand All @@ -88,11 +92,11 @@ protected void refreshPlaceholders() {
protected void refreshSets() {
if(!created) return;

Map<Integer,Object> skins = new HashMap<>();
ArrayList<TabPlayer> list = new ArrayList<>(players);
Map<Object, List<Integer>> playersets = new HashMap<>(this.playersets);

for (TabPlayer p : list) {
Map<Integer,String> skins = new HashMap<>();
for (Object set : playersets.keySet()) {
List<TabPlayer> pset = playerSet(set);
int inList = 0;
Expand All @@ -118,20 +122,23 @@ protected void refreshSets() {
if (pset.size() <= inList || vanished || pInSet == null) {
String format = "";
Object skin = null;
String icon = "";
if (setConfig.containsKey("empty")) {
Map<String,String> empty = (Map<String, String>) setConfig.get("empty");
Map<String, String> empty = (Map<String, String>) setConfig.get("empty");
if (empty.containsKey("text"))
format = TABAdditions.getInstance().parsePlaceholders(empty.get("text"), p);
if (empty.containsKey("icon"))
skin = TABAdditions.getInstance().getSkins().getIcon(empty.get("icon")+"",p);
if (empty.containsKey("icon")) {
skin = TABAdditions.getInstance().getSkins().getIcon(empty.get("icon") + "", p);
icon = TABAdditions.getInstance().parsePlaceholders(empty.get("icon"), p);
}
if (!skinss.containsKey(p) || (!skinss.get(p).get(i).equals(icon))) {
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId)));
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.name, fp.uniqueId, skin, 0, PacketPlayOutPlayerInfo.EnumGamemode.CREATIVE, IChatBaseComponent.fromColoredText(format))));
} else
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId, IChatBaseComponent.fromColoredText(format))));
skins.put(i, icon);
p.sendCustomPacket(new PacketPlayOutScoreboardScore(PacketPlayOutScoreboardScore.Action.CHANGE, "TAB-YellowNumber", fp.name, 0));
}
if (!skinss.containsKey(p) || (skinss.get(p).get(i) != skin)) {
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId)));
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.name, fp.uniqueId, skin, 0, PacketPlayOutPlayerInfo.EnumGamemode.CREATIVE, IChatBaseComponent.fromColoredText(format))));
} else
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId, IChatBaseComponent.fromColoredText(format))));
skins.put(i,skin);
p.sendCustomPacket(new PacketPlayOutScoreboardScore(PacketPlayOutScoreboardScore.Action.CHANGE, "TAB-YellowNumber", fp.name, 0));
} else {
String format = "%player%";
if (setConfig.containsKey("text")) format = setConfig.get("text")+"";
Expand All @@ -153,15 +160,18 @@ protected void refreshSets() {
catch (NumberFormatException ignored) {}

Object skin = pInSet.getSkin();
if (setConfig.containsKey("icon"))
skin = TABAdditions.getInstance().getSkins().getIcon(setConfig.get("icon")+"",pInSet);
if (!skinss.containsKey(p) || (skin != null && skinss.get(p).get(i) != skin)) {
String icon = "player-head:"+pInSet.getName();
if (setConfig.containsKey("icon")) {
skin = TABAdditions.getInstance().getSkins().getIcon(setConfig.get("icon") + "", pInSet);
icon = TABAdditions.getInstance().parsePlaceholders(setConfig.get("icon")+"",pInSet);
}
if (!skinss.containsKey(p) || (skin != null && !skinss.get(p).get(i).equals(icon))) {
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId)));
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.name, fp.uniqueId, skin, 0, PacketPlayOutPlayerInfo.EnumGamemode.CREATIVE, IChatBaseComponent.fromColoredText(format))));
}
else
p.sendCustomPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, new PacketPlayOutPlayerInfo.PlayerInfoData(fp.uniqueId, IChatBaseComponent.fromColoredText(format))));
skins.put(i,skin);
skins.put(i,icon);
p.sendCustomPacket(new PacketPlayOutScoreboardScore(PacketPlayOutScoreboardScore.Action.CHANGE, "TAB-YellowNumber", fp.name, yellownumber2));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void load() {
for (Object layout : TABAdditions.getInstance().getConfig(ConfigType.LAYOUT).getConfigurationSection("layouts").keySet())
layouts.put(layout+"",new Layout(layout.toString()));
togglecmd = TABAdditions.getInstance().getConfig(ConfigType.LAYOUT).getString("toggle-cmd","layout");
refresh();
showLayoutAll();
refresh();
}

@Override
Expand Down Expand Up @@ -114,14 +114,12 @@ public void showLayoutAll() {
if (!TABAdditions.getInstance().checkBedrock(p))
toAdd.put(p,getLayout(p));
}

public void removeLayoutAll() {
for (TabPlayer p : TAB.getInstance().getPlayers())
if (!TABAdditions.getInstance().checkBedrock(p))
toRemove.put(p,getLayout(p));
}


@Override
public boolean onCommand(TabPlayer p, String msg) {
if (msg.equals("/"+togglecmd) || msg.startsWith("/"+togglecmd+" ")) {
Expand Down

0 comments on commit 83339c1

Please sign in to comment.