Add /tpslimit Command #113
@ -79,5 +79,12 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>steamwar</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/ProtocolLib.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -19,6 +19,12 @@
|
||||
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
Lixfel
hat
Millis dürfte für diesen Zweck zu ungenau sein, besser wären Nanosekunden Millis dürfte für diesen Zweck zu ungenau sein, besser wären Nanosekunden
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
Lixfel
hat
Nutzung von versionsspezifischen Teilen in versionsübergreifendem Codeteil Nutzung von versionsspezifischen Teilen in versionsübergreifendem Codeteil
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.world.Welt;
|
||||
@ -34,11 +40,14 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.CraftTNTPrimed;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.List;
|
||||
Lixfel
hat
Besser wäre ein aussenden von Velocity 0-Paketen, das hier dürfte den Server stark belasten. Besser wäre ein aussenden von Velocity 0-Paketen, das hier dürfte den Server stark belasten.
YoyoNow
hat
Wie soll ich das genau umsetzten? Wie soll ich das genau umsetzten?
YoyoNow
hat
Auch verschwindet das TNT nach 4 Sekunden (Clientseitig) sodass man es nicht mehr sieht! Auch verschwindet das TNT nach 4 Sekunden (Clientseitig) sodass man es nicht mehr sieht!
|
||||
|
||||
public class CommandTPSLimiter implements CommandExecutor {
|
||||
|
||||
private static int currentTPSLimit = 20;
|
||||
Lixfel
hat
Ist der überhaupt noch nötig? Ist der überhaupt noch nötig?
|
||||
@ -49,43 +58,71 @@ public class CommandTPSLimiter implements CommandExecutor {
|
||||
private BukkitTask tpsLimiter = null;
|
||||
|
||||
public CommandTPSLimiter() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
if (currentTPSLimit == 20) {
|
||||
return;
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_METADATA) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
// if (tpsLimiterNotActive()) return;
|
||||
if (event.getPacket().getEntityModifier(world).read(0) == null) return;
|
||||
if (!(event.getPacket().getEntityModifier(world).read(0) instanceof CraftTNTPrimed)) return;
|
||||
System.out.println("META: " + event.getPacket().getIntegers().read(0));
|
||||
List<WrappedWatchableObject> dataWatcherObjectList = event.getPacket().getWatchableCollectionModifier().read(0);
|
||||
getByIndex(dataWatcherObjectList, 5).setValue(true);
|
||||
getByIndex(dataWatcherObjectList, 7).setValue((int) ((20.0 / currentTPSLimit) * 80));
|
||||
System.out.println(dataWatcherObjectList);
|
||||
event.getPacket().getWatchableCollectionModifier().write(0, dataWatcherObjectList);
|
||||
}
|
||||
world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> {
|
||||
/*DataWatcher dataWatcher = new DataWatcher(entity);
|
||||
System.out.println("Let " + entity.getName() + " sneak " + sneaking);
|
||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), sneaking ? (byte)0x02 : (byte)0x40);
|
||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
|
||||
});
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.REL_ENTITY_MOVE) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
if (tpsLimiterNotActive()) return;
|
||||
if (event.getPacket().getEntityModifier(world).read(0) == null) return;
|
||||
if (!(event.getPacket().getEntityModifier(world).read(0) instanceof CraftTNTPrimed)) return;
|
||||
System.out.println(event.getPacket().getIntegers().read(0));
|
||||
StructureModifier<Integer> structureModifier = event.getPacket().getIntegers();
|
||||
// structureModifier.write(1, 0);
|
||||
// structureModifier.write(2, 0);
|
||||
// structureModifier.write(3, 0);
|
||||
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
|
||||
}*/
|
||||
Entity entity = event.getPacket().getEntityModifier(world).read(0);
|
||||
System.out.println(entity.getLocation());
|
||||
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
|
||||
Lixfel
hat
player bekommt eine doppelte Nachricht, ich denke, die Nachricht in der ActionBar reicht aus. player bekommt eine doppelte Nachricht, ich denke, die Nachricht in der ActionBar reicht aus.
|
||||
|
||||
net.minecraft.server.v1_15_R1.Entity serverEntitiy = ((CraftEntity) entity).getHandle();
|
||||
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(serverEntity);
|
||||
sendPlayers(packetPlayOutEntityTeleport);
|
||||
|
||||
Lixfel
hat
§c §c
|
||||
PacketPlayOutEntityVelocity packet1 = new PacketPlayOutEntityVelocity(entity.getEntityId(), new Vec3D(0, 0, 0));
|
||||
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true);
|
||||
sendPlayers(packetPlayOutEntityMetadata);
|
||||
|
||||
PacketPlayOutEntityTeleport packet2 = new PacketPlayOutEntityTeleport(serverEntitiy);
|
||||
Vec3D vec3D = serverEntity.getMot();
|
||||
PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20 - currentTPSLimit), vec3D.y / (20 - currentTPSLimit), vec3D.z / (20 - currentTPSLimit)));
|
||||
sendPlayers(packetPlayOutEntityVelocity);
|
||||
}
|
||||
});
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_VELOCITY) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
|
||||
DataWatcher dataWatcher = new DataWatcher(serverEntitiy);
|
||||
dataWatcher.register(new DataWatcherObject<>(5, DataWatcherRegistry.i), true);
|
||||
dataWatcher.register(new DataWatcherObject<>(7, DataWatcherRegistry.b), 80);
|
||||
PacketPlayOutEntityMetadata packet3 = new PacketPlayOutEntityMetadata(serverEntitiy.getId(), dataWatcher, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
||||
connection.sendPacket(packet1);
|
||||
connection.sendPacket(packet2);
|
||||
connection.sendPacket(packet3);
|
||||
});
|
||||
});
|
||||
world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> {
|
||||
Location location = entity.getLocation();
|
||||
world.spawnParticle(Particle.BARRIER, location.getX(), location.getY() + 0.49, location.getZ(), 1);
|
||||
});
|
||||
}, 0, 1);
|
||||
private boolean tpsLimiterNotActive() {
|
||||
return currentTPSLimit == 20;
|
||||
}
|
||||
|
||||
private void sendPlayers(Packet<?> packet) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
||||
connection.sendPacket(packet);
|
||||
});
|
||||
}
|
||||
|
||||
private WrappedWatchableObject getByIndex(List<WrappedWatchableObject> wrappedWatchableObjects, int index) {
|
||||
for (WrappedWatchableObject wrappedWatchableObject : wrappedWatchableObjects) {
|
||||
if (wrappedWatchableObject.getIndex() == index) return wrappedWatchableObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Finde ich nicht so ganz elegant, dass das die ganze Zeit mitläuft. Besser wäre, sich ggf. den Task zu merken und ihn dann zu Stoppen/zu starten.
Wenn ich den Task cancel() dann würde natürlich der server kurzzeitig schneller als 20 tps laufen. Nur damit das klar ist.