FallingBlock #144
@ -24,50 +24,32 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class TPSLimit_12 {
|
class TPSLimit_12 {
|
||||||
|
|
||||||
private static Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
|
private static List<Packet<?>> packets = new ArrayList<>();
|
||||||
|
|
||||||
static void createVelocityPacketCache(World world) {
|
static void createTickCache(World world) {
|
||||||
velocityPackets.clear();
|
packets.clear();
|
||||||
world.getEntitiesByClasses(TNTPrimed.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()));
|
||||||
|
|
||||||
|
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() {
|
static void sendTickPackets() {
|
||||||
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) {
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
||||||
for (Packet<?> p : packets) {
|
for (Packet<?> p : packets) {
|
||||||
|
@ -24,51 +24,32 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
class TPSLimit_15 {
|
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);
|
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).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()));
|
||||||
|
|
||||||
|
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() {
|
static void sendTickPackets() {
|
||||||
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) {
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
||||||
for (Packet<?> p : packets) {
|
for (Packet<?> p : packets) {
|
||||||
|
@ -22,7 +22,7 @@ package de.steamwar.bausystem.commands;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.world.Welt;
|
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.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -35,7 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
|
|
||||||
public class CommandTPSLimiter implements CommandExecutor {
|
public class CommandTPSLimiter implements CommandExecutor {
|
||||||
|
|
||||||
private static int currentTPSLimit = 20;
|
private static double currentTPSLimit = 20;
|
||||||
private static World world = Bukkit.getWorlds().get(0);
|
private static World world = Bukkit.getWorlds().get(0);
|
||||||
private long lastTime = System.nanoTime();
|
private long lastTime = System.nanoTime();
|
||||||
private long currentTime = System.nanoTime();
|
private long currentTime = System.nanoTime();
|
||||||
@ -71,12 +71,12 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int tpsLimitInt = Integer.parseInt(tpsLimit);
|
double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
|
||||||
if (tpsLimitInt < 1 || tpsLimitInt > 20) {
|
if (tpsLimitDouble < 0.5 || tpsLimitDouble > 20) {
|
||||||
|
|||||||
sendInvalidArgumentMessage(player);
|
sendInvalidArgumentMessage(player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
currentTPSLimit = tpsLimitInt;
|
currentTPSLimit = tpsLimitDouble;
|
||||||
sendNewTPSLimitMessage();
|
sendNewTPSLimitMessage();
|
||||||
tpsLimiter();
|
tpsLimiter();
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -91,7 +91,7 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendInvalidArgumentMessage(Player player) {
|
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() {
|
private void tpsLimiter() {
|
||||||
@ -102,13 +102,12 @@ 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(), () -> {
|
||||||
sendTntMetaData();
|
VersionedRunnable.call(new VersionedRunnable(() -> TPSLimit_12.createTickCache(world), 8),
|
||||||
|
new VersionedRunnable(() -> TPSLimit_15.createTickCache(world), 14));
|
||||||
createVelocityData();
|
|
||||||
for (int i = 0; i < (20 / currentTPSLimit); i++) {
|
for (int i = 0; i < (20 / currentTPSLimit); i++) {
|
||||||
sleepUntilNextTick();
|
sleepUntilNextTick();
|
||||||
sendTntData();
|
VersionedRunnable.call(new VersionedRunnable(TPSLimit_12::sendTickPackets, 8),
|
||||||
sendVelocityData();
|
new VersionedRunnable(TPSLimit_15::sendTickPackets, 14));
|
||||||
}
|
}
|
||||||
}, 0, 1);
|
}, 0, 1);
|
||||||
}
|
}
|
||||||
@ -133,47 +132,7 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVelocityData() {
|
public static double getCurrentTPSLimit() {
|
||||||
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() {
|
|
||||||
return currentTPSLimit;
|
return currentTPSLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Hast du das mit 0,5 getestet? Fliegst du dabei nicht vom Bau? Wenn ja, brauchst du das hier mir drunter nicht zu antworten.
Also ja ich habe es getestet für eine längere Zeit und bin nicht vom Bau geflogen.