@Override public final double getOriginalModifierDamage(DamageModifier damageModifier) { checkArgument(damageModifier != null, "The damage modifier cannot be null!"); for (Tuple<DamageModifier, Double> tuple : this.originalModifiers) { if (tuple.getFirst().equals(damageModifier)) { return tuple.getSecond(); } } throw new IllegalArgumentException("The provided damage modifier is not applicable: " + damageModifier.toString()); }
@Override public final double getOriginalModifierDamage(DamageModifier damageModifier) { checkArgument(damageModifier != null, "The damage modifier cannot be null!"); for (Tuple<DamageModifier, Double> tuple : this.originalModifiers) { if (tuple.getFirst().equals(damageModifier)) { return tuple.getSecond(); } } throw new IllegalArgumentException("The provided damage modifier is not applicable: " + damageModifier.toString()); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link Collection} of coupled {@link EnchantmentType} and * {@link VariableAmount} to apply varying enchantments of varying amounts * to the generated {@link ItemStack}. * * @param amount The varying amount of enchantments * @param enchantments The collection of enchantment tuples combining the * enchantment and the variable amount of level to apply * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantments(VariableAmount amount, Collection<Tuple<EnchantmentType, VariableAmount>> enchantments) { checkNotNull(amount, "VariableAmount cannot be null!"); final WeightedTable<Function<Random, Enchantment>> suppliers = new WeightedTable<>(amount); for (Tuple<EnchantmentType, VariableAmount> enchantment : enchantments) { suppliers.add(random -> Enchantment.builder().type(enchantment.getFirst()).level(enchantment.getSecond().getFlooredAmount(random)).build(), 1); } return listValueSuppliers(Keys.ITEM_ENCHANTMENTS, suppliers); }
final Tuple<Vector3d, Vector3d> pair = intersection.get(); final Vector3d narrowHit = pair.getFirst(); hit = new BlockRayHit<>(this.extent, narrowHit.getX(), narrowHit.getY(), narrowHit.getZ(), this.direction, pair.getSecond()); } else {
protected double getFinalAmount(double baseAmount) { double damage = baseAmount; for (Tuple<T, Function<? super Double, Double>> entry : this.modifierFunctions) { damage += checkNotNull(entry.getSecond().apply(damage)); } return damage; }
@Override public final double getOriginalModifierDamage(DamageModifier damageModifier) { checkArgument(damageModifier != null, "The damage modifier cannot be null!"); for (Tuple<DamageModifier, Double> tuple : this.originalModifiers) { if (tuple.getFirst().equals(damageModifier)) { return tuple.getSecond(); } } throw new IllegalArgumentException("The provided damage modifier is not applicable: " + damageModifier.toString()); }
@Override public final double getOriginalModifierDamage(DamageModifier damageModifier) { checkArgument(damageModifier != null, "The damage modifier cannot be null!"); for (Tuple<DamageModifier, Double> tuple : this.originalModifiers) { if (tuple.getFirst().equals(damageModifier)) { return tuple.getSecond(); } } throw new IllegalArgumentException("The provided damage modifier is not applicable: " + damageModifier.toString()); }
public final List<Tuple<T, Function<? super Double, Double>>> getModifiers() { ImmutableList.Builder<Tuple<T, Function<? super Double, Double>>> builder = ImmutableList.builder(); for (Tuple<T, Function<? super Double, Double>> entry : this.modifierFunctions) { builder.add(new Tuple<>(entry.getFirst(), entry.getSecond())); } return builder.build(); } }
/** * Gets the result of a primary token's registered {@link TokenParser} on a {@link CommandSource} * * @param primaryToken The primary identifier that parsed. * @param source The {@link CommandSource} to perform the operation with. * @param variables The variables that could be used in the token. * @return The {@link Text}, if any. */ default Optional<Text> applyPrimaryToken(String primaryToken, CommandSource source, Map<String, Object> variables) { Preconditions.checkArgument(primaryToken != null && !primaryToken.isEmpty()); String[] tokenData = primaryToken.split("\\|", 2); return getPrimaryTokenParserAndIdentifier(tokenData[0].toLowerCase()) .flatMap(x -> x.getFirst().parse(tokenData.length == 2 ? x.getSecond() + "|" + tokenData[1] : x.getSecond(), source, variables)); }
protected ImmutableList<Tuple<T, Function<? super Double, Double>>> init(double originalValue, List<Tuple<T, Function<? super Double, Double>>> originalFunctions) { final ImmutableList.Builder<Tuple<T, Double>> modifierMapBuilder = ImmutableList.builder(); final ImmutableList.Builder<Tuple<T, Function<? super Double, Double>>> functionListBuilder = ImmutableList.builder(); final ImmutableMap.Builder<T, Double> mapBuilder = ImmutableMap.builder(); double finalDamage = originalValue; for (Tuple<T, Function<? super Double, Double>> tuple : originalFunctions) { this.modifierFunctions.add(new Tuple<>(tuple.getFirst(), tuple.getSecond())); double tempDamage = checkNotNull(tuple.getSecond().apply(finalDamage)); finalDamage += tempDamage; modifierMapBuilder.add(new Tuple<>(tuple.getFirst(), tempDamage)); mapBuilder.put(tuple.getFirst(), tempDamage); this.modifiers.put(tuple.getFirst(), tempDamage); functionListBuilder.add(tuple); } this.originalFinalAmount = finalDamage; this.originalModifiers = modifierMapBuilder.build(); this.originalModifierMap = mapBuilder.build(); return functionListBuilder.build(); }
protected void recalculateDamages(double baseAmount) { double tempAmount = baseAmount; this.modifiers.clear(); for (Tuple<T, Function<? super Double, Double>> entry : this.modifierFunctions) { double modifierAmount = checkNotNull(entry.getSecond().apply(tempAmount)); if (this.modifiers.containsKey(entry.getFirst())) { double oldAmount = this.modifiers.get(entry.getFirst()); double difference = oldAmount - modifierAmount; if (oldAmount > 0) { this.modifiers.put(entry.getFirst(), Math.max(0, oldAmount - difference)); } else { this.modifiers.put(entry.getFirst(), Math.min(0, oldAmount - difference)); } } else { this.modifiers.put(entry.getFirst(), modifierAmount); } tempAmount += modifierAmount; } }
@JsonIgnore @ApiModelProperty(hidden = true) public Tuple<Class[], Object[]> getParsedParameters() { Class[] paramTypes = new Class[parameters.size()]; Object[] paramValues = new Object[parameters.size()]; try { for (int i = 0; i < parameters.size(); i++) { Tuple<Class, Object> tup = parameters.get(i).toObject(); paramTypes[i] = tup.getFirst(); paramValues[i] = tup.getSecond(); } } catch (ClassNotFoundException e) { throw new NotFoundException("Class could not be found: " + e.getMessage()); } catch (NoSuchFieldException e) { throw new NotFoundException("Field could not be found: " + e.getMessage()); } catch (IllegalAccessException e) { throw new ForbiddenException("Access not allowed: " + e.getMessage()); } return new Tuple<>(paramTypes, paramValues); } }
stream.write(asset.getSecond()); baseRequest.setHandled(true); return;
@POST @Path("/{world}/{x}/{y}/{z}/method") @Permission("method") @ApiOperation( value = "Execute a method", notes = "Provides direct access to the underlaying tile entity object and can execute any method on it.") public ExecuteMethodResponse executeMethod( @PathParam("world") @ApiParam("The world the tile entity is in") CachedWorld world, @PathParam("x") @ApiParam("The x-coordinate of the tile-entity") Integer x, @PathParam("y") @ApiParam("The x-coordinate of the tile-entity") Integer y, @PathParam("z") @ApiParam("The x-coordinate of the tile-entity") Integer z, ExecuteMethodRequest req) throws BadRequestException, NotFoundException { if (req == null) { throw new BadRequestException("Request body is required"); } if (req.getMethod() == null || req.getMethod().isEmpty()) { throw new BadRequestException("Method must be specified"); } Optional<CachedTileEntity> te = cacheService.getTileEntity(world, x, y, z); if (!te.isPresent()) { throw new NotFoundException("Tile entity in world '" + world.getName() + "' at [" + x + "," + y + "," + z + "] could not be found"); } String mName = req.getMethod(); Tuple<Class[], Object[]> params = req.getParsedParameters(); Object res = cacheService.executeMethod(te.get(), mName, params.getFirst(), params.getSecond()); return new ExecuteMethodResponse(te.get(), res); }
private void testKeysAreNotParents(String bundle) throws Exception { // Get the resource ResourceBundle rb = ResourceBundle.getBundle(bundle, Locale.getDefault()); Enumeration<String> keys = rb.getKeys(); Set<String> s = new HashSet<>(); while (keys.hasMoreElements()) { s.add(keys.nextElement()); } Map<String, List<String>> filter = s.parallelStream() .map(x -> Tuple.of(x.toLowerCase(), s.stream().filter(y -> x.toLowerCase().startsWith(y.toLowerCase() + ".") && !x.equalsIgnoreCase(y)).collect(Collectors.toList()))) .filter(x -> !x.getSecond().isEmpty()) .sorted(Comparator.comparing(Tuple::getFirst)) .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); if (!filter.isEmpty()) { StringBuilder sb = new StringBuilder("Some keys are parents of others!").append(System.lineSeparator()); filter.forEach((x, y) -> sb.append(x).append("->").append(y).append(System.lineSeparator())); Assert.fail(sb.toString()); } }
@POST @Path("/{player}/method") @Permission("method") @ApiOperation( value = "Execute a method", notes = "Provides direct access to the underlying player object and can execute any method on it.") public ExecuteMethodResponse executeMethod( @PathParam("player") @ApiParam("The uuid of the player") CachedPlayer player, ExecuteMethodRequest req) throws NotFoundException, BadRequestException { if (req == null) { throw new BadRequestException("Request body is required"); } if (req.getMethod() == null || req.getMethod().isEmpty()) { throw new BadRequestException("Method must be specified"); } String mName = req.getMethod(); Tuple<Class[], Object[]> params = req.getParsedParameters(); Object res = cacheService.executeMethod(player, mName, params.getFirst(), params.getSecond()); return new ExecuteMethodResponse(player, res); }
@POST @Path("/{world}/method") @Permission("method") @ApiOperation( value = "Execute a method", notes = "Provides direct access to the underlaying world object and can execute any method on it.") public ExecuteMethodResponse executeMethod( @PathParam("world") @ApiParam("The uuid of the world on which to execute the method") CachedWorld world, ExecuteMethodRequest req) throws BadRequestException { if (req == null) { throw new BadRequestException("Request body is required"); } if (req.getMethod() == null || req.getMethod().isEmpty()) { throw new BadRequestException("Method must be specified"); } String mName = req.getMethod(); Tuple<Class[], Object[]> params = req.getParsedParameters(); Object res = cacheService.executeMethod(world, mName, params.getFirst(), params.getSecond()); return new ExecuteMethodResponse(world, res); }
@POST @Path("/{entity}/method") @Permission("method") @ApiOperation( value = "Execute a method", notes = "Provides direct access to the underlaying entity object and can execute any method on it.") public ExecuteMethodResponse executeMethod( @PathParam("entity") @ApiParam("The uuid of the entity") UUID uuid, ExecuteMethodRequest req) throws NotFoundException, BadRequestException { if (req == null) { throw new BadRequestException("Request body is required"); } Optional<CachedEntity> optEntity = WebAPI.getCacheService().getEntity(uuid); if (!optEntity.isPresent()) { throw new NotFoundException("Entity with UUID '" + uuid + "' could not be found"); } if (req.getMethod() == null || req.getMethod().isEmpty()) { throw new BadRequestException("Method must be specified"); } String mName = req.getMethod(); Tuple<Class[], Object[]> params = req.getParsedParameters(); Object res = cacheService.executeMethod(optEntity.get(), mName, params.getFirst(), params.getSecond()); return new ExecuteMethodResponse(optEntity.get(), res); }
/** * Creates a new {@link BiConsumer} that takes the provided * {@link Collection} of coupled {@link Enchantment} and * {@link VariableAmount} to apply varying enchantments of varying amounts * to the generated {@link ItemStack}. * * @param amount The varying amount of enchantments * @param enchantments The collection of enchantment tuples combining the * enchantment and the variable amount of level to apply * @return The new biconsumer to apply to an itemstack builder */ public static BiConsumer<ItemStack.Builder, Random> enchantments(VariableAmount amount, Collection<Tuple<Enchantment, VariableAmount>> enchantments) { checkNotNull(amount, "VariableAmount cannot be null!"); final WeightedTable<Function<Random, ItemEnchantment>> suppliers = new WeightedTable<>(amount); for (Tuple<Enchantment, VariableAmount> enchantment : enchantments) { suppliers.add(random -> new ItemEnchantment(enchantment.getFirst(), enchantment.getSecond().getFlooredAmount(random)), 1); } return listValueSuppliers(Keys.ITEM_ENCHANTMENTS, suppliers); }
final Tuple<Vector3d, Vector3d> pair = intersection.get(); final Vector3d narrowHit = pair.getFirst(); hit = new BlockRayHit<>(this.extent, narrowHit.getX(), narrowHit.getY(), narrowHit.getZ(), this.direction, pair.getSecond()); } else {