use of cn.nukkit.utils.Config in project Nukkit by Nukkit.
the class PluginBase method reloadConfig.
@Override
public void reloadConfig() {
this.config = new Config(this.configFile);
InputStream configStream = this.getResource("config.yml");
if (configStream != null) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
try {
this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
} catch (IOException e) {
Server.getInstance().getLogger().logException(e);
}
}
}
use of cn.nukkit.utils.Config in project LuckPerms by lucko.
the class LPNukkitPlugin method performFinalSetup.
@Override
protected void performFinalSetup() {
// register permissions
try {
PluginManager pm = this.bootstrap.getServer().getPluginManager();
PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
for (CommandPermission p : CommandPermission.values()) {
pm.addPermission(new Permission(p.getPermission(), null, permDefault.toString()));
}
} catch (Exception e) {
// this throws an exception if the plugin is /reloaded, grr
}
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
Config ops = this.bootstrap.getServer().getOps();
ops.getKeys(false).forEach(ops::remove);
}
// replace the temporary executor when the Nukkit one starts
this.bootstrap.getServer().getScheduler().scheduleTask(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false), true);
// Load any online users (in the case of a reload)
for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
this.bootstrap.getScheduler().doAsync(() -> {
try {
User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
if (user != null) {
this.bootstrap.getScheduler().doSync(() -> {
try {
LPPermissible lpPermissible = new LPPermissible(player, user, this);
PermissibleInjector.inject(player, lpPermissible);
} catch (Throwable t) {
t.printStackTrace();
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
use of cn.nukkit.utils.Config in project Nukkit by Nukkit.
the class Item method initCreativeItems.
private static void initCreativeItems() {
clearCreativeItems();
Server server = Server.getInstance();
String path = server.getDataPath() + "creativeitems.json";
if (!new File(path).exists()) {
try {
Utils.writeFile(path, Server.class.getClassLoader().getResourceAsStream("creativeitems.json"));
} catch (IOException e) {
MainLogger.getLogger().logException(e);
return;
}
}
List<Map> list = new Config(path, Config.YAML).getMapList("items");
for (Map map : list) {
try {
int id = (int) map.get("id");
int damage = (int) map.getOrDefault("damage", 0);
String hex = (String) map.get("nbt_hex");
byte[] nbt = hex != null ? Utils.parseHexBinary(hex) : new byte[0];
addCreativeItem(Item.get(id, damage, 1, nbt));
} catch (Exception e) {
MainLogger.getLogger().logException(e);
}
}
}
Aggregations