us.myles.ViaVersion.api.Via Java Examples
The following examples show how to use
us.myles.ViaVersion.api.Via.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappingData.java From ViaVersion with MIT License | 6 votes |
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { super(4084, mapping1_12, mapping1_13); // Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13 if (Via.getConfig().isSnowCollisionFix()) { oldToNew[1248] = 3416; } // Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers if (Via.getConfig().isInfestedBlocksFix()) { oldToNew[1552] = 1; // stone oldToNew[1553] = 14; // cobblestone oldToNew[1554] = 3983; // stone bricks oldToNew[1555] = 3984; // mossy stone bricks oldToNew[1556] = 3985; // cracked stone bricks oldToNew[1557] = 3986; // chiseled stone bricks } }
Example #2
Source File: SpongeViaBulkChunkTranslator.java From ViaVersion with MIT License | 6 votes |
@Override public List<Object> transformMapChunkBulk(Object packet, ClientChunks clientChunks) { List<Object> list = Lists.newArrayList(); try { int[] xcoords = mapChunkBulkRef.getFieldValue("field_149266_a", packet, int[].class); int[] zcoords = mapChunkBulkRef.getFieldValue("field_149264_b", packet, int[].class); Object[] chunkMaps = mapChunkBulkRef.getFieldValue("field_179755_c", packet, Object[].class); for (int i = 0; i < chunkMaps.length; i++) { int x = xcoords[i]; int z = zcoords[i]; Object chunkMap = chunkMaps[i]; Object chunkPacket = mapChunkRef.newInstance(); mapChunkRef.setFieldValue("field_149284_a", chunkPacket, x); mapChunkRef.setFieldValue("field_149282_b", chunkPacket, z); mapChunkRef.setFieldValue("field_179758_c", chunkPacket, chunkMap); mapChunkRef.setFieldValue("field_149279_g", chunkPacket, true); // Chunk bulk chunks are always ground-up clientChunks.getBulkChunks().add(ClientChunks.toLong(x, z)); // Store for later list.add(chunkPacket); } } catch (Exception e) { Via.getPlatform().getLogger().log(Level.WARNING, "Failed to transform chunks bulk", e); } return list; }
Example #3
Source File: ViaBackwardsPlatform.java From ViaBackwards with MIT License | 6 votes |
default boolean isOutdated() { String vvVersion = Via.getPlatform().getPluginVersion(); if (vvVersion != null && new Version(vvVersion).compareTo(new Version(MINIMUM_VV_VERSION + "--")) < 0) { getLogger().severe("================================"); getLogger().severe("YOUR VIAVERSION IS OUTDATED"); getLogger().severe("PLEASE USE VIAVERSION " + MINIMUM_VV_VERSION + " OR NEWER"); getLogger().severe("LINK: https://viaversion.com"); getLogger().severe("VIABACKWARDS WILL NOW DISABLE"); getLogger().severe("================================"); disable(); return true; } return false; }
Example #4
Source File: FlowerConnectionHandler.java From ViaVersion with MIT License | 6 votes |
@Override public int connect(UserConnection user, Position position, int blockState) { int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM)); int connectBelow = flowers.get(blockBelowId); if (connectBelow != 0) { int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP)); if (Via.getConfig().isStemWhenBlockAbove()) { if (blockAboveId == 0) { return connectBelow; } } else if (!flowers.containsKey(blockAboveId)) { return connectBelow; } } return blockState; }
Example #5
Source File: WorldPackets.java From ViaVersion with MIT License | 6 votes |
public static int toNewId(int oldId) { if (oldId < 0) { oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air. } int newId = MappingData.blockMappings.getNewId(oldId); if (newId != -1) { return newId; } newId = MappingData.blockMappings.getNewId(oldId & ~0xF); // Remove data if (newId != -1) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Missing block " + oldId); } return newId; } if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Missing block completely " + oldId); } // Default stone return 1; }
Example #6
Source File: VelocityServerHandler.java From ViaVersion with MIT License | 6 votes |
@Subscribe public void preServerConnect(ServerPreConnectEvent e) { try { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(VelocityStorage.class)) { user.put(new VelocityStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId); // Check if ViaVersion can support that version Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId)); } catch (IllegalAccessException | InvocationTargetException e1) { e1.printStackTrace(); } }
Example #7
Source File: BlockEntityProvider.java From ViaVersion with MIT License | 6 votes |
/** * Transforms the BlockEntities to blocks! * * @param user UserConnection instance * @param position Block Position - WARNING: Position is null when called from a chunk * @param tag BlockEntity NBT * @param sendUpdate send a block change update * @return new block id * @throws Exception Gotta throw that exception */ public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { Tag idTag = tag.get("id"); if (idTag == null) return -1; String id = (String) idTag.getValue(); BlockEntityHandler handler = handlers.get(id); if (handler == null) { if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); } return -1; } int newBlock = handler.transform(user, tag); if (sendUpdate && newBlock != -1) { sendBlockChange(user, position, newBlock); } return newBlock; }
Example #8
Source File: MappingDataLoader.java From ViaVersion with MIT License | 6 votes |
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) { for (int i = 0; i < oldIdentifiers.size(); i++) { JsonElement value = oldIdentifiers.get(i); Integer index = findIndex(newIdentifiers, value.getAsString()); if (index == null) { if (diffIdentifiers != null) { JsonElement diffElement = diffIdentifiers.get(value.getAsString()); if (diffElement != null) { index = findIndex(newIdentifiers, diffElement.getAsString()); } } if (index == null) { if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("No key for " + value + " :( "); } continue; } } output[i] = index.shortValue(); } }
Example #9
Source File: VelocityViaLoader.java From ViaVersion with MIT License | 6 votes |
@Override public void load() { Object plugin = VelocityPlugin.PROXY.getPluginManager() .getPlugin("viaversion").flatMap(PluginContainer::getInstance).get(); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter()); Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider()); VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch()); } Via.getManager().getProviders().use(VersionProvider.class, new VelocityVersionProvider()); // We probably don't need a EntityIdProvider because velocity sends a Join packet on server change // We don't need main hand patch because Join Game packet makes client send hand data again VelocityPlugin.PROXY.getEventManager().register(plugin, new UpdateListener()); VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler()); int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval(); if (pingInterval > 0) { Via.getPlatform().runRepeatingSync( new ProtocolDetectorService(), pingInterval * 20L); } }
Example #10
Source File: SpongePlugin.java From ViaVersion with MIT License | 6 votes |
@Listener public void onGameStart(GameInitializationEvent event) { // Setup Logger logger = new LoggerWrapper(container.getLogger()); // Setup Plugin conf = new SpongeViaConfig(container, spongeConfig.getParentFile()); SpongeCommandHandler commandHandler = new SpongeCommandHandler(); game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge"); logger.info("ViaVersion " + getPluginVersion() + " is now loaded!"); // Init platform Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .injector(new SpongeViaInjector()) .loader(new SpongeViaLoader(this)) .build()); }
Example #11
Source File: BedHandler.java From ViaVersion with MIT License | 6 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); return -1; } // RED_BED + FIRST_BED int blockId = storage.get(position).getOriginal() - 972 + 748; Tag color = tag.get("color"); if (color != null) { blockId += (((Number) color.getValue()).intValue() * 16); } return blockId; }
Example #12
Source File: BukkitViaInjector.java From ViaVersion with MIT License | 6 votes |
public static void patchLists() throws Exception { Object connection = getServerConnection(); if (connection == null) { Via.getPlatform().getLogger().warning("We failed to find the core component 'ServerConnection', please file an issue on our GitHub."); return; } for (Field field : connection.getClass().getDeclaredFields()) { field.setAccessible(true); Object value = field.get(connection); if (!(value instanceof List)) continue; if (value instanceof ConcurrentList) continue; ConcurrentList list = new ConcurrentList(); list.addAll((Collection) value); field.set(connection, list); } }
Example #13
Source File: ViaVersionPlugin.java From ViaVersion with MIT License | 6 votes |
public ViaVersionPlugin() { instance = this; // Command handler commandHandler = new BukkitCommandHandler(); // Init platform Via.init(ViaManager.builder() .platform(this) .commandHandler(commandHandler) .injector(new BukkitViaInjector()) .loader(new BukkitViaLoader(this)) .build()); // Config magic conf = new BukkitViaConfig(); // Check if we're using protocol support too protocolSupport = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null; if (protocolSupport) { getLogger().info("Hooking into ProtocolSupport, to prevent issues!"); try { BukkitViaInjector.patchLists(); } catch (Exception e) { e.printStackTrace(); } } }
Example #14
Source File: BungeeServerHandler.java From ViaVersion with MIT License | 6 votes |
@EventHandler(priority = 120) public void onServerConnect(ServerConnectEvent e) { if (e.isCancelled()) { return; } UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(BungeeStorage.class)) { user.put(new BungeeStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId); // Check if ViaVersion can support that version try { //Object pendingConnection = getPendingConnection.invoke(e.getPlayer()); Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection()); setProtocol.invoke(handshake, protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId); } catch (InvocationTargetException | IllegalAccessException e1) { e1.printStackTrace(); } }
Example #15
Source File: EntityPositionHandler.java From ViaBackwards with MIT License | 6 votes |
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); EntityTracker.StoredEntity storedEntity = entityRewriter.getEntityTracker(wrapper.user()).getEntity(entityId); if (storedEntity == null) { if (Via.getManager().isDebug()) { // There is too many plugins violating this out there, and reading seems to be hard! :> ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing at position: " + x + " - " + y + " - " + z + " in " + storageClass.getSimpleName()); if (entityId == -1 && x == 0 && y == 0 && z == 0) { ViaBackwards.getPlatform().getLogger().warning("DO NOT REPORT THIS TO VIA, THIS IS A PLUGIN ISSUE"); } else if (!warnedForMissingEntity) { warnedForMissingEntity = true; ViaBackwards.getPlatform().getLogger().warning("This is very likely caused by a plugin sending a teleport packet for an entity outside of the player's range."); } } return; } EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass); if (positionStorage == null) { ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName()); return; } positionStorage.setCoordinates(x, y, z, relative); storedEntity.put(positionStorage); }
Example #16
Source File: BackwardsMappings.java From ViaBackwards with MIT License | 5 votes |
private static void mapIdentifiers(short[] output, JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) { for (Map.Entry<String, JsonElement> entry : newIdentifiers.entrySet()) { String key = entry.getValue().getAsString(); Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(oldIdentifiers, key); short hardId = -1; if (value == null) { JsonPrimitive replacement = mapping.getAsJsonPrimitive(key); int propertyIndex; if (replacement == null && (propertyIndex = key.indexOf('[')) != -1) { replacement = mapping.getAsJsonPrimitive(key.substring(0, propertyIndex)); } if (replacement != null) { if (replacement.getAsString().startsWith("id:")) { String id = replacement.getAsString().replace("id:", ""); hardId = Short.parseShort(id); value = MappingDataLoader.findValue(oldIdentifiers, oldIdentifiers.getAsJsonPrimitive(id).getAsString()); } else { value = MappingDataLoader.findValue(oldIdentifiers, replacement.getAsString()); } } if (value == null) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { if (replacement != null) { ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + "/" + replacement.getAsString() + " :( "); } else { ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); } } continue; } } output[Integer.parseInt(entry.getKey())] = hardId != -1 ? hardId : Short.parseShort(value.getKey()); } }
Example #17
Source File: Sponge5ArmorListener.java From ViaVersion with MIT License | 5 votes |
public void sendDelayedArmorUpdate(final Player player) { if (!isOnPipe(player.getUniqueId())) return; // Don't start a task if the player is not on the pipe Via.getPlatform().runSync(new Runnable() { @Override public void run() { sendArmorUpdate(player); } }); }
Example #18
Source File: SpongeViaAPI.java From ViaVersion with MIT License | 5 votes |
@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
Example #19
Source File: UpdateListener.java From ViaVersion with MIT License | 5 votes |
@Subscribe public void onJoin(PostLoginEvent e) { if (e.getPlayer().hasPermission("viaversion.update") && Via.getConfig().isCheckForUpdates()) { UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId()); } }
Example #20
Source File: VelocityServerHandler.java From ViaVersion with MIT License | 5 votes |
@Subscribe(order = PostOrder.LATE) public void connectedEvent(ServerConnectedEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); CompletableFuture.runAsync(() -> { try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }, user.getChannel().eventLoop()).join(); }
Example #21
Source File: UpdateListener.java From ViaVersion with MIT License | 5 votes |
@EventHandler public void onJoin(PostLoginEvent e) { if (e.getPlayer().hasPermission("viaversion.update") && Via.getConfig().isCheckForUpdates()) { UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId()); } }
Example #22
Source File: Protocol1_16To1_15_2.java From ViaVersion with MIT License | 5 votes |
public static int getNewBlockId(int id) { int newId = MappingData.blockMappings.getNewId(id); if (newId == -1) { Via.getPlatform().getLogger().warning("Missing 1.16 block for 1.15.2 block " + id); return 0; } return newId; }
Example #23
Source File: VelocityViaAPI.java From ViaVersion with MIT License | 5 votes |
@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
Example #24
Source File: ProtocolPipeline.java From ViaVersion with MIT License | 5 votes |
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { int originalID = packetWrapper.getId(); List<Protocol> protocols = new ArrayList<>(protocolList); // Other way if outgoing if (direction == Direction.OUTGOING) Collections.reverse(protocols); // Apply protocols packetWrapper.apply(direction, state, 0, protocols); super.transform(direction, state, packetWrapper); if (Via.getManager().isDebug()) { // Debug packet int serverProtocol = userConnection.getProtocolInfo().getServerProtocolVersion(); int clientProtocol = userConnection.getProtocolInfo().getProtocolVersion(); ViaPlatform platform = Via.getPlatform(); String actualUsername = packetWrapper.user().getProtocolInfo().getUsername(); String username = actualUsername != null ? actualUsername + " " : ""; platform.getLogger().log(Level.INFO, "{0}{1} {2}: {3} (0x{4}) -> {5} (0x{6}) [{7}] {8}", new Object[]{ username, direction, state, originalID, Integer.toHexString(originalID), packetWrapper.getId(), Integer.toHexString(packetWrapper.getId()), Integer.toString(clientProtocol), packetWrapper }); } }
Example #25
Source File: ProtocolDetectorService.java From ViaVersion with MIT License | 5 votes |
public static void probeServer(final ServerInfo serverInfo) { final String key = serverInfo.getName(); serverInfo.ping(new Callback<ServerPing>() { @Override public void done(ServerPing serverPing, Throwable throwable) { if (throwable == null && serverPing != null && serverPing.getVersion() != null) { // Ensure protocol is positive, some services will return -1 if (serverPing.getVersion().getProtocol() > 0) { detectedProtocolIds.put(key, serverPing.getVersion().getProtocol()); if (((BungeeViaConfig) Via.getConfig()).isBungeePingSave()) { Map<String, Integer> servers = ((BungeeViaConfig) Via.getConfig()).getBungeeServerProtocols(); Integer protocol = servers.get(key); if (protocol != null && protocol == serverPing.getVersion().getProtocol()) { return; } // Ensure we're the only ones writing to the config synchronized (Via.getPlatform().getConfigurationProvider()) { servers.put(key, serverPing.getVersion().getProtocol()); } // Save Via.getPlatform().getConfigurationProvider().saveConfig(); } } } } }); }
Example #26
Source File: Protocol1_13To1_12_2.java From ViaVersion with MIT License | 5 votes |
@Override public void init(UserConnection userConnection) { userConnection.put(new EntityTracker1_13(userConnection)); userConnection.put(new TabCompleteTracker(userConnection)); if (!userConnection.has(ClientWorld.class)) userConnection.put(new ClientWorld(userConnection)); userConnection.put(new BlockStorage(userConnection)); if (Via.getConfig().isServersideBlockConnections()) { if (Via.getManager().getProviders().get(BlockConnectionProvider.class) instanceof PacketBlockConnectionProvider) { userConnection.put(new BlockConnectionStorage(userConnection)); } } }
Example #27
Source File: ProtocolRegistry.java From ViaVersion with MIT License | 5 votes |
/** * Registers a base protocol. * Base Protocols registered later have higher priority * Only one base protocol will be added to pipeline * * @param baseProtocol Base Protocol to register * @param supportedProtocols Versions that baseProtocol supports */ public static void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) { baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol)); if (Via.getPlatform().isPluginEnabled()) { baseProtocol.register(Via.getManager().getProviders()); refreshVersions(); } else { registerList.add(baseProtocol); } }
Example #28
Source File: BungeeViaLoader.java From ViaVersion with MIT License | 5 votes |
@Override public void load() { // Listeners registerListener(plugin); registerListener(new UpdateListener()); registerListener(new BungeeServerHandler()); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { registerListener(new ElytraPatch()); } // Providers Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider()); Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider()); if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider()); Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider()); } if (plugin.getConf().getBungeePingInterval() > 0) { tasks.add(plugin.getProxy().getScheduler().schedule( plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS )); } }
Example #29
Source File: UserConnection.java From ViaVersion with MIT License | 5 votes |
/** * Send a raw packet to the player. * * @param packet The raw packet to send * @param currentThread Should it run in the same thread */ public void sendRawPacket(ByteBuf packet, boolean currentThread) { ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); if (currentThread) { channel.pipeline().context(handler).writeAndFlush(packet); } else { channel.eventLoop().submit(() -> channel.pipeline().context(handler).writeAndFlush(packet)); } }
Example #30
Source File: ParticleRewriter.java From ViaVersion with MIT License | 5 votes |
public static Particle rewriteParticle(int particleId, Integer[] data) { if (particleId >= particles.size()) { Via.getPlatform().getLogger().severe("Failed to transform particles with id " + particleId + " and data " + Arrays.toString(data)); return null; } NewParticle rewrite = particles.get(particleId); return rewrite.handle(new Particle(rewrite.getId()), data); }