Merge pull request 'Use SpigotCore TinyProtocol instance' (#310) from coreTiny into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #310 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
fd0a7b4e3d
@ -151,7 +151,6 @@ public class FightSystem extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
ProtocolAPI.tinyProtocol.close();
|
|
||||||
GlobalRecorder.getInstance().close();
|
GlobalRecorder.getInstance().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
package de.steamwar.fightsystem.fight;
|
package de.steamwar.fightsystem.fight;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||||
import de.steamwar.fightsystem.utils.ProtocolAPI;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Sound;
|
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);
|
private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent);
|
||||||
public static void pseudoSpectator(Player player, boolean enable) {
|
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) {
|
public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.fightsystem.record;
|
package de.steamwar.fightsystem.record;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
@ -72,22 +73,22 @@ public class REntity {
|
|||||||
public static void playerJoins(Player player) {
|
public static void playerJoins(Player player) {
|
||||||
for(REntity entity : entities.values()){
|
for(REntity entity : entities.values()){
|
||||||
if(entity.entityType == EntityType.PLAYER){
|
if(entity.entityType == EntityType.PLAYER){
|
||||||
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getPlayerInfoPacket());
|
TinyProtocol.instance.sendPacket(player, entity.getPlayerInfoPacket());
|
||||||
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getNamedSpawnPacket());
|
TinyProtocol.instance.sendPacket(player, entity.getNamedSpawnPacket());
|
||||||
for (Map.Entry<String, ItemStack> entry : entity.itemSlots.entrySet()) {
|
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{
|
}else{
|
||||||
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getSpawnEntityPacket());
|
TinyProtocol.instance.sendPacket(player, entity.getSpawnEntityPacket());
|
||||||
}
|
}
|
||||||
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getTeleportPacket());
|
TinyProtocol.instance.sendPacket(player, entity.getTeleportPacket());
|
||||||
ProtocolAPI.tinyProtocol.sendPacket(player, entity.getHeadRotationPacket());
|
TinyProtocol.instance.sendPacket(player, entity.getHeadRotationPacket());
|
||||||
|
|
||||||
if(entity.fireTick != 0) {
|
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) {
|
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
package de.steamwar.fightsystem.utils;
|
package de.steamwar.fightsystem.utils;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
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>> outgoingHandler = new HashMap<>();
|
||||||
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
|
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
|
||||||
|
|
||||||
public static final TinyProtocol tinyProtocol = new TinyProtocol(FightSystem.getPlugin()) {
|
static {
|
||||||
@Override
|
TinyProtocol.instance.setOutFilter((receiver, channel, packet) -> {
|
||||||
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
|
||||||
BiFunction<Player, Object, Object> handler = outgoingHandler.get(packet.getClass());
|
BiFunction<Player, Object, Object> handler = outgoingHandler.get(packet.getClass());
|
||||||
if(handler == null)
|
if(handler == null)
|
||||||
return packet;
|
return packet;
|
||||||
return handler.apply(receiver, packet);
|
return handler.apply(receiver, packet);
|
||||||
}
|
});
|
||||||
|
TinyProtocol.instance.setInFilter((sender, channel, packet) -> {
|
||||||
@Override
|
|
||||||
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
|
||||||
BiFunction<Player, Object, Object> handler = incomingHandler.get(packet.getClass());
|
BiFunction<Player, Object, Object> handler = incomingHandler.get(packet.getClass());
|
||||||
if(handler == null)
|
if(handler == null)
|
||||||
return packet;
|
return packet;
|
||||||
return handler.apply(sender, packet);
|
return handler.apply(sender, packet);
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||||
outgoingHandler.put(packetClass, handler);
|
outgoingHandler.put(packetClass, handler);
|
||||||
@ -77,7 +72,7 @@ public class ProtocolAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void broadcastPacket(Object packet) {
|
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) {
|
public static BiFunction<Object, UnaryOperator<Object>, Object> arrayCloneGenerator(Class<?> elementClass) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren