Add /tpslimit Command #113
@ -79,5 +79,12 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>steamwar</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${main.basedir}/lib/ProtocolLib.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.commands;
|
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;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
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;
|
||||||
@ -34,11 +40,14 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
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.craftbukkit.v1_15_R1.entity.CraftTNTPrimed;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandTPSLimiter implements CommandExecutor {
|
public class CommandTPSLimiter implements CommandExecutor {
|
||||||
|
|
||||||
private static int currentTPSLimit = 20;
|
private static int currentTPSLimit = 20;
|
||||||
@ -49,43 +58,71 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
private BukkitTask tpsLimiter = null;
|
private BukkitTask tpsLimiter = null;
|
||||||
|
|
||||||
public CommandTPSLimiter() {
|
public CommandTPSLimiter() {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_METADATA) {
|
||||||
if (currentTPSLimit == 20) {
|
@Override
|
||||||
return;
|
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);
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.REL_ENTITY_MOVE) {
|
||||||
System.out.println("Let " + entity.getName() + " sneak " + sneaking);
|
@Override
|
||||||
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), sneaking ? (byte)0x02 : (byte)0x40);
|
public void onPacketSending(PacketEvent event) {
|
||||||
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
|
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()){
|
Entity entity = event.getPacket().getEntityModifier(world).read(0);
|
||||||
((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
|
System.out.println(entity.getLocation());
|
||||||
}*/
|
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle();
|
||||||
|
|
||||||
net.minecraft.server.v1_15_R1.Entity serverEntitiy = ((CraftEntity) entity).getHandle();
|
PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(serverEntity);
|
||||||
|
sendPlayers(packetPlayOutEntityTeleport);
|
||||||
|
|
||||||
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 -> {
|
private boolean tpsLimiterNotActive() {
|
||||||
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
return currentTPSLimit == 20;
|
||||||
connection.sendPacket(packet1);
|
}
|
||||||
connection.sendPacket(packet2);
|
|
||||||
connection.sendPacket(packet3);
|
private void sendPlayers(Packet<?> packet) {
|
||||||
});
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
});
|
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
|
||||||
world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> {
|
connection.sendPacket(packet);
|
||||||
Location location = entity.getLocation();
|
});
|
||||||
world.spawnParticle(Particle.BARRIER, location.getX(), location.getY() + 0.49, location.getZ(), 1);
|
}
|
||||||
});
|
|
||||||
}, 0, 1);
|
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) {
|
private boolean permissionCheck(Player player) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren