From eeef18d504e43be4a211285da25ebafe597775cd Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 13:12:52 +0100 Subject: [PATCH 01/13] Add /tpslimit Command --- .../src/de/steamwar/bausystem/BauSystem.java | 2 + .../bausystem/commands/CommandTPSLimiter.java | 100 ++++++++++++++++++ .../CommandTPSLimiterTabComplete.java | 29 +++++ .../commands/CommandTraceTabCompleter.java | 1 - .../bausystem/world/BauScoreboard.java | 7 +- BauSystem_Main/src/plugin.yml | 1 + 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 18d1f2a..b3ce821 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -98,6 +98,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("trace").setExecutor(new CommandTrace()); getCommand("trace").setTabCompleter(new CommandTraceTabCompleter()); + getCommand("tpslimit").setExecutor(new CommandTPSLimiter()); + getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete()); getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java new file mode 100644 index 0000000..c5daea6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -0,0 +1,100 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; + +public class CommandTPSLimiter implements CommandExecutor { + + private static int currentTPSLimit = 20; + private static World world = Bukkit.getWorlds().get(0); + private long lastTime = System.currentTimeMillis(); + private long currentTime = System.currentTimeMillis(); + + public CommandTPSLimiter() { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + lastTime = currentTime; + currentTime = System.currentTimeMillis(); + + long timeDelta = currentTime - lastTime; + long neededDelta = 1000 / currentTPSLimit; + + if (neededDelta - timeDelta < 1) { + return; + } + + try { + Thread.sleep(neededDelta - timeDelta); + currentTime = System.currentTimeMillis(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }, 0, 1); + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + if (currentTPSLimit == 20) { + return; + } + + 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); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + return false; + } else if (args.length == 0) { + sender.sendMessage(BauSystem.PREFIX + "Jetziges TPS limit: " + currentTPSLimit); + sender.sendMessage(BauSystem.PREFIX + "Ändere das TPS limit mit: §8/§etpslimit §8[§7TPS§8|§edefault§8]"); + return false; + } + Player player = (Player) sender; + + String tpsLimit = args[0]; + if (tpsLimit.equals("default")) { + currentTPSLimit = 20; + sendNewTPSLimitMessage(player); + return false; + } + + try { + int tpsLimitInt = Integer.parseInt(tpsLimit); + if (tpsLimitInt < 1 || tpsLimitInt > 20) { + sendInvalidArgumentMessage(player); + return false; + } + currentTPSLimit = tpsLimitInt; + sendNewTPSLimitMessage(player); + } catch (NumberFormatException e) { + sendInvalidArgumentMessage(player); + } + + return false; + } + + private void sendNewTPSLimitMessage(Player player) { + player.sendMessage(BauSystem.PREFIX + "TPS limit auf " + currentTPSLimit + " gesetzt."); + Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt."))); + } + + private void sendInvalidArgumentMessage(Player player) { + player.sendMessage(BauSystem.PREFIX + "Nur Zahlen zwischen 1 und 20, und 'default' erlaubt."); + } + + public static int getCurrentTPSLimit() { + return currentTPSLimit; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java new file mode 100644 index 0000000..a250019 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -0,0 +1,29 @@ +package de.steamwar.bausystem.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CommandTPSLimiterTabComplete implements TabCompleter { + + private List arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) { + return new ArrayList<>(); + } + List validArguments = new ArrayList<>(arguments.size()); + for (String s : arguments) { + if (s.startsWith(args[0])) { + validArguments.add(s); + } + } + return validArguments; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index d21551d..b97fa39 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.tracer.recorder.RecordManager; -import de.steamwar.core.Core; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index bbe4330..e1fb722 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.commands.CommandFreeze; import de.steamwar.bausystem.commands.CommandTNT; +import de.steamwar.bausystem.commands.CommandTPSLimiter; import de.steamwar.bausystem.tracer.TraceManager; import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.bausystem.tracer.recorder.TNTRecorder; @@ -72,7 +73,11 @@ public class BauScoreboard implements Listener { } strings.add("§4"); - strings.add("§eTPS§8: §7" + TPSWatcher.getTPS()); + if (CommandTPSLimiter.getCurrentTPSLimit() == 20) { + strings.add("§eTPS§8: §7" + TPSWatcher.getTPS()); + } else { + strings.add("§eTPS§8: §7" + TPSWatcher.getTPS() + " §eLimit§8: §7" + CommandTPSLimiter.getCurrentTPSLimit()); + } int i = strings.size(); HashMap result = new HashMap<>(); diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 4a21d05..bfd4616 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -11,6 +11,7 @@ commands: tnt: fire: trace: + tpslimit: testblock: aliases: tb reset: -- 2.39.2 From 50c18084b40d6f915737566c5d4236e331aaaf54 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 13:42:19 +0100 Subject: [PATCH 02/13] Fix BauScoreboard Fix TPSLimiter --- .../bausystem/commands/CommandTPSLimiter.java | 99 ++++++++++++++----- .../CommandTPSLimiterTabComplete.java | 19 ++++ .../bausystem/world/BauScoreboard.java | 2 +- 3 files changed, 94 insertions(+), 26 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index c5daea6..af5d181 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -1,49 +1,65 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_15_R1.PacketPlayOutEntityVelocity; +import net.minecraft.server.v1_15_R1.PlayerConnection; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.World; +import org.bukkit.block.data.type.TNT; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitTask; public class CommandTPSLimiter implements CommandExecutor { private static int currentTPSLimit = 20; private static World world = Bukkit.getWorlds().get(0); - private long lastTime = System.currentTimeMillis(); - private long currentTime = System.currentTimeMillis(); + private long lastTime = System.nanoTime(); + private long currentTime = System.nanoTime(); + + private BukkitTask tpsLimiter = null; public CommandTPSLimiter() { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - lastTime = currentTime; - currentTime = System.currentTimeMillis(); - - long timeDelta = currentTime - lastTime; - long neededDelta = 1000 / currentTPSLimit; - - if (neededDelta - timeDelta < 1) { - return; - } - - try { - Thread.sleep(neededDelta - timeDelta); - currentTime = System.currentTimeMillis(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - }, 0, 1); Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { if (currentTPSLimit == 20) { return; } + /*PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(entity); + for(Player player : Bukkit.getOnlinePlayers()){ + PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; + connection.sendPacket(packet); + } + world.getEntities().stream().filter(entity -> entity instanceof TNT).forEach(entity -> entity.setVelocity(0, 0, 0));*/ + 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); @@ -65,7 +81,8 @@ public class CommandTPSLimiter implements CommandExecutor { String tpsLimit = args[0]; if (tpsLimit.equals("default")) { currentTPSLimit = 20; - sendNewTPSLimitMessage(player); + sendNewTPSLimitMessage(); + tpsLimiter(); return false; } @@ -76,7 +93,8 @@ public class CommandTPSLimiter implements CommandExecutor { return false; } currentTPSLimit = tpsLimitInt; - sendNewTPSLimitMessage(player); + sendNewTPSLimitMessage(); + tpsLimiter(); } catch (NumberFormatException e) { sendInvalidArgumentMessage(player); } @@ -84,17 +102,48 @@ public class CommandTPSLimiter implements CommandExecutor { return false; } - private void sendNewTPSLimitMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + "TPS limit auf " + currentTPSLimit + " gesetzt."); + private void sendNewTPSLimitMessage() { Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt."))); } private void sendInvalidArgumentMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + "Nur Zahlen zwischen 1 und 20, und 'default' erlaubt."); + player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 1 und 20, und 'default' erlaubt."); + } + + private void tpsLimiter() { + if (currentTPSLimit == 20) { + if (tpsLimiter == null) return; + tpsLimiter.cancel(); + tpsLimiter = null; + } else { + if (tpsLimiter != null) return; + tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + lastTime = currentTime; + currentTime = System.nanoTime(); + + long timeDelta = (currentTime - lastTime) / 1000000; + long neededDelta = 1000 / currentTPSLimit; + + if (neededDelta - timeDelta < 1) { + return; + } + + try { + Thread.sleep(neededDelta - timeDelta); + currentTime = System.nanoTime(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }, 0, 1); + } } public static int getCurrentTPSLimit() { return currentTPSLimit; } + private void setMotion(Entity entity) { + + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java index a250019..9b401ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bausystem.commands; import org.bukkit.command.Command; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index e1fb722..3c05bdd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -76,7 +76,7 @@ public class BauScoreboard implements Listener { if (CommandTPSLimiter.getCurrentTPSLimit() == 20) { strings.add("§eTPS§8: §7" + TPSWatcher.getTPS()); } else { - strings.add("§eTPS§8: §7" + TPSWatcher.getTPS() + " §eLimit§8: §7" + CommandTPSLimiter.getCurrentTPSLimit()); + strings.add("§eTPS§8: §7" + TPSWatcher.getTPS() + "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit()); } int i = strings.size(); -- 2.39.2 From 179632cd21744890f10c05a7e52c65fae6c7fb27 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 13:54:00 +0100 Subject: [PATCH 03/13] Fix BauScoreboard --- .../bausystem/world/BauScoreboard.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3c05bdd..117a4ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -73,11 +73,7 @@ public class BauScoreboard implements Listener { } strings.add("§4"); - if (CommandTPSLimiter.getCurrentTPSLimit() == 20) { - strings.add("§eTPS§8: §7" + TPSWatcher.getTPS()); - } else { - strings.add("§eTPS§8: §7" + TPSWatcher.getTPS() + "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit()); - } + strings.add("§eTPS§8: " + tpsColor() + TPSWatcher.getTPS() + tpsLimit()); int i = strings.size(); HashMap result = new HashMap<>(); @@ -89,4 +85,22 @@ public class BauScoreboard implements Listener { private long traceTicks() { return (System.currentTimeMillis() - TNTRecorder.recordStart) / 50; } + + private String tpsColor() { + double tps = TPSWatcher.getTPS(); + if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { + return "§a"; + } + if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.5) { + return "§e"; + } + return "§c"; + } + + private String tpsLimit() { + if (CommandTPSLimiter.getCurrentTPSLimit() == 20) { + return ""; + } + return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); + } } -- 2.39.2 From d23875cc3a0ea150d8110510b86dfffe705b27d5 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 14:10:11 +0100 Subject: [PATCH 04/13] Add Permission Check in CommandTPSLimiter --- .../bausystem/commands/CommandTPSLimiter.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index af5d181..b373a7e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -20,6 +20,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Welt; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityVelocity; @@ -67,6 +69,14 @@ public class CommandTPSLimiter implements CommandExecutor { }, 0, 1); } + private boolean permissionCheck(Player player) { + if(Welt.noPermission(player, Permission.world)){ + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen"); + return false; + } + return true; + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { @@ -77,6 +87,8 @@ public class CommandTPSLimiter implements CommandExecutor { return false; } Player player = (Player) sender; + // TODO: Remove on final push + // if (permissionCheck(player)) return false; String tpsLimit = args[0]; if (tpsLimit.equals("default")) { -- 2.39.2 From e9facf92ca865253e7fe584d6f7830e34bb586d6 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 15:55:34 +0100 Subject: [PATCH 05/13] Add velocity (commented) --- .../bausystem/commands/CommandTPSLimiter.java | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index b373a7e..1827ecd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -24,17 +24,13 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_15_R1.PlayerConnection; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.World; -import org.bukkit.block.data.type.TNT; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -50,27 +46,50 @@ public class CommandTPSLimiter implements CommandExecutor { private BukkitTask tpsLimiter = null; public CommandTPSLimiter() { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - if (currentTPSLimit == 20) { - return; - } + /* + + steamwar + ProtocolLib + 1.0 + system + ${main.basedir}/lib/ProtocolLib.jar + + */ + /*ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Core.getInstance(), PacketType.Play.Server.ENTITY_VELOCITY) { + @Override + public void onPacketSending(PacketEvent event) { + if (currentTPSLimit == 20) { + return; + } - /*PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(entity); + StructureModifier structureModifier = event.getPacket().getIntegers(); + structureModifier.write(1, 0); + structureModifier.write(2, 0); + structureModifier.write(3, 0); + // PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity() + } + });*/ + /*PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(entity); for(Player player : Bukkit.getOnlinePlayers()){ PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; connection.sendPacket(packet); + + } world.getEntities().stream().filter(entity -> entity instanceof TNT).forEach(entity -> entity.setVelocity(0, 0, 0));*/ - - 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); - }); + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + if (currentTPSLimit == 20) { + return; + } + 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 permissionCheck(Player player) { - if(Welt.noPermission(player, Permission.world)){ + if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen"); return false; } -- 2.39.2 From 9388e1abd5e2ccaf37b3a831f9417aae7330105e Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 19:35:32 +0100 Subject: [PATCH 06/13] Add velocity --- .../bausystem/commands/CommandTPSLimiter.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 1827ecd..8365aa7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Particle; @@ -31,6 +32,8 @@ import org.bukkit.World; import org.bukkit.command.Command; 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.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -46,41 +49,38 @@ public class CommandTPSLimiter implements CommandExecutor { private BukkitTask tpsLimiter = null; public CommandTPSLimiter() { - /* - - steamwar - ProtocolLib - 1.0 - system - ${main.basedir}/lib/ProtocolLib.jar - - */ - /*ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(Core.getInstance(), PacketType.Play.Server.ENTITY_VELOCITY) { - @Override - public void onPacketSending(PacketEvent event) { - if (currentTPSLimit == 20) { - return; - } - - StructureModifier structureModifier = event.getPacket().getIntegers(); - structureModifier.write(1, 0); - structureModifier.write(2, 0); - structureModifier.write(3, 0); - // PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity() - } - });*/ - /*PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(entity); - for(Player player : Bukkit.getOnlinePlayers()){ - PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; - connection.sendPacket(packet); - - - } - world.getEntities().stream().filter(entity -> entity instanceof TNT).forEach(entity -> entity.setVelocity(0, 0, 0));*/ Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { if (currentTPSLimit == 20) { return; } + 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); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet); + }*/ + + net.minecraft.server.v1_15_R1.Entity serverEntitiy = ((CraftEntity) entity).getHandle(); + + PacketPlayOutEntityVelocity packet1 = new PacketPlayOutEntityVelocity(entity.getEntityId(), new Vec3D(0, 0, 0)); + + PacketPlayOutEntityTeleport packet2 = new PacketPlayOutEntityTeleport(serverEntitiy); + + 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); -- 2.39.2 From ab170426cbddfbff855d24ba7531e78cdf14baa3 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 21:54:06 +0100 Subject: [PATCH 07/13] Fix CommandTPSLimiter --- BauSystem_Main/pom.xml | 7 ++ .../bausystem/commands/CommandTPSLimiter.java | 97 +++++++++++++------ 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index 3aa54e7..62e4e51 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -79,5 +79,12 @@ system ${main.basedir}/lib/WorldEdit-1.15.jar + + steamwar + ProtocolLib + 1.0 + system + ${main.basedir}/lib/ProtocolLib.jar + diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 8365aa7..0d91d83 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -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; +import com.comphenix.protocol.wrappers.WrappedWatchableObject; 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; + public class CommandTPSLimiter implements CommandExecutor { private static int currentTPSLimit = 20; @@ -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 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 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(); - 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 -> { - 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 wrappedWatchableObjects, int index) { + for (WrappedWatchableObject wrappedWatchableObject : wrappedWatchableObjects) { + if (wrappedWatchableObject.getIndex() == index) return wrappedWatchableObject; + } + return null; } private boolean permissionCheck(Player player) { -- 2.39.2 From 36d6c6bedbd6ee24e8adec7fcb4b5768ad3f1436 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 07:28:49 +0100 Subject: [PATCH 08/13] Fix CommandTPSLimiter --- .../bausystem/commands/CommandTPSLimiter.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 0d91d83..093182c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -32,8 +32,6 @@ import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -43,7 +41,6 @@ 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; @@ -64,11 +61,11 @@ public class CommandTPSLimiter implements CommandExecutor { // 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)); + System.out.println("ENTITY_METADATA: " + event.getPacket().getIntegers().read(0)); List dataWatcherObjectList = event.getPacket().getWatchableCollectionModifier().read(0); - getByIndex(dataWatcherObjectList, 5).setValue(true); + // getByIndex(dataWatcherObjectList, 5).setValue(true); getByIndex(dataWatcherObjectList, 7).setValue((int) ((20.0 / currentTPSLimit) * 80)); - System.out.println(dataWatcherObjectList); + // System.out.println(dataWatcherObjectList); event.getPacket().getWatchableCollectionModifier().write(0, dataWatcherObjectList); } }); @@ -78,14 +75,14 @@ public class CommandTPSLimiter implements CommandExecutor { 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)); + System.out.println("REL_ENTITY_MOVE: " + event.getPacket().getIntegers().read(0)); StructureModifier structureModifier = event.getPacket().getIntegers(); // structureModifier.write(1, 0); // structureModifier.write(2, 0); // structureModifier.write(3, 0); Entity entity = event.getPacket().getEntityModifier(world).read(0); - System.out.println(entity.getLocation()); + // System.out.println(entity.getLocation()); net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(serverEntity); @@ -95,7 +92,7 @@ public class CommandTPSLimiter implements CommandExecutor { sendPlayers(packetPlayOutEntityMetadata); Vec3D vec3D = serverEntity.getMot(); - PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20 - currentTPSLimit), vec3D.y / (20 - currentTPSLimit), vec3D.z / (20 - currentTPSLimit))); + PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); sendPlayers(packetPlayOutEntityVelocity); } }); -- 2.39.2 From 9a082dbdbac75dafab9f7c326524523ead6db524 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 13:39:29 +0100 Subject: [PATCH 09/13] Fix CommandTPSLimiter --- .../bausystem/commands/CommandTPSLimiter.java | 116 +++++++++++++++--- 1 file changed, 96 insertions(+), 20 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 093182c..2ba8be0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -41,9 +41,12 @@ 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.HashSet; import java.util.List; +import java.util.Set; public class CommandTPSLimiter implements CommandExecutor { @@ -58,6 +61,7 @@ public class CommandTPSLimiter implements CommandExecutor { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_METADATA) { @Override public void onPacketSending(PacketEvent event) { + if (true) return; // if (tpsLimiterNotActive()) return; if (event.getPacket().getEntityModifier(world).read(0) == null) return; if (!(event.getPacket().getEntityModifier(world).read(0) instanceof CraftTNTPrimed)) return; @@ -72,6 +76,7 @@ public class CommandTPSLimiter implements CommandExecutor { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.REL_ENTITY_MOVE) { @Override public void onPacketSending(PacketEvent event) { + if (true) return; if (tpsLimiterNotActive()) return; if (event.getPacket().getEntityModifier(world).read(0) == null) return; if (!(event.getPacket().getEntityModifier(world).read(0) instanceof CraftTNTPrimed)) return; @@ -92,14 +97,48 @@ public class CommandTPSLimiter implements CommandExecutor { sendPlayers(packetPlayOutEntityMetadata); Vec3D vec3D = serverEntity.getMot(); - PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); - sendPlayers(packetPlayOutEntityVelocity); + /*PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); + sendPlayers(packetPlayOutEntityVelocity);*/ } }); ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_VELOCITY) { + + private Set entitySet = new HashSet<>(); + @Override public void onPacketSending(PacketEvent event) { + if (true) return; + 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("ENTITY_VELOCITY: " + event.getPacket().getIntegers().read(0)); + System.out.println(event.getPacket().getIntegers().getValues()); + // event.setCancelled(true); + + Entity entity = event.getPacket().getEntityModifier(world).read(0); + + if (entitySet.contains(entity)) { + entitySet.remove(entity); + } else { + entitySet.add(entity); + event.setCancelled(true); + + net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); + Vec3D vec3D = serverEntity.getMot(); + PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); + sendPlayers(packetPlayOutEntityVelocity); + } + +// PacketContainer packetContainer = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY); +// StructureModifier structureModifier = packetContainer.getIntegers(); +// structureModifier.write(0, entity.getEntityId()); +// structureModifier.write(1, (int) (serverEntity.getMot().x / (20.0 / currentTPSLimit) * 8000)); +// structureModifier.write(2, (int) (serverEntity.getMot().y / (20.0 / currentTPSLimit) * 8000)); +// structureModifier.write(3, (int) (serverEntity.getMot().z / (20.0 / currentTPSLimit) * 8000)); + // event.setPacket(packetContainer); + + // System.out.println(event.getPacket().getIntegers()); } }); } @@ -115,6 +154,15 @@ public class CommandTPSLimiter implements CommandExecutor { }); } + private void sendPlayers(Set> packets) { + Bukkit.getOnlinePlayers().forEach(player -> { + PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; + for (Packet p : packets) { + connection.sendPacket(p); + } + }); + } + private WrappedWatchableObject getByIndex(List wrappedWatchableObjects, int index) { for (WrappedWatchableObject wrappedWatchableObject : wrappedWatchableObjects) { if (wrappedWatchableObject.getIndex() == index) return wrappedWatchableObject; @@ -183,32 +231,60 @@ public class CommandTPSLimiter implements CommandExecutor { } else { if (tpsLimiter != null) return; tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - lastTime = currentTime; - currentTime = System.nanoTime(); + sendTntMetaData(); - long timeDelta = (currentTime - lastTime) / 1000000; - long neededDelta = 1000 / currentTPSLimit; - - if (neededDelta - timeDelta < 1) { - return; - } - - try { - Thread.sleep(neededDelta - timeDelta); - currentTime = System.nanoTime(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + for (int i = 0; i < (20 / currentTPSLimit); i++) { + sleepUntilNextTick(); + sendTntData(); } }, 0, 1); } } + private void sleepUntilNextTick() { + lastTime = currentTime; + currentTime = System.nanoTime(); + + long timeDelta = (currentTime - lastTime) / 1000000; + long neededDelta = 50; + + if (neededDelta - timeDelta < 0) { + return; + } + + try { + Thread.sleep(neededDelta - timeDelta); + currentTime = System.nanoTime(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + + private void sendTntData() { + Vec3D noMotion = new Vec3D(0, 0, 0); + Set> 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)); + packets.add(new PacketPlayOutEntityVelocity(serverEntity.getId(), noMotion)); + }); + + sendPlayers(packets); + } + + private void sendTntMetaData() { + world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { + net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); + + PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true); + sendPlayers(packetPlayOutEntityMetadata); + }); + } + public static int getCurrentTPSLimit() { return currentTPSLimit; } - private void setMotion(Entity entity) { - - } - } -- 2.39.2 From 9b803facd55022bf85c3d3137907dfd7c388cc64 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 13:59:01 +0100 Subject: [PATCH 10/13] Fix CommandTPSLimiter --- BauSystem_Main/pom.xml | 7 - .../bausystem/commands/CommandTPSLimiter.java | 135 +++--------------- 2 files changed, 19 insertions(+), 123 deletions(-) diff --git a/BauSystem_Main/pom.xml b/BauSystem_Main/pom.xml index 62e4e51..3aa54e7 100644 --- a/BauSystem_Main/pom.xml +++ b/BauSystem_Main/pom.xml @@ -79,12 +79,5 @@ system ${main.basedir}/lib/WorldEdit-1.15.jar - - steamwar - ProtocolLib - 1.0 - system - ${main.basedir}/lib/ProtocolLib.jar - diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 2ba8be0..40cfd84 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -19,12 +19,6 @@ 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.Permission; import de.steamwar.bausystem.world.Welt; @@ -38,14 +32,11 @@ 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.HashSet; -import java.util.List; import java.util.Set; public class CommandTPSLimiter implements CommandExecutor { @@ -58,93 +49,7 @@ public class CommandTPSLimiter implements CommandExecutor { private BukkitTask tpsLimiter = null; public CommandTPSLimiter() { - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_METADATA) { - @Override - public void onPacketSending(PacketEvent event) { - if (true) return; - // 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("ENTITY_METADATA: " + event.getPacket().getIntegers().read(0)); - List 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); - } - }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.REL_ENTITY_MOVE) { - @Override - public void onPacketSending(PacketEvent event) { - if (true) return; - 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("REL_ENTITY_MOVE: " + event.getPacket().getIntegers().read(0)); - StructureModifier structureModifier = event.getPacket().getIntegers(); - // structureModifier.write(1, 0); - // structureModifier.write(2, 0); - // structureModifier.write(3, 0); - Entity entity = event.getPacket().getEntityModifier(world).read(0); - // System.out.println(entity.getLocation()); - net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); - - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(serverEntity); - sendPlayers(packetPlayOutEntityTeleport); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true); - sendPlayers(packetPlayOutEntityMetadata); - - Vec3D vec3D = serverEntity.getMot(); - /*PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); - sendPlayers(packetPlayOutEntityVelocity);*/ - } - }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Server.ENTITY_VELOCITY) { - - private Set entitySet = new HashSet<>(); - - @Override - public void onPacketSending(PacketEvent event) { - if (true) return; - 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("ENTITY_VELOCITY: " + event.getPacket().getIntegers().read(0)); - - System.out.println(event.getPacket().getIntegers().getValues()); - // event.setCancelled(true); - - Entity entity = event.getPacket().getEntityModifier(world).read(0); - - if (entitySet.contains(entity)) { - entitySet.remove(entity); - } else { - entitySet.add(entity); - event.setCancelled(true); - - net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); - Vec3D vec3D = serverEntity.getMot(); - PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(serverEntity.getId(), new Vec3D(vec3D.x / (20.0 / currentTPSLimit), vec3D.y / (20.0 / currentTPSLimit), vec3D.z / (20.0 / currentTPSLimit))); - sendPlayers(packetPlayOutEntityVelocity); - } - -// PacketContainer packetContainer = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY); -// StructureModifier structureModifier = packetContainer.getIntegers(); -// structureModifier.write(0, entity.getEntityId()); -// structureModifier.write(1, (int) (serverEntity.getMot().x / (20.0 / currentTPSLimit) * 8000)); -// structureModifier.write(2, (int) (serverEntity.getMot().y / (20.0 / currentTPSLimit) * 8000)); -// structureModifier.write(3, (int) (serverEntity.getMot().z / (20.0 / currentTPSLimit) * 8000)); - // event.setPacket(packetContainer); - - // System.out.println(event.getPacket().getIntegers()); - } - }); - } - - private boolean tpsLimiterNotActive() { - return currentTPSLimit == 20; } private void sendPlayers(Packet packet) { @@ -163,13 +68,6 @@ public class CommandTPSLimiter implements CommandExecutor { }); } - private WrappedWatchableObject getByIndex(List wrappedWatchableObjects, int index) { - for (WrappedWatchableObject wrappedWatchableObject : wrappedWatchableObjects) { - if (wrappedWatchableObject.getIndex() == index) return wrappedWatchableObject; - } - return null; - } - private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen"); @@ -233,9 +131,16 @@ public class CommandTPSLimiter implements CommandExecutor { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { sendTntMetaData(); + Vec3D noMotion = new Vec3D(0, 0, 0); + Set velocityPackets = new HashSet<>(); + world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { + velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion)); + }); + for (int i = 0; i < (20 / currentTPSLimit); i++) { sleepUntilNextTick(); sendTntData(); + sendPlayers(velocityPackets); } }, 0, 1); } @@ -260,20 +165,6 @@ public class CommandTPSLimiter implements CommandExecutor { } } - private void sendTntData() { - Vec3D noMotion = new Vec3D(0, 0, 0); - Set> 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)); - packets.add(new PacketPlayOutEntityVelocity(serverEntity.getId(), noMotion)); - }); - - sendPlayers(packets); - } - private void sendTntMetaData() { world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); @@ -283,6 +174,18 @@ public class CommandTPSLimiter implements CommandExecutor { }); } + private void sendTntData() { + Set> 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)); + // packets.add(new PacketPlayOutEntityVelocity(serverEntity.getId(), noMotion)); + }); + + sendPlayers(packets); + } + public static int getCurrentTPSLimit() { return currentTPSLimit; } -- 2.39.2 From b2efaa55f66480e45208655c87f5789f63e452ee Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 14:02:05 +0100 Subject: [PATCH 11/13] Add Permission Check --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 40cfd84..a90a51d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -86,8 +86,7 @@ public class CommandTPSLimiter implements CommandExecutor { return false; } Player player = (Player) sender; - // TODO: Remove on final push - // if (permissionCheck(player)) return false; + if (permissionCheck(player)) return false; String tpsLimit = args[0]; if (tpsLimit.equals("default")) { -- 2.39.2 From 87285ee80271a01f3267e6c333c9a3405e12fc14 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 14:04:08 +0100 Subject: [PATCH 12/13] Add Permission Check --- .../src/de/steamwar/bausystem/commands/CommandTPSLimiter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index a90a51d..7b551e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -86,7 +86,7 @@ public class CommandTPSLimiter implements CommandExecutor { return false; } Player player = (Player) sender; - if (permissionCheck(player)) return false; + if (!permissionCheck(player)) return false; String tpsLimit = args[0]; if (tpsLimit.equals("default")) { -- 2.39.2 From ea6505e3c777d9af6338156c712353d83dccad2f Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 16 Nov 2020 14:24:55 +0100 Subject: [PATCH 13/13] Seperate Version dependant code --- .../bausystem/commands/TPSLimit_12.java | 79 +++++++++++++++++ .../bausystem/commands/TPSLimit_15.java | 80 +++++++++++++++++ .../bausystem/commands/CommandTPSLimiter.java | 86 ++++++++----------- 3 files changed, 196 insertions(+), 49 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java new file mode 100644 index 0000000..d32d4cb --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java @@ -0,0 +1,79 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.commands; + +import net.minecraft.server.v1_12_R1.*; +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.TNTPrimed; + +import java.util.HashSet; +import java.util.Set; + +class TPSLimit_12 { + + private static Set velocityPackets = new HashSet<>(); + + static void createVelocityPacketCache(World world) { + velocityPackets.clear(); + world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { + velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0)); + }); + } + + static void sendVelocityPackets() { + sendPacketsToPlayer(velocityPackets); + } + + static void sendTntMetaData(World world) { + Set> 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> 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> packets) { + Bukkit.getOnlinePlayers().forEach(player -> { + PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; + for (Packet p : packets) { + connection.sendPacket(p); + } + }); + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java new file mode 100644 index 0000000..cb32794 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java @@ -0,0 +1,80 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.bausystem.commands; + +import net.minecraft.server.v1_15_R1.*; +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.TNTPrimed; + +import java.util.HashSet; +import java.util.Set; + +class TPSLimit_15 { + + private static Set velocityPackets = new HashSet<>(); + 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 sendVelocityPackets() { + sendPacketsToPlayer(velocityPackets); + } + + static void sendTntMetaData(World world) { + Set> 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> 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> packets) { + Bukkit.getOnlinePlayers().forEach(player -> { + PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; + for (Packet p : packets) { + connection.sendPacket(p); + } + }); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java index 7b551e4..94df329 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java @@ -22,23 +22,17 @@ 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 net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.Command; 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.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.scheduler.BukkitTask; -import java.util.HashSet; -import java.util.Set; - public class CommandTPSLimiter implements CommandExecutor { private static int currentTPSLimit = 20; @@ -48,26 +42,6 @@ public class CommandTPSLimiter implements CommandExecutor { private BukkitTask tpsLimiter = null; - public CommandTPSLimiter() { - - } - - private void sendPlayers(Packet packet) { - Bukkit.getOnlinePlayers().forEach(player -> { - PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; - connection.sendPacket(packet); - }); - } - - private void sendPlayers(Set> packets) { - Bukkit.getOnlinePlayers().forEach(player -> { - PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; - for (Packet p : packets) { - connection.sendPacket(p); - } - }); - } - private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen"); @@ -130,16 +104,11 @@ public class CommandTPSLimiter implements CommandExecutor { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { sendTntMetaData(); - Vec3D noMotion = new Vec3D(0, 0, 0); - Set velocityPackets = new HashSet<>(); - world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { - velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion)); - }); - + createVelocityData(); for (int i = 0; i < (20 / currentTPSLimit); i++) { sleepUntilNextTick(); sendTntData(); - sendPlayers(velocityPackets); + sendVelocityData(); } }, 0, 1); } @@ -164,25 +133,44 @@ public class CommandTPSLimiter implements CommandExecutor { } } - private void sendTntMetaData() { - world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { - net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); + private void createVelocityData() { + switch (Core.getVersion()) { + case 15: + TPSLimit_15.createVelocityPacketCache(world); + break; + default: + TPSLimit_12.createVelocityPacketCache(world); + } + } - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true); - sendPlayers(packetPlayOutEntityMetadata); - }); + 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() { - Set> 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)); - // packets.add(new PacketPlayOutEntityVelocity(serverEntity.getId(), noMotion)); - }); - - sendPlayers(packets); + switch (Core.getVersion()) { + case 15: + TPSLimit_15.sendTntData(world); + break; + default: + TPSLimit_12.sendTntData(world); + } } public static int getCurrentTPSLimit() { -- 2.39.2