Simplify TPSLimit_12
Simplify TPSLimit_15
Dieser Commit ist enthalten in:
Ursprung
7f42fffd0c
Commit
65456ea19c
@ -32,37 +32,20 @@ import java.util.Set;
|
||||
|
||||
class TPSLimit_12 {
|
||||
|
||||
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
|
||||
private static Set<Packet<?>> packets = new HashSet<>();
|
||||
|
||||
static void createVelocityPacketCache(World world) {
|
||||
velocityPackets.clear();
|
||||
static void createTickCache(World world) {
|
||||
packets.clear();
|
||||
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();
|
||||
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
|
||||
});
|
||||
|
||||
sendPacketsToPlayer(packets);
|
||||
}
|
||||
|
||||
static void sendTeleports(World world) {
|
||||
Set<Packet<?>> packets = new HashSet<>();
|
||||
|
||||
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
|
||||
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||
});
|
||||
|
||||
static void sendTickPackets() {
|
||||
sendPacketsToPlayer(packets);
|
||||
}
|
||||
|
||||
|
@ -32,38 +32,21 @@ import java.util.Set;
|
||||
|
||||
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);
|
||||
|
||||
static void createVelocityPacketCache(World world) {
|
||||
velocityPackets.clear();
|
||||
static void createTickCache(World world) {
|
||||
packets.clear();
|
||||
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();
|
||||
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
|
||||
});
|
||||
|
||||
sendPacketsToPlayer(packets);
|
||||
}
|
||||
|
||||
static void sendTeleports(World world) {
|
||||
Set<Packet<?>> packets = new HashSet<>();
|
||||
|
||||
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
|
||||
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
|
||||
});
|
||||
|
||||
static void sendTickPackets() {
|
||||
sendPacketsToPlayer(packets);
|
||||
}
|
||||
|
||||
|
@ -102,13 +102,10 @@ public class CommandTPSLimiter implements CommandExecutor {
|
||||
} else {
|
||||
if (tpsLimiter != null) return;
|
||||
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
versionDependantCall(() -> TPSLimit_12.sendTntMetaData(world), () -> TPSLimit_15.sendTntMetaData(world));
|
||||
|
||||
versionDependantCall(() -> TPSLimit_12.createVelocityPacketCache(world), () -> TPSLimit_15.createVelocityPacketCache(world));
|
||||
versionDependantCall(() -> TPSLimit_12.createTickCache(world), () -> TPSLimit_15.createTickCache(world));
|
||||
for (int i = 0; i < (20 / currentTPSLimit); i++) {
|
||||
sleepUntilNextTick();
|
||||
versionDependantCall(() -> TPSLimit_12.sendTeleports(world), () -> TPSLimit_15.sendTeleports(world));
|
||||
versionDependantCall(TPSLimit_12::sendVelocityPackets, TPSLimit_15::sendVelocityPackets);
|
||||
versionDependantCall(TPSLimit_12::sendTickPackets, TPSLimit_15::sendTickPackets);
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren