public static Protocol getBaseProtocol(int serverVersion) { for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) { if (rangeProtocol.getKey().contains(serverVersion)) { return rangeProtocol.getValue(); } } throw new IllegalStateException("No Base Protocol for " + serverVersion); }
/** * 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 static boolean isBaseProtocol(Protocol protocol) { for (Pair<Range<Integer>, Protocol> p : baseProtocols) { if (p.getValue() == protocol) { return true; } } return false; }
/** * Set a currently existing part in the output * * @param type The type of the part you wish to set. * @param <T> The return type of the type you wish to set. * @param index The index of the part (relative to the type) * @param value The value of the part you wish to set it to. * @throws Exception If it fails to set it, an exception will be thrown. */ public <T> void set(Type<T> type, int index, T value) throws Exception { int currentIndex = 0; for (Pair<Type, Object> packetValue : packetValues) { if (packetValue.getKey() == type) { // Ref check if (currentIndex == index) { packetValue.setValue(value); return; } currentIndex++; } } Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()); }
/** * Check if a type is at an index * * @param type The type of the part you wish to get. * @param index The index of the part (relative to the type) * @return True if the type is at the index */ public boolean is(Type type, int index) { int currentIndex = 0; for (Pair<Type, Object> packetValue : packetValues) { if (packetValue.getKey() == type) { // Ref check if (currentIndex == index) { return true; } currentIndex++; } } return false; }
} else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue());
public static void refreshVersions() { supportedVersions.clear(); supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL); for (ProtocolVersion versions : ProtocolVersion.getProtocols()) { List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL); if (paths == null) continue; supportedVersions.add(versions.getId()); for (Pair<Integer, Protocol> path : paths) supportedVersions.add(path.getKey()); } }
public void setAttackSpeed(double base, ArrayList<Pair<Byte, Double>> modifiers) { attackSpeed = base; for (int j = 0; j<modifiers.size(); j++) { if (modifiers.get(j).getKey()==0) { attackSpeed += modifiers.get(j).getValue(); modifiers.remove(j--); } } for (int j = 0; j<modifiers.size(); j++) { if (modifiers.get(j).getKey()==1) { attackSpeed += base * modifiers.get(j).getValue(); modifiers.remove(j--); } } for (int j = 0; j<modifiers.size(); j++) { if (modifiers.get(j).getKey()==2) { attackSpeed *= (1.0 + modifiers.get(j).getValue()); modifiers.remove(j--); } } }
} else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue());
/** * Check if a type is at an index * * @param type The type of the part you wish to get. * @param index The index of the part (relative to the type) * @return True if the type is at the index */ public boolean isReadable(Type type, int index) { int currentIndex = 0; for (Pair<Type, Object> packetValue : readableObjects) { if (packetValue.getKey().getBaseClass() == type.getBaseClass()) { // Ref check if (currentIndex == index) { return true; } currentIndex++; } } return false; }
/** * Remap a packet wrapper * * @param packetWrapper The wrapper to remap * @throws Exception Throws if it fails to write / read to the packet. */ public void remap(PacketWrapper packetWrapper) throws Exception { try { // Read all the current values for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) { Object object = valueRemapper.getKey().read(packetWrapper); // Convert object to write type :O!!! valueRemapper.getValue().write(packetWrapper, object); } // If we had handlers we'd put them here } catch (InformativeException e) { e.addSource(this.getClass()); throw e; } } }
public void unloadChunk(int x, int z) { blockStorage.remove(new Pair<>(x, z)); }
for (Pair<Type, Object> packetValue : packetValues) { try { Object value = packetValue.getValue(); if (value != null) { if (!packetValue.getKey().getOutputClass().isAssignableFrom(value.getClass())) { if (packetValue.getKey() instanceof TypeConverter) { value = ((TypeConverter) packetValue.getKey()).from(value); } else { Via.getPlatform().getLogger().warning("Possible type mismatch: " + value.getClass().getName() + " -> " + packetValue.getKey().getOutputClass()); packetValue.getKey().write(buffer, value); } catch (Exception e) { throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()).set("Data", packetValues);
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(); }
/** * Get a part from the output * * @param type The type of the part you wish to get. * @param <T> The return type of the type you wish to get. * @param index The index of the part (relative to the type) * @return The requested type or throws ArrayIndexOutOfBounds * @throws Exception If it fails to find it, an exception will be thrown. */ public <T> T get(Type<T> type, int index) throws Exception { int currentIndex = 0; for (Pair<Type, Object> packetValue : packetValues) { if (packetValue.getKey() == type) { // Ref check if (currentIndex == index) { return (T) packetValue.getValue(); } currentIndex++; } } Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index); throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Data", packetValues); }