public static boolean isBaseProtocol(Protocol protocol) { for (Pair<Range<Integer>, Protocol> p : baseProtocols) { if (p.getValue() == protocol) { return true; } } return false; }
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); }
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--); } } }
/** * 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; } } }
/** * 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); }
for (Pair<Type, Object> packetValue : packetValues) { try { Object value = packetValue.getValue(); if (value != null) { if (!packetValue.getKey().getOutputClass().isAssignableFrom(value.getClass())) {
Type rtype = read.getKey(); if (rtype.equals(type) || (type.getBaseClass().equals(rtype.getBaseClass()) && type.getOutputClass().equals(rtype.getOutputClass()))) { return (T) read.getValue(); } else { if (rtype == Type.NOTHING) {
} else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue());
} else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue());