@Override public void onEnable() { // Inject Via.getManager().init(); }
/** * Get the UserConnection from an UUID * * @param uuid UUID object * @return The UserConnection */ protected UserConnection getUserConnection(@NonNull UUID uuid) { return Via.getManager().getConnection(uuid); }
@Override public ViaVersionCommand getCommandHandler() { return Via.getManager().getCommandHandler(); }
@Override public void onDisable() { Via.getManager().destroy(); }
@Override public boolean execute(ViaCommandSender sender, String[] args) { Via.getManager().setDebug(!Via.getManager().isDebug()); sendMessage(sender, "&6Debug mode is now %s", (Via.getManager().isDebug() ? "&aenabled" : "&cdisabled")); return true; } }
@Listener public void onServerStart(GameAboutToStartServerEvent event) { // Inject! logger.info("ViaVersion is injecting!"); Via.getManager().init(); }
/** * Send a raw packet to the player with returning the future * * @param packet The raw packet to send * @return ChannelFuture of the packet being sent */ public ChannelFuture sendRawPacketFuture(final ByteBuf packet) { final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); ChannelFuture future = channel.pipeline().context(handler).writeAndFlush(packet); return future; }
private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } continue; } output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); } }
private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) { Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString()); if (value == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } continue; } output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); } }
@Override public boolean execute(ViaCommandSender sender, String[] args) { Via.getManager().getCommandHandler().showHelp(sender); return true; } }
/** * Called when the server is enabled, to register any non registered listeners. */ public static void onServerLoaded() { for (Protocol protocol : registerList) { protocol.registerListeners(); protocol.register(Via.getManager().getProviders()); } registerList.clear(); }
private void sendPacket(UpdateAction action) { for (UUID uuid : new ArrayList<>(players)) { UserConnection connection = Via.getManager().getConnection(uuid); PacketWrapper wrapper = getPacket(action, connection); sendPacket(uuid, wrapper); } }
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { for (int i = 0; i < oldIdentifiers.size(); i++) { JsonElement v = oldIdentifiers.get(i); Integer index = findIndex(newIdentifiers, v.getAsString()); if (index == null) { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + v + " :( "); } continue; } output[i] = index.shortValue(); } }
@Subscribe public void onQuit(DisconnectEvent e) { UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId()); if (userConnection != null) { // Only remove if the connection is disconnected (eg. relogin) if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) { Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); } } }
@EventHandler public void onQuit(PlayerDisconnectEvent e) { UserConnection userConnection = Via.getManager().getPortedPlayers().get(e.getPlayer().getUniqueId()); if (userConnection != null) { // Only remove if the connection is disconnected (eg. relogin) if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) { Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); } } } }
@Subscribe(order = PostOrder.LATE) public void connectedEvent(ServerConnectedEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }
@EventHandler(priority = EventPriority.LOWEST) public void onServerConnected(ServerConnectedEvent e) { try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }
public int getProvidedEntityId() { try { return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser()); } catch (Exception e) { return entityID; } } }
@EventHandler public void onPlayerQuit(PlayerQuitEvent e) { Via.getManager().removePortedClient(e.getPlayer().getUniqueId()); } });
@Listener public void onDisconnect(ClientConnectionEvent.Disconnect disconnect) { Via.getManager().removePortedClient(disconnect.getTargetEntity().getUniqueId()); } }