本文整理汇总了Java中cn.nukkit.utils.ConfigSection类的典型用法代码示例。如果您正苦于以下问题:Java ConfigSection类的具体用法?Java ConfigSection怎么用?Java ConfigSection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigSection类属于cn.nukkit.utils包,在下文中一共展示了ConfigSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDB
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@SuppressWarnings("serial")
public void initDB() {
skyblockDB = (LinkedHashMap<String, Object>) (new Config(plugin.getDataFolder() + "/skyblockDB.json", Config.JSON)).getAll();
count = (LinkedHashMap<String, Object>) (new Config(plugin.getDataFolder() + "/count.json", Config.JSON, new ConfigSection(new LinkedHashMap<String, Object>() {
{
put("count", 0);
}
}))).getAll();
config = new Config(plugin.getDataFolder() + "/config.yml", Config.YAML, new ConfigSection() {
{
put("create-sponge", false);
put("only-one-skyblock", false);
}
});
if (config.get("only-one-skyblock") == null) {
config.save(true);
}
}
示例2: addPlayer
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@SuppressWarnings("serial")
public void addPlayer(String player, final String group){
File file = new File(this.baseFolder, player.toLowerCase() + ".yml");
if(!file.exists()){
Config config = new Config(new File(this.baseFolder, player.toLowerCase() + ".yml"), Config.YAML);
config.setAll(new ConfigSection(){
{
set("name", player);
set("group", group);
set("permission", new ArrayList<String>());
}
});
config.save();
}
}
示例3: loadUser
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@Override
public User loadUser(String playerName) {
Message.debugMessage("Loading permissions", playerName);
File file = getUserFile(playerName);
User user = new User(playerName);
Config cfg = new Config(Config.YAML);
if (file.exists()) {
cfg.load(file.toString());
Node node = sectionToPass(cfg.getRootSection());
user = new User(playerName, node);
ConfigSection worlds = cfg.getSection("worlds");
for (String world : worlds.getKeys(false)) {
ConfigSection ws = worlds.getSection(world);
if (ws.isEmpty()) continue;
Node wpass = sectionToPass(ws);
user.setWorldPass(world, wpass);
}
}
return user;
}
示例4: saveUser
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@Override
public void saveUser(User user) {
File file = getUserFile(user.getName());
Message.debugMessage("Saving user file: ", file.toString());
if (user.isEmpty()) {
if (file.exists()) {
file.delete();
}
Message.debugMessage(user.getName(), "data is empty. File removed");
} else {
Config cfg = new Config(file, Config.YAML);
ConfigSection cfgSection = passToSection(user, true);
cfg.setAll(cfgSection);
ConfigSection worlds = new ConfigSection();
user.getWorldPass().entrySet().forEach(e -> {
worlds.set(e.getKey(), passToSection(e.getValue(), false));
});
cfg.set("worlds", worlds);
Message.debugMessage(user.getName(), " saved.");
cfg.save(file);
}
}
示例5: loadGroups
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@Override
public Collection<Group> loadGroups() {
List<Group> groups = new ArrayList<>();
if (!groupFile.exists()) return groups;
Config cfg = new Config(groupFile, Config.YAML);
cfg.getSections().entrySet().forEach(e -> {
Node node = sectionToPass((ConfigSection) e.getValue());
Group group = new Group(e.getKey(), node);
ConfigSection worlds = cfg.getSection("worlds");
for (String world : worlds.getKeys(false)) {
ConfigSection ws = worlds.getSection(world);
if (ws.isEmpty()) continue;
Node wpass = sectionToPass(ws);
group.setWorldPass(world, wpass);
}
groups.add(group);
});
Message.debugMessage(groups.size(), "groups loaded");
return groups;
}
示例6: getMirrorWorld
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private String getMirrorWorld(String currentWorld) {
ConfigSection mirros = MultipassPlugin.getCfg().mirros;
if (mirros != null & !mirros.isEmpty())
for (Map.Entry<String, Object> e : mirros.entrySet())
if (e.getValue() instanceof String) {
String[] worlds = ((String) e.getValue()).split(",\\s+");
for (String w : worlds)
if (w.equalsIgnoreCase(currentWorld)) return e.getKey();
}
return currentWorld;
}
示例7: saveGroups
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@Override
public void saveGroups(Collection<Group> groups) {
Config cfg = new Config();
groups.forEach(g -> {
ConfigSection group = passToSection(g, true);
ConfigSection worlds = new ConfigSection();
g.getWorldPass().entrySet().forEach(e -> {
worlds.set(e.getKey(), passToSection(e.getValue(), false));
});
group.set("worlds", worlds);
cfg.set(g.getName(), group);
});
cfg.save(this.groupFile);
}
示例8: passToSection
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private ConfigSection passToSection(Node node, boolean saveAdditions) {
ConfigSection section = new ConfigSection();
section.set("groups", node.getGroupList());
section.set("permissions", node.getPermissionList());
if (saveAdditions) {
section.set("prefix", node.getPrefix());
section.set("suffix", node.getSuffix());
section.set("priority", node.getPriority());
}
return section;
}
示例9: sectionToPass
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private Node sectionToPass(ConfigSection section) {
Node node = new Node();
node.setGroupList(section.getStringList("groups"));
node.setPermissionsList(section.getStringList("permissions"));
node.setPrefix(section.getString("prefix", ""));
node.setSuffix(section.getString("suffix", ""));
node.setPriority(section.getInt("priority", 0));
return node;
}
示例10: passToSection
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private ConfigSection passToSection(Node node) {
ConfigSection section = new ConfigSection();
section.set("groups", node.getGroupList());
section.set("permissions", node.getPermissionList());
section.set("prefix", node.getPrefix());
section.set("suffix", node.getSuffix());
section.set("priority", node.getPriority());
return section;
}
示例11: loadEntries
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private void loadEntries() {
this.saveDefaultConfig();
enable = this.getConfig().getBoolean("enable", true);
this.autoCompress = this.getConfig().getBoolean("autoCompress", true);
if (!enable) {
this.getLogger().warning("The SynapseAPI is not be enabled!");
} else {
if (this.getConfig().getBoolean("disable-rak")) {
for (SourceInterface sourceInterface : this.getServer().getNetwork().getInterfaces()) {
if (sourceInterface instanceof RakNetInterface) {
sourceInterface.shutdown();
}
}
}
List entries = this.getConfig().getList("entries");
for (Object entry : entries) {
@SuppressWarnings("unchecked")
ConfigSection section = new ConfigSection((LinkedHashMap) entry);
String serverIp = section.getString("server-ip", "127.0.0.1");
int port = section.getInt("server-port", 10305);
boolean isMainServer = section.getBoolean("isMainServer");
String password = section.getString("password");
String serverDescription = section.getString("description");
this.autoConnect = section.getBoolean("autoConnect", true);
if (this.autoConnect) {
this.addSynapseAPI(new SynapseEntry(this, serverIp, port, isMainServer, password, serverDescription));
}
}
}
}
示例12: addPlayer
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@SuppressWarnings("serial")
@Override
public void addPlayer(Player player, String hash){
new Config(new File(this.baseFolder, player.getName().toLowerCase() + ".yml"), Config.YAML, new ConfigSection(){
{
put("registered", System.currentTimeMillis());
put("lastJoined", System.currentTimeMillis());
put("lastIP", player.getAddress());
put("uuid", player.getUniqueId().toString());
put("hash", hash);
}
});
}
示例13: DataBase
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
@SuppressWarnings({ "deprecation", "serial" })
public DataBase(Main plugin) {
plugin.getDataFolder().mkdirs();
instance = this;
Config config = new Config(plugin.getDataFolder() + "/mine.json", Config.JSON,
new ConfigSection(new LinkedHashMap<String, Object>() {
{
LinkedHashMap<String, Object> map1 = new LinkedHashMap<>();
map1.put(Block.DIAMOND_ORE + "", "5");
map1.put(Block.EMERALD_ORE + "", "5");
map1.put(Block.GOLD_ORE + "", "50");
map1.put(Block.IRON_ORE + "", "175");
map1.put(Block.COAL_ORE + "", "375");
put("MINE", map1);
LinkedHashMap<String, Object> map2 = new LinkedHashMap<>();
map2.put(Block.OBSIDIAN + "", "100");
map2.put(Block.GLOWSTONE_BLOCK + "", "150");
map2.put(Block.QUARTZ_ORE + "", "200");
put("NETHER", map2);
}
}));
Config positions = new Config(new File(plugin.getDataFolder(), "position.json"), Config.JSON,
new ConfigSection(new LinkedHashMap<String, Object>() {
{
put("MINE", new ArrayList<String>());
}
}));
config.save();
positions.save();
this.mine = this.toMine((Map<String, Object>) config.get("MINE"));
// this.nether = this.toMine((Map<String, Object>) mine.get("NETHER"));
mines = positions.getList("MINE");
nethers = positions.getList("NETHER");
DataBase.plugin = plugin;
}
示例14: getData
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
EnumMap<Keys, ConfigSection> getData() {
return data;
}
示例15: initDatabase
import cn.nukkit.utils.ConfigSection; //导入依赖的package包/类
private void initDatabase() {
switch (getConfig().getString("database-type", "1")) {
case "1": {
db = new HashDatabase(new Config(new File(getDataFolder(), "data.dat"), Config.YAML));
File oldFile = new File(getDataFolder(), "db.dat");
if (db.keySet().size() == 0 && oldFile.exists()) {
convertDatabase(oldFile);
save();
if (oldFile.renameTo(new File(getDataFolder(), "db.dat.bak"))) {
getLogger().notice("数据转换成功! 旧文件已经被重命名为 \"db.dat.bak\", 你可以删除该文件, 或是将其作为一个备份.");
getLogger().notice("Data file converting success! The old data file is renamed as " +
"\"db.dat.bak\", you can delete that file, or make it as a backup.");
} else {
getLogger().notice("数据转换成功, 但重命名旧文件 \"db.dat\" 为 \"db.dat.bak\" 失败, 请手动重命名将其作为一个备份或删除");
getLogger().notice("Data file converting success! But renaming old file \"db.dat\" to \"db.dat.bak\" failed. " +
"Please rename it manually to make it as a backup or delete it.");
}
}
return;
}
case "2": {
ConfigSection section = getConfig().getSection("database-server-settings");
try {
db = new SafeRedisDatabase(
section.getString("host", "localhost"),
section.getInt("port", 6379),
section.getString("user", ""),
section.getString("password", "")
);
((RedisDatabase) db).select(section.getInt("id", 0));
((RedisDatabase) db).getClient().echo("Money plugin is now connected!");
} catch (JedisConnectionException e) {
getLogger().critical("无法连接 Redis 数据库.");
getLogger().critical("Cannot connect redis database server");
Server.getInstance().shutdown();
}
return;
}
default:
getLogger().critical("目前仅支持 Config 和 Redis 数据库");
getLogger().critical("Now this plugin only support Config and Redis database");
Server.getInstance().forceShutdown();
}
}