SteamWar/BauSystem
Archiviert
13
0

Simplify TPSLimit_12

Simplify TPSLimit_15
Dieser Commit ist enthalten in:
jojo 2020-12-25 18:06:19 +01:00
Ursprung 7f42fffd0c
Commit 65456ea19c
3 geänderte Dateien mit 14 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -32,37 +32,20 @@ import java.util.Set;
class TPSLimit_12 { class TPSLimit_12 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>(); private static Set<Packet<?>> packets = new HashSet<>();
static void createVelocityPacketCache(World world) { static void createTickCache(World world) {
velocityPackets.clear(); packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> { world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0)); packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
}); packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
}
static void sendVelocityPackets() {
sendPacketsToPlayer(velocityPackets);
}
static void sendTntMetaData(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
net.minecraft.server.v1_12_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); net.minecraft.server.v1_12_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true)); packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
}); });
sendPacketsToPlayer(packets);
} }
static void sendTeleports(World world) { static void sendTickPackets() {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
});
sendPacketsToPlayer(packets); sendPacketsToPlayer(packets);
} }

Datei anzeigen

@ -32,38 +32,21 @@ import java.util.Set;
class TPSLimit_15 { class TPSLimit_15 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>(); private static Set<Packet<?>> packets = new HashSet<>();
private static final Vec3D noMotion = new Vec3D(0, 0, 0); private static final Vec3D noMotion = new Vec3D(0, 0, 0);
static void createVelocityPacketCache(World world) { static void createTickCache(World world) {
velocityPackets.clear(); packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> { world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion)); packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
}); packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
}
static void sendVelocityPackets() {
sendPacketsToPlayer(velocityPackets);
}
static void sendTntMetaData(World world) {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true)); packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
}); });
sendPacketsToPlayer(packets);
} }
static void sendTeleports(World world) { static void sendTickPackets() {
Set<Packet<?>> packets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
});
sendPacketsToPlayer(packets); sendPacketsToPlayer(packets);
} }

Datei anzeigen

@ -102,13 +102,10 @@ public class CommandTPSLimiter implements CommandExecutor {
} else { } else {
if (tpsLimiter != null) return; if (tpsLimiter != null) return;
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
versionDependantCall(() -> TPSLimit_12.sendTntMetaData(world), () -> TPSLimit_15.sendTntMetaData(world)); versionDependantCall(() -> TPSLimit_12.createTickCache(world), () -> TPSLimit_15.createTickCache(world));
versionDependantCall(() -> TPSLimit_12.createVelocityPacketCache(world), () -> TPSLimit_15.createVelocityPacketCache(world));
for (int i = 0; i < (20 / currentTPSLimit); i++) { for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick(); sleepUntilNextTick();
versionDependantCall(() -> TPSLimit_12.sendTeleports(world), () -> TPSLimit_15.sendTeleports(world)); versionDependantCall(TPSLimit_12::sendTickPackets, TPSLimit_15::sendTickPackets);
versionDependantCall(TPSLimit_12::sendVelocityPackets, TPSLimit_15::sendVelocityPackets);
} }
}, 0, 1); }, 0, 1);
} }