/** * Map a type using a basic ValueReader to a ValueWriter * * @param inputReader The reader to read with. * @param outputWriter The writer to write with * @param <T> The return type */ public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) { valueRemappers.add(new Pair<ValueReader, ValueWriter>(inputReader, outputWriter)); }
public void unloadChunk(int x, int z) { blockStorage.remove(new Pair<>(x, z)); }
public void unloadChunk(int x, int z) { Pair<Integer, Integer> chunkPos = new Pair<>(x, z); storedCommandBlocks.remove(chunkPos); }
private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); return Optional.fromNullable(metadataRewrites.get(pair)); }
private static Optional<MetaIndex1_8to1_7_6_10> getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); if (metadataRewrites.containsKey(pair)) { return Optional.of(metadataRewrites.get(pair)); } return Optional.empty(); }
private static Optional<MetaIndex> getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); if (metadataRewrites.containsKey(pair)) { return Optional.of(metadataRewrites.get(pair)); } return Optional.empty(); }
private static Optional<MetaIndex1_8to1_7_6_10> getIndex(Entity1_10Types.EntityType type, int index) { Pair pair = new Pair<>(type, index); if (metadataRewrites.containsKey(pair)) { return Optional.of(metadataRewrites.get(pair)); } return Optional.empty(); }
/** * Register an incoming packet, with id transformation and remapper. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID * @param packetRemapper The remapper to use for the packet */ public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); incoming.put(new Pair<>(state, newPacketID), protocolPacket); }
/** * Register an outgoing packet, with id transformation and remapper. * * @param state The state which the packet is sent in. * @param oldPacketID The old packet ID * @param newPacketID The new packet ID * @param packetRemapper The remapper to use for the packet */ public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper); outgoing.put(new Pair<>(state, oldPacketID), protocolPacket); }
private Pair<Integer, Integer> getChunkCoords(Position position) { int chunkX = (int) Math.floor(position.getX() / 16); int chunkZ = (int) Math.floor(position.getZ() / 16); return new Pair<>(chunkX, chunkZ); }
/** * Calculate a path from a client version to server version * * @param clientVersion The input client version * @param serverVersion The desired output server version * @return The path it generated, null if it failed. */ public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) { Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion); // Check cache List<Pair<Integer, Protocol>> protocolList = pathCache.get(protocolKey); if (protocolList != null) { return protocolList; } // Generate path List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion); // If it found a path, cache it. if (outputPath != null) { pathCache.put(protocolKey, outputPath); } return outputPath; }
private Pair<Integer, Integer> getPair(Position position) { int chunkX = (int) (position.getX() >> 4); int chunkZ = (int) (position.getZ() >> 4); return new Pair<>(chunkX, chunkZ); }
/** * Write a type to the output. * * @param type The type to write. * @param <T> The return type of the type you wish to write. * @param value The value of the type to write. */ public <T> void write(Type<T> type, T value) { if (value != null) { if (!type.getOutputClass().isAssignableFrom(value.getClass())) { // attempt conversion if (type instanceof TypeConverter) { value = (T) ((TypeConverter) type).from(value); } else { Via.getPlatform().getLogger().warning("Possible type mismatch: " + value.getClass().getName() + " -> " + type.getOutputClass()); } } } packetValues.add(new Pair<Type, Object>(type, value)); }
injectedLists.add(new Pair<>(field, connection)); field.set(connection, wrapper);
@Override public int transform(UserConnection user, CompoundTag tag) { Object item = tag.get("Item").getValue(); byte data = ((Number) tag.get("Data").getValue()).byteValue(); Pair<?, Byte> pair = item instanceof Number ? new Pair<>(((Number) item).byteValue(), data) : new Pair<>((String) item, data); // Return air on empty string if (item instanceof String && ((String) item).isEmpty()) return 5265; else if (flowers.containsKey(pair)) { return flowers.get(pair); } else if (flowersNumberId.containsKey(pair)) { return flowersNumberId.get(pair); } else { if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag); } } return -1; } }
injectedLists.add(new Pair<>(field, connection)); field.set(connection, wrapper);
/** * 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.registerListeners(); baseProtocol.register(Via.getManager().getProviders()); refreshVersions(); } else { registerList.add(baseProtocol); } }
/** * Transform a packet using this protocol * * @param direction The direction the packet is going in * @param state The current protocol state * @param packetWrapper The packet wrapper to transform * @throws Exception Throws exception if it fails to transform */ public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { Pair<State, Integer> statePacket = new Pair<>(state, packetWrapper.getId()); Map<Pair<State, Integer>, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming); ProtocolPacket protocolPacket = packetMap.get(statePacket); if (protocolPacket == null) { return; } // write packet id int newID = direction == Direction.OUTGOING ? protocolPacket.getNewID() : protocolPacket.getOldID(); packetWrapper.setId(newID); // remap if (protocolPacket.getRemapper() != null) { protocolPacket.getRemapper().remap(packetWrapper); if (packetWrapper.isCancelled()) throw new CancelException(); } }