SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'FallingBlock' (#144) from FallingBlock into master

Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
YoyoNow 2020-12-26 23:21:21 +01:00
Commit fdd74296b8
3 geänderte Dateien mit 41 neuen und 119 gelöschten Zeilen

Datei anzeigen

@ -24,50 +24,32 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.TNTPrimed;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class TPSLimit_12 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
private static List<Packet<?>> packets = new ArrayList<>();
static void createVelocityPacketCache(World world) {
velocityPackets.clear();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
static void createTickCache(World world) {
packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0));
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
if (entity instanceof TNTPrimed) {
net.minecraft.server.v1_12_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
}
});
}
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 sendTntData(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 PacketPlayOutEntityTeleport(serverEntity));
});
sendPacketsToPlayer(packets);
}
static void sendPacketsToPlayer(Set<? extends Packet<?>> packets) {
static void sendTickPackets() {
Bukkit.getOnlinePlayers().forEach(player -> {
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
for (Packet<?> p : packets) {

Datei anzeigen

@ -24,51 +24,32 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.TNTPrimed;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
class TPSLimit_15 {
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
private static List<Packet<?>> packets = new ArrayList<>();
private static final Vec3D noMotion = new Vec3D(0, 0, 0);
static void createVelocityPacketCache(World world) {
velocityPackets.clear();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
static void createTickCache(World world) {
packets.clear();
world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> {
packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle()));
if (entity instanceof TNTPrimed) {
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
packets.add(new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true));
}
});
}
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 sendTntData(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 PacketPlayOutEntityTeleport(serverEntity));
});
sendPacketsToPlayer(packets);
}
static void sendPacketsToPlayer(Set<? extends Packet<?>> packets) {
static void sendTickPackets() {
Bukkit.getOnlinePlayers().forEach(player -> {
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
for (Packet<?> p : packets) {

Datei anzeigen

@ -22,7 +22,7 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedRunnable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@ -35,7 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
public class CommandTPSLimiter implements CommandExecutor {
private static int currentTPSLimit = 20;
private static double currentTPSLimit = 20;
private static World world = Bukkit.getWorlds().get(0);
private long lastTime = System.nanoTime();
private long currentTime = System.nanoTime();
@ -71,12 +71,12 @@ public class CommandTPSLimiter implements CommandExecutor {
}
try {
int tpsLimitInt = Integer.parseInt(tpsLimit);
if (tpsLimitInt < 1 || tpsLimitInt > 20) {
double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) {
sendInvalidArgumentMessage(player);
return false;
}
currentTPSLimit = tpsLimitInt;
currentTPSLimit = tpsLimitDouble;
sendNewTPSLimitMessage();
tpsLimiter();
} catch (NumberFormatException e) {
@ -91,7 +91,7 @@ public class CommandTPSLimiter implements CommandExecutor {
}
private void sendInvalidArgumentMessage(Player player) {
player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 1 und 20, und 'default' erlaubt.");
player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und 20, und 'default' erlaubt.");
}
private void tpsLimiter() {
@ -102,13 +102,12 @@ public class CommandTPSLimiter implements CommandExecutor {
} else {
if (tpsLimiter != null) return;
tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
sendTntMetaData();
createVelocityData();
VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8),
new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14));
for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick();
sendTntData();
sendVelocityData();
VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8),
new VersionedRunnable(TPSLimit_15::sendTickPackets, 14));
}
}, 0, 1);
}
@ -133,47 +132,7 @@ public class CommandTPSLimiter implements CommandExecutor {
}
}
private void createVelocityData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.createVelocityPacketCache(world);
break;
default:
TPSLimit_12.createVelocityPacketCache(world);
}
}
private void sendVelocityData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendVelocityPackets();
break;
default:
TPSLimit_12.sendVelocityPackets();
}
}
private void sendTntMetaData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendTntMetaData(world);
break;
default:
TPSLimit_12.sendTntMetaData(world);
}
}
private void sendTntData() {
switch (Core.getVersion()) {
case 15:
TPSLimit_15.sendTntData(world);
break;
default:
TPSLimit_12.sendTntData(world);
}
}
public static int getCurrentTPSLimit() {
public static double getCurrentTPSLimit() {
return currentTPSLimit;
}