当前位置: 首页>>代码示例>>Java>>正文


Java FileConfiguration类代码示例

本文整理汇总了Java中org.bukkit.configuration.file.FileConfiguration的典型用法代码示例。如果您正苦于以下问题:Java FileConfiguration类的具体用法?Java FileConfiguration怎么用?Java FileConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileConfiguration类属于org.bukkit.configuration.file包,在下文中一共展示了FileConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sync

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
/**
 * Write in-memory changes of config to its file
 *
 * @param clazz The configuration class to sync.
 */
public static void sync(Class clazz) {
    Object config = configurations.get(clazz);

    if (config == null)
        return;

    String name = config.getClass().getDeclaredAnnotation(Configuration.class).value();
    File file = new File(JavaPlugin.getProvidingPlugin(clazz).getDataFolder(), String.format("%s.yml", name));
    FileConfiguration configFile = new YamlConfiguration();

    buildToConfig(config, configFile);

    try {
        configFile.save(file);
    } catch (IOException e) {
        Logger.err("Couldn't sync config " + name + " to its file!");
    }
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:24,代码来源:ConfigurationBuilder.java

示例2: initiateArenas

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
private void initiateArenas() {
    FileConfiguration config = ManagerHandler.getConfig().getArenasConfig().getConfig();

    if (!config.contains("arenas")) return;

    for (String name : config.getConfigurationSection("arenas").getKeys(false)) {
        try {
            String displayName = config.getString("arenas." + name + ".display-name");
            Integer displayOrder = config.getInt("arenas." + name + ".display-order");
            Location location1 = LocationUtils.getLocation(config.getString("arenas." + name + ".location1"));
            Location location2 = LocationUtils.getLocation(config.getString("arenas." + name + ".location2"));
            Arena arena = new Arena(name, displayName, displayOrder, location1, location2);
            this.arenas.put(name, arena);
        }
        catch (Exception e) {
            PracticePlugin.getInstance().getLogger().severe("Failed to load arena '" + name + "', stack trace below:");
            PracticePlugin.getInstance().getLogger().severe("------------------------------------------------------");
            e.printStackTrace();
            PracticePlugin.getInstance().getLogger().severe("------------------------------------------------------");
        }
    }
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:23,代码来源:ArenaManager.java

示例3: buildFromConfig

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
private static Object buildFromConfig(FileConfiguration config, Class clazz, Object instance) {
    for (String key : config.getKeys(false)) {
        try {
            Field field = clazz.getField(key);

            field.setAccessible(true);
            fieldSet(field, config, instance, key);
        } catch (NoSuchFieldException ignored) {
            Logger.log(Level.FINER, "A key in YAML was not found in the class it is being rebuilt to.");
        } catch (IllegalAccessException e) {
            Logger.err("Couldn't access a field when rebuilding a config!");
        }
    }

    return instance;
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:17,代码来源:ConfigurationBuilder.java

示例4: loadUsers

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
public void loadUsers(){
	allowedUsers.clear();
	FileConfiguration config = getConfig();
	for(String key : config.getKeys(false)){
		allowedUsers.put(key.replace("_(dot)_", "."), (Date) config.get(key));
	}
	ArrayList<String> toRemove = new ArrayList<>();
	for(Entry<String, Date> ent : allowedUsers.entrySet()){
		if(Calendar.getInstance().getTime().after(ent.getValue())){
			try {
				Core.send(Core.skype.getOrLoadContact(ent.getKey()).getPrivateConversation(), "You DDoS-Attack permission is over");
			} catch (ConnectionException | ChatNotFoundException e) {
				e.printStackTrace();
			}
			toRemove.add(ent.getKey());
		}
	}
	for(String user : toRemove){
		allowedUsers.remove(user);
	}
}
 
开发者ID:Kitt3120,项目名称:ViperBot,代码行数:22,代码来源:DDoSManager.java

示例5: loadCommands

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
/**
 * Loads all of the startup commands from the plugin's configuration file.
 * @param plugin the StartupCommands plugin instance
 */
public static void loadCommands(StartupCommands plugin) {
	FileConfiguration config = plugin.getConfig();
		
		if (config.getConfigurationSection("commands") == null) {
			plugin.getLogger().info("There are no startup commands present.");
		} else {
			int delay = 0;

			for (String command : config.getConfigurationSection("commands").getKeys(false)) {
				delay = config.getInt("commands." + command + ".delay", 0);
				
				// Try to create the command
				try {
					plugin.getCommands().add(new Command(command, delay));
				} catch (IllegalArgumentException e) {
					plugin.getLogger().severe(e.getMessage());
				}
	 		}
		}
}
 
开发者ID:mattgd,项目名称:StartupCommands,代码行数:25,代码来源:Command.java

示例6: removeCraft

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
public void removeCraft(int nb) {
try {
	//replacing in the file
   	File craftfile = new File(plugin.getDataFolder(), "crafts.yml");
	craftfile.createNewFile();
	FileConfiguration craftconfig = YamlConfiguration.loadConfiguration(craftfile);
	int count = 0;
	for(String craftuuid : craftconfig.getConfigurationSection("Crafts").getKeys(false)) {
		if(nb == count) {
			craftconfig.set("Crafts." + craftuuid, null);
		}
		count++;
	}
	craftconfig.save(craftfile);
  	} catch (Exception e) {
  		//
  	}
  }
 
开发者ID:Slaymd,项目名称:CaulCrafting,代码行数:19,代码来源:CraftStorage.java

示例7: build

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
private static Object build(Class clazz) {
    Object object;

    try {
        object = clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        Logger.err("Failed to build a configuration - couldn't access the class!");
        return null;
    }

    String name = object.getClass().getDeclaredAnnotation(Configuration.class).value();
    File file = new File(JavaPlugin.getProvidingPlugin(clazz).getDataFolder(), String.format("%s.yml", name));
    FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);

    buildFromConfig(configFile, clazz, object);

    return object;
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:19,代码来源:ConfigurationBuilder.java

示例8: onEnable

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
@Override
public void onEnable() {
  world = Bukkit.createWorld(new WorldCreator(OpenUHC.WORLD_DIR_PREFIX + "lobby"));
  // Read lobby yml if it exists
  File lobbyFile = new File(OpenUHC.WORLD_DIR_PREFIX + "lobby/lobby.yml");
  if (lobbyFile.exists()) {
    FileConfiguration lobbyConfig = YamlConfiguration.loadConfiguration(lobbyFile);
    ConfigurationSection spawn = lobbyConfig.getConfigurationSection("spawn");
    if (spawn != null) {
      double x = spawn.getDouble("x", 0);
      double y = spawn.getDouble("y", 64);
      double z = spawn.getDouble("z", 0);
      double r = spawn.getDouble("r", 1);
      this.spawn = new Vector(x, y, z);
      radius = (float) r;
    }
  }
  OpenUHC.registerEvents(this);
}
 
开发者ID:twizmwazin,项目名称:OpenUHC,代码行数:20,代码来源:LobbyModule.java

示例9: removeSignJoinGame

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
public void removeSignJoinGame(String gameNumber) {
	File signJoinFile = new File(SkyWarsReloaded.get().getDataFolder(), "signJoinGames.yml");
	FileConfiguration storage = YamlConfiguration.loadConfiguration(signJoinFile);
 		storage.set("games." + gameNumber, null);
 		try {
		storage.save(signJoinFile);
	} catch (IOException e) {
		e.printStackTrace();
	}
       signJoinGames.remove(Integer.valueOf(gameNumber));
       Game game = getGame(Integer.valueOf(gameNumber));
       if (game != null) {
           if (game.getState() != GameState.PLAYING) {
           	game.endGame();
           }
       }
}
 
开发者ID:smessie,项目名称:SkyWarsReloaded,代码行数:18,代码来源:GameController.java

示例10: read

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
/**
 * Get the data from config file.
 *
 * @param config the configuration file.
 */
public void read(FileConfiguration config) {

    // read type and time.
    banType = BanList.Type.valueOf(config.getString("ban-type"));
    banTime = config.getInt("ban-time", banTime);

    // convert the days into a date.
    String days = config.getString("ban-days");
    if (Objects.isNull(days) || Objects.equals(days, "0")) {
        banDate = null;
    } else {
        GregorianCalendar c = new GregorianCalendar();
        c.add(GregorianCalendar.DATE, Integer.parseInt(days));
        banDate = c.getTime();
    }

    tpsLimit = config.getInt("tps-limit", tpsLimit);

    broadcastBan = config.getBoolean("broadcast-ban");
    if (broadcastBan) {
        String message = config.getString("broadcast-message");
        broadcastMessage = ChatColor.translateAlternateColorCodes('&', message);
    }

}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:31,代码来源:ArcConfiguration.java

示例11: reload

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
public boolean reload() {
	ConfigAPI api = new ConfigAPI(getConfig());
       FileConfiguration config = api.getConfig();
       String title = config.getString("info.title");
       String worldName = config.getString("info.worldName");
       
       List<Location> spawns = new ArrayList<Location>();
       for (String s : config.getConfigurationSection("spawns").getKeys(false)) {
       	Location l = api.getLocation("spawns." + s);
       		spawns.add(l);
       }
       Location specSpawn = api.getLocation("spawns.spec");
       
       this.title = title;
       this.worldName = worldName;
       this.specSpawn = specSpawn;
       this.spawns = spawns;
	return true;
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:20,代码来源:Map.java

示例12: add

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
public void add(String server, Location location) {
    final BungeeCordSignInfo info = new BungeeCordSignInfo.Container(location, server);
    this.signs.add(info);
    final BungeeCordSignInfo[] signInfos = this.signs.toArray(new BungeeCordSignInfo[this.signs.size()]);
    this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
        try {
            final FileConfiguration configuration = new YamlConfiguration();
            final File file = new File(BungeeCordController.this.plugin.getDataFolder(), "bungeecord_signs.yml");
            if (file.exists()) {
                if (!file.delete()) {
                    Bukkit.getLogger().log(Level.WARNING, "File cannot get deleted.");
                }
            }
            for (int i = 0; i < signInfos.length; i++) {
                configuration.set("signs." + i, signInfos[i].serialize());
            }
            configuration.save(file);
        } catch (final IOException e) {
            Bukkit.getLogger().log(Level.WARNING, "Save sign location.", e);
        }
    });
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:23,代码来源:BungeeCordController.java

示例13: load

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
private void load(JavaPlugin plugin) {
    try {
        final FileConfiguration configuration = new YamlConfiguration();
        final File file = new File(plugin.getDataFolder(), "bungeecord_signs.yml");
        if (!file.exists()) {
            if (!file.createNewFile()) {
                Bukkit.getLogger().log(Level.WARNING, "File cannot get created.");
            }
        }
        configuration.load(file);
        if (configuration.getConfigurationSection("signs") != null) {
            final Map<String, Object> data = configuration.getConfigurationSection("signs").getValues(false);
            for (final String s : data.keySet()) {
                this.signs.add(new BungeeCordSignInfo.Container(((ConfigurationSection) data.get(s)).getValues(true)));
            }
        }
    } catch (IOException | InvalidConfigurationException e) {
        Bukkit.getLogger().log(Level.WARNING, "Save load location.", e);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:21,代码来源:BungeeCordController.java

示例14: save

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
void save(Arena item) {
    if (item != null && item.getName() != null) {
        try {
            final FileConfiguration configuration = new YamlConfiguration();
            final File file = new File(this.getFolder(), "arena_" + item.getName() + ".yml");
            if (file.exists()) {
                if (!file.delete())
                    throw new IllegalStateException("Cannot delete file!");
            }
            if (!file.createNewFile())
                throw new IllegalStateException("Cannot create file!");
            configuration.load(file);
            final Map<String, Object> data = item.serialize();
            for (final String key : data.keySet()) {
                configuration.set("arena." + key, data.get(key));
            }
            configuration.save(file);
        } catch (IOException | InvalidConfigurationException ex) {
            Bukkit.getLogger().log(Level.WARNING,"Cannot save arena." ,ex.getMessage());
        }
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:23,代码来源:ArenaFileManager.java

示例15: load

import org.bukkit.configuration.file.FileConfiguration; //导入依赖的package包/类
Arena[] load() {
    final List<Arena> items = new ArrayList<>();
    for (int i = 0; (this.getFolder() != null) && (i < this.getFolder().list().length); i++) {
        final String s = this.getFolder().list()[i];
        try {
            if (s.contains("arena_")) {
                final FileConfiguration configuration = new YamlConfiguration();
                final File file = new File(this.getFolder(), s);
                configuration.load(file);
                final Map<String, Object> data = configuration.getConfigurationSection("arena").getValues(true);
                final Arena arenaEntity = new ArenaEntity(data, configuration.getStringList("arena.properties.wall-bouncing"));
                items.add(arenaEntity);
            }
        } catch (final Exception ex) {
            Bukkit.getLogger().log(Level.WARNING, "Cannot read arena file " + s + '.', ex);
        }
    }
    return items.toArray(new Arena[items.size()]);
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:20,代码来源:ArenaFileManager.java


注:本文中的org.bukkit.configuration.file.FileConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。