mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2026-01-06 15:42:00 +00:00
improve team management
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.BossBarManager;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.DisplayController;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.ConfigUtils;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.bossbar;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.requirement.Condition;
|
||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.DisplayController;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ import net.kyori.adventure.text.minimessage.internal.parser.node.TagNode;
|
||||
import net.kyori.adventure.text.minimessage.internal.parser.node.ValueNode;
|
||||
import net.kyori.adventure.text.minimessage.tag.Inserting;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.Key;
|
||||
import net.momirealms.customnameplates.common.Tuple;
|
||||
import net.momirealms.customnameplates.api.manager.WidthManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.background.BackGround;
|
||||
import net.momirealms.customnameplates.api.mechanic.character.ConfiguredChar;
|
||||
@@ -22,6 +20,8 @@ import net.momirealms.customnameplates.api.mechanic.font.FontData;
|
||||
import net.momirealms.customnameplates.api.mechanic.font.OffsetFont;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Key;
|
||||
import net.momirealms.customnameplates.common.Tuple;
|
||||
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
|
||||
import net.momirealms.customnameplates.paper.setting.CNConfig;
|
||||
import net.momirealms.customnameplates.paper.util.ConfigUtils;
|
||||
@@ -32,7 +32,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.misc;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@@ -30,4 +31,15 @@ public class PacketManager {
|
||||
this.plugin.debug("Packet sent: " + packet.getType() + " to " + player.getName());
|
||||
this.protocolManager.sendServerPacket(player, packet);
|
||||
}
|
||||
|
||||
public void send(Player player, PacketContainer... packets) {
|
||||
if (plugin.getVersionManager().isVersionNewerThan1_20()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BUNDLE);
|
||||
|
||||
} else {
|
||||
for (PacketContainer packet : packets) {
|
||||
send(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ import net.momirealms.customnameplates.api.mechanic.nameplate.Nameplate;
|
||||
import net.momirealms.customnameplates.api.mechanic.nameplate.TagMode;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.NameplatePlayer;
|
||||
import net.momirealms.customnameplates.api.mechanic.tag.unlimited.UnlimitedTagSetting;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.scheduler.CancellableTask;
|
||||
import net.momirealms.customnameplates.api.util.FontUtils;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.listener.*;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.team.TeamTagManagerImpl;
|
||||
import net.momirealms.customnameplates.paper.mechanic.nameplate.tag.unlimited.UnlimitedTagManagerImpl;
|
||||
@@ -36,6 +36,7 @@ import org.bukkit.event.entity.EntityPoseChangeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -270,10 +271,12 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
var player = event.getPlayer();
|
||||
this.putEntityIDToMap(player.getEntityId(), player);
|
||||
if (!CNConfig.isOtherTeamPluginHooked())
|
||||
if (!proxyMode) plugin.getTeamManager().createTeam(player);
|
||||
else plugin.getTeamManager().createProxyTeam(player);
|
||||
this.createNameTag(player);
|
||||
if (!CNConfig.isOtherTeamPluginHooked() && !isProxyMode())
|
||||
plugin.getTeamManager().createTeam(player);
|
||||
plugin.getScheduler().runTaskAsyncLater(() -> {
|
||||
if (player.isOnline())
|
||||
this.createNameTag(player);
|
||||
}, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -285,7 +288,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
this.teamTagManager.handlePlayerQuit(player);
|
||||
this.unlimitedTagManager.handlePlayerQuit(player);
|
||||
|
||||
if (!proxyMode && !CNConfig.isOtherTeamPluginHooked()) {
|
||||
if (!CNConfig.isOtherTeamPluginHooked() && !isProxyMode()) {
|
||||
plugin.getTeamManager().removeTeam(player);
|
||||
}
|
||||
}
|
||||
@@ -500,7 +503,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
|
||||
@Override
|
||||
public boolean isProxyMode() {
|
||||
return proxyMode;
|
||||
return CNConfig.velocitab;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -535,6 +538,7 @@ public class NameplateManagerImpl implements NameplateManager, Listener {
|
||||
return nameplate == null ? TeamColor.WHITE : nameplate.getTeamColor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDefaultNameplate() {
|
||||
return defaultNameplate;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.placeholder;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.PlaceholderManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.placeholder.*;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -19,12 +19,12 @@ package net.momirealms.customnameplates.paper.mechanic.requirement;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.biomeapi.BiomeAPI;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.manager.RequirementManager;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.requirement.RequirementExpansion;
|
||||
import net.momirealms.customnameplates.api.requirement.RequirementFactory;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
|
||||
import net.momirealms.customnameplates.paper.util.ClassUtils;
|
||||
import net.momirealms.customnameplates.paper.util.ConfigUtils;
|
||||
|
||||
@@ -4,17 +4,14 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.manager.TeamManager;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.*;
|
||||
import net.momirealms.customnameplates.common.message.MessageType;
|
||||
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.packet.TeamPacketAdaptor;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.packet.TeamPacket_1_17;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.packet.*;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.provider.CMIProvider;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.provider.DefaultProvider;
|
||||
import net.momirealms.customnameplates.paper.mechanic.team.provider.TABProvider;
|
||||
@@ -32,64 +29,53 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
|
||||
private final CustomNameplatesPlugin plugin;
|
||||
private final TeamPacketAdaptor teamPacketAdaptor;
|
||||
private final TeamProvider teamProvider;
|
||||
private TeamProvider teamProvider;
|
||||
private static final String CHANNEL = "customnameplates:cnp";
|
||||
|
||||
public TeamManagerImpl(CustomNameplatesPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.teamPacketAdaptor = new TeamPacket_1_17();
|
||||
if (CNConfig.tabTeam) {
|
||||
teamProvider = new TABProvider();
|
||||
} else if (CNConfig.cmiTeam) {
|
||||
teamProvider = new CMIProvider();
|
||||
} else {
|
||||
teamProvider = new DefaultProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTeam(Player player) {
|
||||
if (CNConfig.isOtherTeamPluginHooked()) {
|
||||
return;
|
||||
}
|
||||
if (CNConfig.disableTeamManage) return;
|
||||
PacketContainer createOwner = teamPacketAdaptor.getTeamCreatePacket(
|
||||
TeamCreatePacket.builder()
|
||||
TeamCreate.builder()
|
||||
.teamName(teamProvider.getTeam(player))
|
||||
.color(TeamColor.WHITE)
|
||||
.prefix(Component.text(""))
|
||||
.suffix(Component.text(""))
|
||||
.display("")
|
||||
.prefix("")
|
||||
.suffix("")
|
||||
.members(Collections.singletonList(player.getName()))
|
||||
.collisionRule(TeamCollisionRule.ALWAYS)
|
||||
.tagVisibility(TeamTagVisibility.ALWAYS)
|
||||
.build()
|
||||
);
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
PacketManager.getInstance().send(online, createOwner);
|
||||
if (online == player) continue;
|
||||
PacketContainer createOther = teamPacketAdaptor.getTeamCreatePacket(
|
||||
TeamCreatePacket.builder()
|
||||
TeamCreate.builder()
|
||||
.teamName(teamProvider.getTeam(online))
|
||||
.color(TeamColor.WHITE)
|
||||
.prefix(Component.text(""))
|
||||
.suffix(Component.text(""))
|
||||
.display("")
|
||||
.prefix("")
|
||||
.suffix("")
|
||||
.members(Collections.singletonList(online.getName()))
|
||||
.collisionRule(TeamCollisionRule.ALWAYS)
|
||||
.tagVisibility(TeamTagVisibility.ALWAYS)
|
||||
.build()
|
||||
);
|
||||
PacketManager.getInstance().send(player, createOther);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createProxyTeam(Player player) {
|
||||
sendPluginMessage(
|
||||
MessageType.CREATE,
|
||||
player.getUniqueId().toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTeam(Player player) {
|
||||
if (CNConfig.isOtherTeamPluginHooked()) return;
|
||||
if (CNConfig.disableTeamManage) return;
|
||||
PacketContainer packet = teamPacketAdaptor.getTeamRemovePacket(
|
||||
TeamRemovePacket.builder()
|
||||
TeamRemove.builder()
|
||||
.teamName(teamProvider.getTeam(player))
|
||||
.build()
|
||||
);
|
||||
@@ -100,15 +86,8 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeProxyTeam(Player player) {
|
||||
this.sendPluginMessage(
|
||||
MessageType.REMOVE,
|
||||
player.getName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTeam(Player owner, Player viewer, Component prefix, Component suffix, TeamColor color, TeamTagVisibility visibility) {
|
||||
public void updateTeam(Player owner, Player viewer, String prefix, String suffix, TeamColor color, TeamTagVisibility visibility) {
|
||||
if (CNConfig.disableTeamManage) return;
|
||||
if (color == TeamColor.NONE || color == TeamColor.CUSTOM)
|
||||
color = TeamColor.WHITE;
|
||||
if (plugin.getNameplateManager().isProxyMode()) {
|
||||
@@ -116,19 +95,21 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
MessageType.UPDATE,
|
||||
owner.getName(),
|
||||
viewer.getName(),
|
||||
GsonComponentSerializer.gson().serialize(prefix),
|
||||
GsonComponentSerializer.gson().serialize(suffix),
|
||||
prefix,
|
||||
suffix,
|
||||
color.name(),
|
||||
visibility.name()
|
||||
);
|
||||
} else {
|
||||
PacketContainer packet = teamPacketAdaptor.getTeamUpdatePacket(
|
||||
TeamUpdatePacket.builder()
|
||||
TeamUpdate.builder()
|
||||
.teamName(teamProvider.getTeam(owner))
|
||||
.color(color)
|
||||
.display("")
|
||||
.prefix(prefix)
|
||||
.suffix(suffix)
|
||||
.tagVisibility(visibility)
|
||||
.collisionRule(TeamCollisionRule.ALWAYS)
|
||||
.build()
|
||||
);
|
||||
PacketManager.getInstance().send(viewer, packet);
|
||||
@@ -146,6 +127,13 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (CNConfig.tabTeam) {
|
||||
teamProvider = new TABProvider();
|
||||
} else if (CNConfig.cmiTeam) {
|
||||
teamProvider = new CMIProvider();
|
||||
} else {
|
||||
teamProvider = new DefaultProvider();
|
||||
}
|
||||
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
|
||||
Bukkit.getServer().getMessenger().registerIncomingPluginChannel(plugin, CHANNEL, this);
|
||||
}
|
||||
@@ -179,7 +167,6 @@ public class TeamManagerImpl implements TeamManager, PluginMessageListener {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeByte(messages.length);
|
||||
for (String message : messages) {
|
||||
plugin.debug(message);
|
||||
dataOutput.writeUTF(message);
|
||||
}
|
||||
Bukkit.getOnlinePlayers().stream().findAny().ifPresent(player -> {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.team.packet;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class TeamCreate {
|
||||
|
||||
// String i
|
||||
private String teamName;
|
||||
// Collection<String> j
|
||||
private Collection<String> members;
|
||||
|
||||
/*
|
||||
Optional<b> k
|
||||
*/
|
||||
// IChatBaseComponent a
|
||||
private Object teamDisplay;
|
||||
// IChatBaseComponent b
|
||||
private Object teamPrefix;
|
||||
// IChatBaseComponent c
|
||||
private Object teamSuffix;
|
||||
// String d
|
||||
private TeamTagVisibility tagVisibility;
|
||||
// String e
|
||||
private TeamCollisionRule collisionRule;
|
||||
// Enum f
|
||||
private TeamColor teamColor;
|
||||
|
||||
private TeamCreate() {
|
||||
}
|
||||
|
||||
public TeamCreate(
|
||||
String teamName,
|
||||
Collection<String> members,
|
||||
Component teamDisplay,
|
||||
Component teamPrefix,
|
||||
Component teamSuffix,
|
||||
TeamTagVisibility tagVisibility,
|
||||
TeamCollisionRule collisionRule,
|
||||
TeamColor teamColor
|
||||
) {
|
||||
this.teamName = teamName;
|
||||
this.members = members;
|
||||
this.teamDisplay = teamDisplay;
|
||||
this.teamPrefix = teamPrefix;
|
||||
this.teamSuffix = teamSuffix;
|
||||
this.tagVisibility = tagVisibility;
|
||||
this.collisionRule = collisionRule;
|
||||
this.teamColor = teamColor;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public Collection<String> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public Object getTeamDisplay() {
|
||||
return teamDisplay;
|
||||
}
|
||||
|
||||
public Object getTeamPrefix() {
|
||||
return teamPrefix;
|
||||
}
|
||||
|
||||
public Object getTeamSuffix() {
|
||||
return teamSuffix;
|
||||
}
|
||||
|
||||
public TeamTagVisibility getTagVisibility() {
|
||||
return tagVisibility;
|
||||
}
|
||||
|
||||
public TeamCollisionRule getCollisionRule() {
|
||||
return collisionRule;
|
||||
}
|
||||
|
||||
public TeamColor getTeamColor() {
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final TeamCreate packet;
|
||||
|
||||
public Builder() {
|
||||
this.packet = new TeamCreate();
|
||||
}
|
||||
|
||||
public static Builder of() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder teamName(String name) {
|
||||
packet.teamName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder members(Collection<String> members) {
|
||||
packet.members = members;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder display(String display) {
|
||||
packet.teamDisplay = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(display);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder prefix(String prefix) {
|
||||
packet.teamPrefix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(prefix);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder suffix(String suffix) {
|
||||
packet.teamSuffix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(suffix);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder color(TeamColor color) {
|
||||
packet.teamColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tagVisibility(TeamTagVisibility visibility) {
|
||||
packet.tagVisibility = visibility;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder collisionRule(TeamCollisionRule rule) {
|
||||
packet.collisionRule = rule;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TeamCreate build() {
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.team.packet;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamCreatePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamRemovePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamUpdatePacket;
|
||||
|
||||
public interface TeamPacketAdaptor {
|
||||
|
||||
PacketContainer getTeamCreatePacket(TeamCreatePacket teamCreatePacket);
|
||||
PacketContainer getTeamCreatePacket(TeamCreate teamCreate);
|
||||
|
||||
PacketContainer getTeamUpdatePacket(TeamUpdatePacket teamUpdatePacket);
|
||||
PacketContainer getTeamUpdatePacket(TeamUpdate teamUpdate);
|
||||
|
||||
PacketContainer getTeamRemovePacket(TeamRemovePacket teamRemovePacket);
|
||||
PacketContainer getTeamRemovePacket(TeamRemove teamRemove);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,7 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamCreatePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamRemovePacket;
|
||||
import net.momirealms.customnameplates.api.mechanic.team.TeamUpdatePacket;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -17,52 +12,52 @@ import java.util.Optional;
|
||||
public class TeamPacket_1_17 implements TeamPacketAdaptor {
|
||||
|
||||
@Override
|
||||
public PacketContainer getTeamCreatePacket(TeamCreatePacket teamCreatePacket) {
|
||||
public PacketContainer getTeamCreatePacket(TeamCreate teamCreate) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
// 0 = create team
|
||||
packet.getModifier().write(0,0);
|
||||
packet.getModifier().write(1, teamCreatePacket.getTeamName());
|
||||
packet.getModifier().write(2, teamCreatePacket.getMembers());
|
||||
packet.getModifier().write(1, teamCreate.getTeamName());
|
||||
packet.getModifier().write(2, teamCreate.getMembers());
|
||||
Optional<InternalStructure> optionalInternalStructure = packet.getOptionalStructures().read(0);
|
||||
if (optionalInternalStructure.isPresent()) {
|
||||
InternalStructure is = optionalInternalStructure.get();
|
||||
// Team
|
||||
is.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamCreatePacket.getTeamDisplay())));
|
||||
is.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamCreatePacket.getTeamPrefix())));
|
||||
is.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamCreatePacket.getTeamSuffix())));
|
||||
is.getModifier().write(3, teamCreatePacket.getTagVisibility().getId());
|
||||
is.getModifier().write(4, teamCreatePacket.getCollisionRule().getId());
|
||||
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamCreatePacket.getTeamColor());
|
||||
is.getModifier().write(6, teamCreatePacket.getMembers().size());
|
||||
is.getModifier().write(0, teamCreate.getTeamDisplay());
|
||||
is.getModifier().write(1, teamCreate.getTeamPrefix());
|
||||
is.getModifier().write(2, teamCreate.getTeamSuffix());
|
||||
is.getModifier().write(3, teamCreate.getTagVisibility().getId());
|
||||
is.getModifier().write(4, teamCreate.getCollisionRule().getId());
|
||||
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamCreate.getTeamColor());
|
||||
is.getModifier().write(6, teamCreate.getMembers().size());
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketContainer getTeamRemovePacket(TeamRemovePacket teamRemovePacket) {
|
||||
public PacketContainer getTeamRemovePacket(TeamRemove teamRemove) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
// 1 = remove team
|
||||
packet.getModifier().write(0,1);
|
||||
packet.getStrings().write(0, teamRemovePacket.getTeamName());
|
||||
packet.getStrings().write(0, teamRemove.getTeamName());
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketContainer getTeamUpdatePacket(TeamUpdatePacket teamUpdatePacket) {
|
||||
public PacketContainer getTeamUpdatePacket(TeamUpdate teamUpdate) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);
|
||||
// 2 = update team
|
||||
packet.getModifier().write(0,2);
|
||||
packet.getModifier().write(1, teamUpdatePacket.getTeamName());
|
||||
packet.getModifier().write(1, teamUpdate.getTeamName());
|
||||
Optional<InternalStructure> optionalInternalStructure = packet.getOptionalStructures().read(0);
|
||||
if (optionalInternalStructure.isPresent()) {
|
||||
InternalStructure is = optionalInternalStructure.get();
|
||||
// Team
|
||||
is.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamUpdatePacket.getTeamDisplay())));
|
||||
is.getChatComponents().write(1, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamUpdatePacket.getTeamPrefix())));
|
||||
is.getChatComponents().write(2, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(teamUpdatePacket.getTeamSuffix())));
|
||||
is.getModifier().write(3, teamUpdatePacket.getTagVisibility().getId());
|
||||
is.getModifier().write(4, teamUpdatePacket.getCollisionRule().getId());
|
||||
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamUpdatePacket.getTeamColor());
|
||||
is.getModifier().write(0, teamUpdate.getTeamDisplay());
|
||||
is.getModifier().write(1, teamUpdate.getTeamPrefix());
|
||||
is.getModifier().write(2, teamUpdate.getTeamSuffix());
|
||||
is.getModifier().write(3, teamUpdate.getTagVisibility().getId());
|
||||
is.getModifier().write(4, teamUpdate.getCollisionRule().getId());
|
||||
is.getEnumModifier(TeamColor.class, MinecraftReflection.getMinecraftClass("EnumChatFormat")).write(0, teamUpdate.getTeamColor());
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.team.packet;
|
||||
|
||||
public class TeamRemove {
|
||||
|
||||
private String teamName;
|
||||
|
||||
private TeamRemove() {
|
||||
}
|
||||
|
||||
public TeamRemove(String teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final TeamRemove packet;
|
||||
|
||||
public Builder() {
|
||||
this.packet = new TeamRemove();
|
||||
}
|
||||
|
||||
public Builder teamName(String teamName) {
|
||||
packet.teamName = teamName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TeamRemove build() {
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package net.momirealms.customnameplates.paper.mechanic.team.packet;
|
||||
|
||||
import net.momirealms.customnameplates.common.team.TeamCollisionRule;
|
||||
import net.momirealms.customnameplates.common.team.TeamColor;
|
||||
import net.momirealms.customnameplates.common.team.TeamTagVisibility;
|
||||
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
|
||||
|
||||
public class TeamUpdate {
|
||||
|
||||
private String teamName;
|
||||
|
||||
/*
|
||||
Optional<b> k
|
||||
*/
|
||||
// IChatBaseComponent a
|
||||
private Object teamDisplay;
|
||||
// IChatBaseComponent b
|
||||
private Object teamPrefix;
|
||||
// IChatBaseComponent c
|
||||
private Object teamSuffix;
|
||||
// String d
|
||||
private TeamTagVisibility tagVisibility;
|
||||
// String e
|
||||
private TeamCollisionRule collisionRule;
|
||||
// Enum f
|
||||
private TeamColor teamColor;
|
||||
|
||||
private TeamUpdate() {
|
||||
}
|
||||
|
||||
public TeamUpdate(
|
||||
String teamName,
|
||||
Object teamDisplay,
|
||||
Object teamPrefix,
|
||||
Object teamSuffix,
|
||||
TeamTagVisibility tagVisibility,
|
||||
TeamCollisionRule collisionRule,
|
||||
TeamColor teamColor
|
||||
) {
|
||||
this.teamName = teamName;
|
||||
this.teamDisplay = teamDisplay;
|
||||
this.teamPrefix = teamPrefix;
|
||||
this.teamSuffix = teamSuffix;
|
||||
this.tagVisibility = tagVisibility;
|
||||
this.collisionRule = collisionRule;
|
||||
this.teamColor = teamColor;
|
||||
}
|
||||
|
||||
public String getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public Object getTeamDisplay() {
|
||||
return teamDisplay;
|
||||
}
|
||||
|
||||
public Object getTeamPrefix() {
|
||||
return teamPrefix;
|
||||
}
|
||||
|
||||
public Object getTeamSuffix() {
|
||||
return teamSuffix;
|
||||
}
|
||||
|
||||
public TeamTagVisibility getTagVisibility() {
|
||||
return tagVisibility;
|
||||
}
|
||||
|
||||
public TeamCollisionRule getCollisionRule() {
|
||||
return collisionRule;
|
||||
}
|
||||
|
||||
public TeamColor getTeamColor() {
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private final TeamUpdate packet;
|
||||
|
||||
public Builder() {
|
||||
this.packet = new TeamUpdate();
|
||||
}
|
||||
|
||||
public static Builder of() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder teamName(String name) {
|
||||
packet.teamName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder display(String display) {
|
||||
packet.teamDisplay = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(display);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder prefix(String prefix) {
|
||||
packet.teamPrefix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(prefix);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder suffix(String suffix) {
|
||||
packet.teamSuffix = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(suffix);;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder color(TeamColor color) {
|
||||
packet.teamColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tagVisibility(TeamTagVisibility visibility) {
|
||||
packet.tagVisibility = visibility;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder collisionRule(TeamCollisionRule rule) {
|
||||
packet.collisionRule = rule;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TeamUpdate build() {
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,12 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class TABProvider implements TeamProvider {
|
||||
|
||||
private final TabAPI api;
|
||||
private final SortingManager sortingManager;
|
||||
|
||||
public TABProvider() {
|
||||
this.sortingManager = TabAPI.getInstance().getSortingManager();
|
||||
this.api = TabAPI.getInstance();
|
||||
this.sortingManager = api.getSortingManager();
|
||||
if (sortingManager == null) {
|
||||
LogUtils.warn("Detected that team management is disabled in TAB. Using player name as team name.");
|
||||
}
|
||||
@@ -19,8 +21,14 @@ public class TABProvider implements TeamProvider {
|
||||
|
||||
@Override
|
||||
public String getTeam(Player player) {
|
||||
TabPlayer tabPlayer = TabAPI.getInstance().getPlayer(player.getUniqueId());
|
||||
if (tabPlayer == null || sortingManager == null) return player.getName();
|
||||
TabPlayer tabPlayer = api.getPlayer(player.getUniqueId());
|
||||
if (tabPlayer == null) {
|
||||
return null;
|
||||
}
|
||||
String forced = sortingManager.getForcedTeamName(tabPlayer);
|
||||
if (forced != null) {
|
||||
return forced;
|
||||
}
|
||||
return sortingManager.getOriginalTeamName(tabPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ public class CNConfig {
|
||||
public static boolean hideScoreboardNumber;
|
||||
public static boolean animatedImage;
|
||||
public static boolean textEffects;
|
||||
public static boolean disableTeamManage;
|
||||
public static boolean velocitab;
|
||||
|
||||
public static void load() {
|
||||
try {
|
||||
@@ -108,6 +110,7 @@ public class CNConfig {
|
||||
ventureChatChannel = integrationSection.getBoolean("chat.VentureChat", false);
|
||||
tabTeam = integrationSection.getBoolean("team.TAB", false);
|
||||
cmiTeam = integrationSection.getBoolean("team.CMI", false);
|
||||
velocitab = integrationSection.getBoolean("team.Velocitab", false);
|
||||
}
|
||||
|
||||
ConfigurationSection packSection = config.getConfigurationSection("resource-pack");
|
||||
@@ -137,6 +140,7 @@ public class CNConfig {
|
||||
textEffects = packSection.getBoolean("shader.ItemsAdder-text-effects", false);
|
||||
}
|
||||
|
||||
disableTeamManage = config.getBoolean("other-settings.disable-team-management", false);
|
||||
corePoolSize = config.getInt("other-settings.thread-pool-settings.corePoolSize", 10);
|
||||
maximumPoolSize = config.getInt("other-settings.thread-pool-settings.maximumPoolSize", 10);
|
||||
keepAliveTime = config.getInt("other-settings.thread-pool-settings.keepAliveTime", 30);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.momirealms.customnameplates.paper.util;
|
||||
|
||||
import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.api.requirement.Requirement;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import net.momirealms.customnameplates.common.Pair;
|
||||
import net.momirealms.customnameplates.paper.mechanic.misc.TimeLimitText;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,20 +26,14 @@ modules:
|
||||
# Integrations
|
||||
integrations:
|
||||
resource-pack:
|
||||
# If enabled, CustomNameplates will automatically place the generated resource pack into ItemsAdder/Oraxen.
|
||||
# To apply this change, run "/nameplates reload" & "/iazip" or "/oraxen reload all"
|
||||
ItemsAdder: false
|
||||
Oraxen: false
|
||||
# Require a restart to apply this
|
||||
team:
|
||||
# When enabled, CustomNameplates will hook into TAB's team management
|
||||
TAB: false
|
||||
# When enabled, CustomNameplates will hook into CMI's team management
|
||||
CMI: false
|
||||
Velocitab: false
|
||||
chat:
|
||||
# TrChat channels
|
||||
TrChat: false
|
||||
# VentureChat channels
|
||||
VentureChat: false
|
||||
|
||||
resource-pack:
|
||||
@@ -82,6 +76,9 @@ resource-pack:
|
||||
legacy-unicodes: true
|
||||
|
||||
other-settings:
|
||||
# Disable CustomNameplates' team management
|
||||
disable-team-management: false
|
||||
|
||||
# It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below.
|
||||
legacy-color-code-support: false
|
||||
|
||||
@@ -95,8 +92,6 @@ other-settings:
|
||||
# If a thread is idle for more than this attribute value, it will exit due to timeout
|
||||
keepAliveTime: 30
|
||||
|
||||
# default width
|
||||
default-character-width: 8
|
||||
# delay x ticks before actionbar/bossbar is sent to players
|
||||
send-delay: 0
|
||||
# Set the size for the cache system. This is useful and would bring huge performance if you keep it to a reasonable value
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
# Team / Unlimited / Disable
|
||||
mode: TEAM
|
||||
|
||||
# You should enable this when you are
|
||||
# ① using Velocitab by William278 on Velocity
|
||||
# ② using TAB by NEZNAMY on BungeeCord
|
||||
proxy: false
|
||||
|
||||
# The duration (in seconds) that the nameplate preview will last for.
|
||||
preview-duration: 5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user