SteamWar/BauSystem
Archiviert
13
0

Seperate Version dependant code

Dieser Commit ist enthalten in:
jojo 2020-11-16 14:24:55 +01:00
Ursprung 87285ee802
Commit ea6505e3c7
3 geänderte Dateien mit 196 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<PacketPlayOutEntityVelocity> 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<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 -> {
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
for (Packet<?> p : packets) {
connection.sendPacket(p);
}
});
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<PacketPlayOutEntityVelocity> 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<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 -> {
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
for (Packet<?> p : packets) {
connection.sendPacket(p);
}
});
}
}

Datei anzeigen

@ -22,23 +22,17 @@ 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 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 net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; 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.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.HashSet;
import java.util.Set;
public class CommandTPSLimiter implements CommandExecutor { public class CommandTPSLimiter implements CommandExecutor {
private static int currentTPSLimit = 20; private static int currentTPSLimit = 20;
@ -48,26 +42,6 @@ public class CommandTPSLimiter implements CommandExecutor {
private BukkitTask tpsLimiter = null; 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<? extends Packet<?>> packets) {
Bukkit.getOnlinePlayers().forEach(player -> {
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
for (Packet<?> p : packets) {
connection.sendPacket(p);
}
});
}
private boolean permissionCheck(Player player) { 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"); 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(), () -> { tpsLimiter = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
sendTntMetaData(); sendTntMetaData();
Vec3D noMotion = new Vec3D(0, 0, 0); createVelocityData();
Set<PacketPlayOutEntityVelocity> velocityPackets = new HashSet<>();
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> {
velocityPackets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion));
});
for (int i = 0; i < (20 / currentTPSLimit); i++) { for (int i = 0; i < (20 / currentTPSLimit); i++) {
sleepUntilNextTick(); sleepUntilNextTick();
sendTntData(); sendTntData();
sendPlayers(velocityPackets); sendVelocityData();
} }
}, 0, 1); }, 0, 1);
} }
@ -164,25 +133,44 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
} }
private void sendTntMetaData() { private void createVelocityData() {
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { switch (Core.getVersion()) {
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); case 15:
TPSLimit_15.createVelocityPacketCache(world);
break;
default:
TPSLimit_12.createVelocityPacketCache(world);
}
}
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(serverEntity.getId(), serverEntity.getDataWatcher(), true); private void sendVelocityData() {
sendPlayers(packetPlayOutEntityMetadata); 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() { private void sendTntData() {
Set<Packet<?>> packets = new HashSet<>(); switch (Core.getVersion()) {
case 15:
world.getEntitiesByClasses(TNTPrimed.class).forEach(entity -> { TPSLimit_15.sendTntData(world);
net.minecraft.server.v1_15_R1.Entity serverEntity = ((CraftEntity) entity).getHandle(); break;
packets.add(new PacketPlayOutEntityTeleport(serverEntity)); default:
// packets.add(new PacketPlayOutEntityVelocity(serverEntity.getId(), noMotion)); TPSLimit_12.sendTntData(world);
}); }
sendPlayers(packets);
} }
public static int getCurrentTPSLimit() { public static int getCurrentTPSLimit() {