/** * Gets the value typed using the appropriate type conversion from {@link Types} * * @see #getValue() * @return The appropriate type conversion, 0 if no appropriate value is available */ default int getInt() { return getInt(NUMBER_DEF); }
/** * Gets the value typed using the appropriate type conversion from {@link Types} * * @see #getValue() * @return The appropriate type conversion, 0 if no appropriate value is available */ default int getInt() { return getInt(NUMBER_DEF); }
/** * Gets the value typed using the appropriate type conversion from {@link Types} * * @see #getValue() * @return The appropriate type conversion, 0 if no appropriate value is available */ default int getInt() { return getInt(NUMBER_DEF); }
@Override public Number deserialize(TypeToken<?> type, ConfigurationNode value) throws InvalidTypeException { type = type.wrap(); Class<?> clazz = type.getRawType(); if (Integer.class.equals(clazz)) { return value.getInt(); } else if (Long.class.equals(clazz)) { return value.getLong(); } else if (Short.class.equals(clazz)) { return (short) value.getInt(); } else if (Byte.class.equals(clazz)) { return (byte) value.getInt(); } else if (Float.class.equals(clazz)) { return value.getFloat(); } else if (Double.class.equals(clazz)) { return value.getDouble(); } return null; }
@Override public void apply(ConfigurationNode node) { ConfigurationNode versionNode = node.getNode(versionPath); int currentVersion = versionNode.getInt(-1); for (SortedMap.Entry<Integer, ConfigurationTransformation> entry : versionTransformations.entrySet()) { if (entry.getKey() <= currentVersion) { continue; } entry.getValue().apply(node); currentVersion = entry.getKey(); } versionNode.setValue(currentVersion); } }
@Override public Number deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws InvalidTypeException { type = type.wrap(); Class<?> clazz = type.getRawType(); if (Integer.class.equals(clazz)) { return value.getInt(); } else if (Long.class.equals(clazz)) { return value.getLong(); } else if (Short.class.equals(clazz)) { return (short) value.getInt(); } else if (Byte.class.equals(clazz)) { return (byte) value.getInt(); } else if (Float.class.equals(clazz)) { return value.getFloat(); } else if (Double.class.equals(clazz)) { return value.getDouble(); } return null; }
@Override public Number deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws InvalidTypeException { type = type.wrap(); Class<?> clazz = type.getRawType(); if (Integer.class.equals(clazz)) { return value.getInt(); } else if (Long.class.equals(clazz)) { return value.getLong(); } else if (Short.class.equals(clazz)) { return (short) value.getInt(); } else if (Byte.class.equals(clazz)) { return (byte) value.getInt(); } else if (Float.class.equals(clazz)) { return value.getFloat(); } else if (Double.class.equals(clazz)) { return value.getDouble(); } return null; }
@Override public void apply(@NonNull ConfigurationNode node) { ConfigurationNode versionNode = node.getNode(versionPath); int currentVersion = versionNode.getInt(-1); for (SortedMap.Entry<Integer, ConfigurationTransformation> entry : versionTransformations.entrySet()) { if (entry.getKey() <= currentVersion) { continue; } entry.getValue().apply(node); currentVersion = entry.getKey(); } versionNode.setValue(currentVersion); } }
@Override public void apply(@NonNull ConfigurationNode node) { ConfigurationNode versionNode = node.getNode(versionPath); int currentVersion = versionNode.getInt(-1); for (SortedMap.Entry<Integer, ConfigurationTransformation> entry : versionTransformations.entrySet()) { if (entry.getKey() <= currentVersion) { continue; } entry.getValue().apply(node); currentVersion = entry.getKey(); } versionNode.setValue(currentVersion); } }
@Override public Optional<Pair<String, String>> processDefault(QuerySession session, Query query) { if (session.getCommandSource() instanceof Player) { // Default radius from config int defaultRadius = Prism.getInstance().getConfiguration().getNode("defaults", "radius").getInt(); // Player location Location<World> location = ((Player) session.getCommandSource()).getLocation(); query.addCondition(ConditionGroup.from(location, defaultRadius)); session.setRadius(defaultRadius); return Optional.of(Pair.of(aliases.get(0), "" + defaultRadius)); } return Optional.empty(); } }
@Override public PermissionStruct deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { String key = value.getKey().toString(); TreeNode perms = WebAPI.getSecurityService().permissionTreeFromConfig(value.getNode("permissions")); int rateLimit = value.getNode("rateLimit").getInt(); return new PermissionStruct(key, perms, rateLimit); }
@Override public boolean connect() throws Exception { try { // Get data source HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:h2:" + dbPath.toString()); config.setMaximumPoolSize(Prism.getInstance().getConfiguration().getNode("storage", "maxPoolSize").getInt()); config.setMinimumIdle(Prism.getInstance().getConfiguration().getNode("storage", "minPoolSize").getInt()); db = new HikariDataSource(config); // Create table if needed createTables(); // Purge async Task.builder() .async() .name("PrismH2Purge") .execute(this::purge) .submit(Prism.getInstance().getPluginContainer()); return true; } catch (SQLException e) { e.printStackTrace(); return false; } }
@Override public Optional<CompletableFuture<?>> process(QuerySession session, String parameter, String value, Query query) { if (session.getCommandSource() instanceof Player) { Player player = (Player) session.getCommandSource(); Location<World> location = player.getLocation(); int radius = Integer.parseInt(value); int maxRadius = Prism.getInstance().getConfiguration().getNode("limits", "radius", "max").getInt(); // Enforce max radius unless player has override perms if (radius > maxRadius && !player.hasPermission("prism.override.radius")) { // @todo move this player.sendMessage(Format.subduedHeading(String.format("Limiting radius to maximum of %d", maxRadius))); radius = maxRadius; } session.setRadius(radius); query.addCondition(ConditionGroup.from(location, radius)); } return Optional.empty(); }
/** * Helper utility for running a lookup asynchronously. * * @param session QuerySession running this lookup. */ public static void lookup(final QuerySession session) { // Enforce lookup limits session.getQuery().setLimit(Prism.getInstance().getConfiguration().getNode("query", "lookup", "limit").getInt()); async(session, new LookupCallback(session)); }
ServerAddress address = new ServerAddress( Prism.getInstance().getConfiguration().getNode("db", "mongo", "host").getString(), Prism.getInstance().getConfiguration().getNode("db", "mongo", "port").getInt() );
@Override public boolean connect() throws Exception { try { // Get data source HikariConfig config = new HikariConfig(); config.setJdbcUrl(dns); config.setUsername(Prism.getInstance().getConfiguration().getNode("db", "mysql", "user").getString()); config.setPassword(Prism.getInstance().getConfiguration().getNode("db", "mysql", "pass").getString()); config.setMaximumPoolSize(Prism.getInstance().getConfiguration().getNode("storage", "maxPoolSize").getInt()); config.setMinimumIdle(Prism.getInstance().getConfiguration().getNode("storage", "minPoolSize").getInt()); db = new HikariDataSource(config); // Create table if needed createTables(); // Purge async Task.builder() .async() .name("PrismMySQLPurge") .execute(this::purge) .submit(Prism.getInstance().getPluginContainer()); return true; } catch (SQLException e) { e.printStackTrace(); return false; } }
int startVersion = permissionsConfig.getNode("schema-version").getInt(-1); versionUpdater.apply(permissionsConfig); int endVersion = permissionsConfig.getNode("schema-version").getInt(); if (endVersion > startVersion) { getManager().getLogger().info(t("%s schema version updated from %s to %s", permissionsFile, startVersion, endVersion));
@Test public void testMapSerializer() throws ObjectMappingException { final TypeToken<Map<String, Integer>> mapStringIntType = new TypeToken<Map<String, Integer>>() {}; final TypeSerializer<Map<String, Integer>> mapStringIntSerializer = SERIALIZERS.get(mapStringIntType); final ConfigurationNode value = SimpleConfigurationNode.root(); value.getNode("fish").setValue(5); value.getNode("bugs").setValue("124880"); value.getNode("time").setValue("-1"); final Map<String, Integer> expectedValues = ImmutableMap.of("fish", 5, "bugs", 124880, "time", -1); assertEquals(expectedValues, mapStringIntSerializer.deserialize(mapStringIntType, value)); value.setValue(null); mapStringIntSerializer.serialize(mapStringIntType, expectedValues, value); assertEquals(5, value.getNode("fish").getInt()); assertEquals(124880, value.getNode("bugs").getInt()); assertEquals(-1, value.getNode("time").getInt()); }
public static CommandSpec getCommand() { return CommandSpec.builder() .description(Text.of("Alias of /pr l r:(default radius)")) .permission("prism.lookup") .executor((source, args) -> { int radius = Prism.getInstance().getConfiguration().getNode("commands", "near", "defaultRadius").getInt(); source.sendMessage(Format.heading("Querying records...")); // Create a new query session final QuerySession session = new QuerySession(source); session.newQuery().addCondition(ConditionGroup.from(((Player) source).getLocation(), radius)); // Pass off to an async lookup helper AsyncUtil.lookup(session); return CommandResult.success(); }).build(); } }
.build(); versionTransform.apply(target); assertEquals(2, target.getNode("version").getInt()); assertEquals(ImmutableList.of(0, 1, 2), updatedVersions);