gpt4 book ai didi

com.sk89q.util.yaml.YAMLProcessor类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 05:40:49 28 4
gpt4 key购买 nike

本文整理了Java中com.sk89q.util.yaml.YAMLProcessor类的一些代码示例,展示了YAMLProcessor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YAMLProcessor类的具体详情如下:
包路径:com.sk89q.util.yaml.YAMLProcessor
类名称:YAMLProcessor

YAMLProcessor介绍

[英]YAML configuration loader. To use this class, construct it with path to a file and call its load() method. For specifying node paths in the various get*() methods, they support SK's path notation, allowing you to select child nodes by delimiting node names with periods.

For example, given the following configuration file:

members: 
- Hollie 
- Jason 
- Bobo 
- Aya 
- Tetsu 
worldguard: 
fire: 
spread: false 
blocks: [cloth, rock, glass] 
sturmeh: 
cool: false 
eats: 
babies: true

Calling code could access sturmeh's baby eating state by using getBoolean("sturmeh.eats.babies", false). For lists, there are methods such as getStringList that will return a type safe list.
[中]YAML配置加载程序。要使用这个类,请使用文件的路径构造它,并调用其load()方法。为了在各种get*()方法中指定节点路径,它们支持SK的路径表示法,允许您通过用句点分隔节点名称来选择子节点。
例如,给定以下配置文件:

members: 
- Hollie 
- Jason 
- Bobo 
- Aya 
- Tetsu 
worldguard: 
fire: 
spread: false 
blocks: [cloth, rock, glass] 
sturmeh: 
cool: false 
eats: 
babies: true

调用代码可以使用getBoolean(“sturmeh.eats.babyes”,false)访问sturmeh的婴儿进食状态。对于列表,有一些方法(如getStringList)将返回类型安全列表。

代码示例

代码示例来源:origin: EngineHub/WorldEdit

config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
try {
  config.load();
} catch (IOException e) {
  logger.log(Level.WARNING, "Error loading WEPIF configuration", e);
List<String> keys = config.getKeys(null);
config.setHeader(CONFIG_HEADER);
  config.setProperty("ignore-nijiperms-bridges", true);
  isUpdated = true;
  config.setProperty("resolvers.enabled", resolvers);
  isUpdated = true;
} else {
  List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<>());
  List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
  for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext();) {
    String nextName = i.next();
  config.setProperty("resolvers.disabled", disabledResolvers);
  config.setProperty("resolvers.enabled", stagedEnabled);
  config.removeProperty("dinner-perms");
  config.removeProperty("dinnerperms");
  isUpdated = true;
      config.addNode("permissions"));
  isUpdated = true;

代码示例来源:origin: EngineHub/WorldEdit

@Override
public void load() {
  try {
    config.load();
  } catch (IOException e) {
    logger.log(Level.WARNING, "Error loading WorldEdit configuration", e);
  profile = config.getBoolean("debug", profile);
  traceUnflushedSessions = config.getBoolean("debugging.trace-unflushed-sessions", traceUnflushedSessions);
  wandItem = convertLegacyItem(config.getString("wand-item", wandItem));
  defaultChangeLimit = Math.max(-1, config.getInt(
      "limits.max-blocks-changed.default", defaultChangeLimit));
  maxChangeLimit = Math.max(-1,
      config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
      config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints));
  maxPolygonalPoints = Math.max(-1,
      config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints));
  defaultMaxPolyhedronPoints = Math.max(-1, config.getInt("limits.max-polyhedron-points.default", defaultMaxPolyhedronPoints));
  maxPolyhedronPoints = Math.max(-1, config.getInt("limits.max-polyhedron-points.maximum", maxPolyhedronPoints));
  maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
  maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
  maxSuperPickaxeSize = Math.max(1, config.getInt(
      "limits.max-super-pickaxe-size", maxSuperPickaxeSize));
  butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius));
  butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));

代码示例来源:origin: EngineHub/WorldGuard

config = new YAMLProcessor(new File(getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
try {
  config.load();
} catch (IOException e) {
  log.severe("Error reading configuration for global config: ");
config.removeProperty("suppress-tick-sync-warnings");
migrateRegionsToUuid = config.getBoolean("regions.uuid-migration.perform-on-next-start", true);
keepUnresolvedNames = config.getBoolean("regions.uuid-migration.keep-names-that-lack-uuids", true);
useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
useGodPermission = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
useGodGroup = config.getBoolean("auto-invincible-group", false);
useAmphibiousGroup = config.getBoolean("auto-no-drowning-group", false);
config.removeProperty("auto-invincible-permission");
usePlayerMove = config.getBoolean("use-player-move-event", true);
usePlayerTeleports = config.getBoolean("use-player-teleports", true);
particleEffects = config.getBoolean("use-particle-effects", true);
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
Object hostKeysRaw = config.getProperty("host-keys");
if (!(hostKeysRaw instanceof Map)) {
  config.setProperty("host-keys", new HashMap<String, String>());
} else {
  for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
hostKeysAllowFMLClients = config.getBoolean("security.host-keys-allow-forge-clients", false);

代码示例来源:origin: EngineHub/CommandBook

private boolean reloadMessages() {
  try {
    help.load();
  } catch (IOException e) {
    return false;
  }
  List<String> keys = help.getKeys("topics");
  if (keys == null) {
    help.setProperty("topics.help", demoHelpMessage);
    keys = new ArrayList<String>();
    keys.add("help");
    help.save();
  }
  for (String key : keys) {
    String information = help.getString("topics." + key);
    if (information != null && information.trim().length() != 0) {
      information = replaceColorMacros(information);
      String[] split = information.split("\\n");
      for (int i = 0; i < split.length; i++) {
        split[i] = split[i].replaceAll("[\\r\\n]", "");
      }
      messages.put(key.toLowerCase(), split);
    }
  }
  return true;
}

代码示例来源:origin: EngineHub/CommandBook

@Override
  public ConfigurationFile createConfigurationNode(File file) {
    return new YAMLProcessorConfigurationFile(new YAMLProcessor(file, true, YAMLFormat.EXTENDED));
  jarComponentAliases.load();
} catch (IOException e) {
  getLogger().severe("Error loading component aliases!");
    new YAMLNodeConfigurationNode(jarComponentAliases), configDir));
for (String dir : config.getStringList("component-class-dirs", Arrays.asList("component-classes"))) {
  final File classesDir = new File(getDataFolder(), dir);
  if (!classesDir.exists() || !classesDir.isDirectory()) {
    @Override
    public ConfigurationFile createConfigurationNode(File file) {
      return new YAMLProcessorConfigurationFile(new YAMLProcessor(file, true, YAMLFormat.EXTENDED));
for (String dir : config.getStringList("component-jar-dirs", Arrays.asList("component-jars"))) {
  final File classesDir = new File(getDataFolder(), dir);
  if (!classesDir.exists() || !classesDir.isDirectory()) {
    @Override
    public ConfigurationFile createConfigurationNode(File file) {
      return new YAMLProcessorConfigurationFile(new YAMLProcessor(file, true, YAMLFormat.EXTENDED));

代码示例来源:origin: EngineHub/WorldGuard

public void loadConfiguration() {
  try {
    config.load();
  } catch (IOException e) {
    log.severe("Error reading configuration for world " + worldName + ": ");
  config.setHeader(CONFIG_HEADER);
  config.save();

代码示例来源:origin: EngineHub/CommandBook

public WrappedSpawn setWorldSpawn(Location loc) {
  WrappedSpawn spawn = getEnrichment(loc.getWorld());
  loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
  spawn.setPitch(loc.getPitch());
  spawn.setYaw(loc.getYaw());
  config.setProperty(spawn.getWorldName() + ".pitch", spawn.getPitch());
  config.setProperty(spawn.getWorldName() + ".yaw", spawn.getYaw());
  config.setHeader(CONFIG_HEADER);
  config.save();
  return spawn;
}

代码示例来源:origin: EngineHub/WorldGuard

YAMLProcessor config = createYamlProcessor(tempFile);
config.clear();
YAMLNode regionsNode = config.addNode("regions");
Map<String, Object> map = regionsNode.getMap();
config.setHeader(FILE_HEADER);
config.save();

代码示例来源:origin: EngineHub/CommandBook

/**
 * Loads the configuration.
 */
@Override
public YAMLProcessor createConfiguration() {
  final File configFile = new File(getDataFolder(), "config.yml");
  YAMLProcessor config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
  YAMLProcessor comments = new DefaultsFileYAMLProcessor("config-comments.yml", false);
  try {
    if (!configFile.exists()) {
      configFile.getParentFile().mkdirs();
      configFile.createNewFile();
    }
    config.load();
    comments.load();
  } catch (Exception e) {
    getLogger().log(Level.WARNING, "Error loading configuration: ", e);
  }
  for (Map.Entry<String, Object> e : comments.getMap().entrySet()) {
    if (e.getValue() != null) {
      config.setComment(e.getKey(), e.getValue().toString());
    }
  }
  // Migrate the old configuration, if we need to
  final String result = new LegacyCommandBookConfigurationMigrator(configFile, config).migrate();
  if (result != null) {
    logger().severe("Error migrating CommandBook configuration: " + result);
  }
  return config;
}

代码示例来源:origin: EngineHub/WorldEdit

private void loadConfig() {
  createDefaultConfiguration("config.yml"); // Create the default configuration file
  config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
  config.load();
}

代码示例来源:origin: EngineHub/WorldGuard

public List<String> getStringList(String node, List<String> def) {
  List<String> res = parentConfig.getStringList(node, def);
  if (res == null || res.size() == 0) {
    parentConfig.setProperty(node, new ArrayList<String>());
  }
  if (config.getProperty(node) != null) {
    res = config.getStringList(node, def);
  }
  return res;
}

代码示例来源:origin: EngineHub/WorldGuard

private TargetMatcherSet getTargetMatchers(String node) {
  TargetMatcherSet set = new TargetMatcherSet();
  List<String> inputs = parentConfig.getStringList(node, null);
  if (inputs == null || inputs.size() == 0) {
    parentConfig.setProperty(node, new ArrayList<String>());
    return set;
  }
  for (String input : inputs) {
    try {
      set.add(matcherParser.fromInput(input));
    } catch (TargetMatcherParseException e) {
      log.warning("Failed to parse the block / item type specified as '" + input + "'");
    }
  }
  return set;
}

代码示例来源:origin: EngineHub/CommandBook

processor = new YAMLProcessor(userFile, false, YAMLFormat.COMPACT);
try {
  processor.load();
} catch (IOException e) {
  CommandBook.logger().log(Level.WARNING, "Error loading sessions persistence file for user " + commander, e);

代码示例来源:origin: EngineHub/WorldGuard

@Override
  public void disableUuidMigration() {
    config.setProperty("regions.uuid-migration.perform-on-next-start", false);
    if (!config.save()) {
      log.severe("Error saving configuration!");
    }
  }
}

代码示例来源:origin: EngineHub/CommandBook

public void load() {
  storedSpawns.clear();
  try {
    config.load();
  } catch (IOException ignore) {}
  for (World world : Bukkit.getServer().getWorlds())
    loadWorld(world);
}

代码示例来源:origin: EngineHub/WorldEdit

/**
 * Set the header for the file as a series of lines that are terminated
 * by a new line sequence.
 *
 * @param headerLines header lines to prepend
 */
public void setHeader(String... headerLines) {
  StringBuilder header = new StringBuilder();
  for (String line : headerLines) {
    if (header.length() > 0) {
      header.append(LINE_BREAK);
    }
    header.append(line);
  }
  setHeader(header.toString());
}

代码示例来源:origin: EngineHub/WorldGuard

public List<Integer> getIntList(String node, List<Integer> def) {
  List<Integer> res = parentConfig.getIntList(node, def);
  if (res == null || res.size() == 0) {
    parentConfig.setProperty(node, new ArrayList<Integer>());
  }
  if (config.getProperty(node) != null) {
    res = config.getIntList(node, def);
  }
  return res;
}

代码示例来源:origin: EngineHub/WorldEdit

@Override
public void load() {
  super.load();
  noOpPermissions = config.getBoolean("no-op-permissions", false);
  migrateLegacyFolders();
}

代码示例来源:origin: EngineHub/CommandBook

@Command(aliases = {"save"}, usage = "", desc = "Save CommandBook's settings", min = 0, max = 0)
@CommandPermissions({"commandbook.save"})
public static void save(CommandContext args, CommandSender sender) throws CommandException {
  CommandBook.inst().getGlobalConfiguration().save();
  sender.sendMessage(ChatColor.YELLOW + "CommandBook's configuration has been reloaded.");
}

代码示例来源:origin: EngineHub/WorldEdit

List<String> groupKeys = config.getStringList("permissions.groups", null);
        config.getStringList("permissions.groups." + key + ".permissions", null);
List<String> userKeys = config.getStringList("permissions.users", null);
        config.getStringList("permissions.users." + key + ".permissions", null);
        config.getStringList("permissions.users." + key + ".groups", null);
    groups.add("default");

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com