Skip to content

Commit

Permalink
[Scoreboard & Nametags] Add a config option to enforce <1.13 limits e…
Browse files Browse the repository at this point in the history
…ven for 1.13+ players (#1412, #1413)
  • Loading branch information
NEZNAMY committed Jan 19, 2025
1 parent 390c239 commit 968cef7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private Object newObjective(@NonNull Objective objective) {
// 1.5 - 1.12.2
Object nmsObjective = newScoreboardObjective.newInstance(emptyScoreboard, objective.getName(), IScoreboardCriteria_dummy);
String title = objective.getTitle().toLegacyText();
if (player.getVersion().getMinorVersion() < 13) {
if (player.getVersion().getMinorVersion() < 13 || TAB.getInstance().getConfiguration().getConfig().isPacketEventsCompensation()) {
title = cutTo(title, Limitations.SCOREBOARD_TITLE_PRE_1_13);
}
ScoreboardObjective_setDisplayName.invoke(nmsObjective, title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.neznamy.tab.platforms.bukkit.nms.BukkitReflection;
import me.neznamy.tab.shared.Limitations;
import me.neznamy.tab.shared.ProtocolVersion;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.platform.decorators.SafeScoreboard;
import me.neznamy.tab.shared.platform.decorators.SafeScoreboard.Team;
import me.neznamy.tab.shared.platform.Scoreboard;
Expand Down Expand Up @@ -230,7 +231,7 @@ private void updateTeamData(@NonNull Team team, @NotNull ProtocolVersion clientV
} else {
String prefix = team.getPrefix().toLegacyText();
String suffix = team.getSuffix().toLegacyText();
if (clientVersion.getMinorVersion() < 13) {
if (clientVersion.getMinorVersion() < 13 || TAB.getInstance().getConfiguration().getConfig().isPacketEventsCompensation()) {
prefix = SafeScoreboard.cutTo(prefix, Limitations.TEAM_PREFIX_SUFFIX_PRE_1_13);
suffix = SafeScoreboard.cutTo(suffix, Limitations.TEAM_PREFIX_SUFFIX_PRE_1_13);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Config {
@NotNull private final String serverName = getSecretOption("server-name", "N/A");
private final int permissionRefreshInterval = config.getInt("permission-refresh-interval", 1000);
private final boolean enableRedisHook = config.getBoolean("enable-redisbungee-support", true);
private final boolean packetEventsCompensation = config.getBoolean("compensate-for-packetevents-bug", false);

/** If enabled, groups are assigned via permissions instead of permission plugin */
private final boolean groupsByPermissions = config.getBoolean("assign-groups-by-permissions", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.NonNull;
import me.neznamy.tab.shared.Limitations;
import me.neznamy.tab.shared.Property;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.platform.TabPlayer;
import me.neznamy.tab.shared.features.scoreboard.ScoreboardImpl;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void refresh(@NotNull TabPlayer refreshed, boolean force) {
if (refreshed.scoreboardData.activeScoreboard != parent) return; //player has different scoreboard displayed
Property lineProperty = refreshed.scoreboardData.lineProperties.get(this);
if (lineProperty.update()) {
if (refreshed.getVersion().getMinorVersion() >= 13) {
if (refreshed.getVersion().getMinorVersion() >= 13 && !TAB.getInstance().getConfiguration().getConfig().isPacketEventsCompensation()) {
updateTeam(refreshed, lineProperty.get(), "");
} else {
removeLine(refreshed, refreshed.scoreboardData.lineNameProperties.get(this).get());
Expand All @@ -55,7 +56,7 @@ public void register(@NonNull TabPlayer p) {
p.scoreboardData.lineProperties.put(this, new Property(this, p, text));
getScoreRefresher().registerProperties(p);
String value = p.scoreboardData.lineProperties.get(this).get();
if (p.getVersion().getMinorVersion() >= 13) {
if (p.getVersion().getMinorVersion() >= 13 && !TAB.getInstance().getConfiguration().getConfig().isPacketEventsCompensation()) {
addLine(p, playerName, value, "");
p.scoreboardData.lineNameProperties.put(this, new Property(this, p, playerName));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.NonNull;
import me.neznamy.tab.shared.Limitations;
import me.neznamy.tab.shared.Property;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.chat.EnumChatFormat;
import me.neznamy.tab.shared.features.scoreboard.ScoreboardImpl;
import me.neznamy.tab.shared.platform.TabPlayer;
Expand Down Expand Up @@ -107,7 +108,7 @@ private String[] replaceText(TabPlayer p, boolean force, boolean suppressToggle)
* @return array of 2 elements for prefix and suffix
*/
private String[] split(@NonNull TabPlayer p, @NonNull String text) {
if (p.getVersion().getMinorVersion() >= 13) return new String[] {text, ""};
if (p.getVersion().getMinorVersion() >= 13 && !TAB.getInstance().getConfiguration().getConfig().isPacketEventsCompensation()) return new String[] {text, ""};
int charLimit = Limitations.TEAM_PREFIX_SUFFIX_PRE_1_13;
if (text.length() > charLimit) {
StringBuilder prefix = new StringBuilder(text);
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ per-world-playerlist:
- paintball
- bedwars

compensate-for-packetevents-bug: false

#####################################################################
# PROXY ONLY - THE FOLLOWING SECTION IS ONLY FOR PROXY INSTALLATION #
#####################################################################
Expand Down

0 comments on commit 968cef7

Please sign in to comment.