當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration類代碼示例

本文整理匯總了Java中org.bukkit.configuration.Configuration的典型用法代碼示例。如果您正苦於以下問題:Java Configuration類的具體用法?Java Configuration怎麽用?Java Configuration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Configuration類屬於org.bukkit.configuration包,在下文中一共展示了Configuration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveScoreboard

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Saves a scoreboard to a configuration file.
 *
 * @param config
 *            The configuration file.
 * @param scoreboard
 *            The scoreboard.
 */
public void saveScoreboard(Configuration config, Scoreboard scoreboard) {
	// Save teams
	ConfigurationSection teamsSection = config.createSection("teams");
	scoreboard.getTeams().forEach(team -> {
		ConfigurationSection teamSection = teamsSection.createSection(team.getName());
		saveTeam(teamSection, team);
	});

	// Save objectives
	ConfigurationSection objectivesSection = config.createSection("objectives");
	scoreboard.getObjectives().forEach(objective -> {
		ConfigurationSection objectiveSection = objectivesSection.createSection(objective.getName());
		objectiveSection.set("criteria", objective.getCriteria());
		objectiveSection.set("display_name", objective.getDisplayName());
		objectiveSection.set("display_slot", objective.getDisplaySlot().toString().toLowerCase());
	});

	// Save scores
	ConfigurationSection scoresSection = config.createSection("scores");
	scoreboard.getEntries().forEach(playerName -> {
		ConfigurationSection playerSection = scoresSection.createSection(playerName);
		scoreboard.getScores(playerName)
				.forEach(score -> playerSection.set(score.getObjective().getName(), score.getScore()));
	});
}
 
開發者ID:rutgerkok,項目名稱:Pokkit,代碼行數:34,代碼來源:ScoreboardPersister.java

示例2: MatchManager

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Creates a new map manager with a specified map rotation.
 */
@Inject MatchManager(Loggers loggers,
                     @Named("pluginData") Path pluginDataFolder,
                     Provider<Configuration> config,
                     MapLibrary mapLibrary,
                     MapLoader mapLoader,
                     MapErrorTracker mapErrorTracker,
                     FileRotationProviderFactory fileRotationProviderFactory,
                     EventBus eventBus,
                     MatchLoader matchLoader) throws MapNotFoundException {

    this.pluginDataFolder = pluginDataFolder;
    this.mapErrorTracker = mapErrorTracker;
    this.fileRotationProviderFactory = fileRotationProviderFactory;
    this.log = loggers.get(getClass());
    this.config = config;
    this.mapLibrary = mapLibrary;
    this.mapLoader = mapLoader;
    this.eventBus = eventBus;
    this.matchLoader = matchLoader;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:24,代碼來源:MatchManager.java

示例3: QuotaConfig

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
@Inject QuotaConfig(Configuration root) {
    this.config = root.getConfigurationSection("match-quotas");
    if(config == null) {
        quotas = new TreeSet<>();
    } else {
        quotas = new TreeSet<>(Collections2.transform(
            config.getKeys(false),
            new Function<String, Entry>() {
                @Override
                public Entry apply(@Nullable String key) {
                    return new Entry(config.getConfigurationSection(key));
                }
            }
        ));
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:17,代碼來源:QuotaConfig.java

示例4: parse

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
public Set<RotationProviderInfo> parse(MapLibrary mapLibrary, Path dataPath, Configuration config) {
    ConfigurationSection base = config.getConfigurationSection("rotation.providers.file");
    if(base == null) return Collections.emptySet();

    Set<RotationProviderInfo> providers = new HashSet<>();
    for(String name : base.getKeys(false)) {
        ConfigurationSection provider = base.getConfigurationSection(name);

        Path rotationFile = Paths.get(provider.getString("path"));
        if(!rotationFile.isAbsolute()) rotationFile = dataPath.resolve(rotationFile);

        int priority = provider.getInt("priority", 0);

        if(Files.isRegularFile(rotationFile)) {
            providers.add(new RotationProviderInfo(new FileRotationProvider(mapLibrary, name, rotationFile, dataPath), name, priority));
        } else if(minecraftService.getLocalServer().startup_visibility() == ServerDoc.Visibility.PUBLIC) {
            // This is not a perfect way to decide whether or not to throw an error, but it's the best we can do right now
            mapLibrary.getLogger().severe("Missing rotation file: " + rotationFile);
        }
    }

    return providers;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:24,代碼來源:FileRotationProviderFactory.java

示例5: loadConfig

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
public void loadConfig() {
    Configuration configuration = YamlConfiguration.loadConfiguration(configFile);
    ConfigurationSection bungeeSection;
    if (configuration.contains("bungee")){
        bungeeSection = configuration.getConfigurationSection("bungee");
    } else {
        getLogger().warning("The section 'bungee' in the configuration is not found, " +
                "defaults will be assumed. Delete the config file and restart to have a " +
                "clean valid configuration file.");
        bungeeSection = configuration.createSection("bungee");
    }
    boolean serverSocketEnabled = configuration.getBoolean("server-socket", true);
    boolean serverPortAuto = configuration.getBoolean("port-automatic", true);
    int serverPort = configuration.getInt("port", 3112);
    String host = bungeeSection.getString("host");
    int port = bungeeSection.getInt("port");
    char[] password = bungeeSection.getString("password", "").toCharArray();
    int heartbeatSeconds = bungeeSection.getInt("heartbeat-seconds", 30);
    int reconnectAttempts = bungeeSection.getInt("reconnect-attempts", 7);
    bungeeMasterSpigotConfig = new BungeeMasterSpigotConfig(serverSocketEnabled, serverPortAuto, serverPort, host, port, password, heartbeatSeconds, reconnectAttempts);
}
 
開發者ID:TonyMaster21,項目名稱:BungeeMaster,代碼行數:22,代碼來源:BungeeMaster.java

示例6: checkConfigVersions

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
private void checkConfigVersions(Configuration config, Path dataFolder) {
    if (config.getInt("config-version", 0) < TradeConfiguration.CURRENT_CONFIG_VERSION) {
        Path configSource = dataFolder.resolve(TradeConfiguration.DESTINATION_FILE_NAME);
        Path configTarget = dataFolder.resolve("config_old.yml");

        try {
            Files.move(configSource, configTarget, StandardCopyOption.REPLACE_EXISTING);
            URL configResource = getClass().getResource(TradeConfiguration.CLASSPATH_RESOURCE_NAME);

            copyResource(configResource, configSource.toFile());

            ConsoleCommandSender sender = Bukkit.getConsoleSender();
            sender.sendMessage(ChatColor.RED + "Due to a SimpleTrading update your old configuration has been renamed");
            sender.sendMessage(ChatColor.RED + "to config_old.yml and a new one has been generated. Make sure to");
            sender.sendMessage(ChatColor.RED + "apply your old changes to the new config!");
        } catch (IOException e) {
            getLogger().log(Level.SEVERE, "Could not create updated configuration due to an IOException", e);
        }
    }
}
 
開發者ID:xaniox,項目名稱:simple-trading,代碼行數:21,代碼來源:SimpleTrading.java

示例7: getJarConfig

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Gets a configuration file from the jar file.
 *
 * @param path
 *            Path in the jar file.
 * @return The configuration file.
 */
private Configuration getJarConfig(String path) {
    InputStream resource = getResource(path);
    if (resource == null) {
        // Not found
        return new YamlConfiguration();
    }
    Reader reader = new InputStreamReader(resource, Charsets.UTF_8);
    Configuration config = YamlConfiguration.loadConfiguration(reader);
    try {
        resource.close();
    } catch (IOException e) {
        getLogger().log(Level.SEVERE, "Failed to close stream", e);
    }
    return config;
}
 
開發者ID:rutgerkok,項目名稱:BlockLocker,代碼行數:23,代碼來源:BlockLockerPluginImpl.java

示例8: loadTranslations

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
private Translator loadTranslations(String fileName) {
    File file = new File(getDataFolder(), fileName);
    Configuration config = YamlConfiguration.loadConfiguration(file);
    config.addDefaults(getJarConfig(Config.DEFAULT_TRANSLATIONS_FILE));

    ConfigTranslator translator = new ConfigTranslator(config);
    if (translator.needsSave()) {
        getLogger().info("Saving translations");
        try {
            translator.save(file);
        } catch (IOException e) {
            getLogger().log(Level.SEVERE, "Failed to save translation file", e);
        }
    }
    return translator;
}
 
開發者ID:rutgerkok,項目名稱:BlockLocker,代碼行數:17,代碼來源:BlockLockerPluginImpl.java

示例9: ModConfig

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Initialize mod config based on the configuration file
 *
 * @param config
 */
public ModConfig(Configuration config) {
    m_isInitialized = false;
    if (config == null) {
        m_blocks = null;
        m_mobs = null;
        m_modIdRegex = null;
        m_textureRes = 0;
        m_versionRegex = null;
        return;
    }

    m_name = config.getString("DisplayName", null);
    m_blocks = config.getConfigurationSection("Blocks");
    m_mobs = config.getConfigurationSection("Mobs");
    m_modIdRegex = config.getString("ModId", null);
    m_alternativeId = config.getString("ModIdAlternative", null);
    m_versionRegex = config.getString("Version", null);
    m_textureRes = config.getInt("TextureRes", 0);
}
 
開發者ID:SBPrime,項目名稱:MCPainter,代碼行數:25,代碼來源:ModConfig.java

示例10: load

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Load palette from file
 *
 * @param file
 * @return
 */
public static Palette load(File file) {
    Configuration config = YamlConfiguration.loadConfiguration(file);

    String name = config.getString("name", null);
    BlockEntry[] blockEntries = parseBlocksSection(config);
    
    if (name == null) {
        MCPainterMain.log("* " + file.getName() + "...invalid file format, no name palette defined.");
        return null;
    }
    
    name = name.toLowerCase();
    if (blockEntries == null || blockEntries.length < 2) {
        MCPainterMain.log("* " + name + "...invalid file format, minimum number of blocks in palette is 2.");
        return null;
    }
    
    MCPainterMain.log("* " + name + "..." + blockEntries.length + " blocks defined.");
    return new Palette(name, blockEntries);
}
 
開發者ID:SBPrime,項目名稱:MCPainter,代碼行數:27,代碼來源:Palette.java

示例11: parseBlocksSection

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
/**
 * Parse blocks section entry
 *
 * @param configuration
 * @return
 */
private static BlockEntry[] parseBlocksSection(Configuration configuration) {
    List<BlockEntry> blocks = new ArrayList();
    for (String string : configuration.getStringList("blocks")) {
        try {
            BlockEntry entry = BlockEntry.parse(string);
            if (entry == null) {
                MCPainterMain.log("* Error parsing block entry: " + string);
            } else {
                blocks.add(entry);
            }
        } catch (Exception e) {
            MCPainterMain.log("* Error parsing block entry: " + string);
        }
    }
    return blocks.toArray(new BlockEntry[0]);
}
 
開發者ID:SBPrime,項目名稱:MCPainter,代碼行數:23,代碼來源:Palette.java

示例12: load

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
public void load() {
    BukkitScheduler scheduler = plugin.getServer().getScheduler();
    if (task != null) {
        task.cancel();
        task = null;
    }
    ConfigurationSection arenaConfiguration = loadDataFile("arenas");
    load(arenaConfiguration);

    ConfigurationSection arenaData = loadDataFile("data");
    loadData(arenaData);

    plugin.reloadConfig();
    Configuration config = plugin.getConfig();
    pathTemplate = config.getString("path_template", pathTemplate);
    tickInterval = config.getInt("tick_interval", 40);

    task = scheduler.runTaskTimer(plugin, this, 1, tickInterval);
}
 
開發者ID:elBukkit,項目名稱:MagicArenas,代碼行數:20,代碼來源:ArenaController.java

示例13: isSTBItem

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
@Override
public boolean isSTBItem(ItemStack stack, Class<? extends BaseSTBItem> c) {
    if (stack == null || !stack.hasItemMeta()) {
        return false;
    }
    ItemMeta im = stack.getItemMeta();
    if (im.hasLore()) {
        List<String> lore = im.getLore();
        if (!lore.isEmpty() && lore.get(0).startsWith(LORE_PREFIX)) {
            if (c != null) {
                Configuration conf = getItemAttributes(stack);
                ReflectionDetails details = reflectionDetailsMap.get(conf.getString("*TYPE"));
                return details != null && c.isAssignableFrom(details.clazz);
            } else {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:21,代碼來源:STBItemRegistry.java

示例14: getItemAttributes

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
private Configuration getItemAttributes(ItemStack stack) {
    AttributeStorage storage = AttributeStorage.newTarget(stack, STB_ATTRIBUTE_ID);
    YamlConfiguration conf = new YamlConfiguration();
    try {
        String s = storage.getData("");
        if (s != null) {
            conf.loadFromString(s);
            if (Debugger.getInstance().getLevel() > 2) {
                Debugger.getInstance().debug(3, "get item attributes for " + STBUtil.describeItemStack(stack) + ":");
                for (String k : conf.getKeys(false)) {
                    Debugger.getInstance().debug(3, "- " + k + " = " + conf.get(k));
                }
            }
            return conf;
        } else {
            throw new IllegalStateException("ItemStack " + stack + " has no STB attribute data!");
        }
    } catch (InvalidConfigurationException e) {
        e.printStackTrace();
        return new MemoryConfiguration();
    }
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:23,代碼來源:STBItemRegistry.java

示例15: loadCharacter

import org.bukkit.configuration.Configuration; //導入依賴的package包/類
private RpChar loadCharacter(File playerFile)
   {
       OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(playerFile.getName().substring(0, playerFile.getName().length() - 4)));
       RpChar character = new RpChar(player,plugin);

	Configuration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
		
       for (Field field : plugin.getCharacterManager().getFields().values())
       {
           if (!playerConfig.isSet(field.getName()))
               continue;

           character.setField(field.getName(), playerConfig.getString(field.getName()));
       }

       return character;
}
 
開發者ID:AaronFoley,項目名稱:CharacterCards,代碼行數:18,代碼來源:YMLCharacterStorage.java


注:本文中的org.bukkit.configuration.Configuration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。