SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Use SpigotCore TinyProtocol instance' (#310) from coreTiny into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #310
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2021-12-22 11:11:39 +01:00
Commit fd0a7b4e3d
4 geänderte Dateien mit 18 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -151,7 +151,6 @@ public class FightSystem extends JavaPlugin {
@Override
public void onDisable() {
ProtocolAPI.tinyProtocol.close();
GlobalRecorder.getInstance().close();
}

Datei anzeigen

@ -20,13 +20,13 @@
package de.steamwar.fightsystem.fight;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.record.GlobalRecorder;
import de.steamwar.fightsystem.utils.ProtocolAPI;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Sound;
@ -146,7 +146,7 @@ public class Fight {
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
public static void pseudoSpectator(Player player, boolean enable) {
ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator));
TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator));
}
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.fightsystem.record;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.core.Core;
import de.steamwar.fightsystem.fight.Fight;
@ -72,22 +73,22 @@ public class REntity {
public static void playerJoins(Player player) {
for(REntity entity : entities.values()){
if(entity.entityType == EntityType.PLAYER){
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getPlayerInfoPacket());
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getNamedSpawnPacket());
TinyProtocol.instance.sendPacket(player, entity.getPlayerInfoPacket());
TinyProtocol.instance.sendPacket(player, entity.getNamedSpawnPacket());
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
TinyProtocol.instance.sendPacket(player, entity.getEquipmentPacket(entry.getKey(), entry.getValue()));
}
}else{
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getSpawnEntityPacket());
TinyProtocol.instance.sendPacket(player, entity.getSpawnEntityPacket());
}
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getTeleportPacket());
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getHeadRotationPacket());
TinyProtocol.instance.sendPacket(player, entity.getTeleportPacket());
TinyProtocol.instance.sendPacket(player, entity.getHeadRotationPacket());
if(entity.fireTick != 0) {
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(entityStatusWatcher, (byte) 1));
TinyProtocol.instance.sendPacket(player, entity.getDataWatcherPacket(entityStatusWatcher, (byte) 1));
}
if(entity.sneaks) {
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(true)));
TinyProtocol.instance.sendPacket(player, entity.getDataWatcherPacket(sneakingDataWatcher, BlockIdWrapper.impl.getPose(true)));
}
}
}

Datei anzeigen

@ -20,8 +20,6 @@
package de.steamwar.fightsystem.utils;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.fightsystem.FightSystem;
import io.netty.channel.Channel;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -42,23 +40,20 @@ public class ProtocolAPI {
private static final Map<Class<?>, BiFunction<Player, Object, Object>> outgoingHandler = new HashMap<>();
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
public static final TinyProtocol tinyProtocol = new TinyProtocol(FightSystem.getPlugin()) {
@Override
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
static {
TinyProtocol.instance.setOutFilter((receiver, channel, packet) -> {
BiFunction<Player, Object, Object> handler = outgoingHandler.get(packet.getClass());
if(handler == null)
return packet;
return handler.apply(receiver, packet);
}
@Override
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
});
TinyProtocol.instance.setInFilter((sender, channel, packet) -> {
BiFunction<Player, Object, Object> handler = incomingHandler.get(packet.getClass());
if(handler == null)
return packet;
return handler.apply(sender, packet);
});
}
};
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
outgoingHandler.put(packetClass, handler);
@ -77,7 +72,7 @@ public class ProtocolAPI {
}
public static void broadcastPacket(Object packet) {
Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet));
Bukkit.getOnlinePlayers().stream().map(TinyProtocol.instance::getChannel).filter(TinyProtocol.instance::hasInjected).forEach(channel -> TinyProtocol.instance.sendPacket(channel, packet));
}
public static BiFunction<Object, UnaryOperator<Object>, Object> arrayCloneGenerator(Class<?> elementClass) {