mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-26 02:19:28 +00:00
bundle packets
This commit is contained in:
@@ -8,6 +8,10 @@ import net.momirealms.customnameplates.api.CustomNameplatesPlugin;
|
||||
import net.momirealms.customnameplates.api.util.LogUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private static PacketManager instance;
|
||||
@@ -33,9 +37,11 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
public void send(Player player, PacketContainer... packets) {
|
||||
if (plugin.getVersionManager().isVersionNewerThan1_20()) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BUNDLE);
|
||||
|
||||
if (plugin.getVersionManager().isVersionNewerThan1_19_R3()) {
|
||||
List<PacketContainer> bundle = new ArrayList<>(Arrays.asList(packets));
|
||||
PacketContainer bundlePacket = new PacketContainer(PacketType.Play.Server.BUNDLE);
|
||||
bundlePacket.getPacketBundles().write(0, bundle);
|
||||
send(player, bundlePacket);
|
||||
} else {
|
||||
for (PacketContainer packet : packets) {
|
||||
send(player, packet);
|
||||
|
||||
@@ -33,9 +33,10 @@ import java.util.concurrent.CompletableFuture;
|
||||
*/
|
||||
public class VersionManagerImpl implements VersionManager {
|
||||
|
||||
private final boolean isNewerThan1_19_R2;
|
||||
private final boolean isNewerThan1_20;
|
||||
private final boolean isNewerThan1_19;
|
||||
private final boolean isNewerThan1_19_R2;
|
||||
private final boolean isNewerThan1_19_R3;
|
||||
private final boolean isNewerThan1_20;
|
||||
private final boolean isNewerThan1_20_R2;
|
||||
private final String serverVersion;
|
||||
private final CustomNameplatesPluginImpl plugin;
|
||||
@@ -53,19 +54,17 @@ public class VersionManagerImpl implements VersionManager {
|
||||
// Determine if the server version is newer than 1_19_R2 and 1_20_R1
|
||||
if (main_ver >= 20) {
|
||||
isNewerThan1_20_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
|
||||
isNewerThan1_19_R2 = true;
|
||||
isNewerThan1_19_R2 = isNewerThan1_19_R3 = true;
|
||||
isNewerThan1_20 = true;
|
||||
isNewerThan1_19 = true;
|
||||
} else if (main_ver == 19) {
|
||||
isNewerThan1_19_R2 = Integer.parseInt(split[2].substring(1)) >= 2;
|
||||
isNewerThan1_20 = false;
|
||||
isNewerThan1_19_R3 = Integer.parseInt(split[2].substring(1)) >= 3;
|
||||
isNewerThan1_20 = isNewerThan1_20_R2 = false;
|
||||
isNewerThan1_19 = true;
|
||||
isNewerThan1_20_R2 = false;
|
||||
} else {
|
||||
isNewerThan1_19_R2 = false;
|
||||
isNewerThan1_20 = false;
|
||||
isNewerThan1_19 = false;
|
||||
isNewerThan1_20_R2 = false;
|
||||
isNewerThan1_19 = isNewerThan1_19_R2= isNewerThan1_19_R3 = false;
|
||||
isNewerThan1_20 = isNewerThan1_20_R2 = false;
|
||||
}
|
||||
// Check if the server is Folia
|
||||
try {
|
||||
@@ -92,7 +91,6 @@ public class VersionManagerImpl implements VersionManager {
|
||||
return isNewerThan1_20_R2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPluginVersion() {
|
||||
return pluginVersion;
|
||||
@@ -108,6 +106,11 @@ public class VersionManagerImpl implements VersionManager {
|
||||
return isNewerThan1_19;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVersionNewerThan1_19_R3() {
|
||||
return isNewerThan1_19_R3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPackFormat() {
|
||||
switch (serverVersion) {
|
||||
|
||||
@@ -179,9 +179,7 @@ public class NamedEntityImpl implements NamedEntity {
|
||||
@Override
|
||||
public void spawn(Player viewer, Pose pose) {
|
||||
if (viewerText.updateForViewer(viewer)) {
|
||||
for (PacketContainer packet : getSpawnPackets(viewerText.getLatestValue(viewer), pose)) {
|
||||
PacketManager.getInstance().send(viewer, packet);
|
||||
}
|
||||
PacketManager.getInstance().send(viewer, getSpawnPackets(viewerText.getLatestValue(viewer), pose));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ modules:
|
||||
images: true
|
||||
|
||||
# Integrations
|
||||
# https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customnameplates/compatibility
|
||||
integrations:
|
||||
resource-pack:
|
||||
ItemsAdder: false
|
||||
|
||||
@@ -8,7 +8,6 @@ preview-duration: 5
|
||||
default-nameplate: 'none'
|
||||
|
||||
# This decides what %nameplates_prefix/suffix% would return
|
||||
# Check xxx for examples
|
||||
nameplate:
|
||||
refresh-frequency: 10
|
||||
prefix: ''
|
||||
|
||||
Reference in New Issue
Block a user