fix: fix some bugs
fix crash in contain view (#44) fix tps and mspt send in servux
This commit is contained in:
+26
-18
@@ -29,8 +29,6 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.leavesmc.leaves.plugin.MinecraftInternalPlugin;
|
||||
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
|
||||
import org.leavesmc.leaves.protocol.core.LeavesProtocol;
|
||||
import org.leavesmc.leaves.protocol.core.ProtocolHandler;
|
||||
@@ -102,27 +100,37 @@ public class ServuxEntityDataProtocol implements LeavesProtocol {
|
||||
}
|
||||
|
||||
public static void onBlockEntityRequest(ServerPlayer player, BlockPos pos) {
|
||||
Bukkit.getGlobalRegionScheduler().run(MinecraftInternalPlugin.INSTANCE, (task) -> {
|
||||
BlockEntity be = player.level().getBlockEntity(pos);
|
||||
CompoundTag nbt = be != null ? be.saveWithFullMetadata(player.registryAccess()) : new CompoundTag();
|
||||
io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(
|
||||
player.level(),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(player.position()),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(player.position()),
|
||||
() -> {
|
||||
BlockEntity be = player.level().getBlockEntity(pos);
|
||||
CompoundTag nbt = be != null ? be.saveWithFullMetadata(player.registryAccess()) : new CompoundTag();
|
||||
|
||||
EntityDataPayload payload = new EntityDataPayload(EntityDataPayloadType.PACKET_S2C_BLOCK_NBT_RESPONSE_SIMPLE);
|
||||
payload.pos = pos.immutable();
|
||||
payload.nbt.merge(nbt);
|
||||
sendPacket(player, payload);
|
||||
});
|
||||
EntityDataPayload payload = new EntityDataPayload(EntityDataPayloadType.PACKET_S2C_BLOCK_NBT_RESPONSE_SIMPLE);
|
||||
payload.pos = pos.immutable();
|
||||
payload.nbt.merge(nbt);
|
||||
sendPacket(player, payload);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void onEntityRequest(ServerPlayer player, int entityId) {
|
||||
Bukkit.getGlobalRegionScheduler().run(MinecraftInternalPlugin.INSTANCE, (task) -> {
|
||||
Entity entity = player.level().getEntity(entityId);
|
||||
CompoundTag nbt = TagUtil.saveEntityWithoutId(entity);
|
||||
io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(
|
||||
player.level(),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(player.position()),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(player.position()),
|
||||
() -> {
|
||||
Entity entity = player.level().getEntity(entityId);
|
||||
CompoundTag nbt = TagUtil.saveEntityWithoutId(entity);
|
||||
|
||||
EntityDataPayload payload = new EntityDataPayload(EntityDataPayloadType.PACKET_S2C_ENTITY_NBT_RESPONSE_SIMPLE);
|
||||
payload.entityId = entityId;
|
||||
payload.nbt.merge(nbt);
|
||||
sendPacket(player, payload);
|
||||
});
|
||||
EntityDataPayload payload = new EntityDataPayload(EntityDataPayloadType.PACKET_S2C_ENTITY_NBT_RESPONSE_SIMPLE);
|
||||
payload.entityId = entityId;
|
||||
payload.nbt.merge(nbt);
|
||||
sendPacket(player, payload);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void sendPacket(ServerPlayer player, EntityDataPayload payload) {
|
||||
|
||||
+17
-5
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.leavesmc.leaves.protocol.servux;
|
||||
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -54,7 +56,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
|
||||
|
||||
private static final HashMap<ServerPlayer, List<DataLogger.Type>> loggerPlayers = new HashMap<>();
|
||||
private static final HashMap<DataLogger.Type, DataLogger<?>> LOGGERS = new HashMap<>();
|
||||
private static final HashMap<DataLogger.Type, Tag> DATA = new HashMap<>();
|
||||
private static final Table<DataLogger.Type, ServerPlayer, Tag> DATA = HashBasedTable.create();
|
||||
|
||||
public static boolean refreshSpawnMetadata = false;
|
||||
|
||||
@@ -237,12 +239,16 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
|
||||
if (server.getTickCount() % fun.bm.lophine.config.modules.misc.SurvuxProtocolConfig.hudUpdateInterval == 0) {
|
||||
DATA.clear();
|
||||
LOGGERS.forEach((type, logger) -> {
|
||||
if (!isLoggerTypeEnabled(type)) {
|
||||
return;
|
||||
}
|
||||
DATA.put(type, logger.getResult(server));
|
||||
for (ServerPlayer player : players) {
|
||||
Tag ret = logger.getResult(server, this, player);
|
||||
if (ret != null) {
|
||||
DATA.put(type, player, ret);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -254,14 +260,20 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
|
||||
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
for (DataLogger.Type type : list) {
|
||||
if (DATA.containsKey(type)) {
|
||||
nbt.put(type.getSerializedName(), DATA.get(type));
|
||||
Tag data = DATA.get(type, player);
|
||||
if (data != null) {
|
||||
nbt.put(type.getSerializedName(), data);
|
||||
DATA.remove(type, player);
|
||||
}
|
||||
}
|
||||
sendPacket(player, new HudDataPayload(HudDataPayloadType.PACKET_S2C_DATA_LOGGER_TICK, nbt));
|
||||
}
|
||||
}
|
||||
|
||||
public void applyData(DataLogger.Type type, ServerPlayer player, Tag tag) {
|
||||
DATA.put(type, player, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return fun.bm.lophine.config.modules.misc.SurvuxProtocolConfig.hudMetadataProtocol;
|
||||
|
||||
+37
-23
@@ -146,35 +146,49 @@ public class ServuxLitematicsProtocol implements LeavesProtocol {
|
||||
if (!hasPermission(player)) {
|
||||
return;
|
||||
}
|
||||
BlockEntity be = player.level().getBlockEntity(pos);
|
||||
CompoundTag tag = be != null ? be.saveWithFullMetadata(MinecraftServer.getServer().registryAccess()) : new CompoundTag();
|
||||
ServuxLitematicaPayload payload = new ServuxLitematicaPayload(ServuxLitematicaPayloadType.PACKET_S2C_BLOCK_NBT_RESPONSE_SIMPLE);
|
||||
payload.pos = pos;
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(
|
||||
player.level(),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(player.position()),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(player.position()),
|
||||
() -> {
|
||||
BlockEntity be = player.level().getBlockEntity(pos);
|
||||
CompoundTag tag = be != null ? be.saveWithFullMetadata(MinecraftServer.getServer().registryAccess()) : new CompoundTag();
|
||||
ServuxLitematicaPayload payload = new ServuxLitematicaPayload(ServuxLitematicaPayloadType.PACKET_S2C_BLOCK_NBT_RESPONSE_SIMPLE);
|
||||
payload.pos = pos;
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void onEntityRequest(ServerPlayer player, int entityId) {
|
||||
if (!hasPermission(player)) {
|
||||
return;
|
||||
}
|
||||
Entity entity = player.level().getEntity(entityId);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
CompoundTag tag = new CompoundTag();
|
||||
ServuxLitematicaPayload payload = new ServuxLitematicaPayload(ServuxLitematicaPayloadType.PACKET_S2C_ENTITY_NBT_RESPONSE_SIMPLE);
|
||||
payload.entityId = entityId;
|
||||
if (entity instanceof net.minecraft.world.entity.player.Player) {
|
||||
ResourceLocation loc = EntityType.getKey(entity.getType());
|
||||
tag = TagUtil.saveEntity(entity);
|
||||
tag.putString("id", loc.toString());
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
} else if (TagUtil.saveEntityAsPassenger(entity, tag)) {
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
}
|
||||
io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(
|
||||
player.level(),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(player.position()),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(player.position()),
|
||||
() -> {
|
||||
Entity entity = player.level().getEntity(entityId);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
CompoundTag tag = new CompoundTag();
|
||||
ServuxLitematicaPayload payload = new ServuxLitematicaPayload(ServuxLitematicaPayloadType.PACKET_S2C_ENTITY_NBT_RESPONSE_SIMPLE);
|
||||
payload.entityId = entityId;
|
||||
if (entity instanceof net.minecraft.world.entity.player.Player) {
|
||||
ResourceLocation loc = EntityType.getKey(entity.getType());
|
||||
tag = TagUtil.saveEntity(entity);
|
||||
tag.putString("id", loc.toString());
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
} else if (TagUtil.saveEntityAsPassenger(entity, tag)) {
|
||||
payload.nbt = tag;
|
||||
encodeServerData(player, payload);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void onBulkEntityRequest(ServerPlayer player, ChunkPos chunkPos, CompoundTag req) {
|
||||
|
||||
+31
-23
@@ -19,6 +19,7 @@ package org.leavesmc.leaves.protocol.servux.logger;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.papermc.paper.threadedregions.TickRegionScheduler;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
@@ -26,11 +27,13 @@ import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerTickRateManager;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.NaturalSpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.leavesmc.leaves.protocol.servux.ServuxHudDataProtocol;
|
||||
import org.leavesmc.leaves.protocol.servux.logger.data.MobCapData;
|
||||
import org.leavesmc.leaves.protocol.servux.logger.data.TickData;
|
||||
|
||||
@@ -49,7 +52,7 @@ public abstract class DataLogger<T extends Tag> {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public abstract T getResult(MinecraftServer server);
|
||||
public abstract T getResult(MinecraftServer server, ServuxHudDataProtocol protocol, ServerPlayer player);
|
||||
|
||||
public enum Type implements StringRepresentable {
|
||||
TPS("tps", Tps::new, Tps.CODEC),
|
||||
@@ -105,31 +108,36 @@ public abstract class DataLogger<T extends Tag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getResult(MinecraftServer server) {
|
||||
try {
|
||||
return (CompoundTag) TickData.CODEC.encodeStart(server.registryAccess().createSerializationContext(NbtOps.INSTANCE), this.build(server)).getOrThrow();
|
||||
} catch (Exception e) {
|
||||
return new CompoundTag();
|
||||
}
|
||||
public CompoundTag getResult(MinecraftServer server, ServuxHudDataProtocol protocol, ServerPlayer player) {
|
||||
this.build(server, protocol, player);
|
||||
return null;
|
||||
}
|
||||
|
||||
private TickData build(MinecraftServer server) {
|
||||
ServerTickRateManager tickManager = server.tickRateManager();
|
||||
boolean frozen = tickManager.isFrozen();
|
||||
boolean sprinting = tickManager.isSprinting();
|
||||
final double mspt = server.tickTimes5s.getAverage();
|
||||
double tps = 1000.0D / Math.max(sprinting ? 0.0 : tickManager.millisecondsPerTick(), mspt);
|
||||
private TickData build(MinecraftServer server, ServuxHudDataProtocol protocol, ServerPlayer player) {
|
||||
io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(
|
||||
player.level(),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(player.position()),
|
||||
ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(player.position()),
|
||||
() -> {
|
||||
ServerTickRateManager tickManager = server.tickRateManager();
|
||||
boolean frozen = tickManager.isFrozen();
|
||||
boolean sprinting = tickManager.isSprinting();
|
||||
io.papermc.paper.threadedregions.TickData.TickReportData tickData = TickRegionScheduler.getCurrentRegion().getData().getRegionSchedulingHandle().getTickReport5s(System.nanoTime());
|
||||
final double tps = tickData.tpsData().segmentAll().average();
|
||||
final double mspt = tickData.timePerTickData().segmentAll().average() / 1.0E6;
|
||||
|
||||
if (frozen) {
|
||||
tps = 0.0d;
|
||||
}
|
||||
|
||||
return new TickData(
|
||||
mspt, tps,
|
||||
tickManager.getRemainingSprintTicks(),
|
||||
frozen, sprinting,
|
||||
tickManager.isSteppingForward()
|
||||
TickData tk = new TickData(
|
||||
mspt, tps,
|
||||
tickManager.getRemainingSprintTicks(),
|
||||
frozen, sprinting,
|
||||
tickManager.isSteppingForward()
|
||||
);
|
||||
Tag ret = TickData.CODEC.encodeStart(server.registryAccess().createSerializationContext(NbtOps.INSTANCE), tk).getOrThrow();
|
||||
protocol.applyData(Type.TPS, player, ret);
|
||||
}
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +150,7 @@ public abstract class DataLogger<T extends Tag> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getResult(MinecraftServer server) {
|
||||
public CompoundTag getResult(MinecraftServer server, ServuxHudDataProtocol protocol, ServerPlayer player) {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
|
||||
for (ServerLevel world : server.getAllLevels()) {
|
||||
|
||||
Reference in New Issue
Block a user