public void save() { try { // Reload the actual config to account for changes. But don't load it back into the ConfigValues. config = configManager.load(CraftBookPlugin.spongeInst().configurationOptions); enabledMechanics.save(config); dataOnlyMode.save(config); List<String> disabledMechanicsList = plugin.moduleController.getModules().stream().filter(entry -> !enabledMechanics.getValue().contains(entry.getName())).map(ModuleWrapper::getName).collect(Collectors.toList()); disabledMechanics.setValue(disabledMechanicsList); disabledMechanics.save(config); configManager.save(config); } catch (IOException e) { CraftBookPlugin.spongeInst().getLogger().error("The CraftBook configuration could not be saved!", e); } }
public ConfigValue<T> load(ConfigurationNode configurationNode) { this.value = getValueInternal(configurationNode); save(configurationNode); return this; }
@Override public SpongeBlockFilter getBlockFilter() { return allowedBlocks.getValue(); }
if(configValue.getKey().length() > nodeLength) nodeLength = configValue.getKey().length(); if(configValue.getComment().length() > commentLength) commentLength = configValue.getComment().length(); if(configValue.getTypeToken().getRawType().getSimpleName().length() > typeLength) typeLength = configValue.getTypeToken().getRawType().getSimpleName().length(); configValue.serializeDefault(node); for(ConfigValue<?> configValue : provider.getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); configValue.serializeDefault(node); configSection.append(padToLength(configValue.getKey(), nodeLength + 1)).append(padToLength(configValue.getComment(), commentLength + 1)).append(padToLength(configValue.getTypeToken().getRawType().getSimpleName(), typeLength + 1)).append(padToLength(node.getString("null"), defaultLength + 1)).append('\n');
private void appendModuleConfigurations() { appendHeader("Module Configurations"); LogListBlock log = new LogListBlock(); List<ModuleWrapper> enabledModules = CraftBookPlugin.spongeInst().moduleController.getModules().stream() .filter(ModuleWrapper::isEnabled).collect(Collectors.toList()); for (ModuleWrapper<?> moduleWrapper : enabledModules) { Object module = moduleWrapper.getModule().orElse(null); if (module == null || !(module instanceof DocumentationProvider)) { continue; } LogListBlock configLog = log.putChild(moduleWrapper.getName()); for (ConfigValue config : ((DocumentationProvider) module).getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); config.serializeDefault(node); configLog.put(config.getKey(), node.getString("UNKNOWN")); } } append(log); appendln(); } }
@Override public void onDisable() { super.onDisable(); disabledPlayers.save(config); if (treelopperCommandMapping != null) { Sponge.getCommandManager().removeMapping(treelopperCommandMapping); } }
public ConfigValue<T> save(ConfigurationNode configurationNode) { setValueInternal(configurationNode); return this; }
@Override public SpongeBlockFilter getBlockFilter() { return allowedBlocks.getValue(); }
private void appendGlobalConfiguration() { appendHeader("Global Configuration"); LogListBlock log = new LogListBlock(); LogListBlock configLog = log.putChild("Configuration"); for (ConfigValue config : CraftBookPlugin.spongeInst().getConfig().getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); config.serializeDefault(node); configLog.put(config.getKey(), node.getString("UNKNOWN")); } append(log); appendln(); }
@Override public void onInitialize() throws CraftBookException { super.onInitialize(); cannon.load(config); fan.load(config); vacuum.load(config); fireArrows.load(config); snowShooter.load(config); xpShooter.load(config); if (cannon.getValue()) { recipes.add(new Cannon()); } if (fan.getValue()) { recipes.add(new Fan()); } if (vacuum.getValue()) { recipes.add(new Vacuum()); } if (fireArrows.getValue()) { recipes.add(new FireArrows()); } if (snowShooter.getValue()) { recipes.add(new SnowShooter()); } if (xpShooter.getValue()) { recipes.add(new XPShooter()); } }
@Override public SpongeBlockFilter getBlockFilter() { return allowedBlocks.getValue(); }
@Override public void onInitialize() throws CraftBookException { super.onInitialize(); chairs = new HashMap<>(); allowedBlocks.load(config); exitAtEntry.load(config); requireSigns.load(config); maxSignDistance.load(config); faceCorrectDirection.load(config); healPassenger.load(config); healAmount.load(config); usePermissions.register(); Sponge.getGame().getScheduler().createTaskBuilder().intervalTicks(10).execute(task -> { for (Map.Entry<UUID, Chair<?>> chair : new HashSet<>(chairs.entrySet())) { Player player = Sponge.getGame().getServer().getPlayer(chair.getKey()).orElse(null); if (player == null) { removeChair(chair.getValue(), false); return; } if (healPassenger.getValue()) { if (player.get(Keys.HEALTH).orElse(0d) < player.get(Keys.MAX_HEALTH).orElse(0d)) { player.offer(Keys.HEALTH, Math.min(player.get(Keys.HEALTH).orElse(0d) + healAmount.getValue(), player.get(Keys.MAX_HEALTH).orElse(0d))); } } if (player.get(Keys.EXHAUSTION).orElse(-20d) > -20d) { player.offer(Keys.EXHAUSTION, player.get(Keys.EXHAUSTION).orElse(-20d) - 0.1d); } } }).submit(CraftBookPlugin.inst()); }
private int getMultiplier(Sign sign) { int multiplier; try { multiplier = Integer.parseInt(SignUtil.getTextRaw(sign, 3)); } catch (Exception e) { multiplier = requireFuel.getValue() ? 0 : 1; setMultiplier(sign, multiplier); } if (multiplier <= 0 && !requireFuel.getValue()) return 1; return Math.max(0, multiplier); }
@Override public void onInitialize() throws CraftBookException { offBlock.load(config); }
@Listener public void onEntityConstruct(SpawnEntityEvent event) { event.getEntities().stream().filter(entity -> entity instanceof Boat).forEach(boat -> { if (maxSpeed.getValue() >= 0) { ((Boat) boat).setMaxSpeed(maxSpeed.getValue()); } if (occupiedDeceleration.getValue() >= 0) { ((Boat) boat).setOccupiedDeceleration(occupiedDeceleration.getValue()); } if (unoccupiedDeceleration.getValue() >= 0) { ((Boat) boat).setUnoccupiedDeceleration(unoccupiedDeceleration.getValue()); } }); }
@Override public boolean isValid(Location<World> location) { return fallingLadders.getValue() && FallingLadders.isValid(location); }