use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class BukkitViaLoader method load.
@Override
public void load() {
// Update Listener
registerListener(new UpdateListener());
/* Base Protocol */
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
// Add ProtocolSupport ConnectListener if necessary.
ClassGenerator.registerPSConnectListener(plugin);
int serverProtocolVersion = Via.getAPI().getServerVersion().lowestSupportedVersion();
/* 1.9 client to 1.8 server */
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
storeListener(new ArmorListener(plugin)).register();
storeListener(new DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
if (plugin.getConf().isItemCache()) {
handItemCache = new HandItemCache();
// Updates player's items :)
tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 1L, 1L));
}
}
if (serverProtocolVersion < ProtocolVersion.v1_14.getVersion()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && serverProtocolVersion < ProtocolVersion.v1_9.getVersion();
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
try {
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
} catch (ReflectiveOperationException e) {
Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub");
e.printStackTrace();
}
}
}
if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) {
try {
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
storeListener(new EntityToggleGlideListener(plugin)).register();
} catch (ClassNotFoundException ignored) {
}
}
if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion() && !Boolean.getBoolean("com.viaversion.ignorePaperBlockPlacePatch")) {
boolean paper = true;
try {
// Paper 1.8 ?
Class.forName("org.github.paperspigot.PaperSpigotConfig");
} catch (ClassNotFoundException ignored) {
try {
// Paper 1.9+ ?
Class.forName("com.destroystokyo.paper.PaperConfig");
} catch (ClassNotFoundException alsoIgnored) {
// Definitely not Paper
paper = false;
}
}
if (paper) {
storeListener(new PaperPatch(plugin)).register();
}
}
/* Providers */
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
@Override
public Item getHandItem(final UserConnection info) {
if (handItemCache != null) {
return handItemCache.getHandItem(info.getProtocolInfo().getUuid());
}
try {
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), () -> {
UUID playerUUID = info.getProtocolInfo().getUuid();
Player player = Bukkit.getPlayer(playerUUID);
if (player != null) {
return HandItemCache.convert(player.getItemInHand());
}
return null;
}).get(10, TimeUnit.SECONDS);
} catch (Exception e) {
Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName());
if (Via.getManager().isDebug())
e.printStackTrace();
return null;
}
}
});
}
if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) {
if (plugin.getConf().is1_12QuickMoveActionFix()) {
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
}
}
if (serverProtocolVersion < ProtocolVersion.v1_13.getVersion()) {
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);
ConnectionData.blockConnectionProvider = blockConnectionProvider;
}
}
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class ViaAPIBase method sendRawPacket.
@Override
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
if (!isInjected(uuid)) {
throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
}
UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(uuid);
user.scheduleSendRawPacket(packet);
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class BukkitChannelInitializer method afterChannelInitialize.
public static void afterChannelInitialize(Channel channel) {
UserConnection connection = new UserConnectionImpl(channel);
new ProtocolPipelineImpl(connection);
if (PaperViaInjector.PAPER_PACKET_LIMITER) {
connection.setPacketLimiterEnabled(false);
}
// Add our transformers
HandlerConstructor constructor = ClassGenerator.getConstructor();
MessageToByteEncoder encoder = constructor.newEncodeHandler(connection, (MessageToByteEncoder) channel.pipeline().get("encoder"));
ByteToMessageDecoder decoder = constructor.newDecodeHandler(connection, (ByteToMessageDecoder) channel.pipeline().get("decoder"));
channel.pipeline().replace("encoder", "encoder", encoder);
channel.pipeline().replace("decoder", "decoder", decoder);
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class ElytraPatch method onServerConnected.
@EventHandler(priority = EventPriority.HIGH)
public void onServerConnected(ServerConnectedEvent event) {
UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId());
if (user == null)
return;
try {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
int entityId = tracker.getProvidedEntityId();
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user);
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));
wrapper.scheduleSend(Protocol1_9To1_8.class);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.viaversion.viaversion.api.connection.UserConnection in project ViaVersion by ViaVersion.
the class PPSSubCmd method execute.
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
Map<Integer, Set<String>> playerVersions = new HashMap<>();
int totalPackets = 0;
int clients = 0;
long max = 0;
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
if (!playerVersions.containsKey(playerVersion))
playerVersions.put(playerVersion, new HashSet<>());
UserConnection uc = Via.getManager().getConnectionManager().getConnectedClient(p.getUUID());
if (uc != null && uc.getPacketTracker().getPacketsPerSecond() > -1) {
playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketTracker().getPacketsPerSecond() + " PPS)");
totalPackets += uc.getPacketTracker().getPacketsPerSecond();
if (uc.getPacketTracker().getPacketsPerSecond() > max) {
max = uc.getPacketTracker().getPacketsPerSecond();
}
clients++;
}
}
Map<Integer, Set<String>> sorted = new TreeMap<>(playerVersions);
sendMessage(sender, "&4Live Packets Per Second");
if (clients > 1) {
sendMessage(sender, "&cAverage: &f" + (totalPackets / clients));
sendMessage(sender, "&cHighest: &f" + max);
}
if (clients == 0) {
sendMessage(sender, "&cNo clients to display.");
}
for (Map.Entry<Integer, Set<String>> entry : sorted.entrySet()) sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue());
sorted.clear();
return true;
}
Aggregations