ninja.leaping.configurate.commented.CommentedConfigurationNode Java Examples
The following examples show how to use
ninja.leaping.configurate.commented.CommentedConfigurationNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IpCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { String ip; GameProfile profile = args.<GameProfile>getOne("player").get(); if (UltimateCore.get().getUserService().getUser(profile).get().getUser().isOnline()) { Player p = UltimateCore.get().getUserService().getUser(profile).get().getUser().getPlayer().get(); ip = p.getConnection().getAddress().getAddress().toString().replace("/", ""); } else { PlayerDataFile config = new PlayerDataFile(profile.getUniqueId()); CommentedConfigurationNode node = config.get(); ip = node.getNode("lastip").getString(); } Messages.send(src, "ban.command.ip.success", "%player%", profile.getName().orElse(""), "%ip%", ip); return CommandResult.success(); }
Example #2
Source File: DefaultListener.java From UltimateCore with MIT License | 6 votes |
@Listener(order = Order.EARLY) public void onJoin(ClientConnectionEvent.Join event) { Player p = event.getTargetEntity(); //Player file PlayerDataFile config = new PlayerDataFile(event.getTargetEntity().getUniqueId()); CommentedConfigurationNode node = config.get(); node.getNode("lastconnect").setValue(System.currentTimeMillis()); String ip = event.getTargetEntity().getConnection().getAddress().getAddress().toString().replace("/", ""); node.getNode("lastip").setValue(ip); config.save(node); //Ipcache file GlobalDataFile file = new GlobalDataFile("ipcache"); CommentedConfigurationNode node2 = file.get(); node2.getNode(ip, "name").setValue(p.getName()); node2.getNode(ip, "uuid").setValue(p.getUniqueId().toString()); file.save(node2); }
Example #3
Source File: ConfigCompleter.java From UltimateCore with MIT License | 6 votes |
/** * This method completes a datafile. * Any fields that are in the asset provided but not in the datafile will be set in the datafile. * * @param file The file to complete * @param asset The asset with the default values * @return Whether anything was added to the file */ public static boolean complete(RawConfig file, Asset asset) { try { ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(asset.getUrl()).build(); CommentedConfigurationNode assetnode = loader.load(); CommentedConfigurationNode sourcenode = file.get(); // if (complete(assetnode, sourcenode)) { // file.save(assetnode); // return true; // } return false; } catch (Exception ex) { ErrorLogger.log(ex, "Config completion failed for " + file + " / " + asset); return false; } }
Example #4
Source File: Utils.java From EssentialCmds with MIT License | 6 votes |
public static void addRule(String rule) { CommentedConfigurationNode node = Configs.getConfig(rulesConfig).getNode("rules", "rules"); String formattedItem = (rule + ","); if (configManager.getString(node).isPresent()) { String items = node.getString(); if (!items.contains(formattedItem)) Configs.setValue(rulesConfig, node.getPath(), items + formattedItem); return; } Configs.setValue(rulesConfig, node.getPath(), formattedItem); }
Example #5
Source File: ItemListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onDrop(DropItemEvent.Dispense event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Entity en : event.getEntities()) { if (!(en instanceof Item)) continue; Item item = (Item) en; CommentedConfigurationNode node = hnode.getNode("items", item.getItemType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-drop").getBoolean()) { event.setCancelled(true); } } } }
Example #6
Source File: VirtualChestInventoryDispatcher.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
public void loadConfig(CommentedConfigurationNode node) throws IOException { try { Path configDir = plugin.getConfigDir(); Map<String, VirtualChestInventory> newOnes = new LinkedHashMap<>(); this.menuDirs = ImmutableList.copyOf(node.getList(TypeToken.of(String.class), this::releaseExample)); this.menuDirs.stream().map(configDir::resolve).forEach(p -> newOnes.putAll(this.scanDir(p.toFile()))); this.updateInventories(newOnes); this.fireLoadEvent(); } catch (ObjectMappingException e) { throw new IOException(e); } }
Example #7
Source File: VirtualChestRecordManager.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
public void saveConfig(CommentedConfigurationNode node) { String databaseUrlComment = "virtualchest.config.recording.databaseUrl.comment"; String rulesComment = "virtualchest.config.recording.filter.rules.comment"; String modeComment = "virtualchest.config.recording.filter.mode.comment"; String enabledComment = "virtualchest.config.recording.enabled.comment"; String filterComment = "virtualchest.config.recording.filter.comment"; String recordingComment = "virtualchest.config.recording.comment"; if (this.databaseUrl.isEmpty()) { this.translation.withComment(node.getNode("enabled"), enabledComment).setValue(false); this.translation.withComment(node, recordingComment); } else { this.translation.withComment(node.getNode("filter", "mode"), modeComment).setValue(this.filterMode.name().toLowerCase()); this.translation.withComment(node.getNode("filter", "rules"), rulesComment).setValue(this.filterRuleList); this.translation.withComment(node.getNode("database-url"), databaseUrlComment).setValue(this.databaseUrl); this.translation.withComment(node.getNode("enabled"), enabledComment).setValue(true); this.translation.withComment(node.getNode("filter"), filterComment); this.translation.withComment(node, recordingComment); } }
Example #8
Source File: ItemListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onChange(ChangeInventoryEvent event, @First Player p) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); try { for (Inventory s : event.getTargetInventory().slots()) { ItemStack item = s.peek(); CommentedConfigurationNode node = hnode.getNode("items", item.getType().getKey()); if (!node.isVirtual()) { if (node.getNode("deny-possession").getBoolean()) { s.poll(); } } } } catch (Exception ignore) { } }
Example #9
Source File: MessageStorage.java From GriefPrevention with MIT License | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public void resetMessageData(String message) { for (Map.Entry<Object, ? extends CommentedConfigurationNode> mapEntry : this.root.getNode(GriefPreventionPlugin.MOD_ID).getChildrenMap().entrySet()) { CommentedConfigurationNode node = (CommentedConfigurationNode) mapEntry.getValue(); String key = ""; String comment = node.getComment().orElse(null); if (comment == null && node.getKey() instanceof String) { key = (String) node.getKey(); if (key.equalsIgnoreCase(message)) { this.root.getNode(GriefPreventionPlugin.MOD_ID).removeChild(mapEntry.getKey()); } } } try { this.loader.save(this.root); this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(MessageDataConfig.class).bindToNew(); this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID)); } catch (IOException | ObjectMappingException e) { e.printStackTrace(); } GriefPreventionPlugin.instance.messageData = this.configBase; }
Example #10
Source File: Utils.java From EssentialCmds with MIT License | 6 votes |
public static void removeLockedWeatherWorld(UUID worldUuid) { CommentedConfigurationNode valueNode = Configs.getConfig(worldConfig).getNode("world", "weather", "locked"); if (valueNode.getValue() != null) { if (valueNode.getString().contains(worldUuid.toString() + ", ")) { Configs.setValue(worldConfig, valueNode.getPath(), valueNode.getString().replace(worldUuid.toString() + ", ", "")); } else { Configs.setValue(worldConfig, valueNode.getPath(), valueNode.getString().replace(worldUuid.toString(), "")); } } }
Example #11
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get boolean {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional.empty. * * @param node The node for which the boolean value is needed * @return Optional.empty if null or Optional#of(Boolean) if not */ public Optional<Boolean> getBoolean(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getBoolean()); }
Example #12
Source File: WebHookSerializer.java From Web-API with MIT License | 5 votes |
private <T> void setValueAndComment(ConfigurationNode node, TypeToken<T> type, T value, String comment) throws ObjectMappingException { node.setValue(type, value); if (node instanceof CommentedConfigurationNode) { ((CommentedConfigurationNode) node).setComment(comment); } }
Example #13
Source File: AfkTitleTask.java From UltimateCore with MIT License | 5 votes |
@Override public void run() { CommentedConfigurationNode config = Modules.AFK.get().getConfig().get().get(); for (Player player : Sponge.getServer().getOnlinePlayers()) { UltimateUser user = UltimateCore.get().getUserService().getUser(player); if (user.get(AfkKeys.IS_AFK).get()) { Text title = Messages.getFormatted("afk.title.title"); Text subtitle; long timediff = (config.getNode("time", "kicktime").getInt() * 1000) - (System.currentTimeMillis() - user.get(AfkKeys.AFK_TIME).get()); if (config.getNode("time", "kicktime").getInt() != -1 && timediff <= 0 && !player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get())) { player.kick(Messages.getFormatted("afk.kick.reason")); } if (player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("time", "kicktime").getInt() == -1) { subtitle = Messages.getFormatted("afk.title.subtitle.exempt"); } else if (config.getNode("title", "subtitle-show-seconds").getBoolean(true)) { subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(timediff, 3, null)); } else { subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(timediff, 3, 11)); } if (config.getNode("title", "subtitle").getBoolean(false) && (!player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("title", "subtitle-exempt").getBoolean(false))) { //Show subtitle player.sendTitle(Title.builder().title(title).subtitle(subtitle).fadeIn(0).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build()); } else { //Don't show subtitle //TODO refresh? player.sendTitle(Title.builder().title(title).fadeIn(0).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build()); } } } }
Example #14
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
private boolean checkNull(CommentedConfigurationNode node) { if (node.getValue() == null) return true; else return false; }
Example #15
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get String {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional#empty. * * @param node The node for which the String value is needed * @return Optional#empty if null or Optional#of(String) if not */ public Optional<String> getString(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getString()); }
Example #16
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get long {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional#empty. * * @param node The node for which the long value is needed * @return Optional#empty if null or Optional#of(Long) if not */ public Optional<Long> getLong(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getLong()); }
Example #17
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get int {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional#empty. * * @param node The node for which the int value is needed * @return Optional#empty if null or Optional#of(Integer) if not */ public Optional<Integer> getInt(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getInt()); }
Example #18
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get float {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional#empty. * * @param node The node for which the float value is needed * @return Optional#empty if null or double value Optional#of(Float) if not */ public Optional<Float> getFloat(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getFloat()); }
Example #19
Source File: ConfigManager.java From EssentialCmds with MIT License | 5 votes |
/** * Get double {@link Optional} value for CommentedConfigurationNode if it is not null; Otherwise return Optional.empty. * * @param node The node for which the double value is needed * @return Optional.empty if null or Optional#of(Double) if not */ public Optional<Double> getDouble(CommentedConfigurationNode node) { if (checkNull(node)) return Optional.empty(); return Optional.of(node.getDouble()); }
Example #20
Source File: KitKeys.java From UltimateCore with MIT License | 5 votes |
@Override public void save(Game arg, List<Kit> kits) { ModuleConfig loader = Modules.KIT.get().getConfig().get(); CommentedConfigurationNode node = loader.get(); node.getNode("kits").getChildrenMap().keySet().forEach(node.getNode("kits")::removeChild); for (Kit kit : kits) { try { node.getNode("kits", kit.getId()).setValue(TypeToken.of(Kit.class), kit); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to save kits key"); } } loader.save(node); }
Example #21
Source File: Zone.java From Nations with MIT License | 5 votes |
@SuppressWarnings("serial") public Zone(UUID uuid, String name, Rect rect, UUID owner) { this.uuid = uuid; this.name = name; this.owner = owner; this.coowners = new ArrayList<UUID>(); this.rect = rect; this.flags = new Hashtable<String, Boolean>(); for (Entry<Object, ? extends CommentedConfigurationNode> e : ConfigHandler.getNode("flags", "zones").getChildrenMap().entrySet()) { flags.put(e.getKey().toString(), e.getValue().getBoolean()); } this.perms = new Hashtable<String, Hashtable<String, Boolean>>() {{ put(Nation.TYPE_OUTSIDER, new Hashtable<String, Boolean>() {{ put(Nation.PERM_BUILD, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_OUTSIDER).getNode(Nation.PERM_BUILD).getBoolean()); put(Nation.PERM_INTERACT, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_OUTSIDER).getNode(Nation.PERM_INTERACT).getBoolean()); }}); put(Nation.TYPE_CITIZEN, new Hashtable<String, Boolean>() {{ put(Nation.PERM_BUILD, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_CITIZEN).getNode(Nation.PERM_BUILD).getBoolean()); put(Nation.PERM_INTERACT, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_CITIZEN).getNode(Nation.PERM_INTERACT).getBoolean()); }}); put(Nation.TYPE_COOWNER, new Hashtable<String, Boolean>() {{ put(Nation.PERM_BUILD, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_COOWNER).getNode(Nation.PERM_BUILD).getBoolean()); put(Nation.PERM_INTERACT, ConfigHandler.getNode("zones", "perms").getNode(Nation.TYPE_COOWNER).getNode(Nation.PERM_INTERACT).getBoolean()); }}); }}; }
Example #22
Source File: Utils.java From EssentialCmds with MIT License | 5 votes |
public static boolean useMySQL() { CommentedConfigurationNode node = Configs.getConfig(mainConfig).getNode("mysql", "use"); if (configManager.getBoolean(node).isPresent()) return node.getBoolean(); setUseMySQL(false); return false; }
Example #23
Source File: ConfigHandler.java From Nations with MIT License | 5 votes |
public static void ensurePositiveNumber(CommentedConfigurationNode node, Number def) { if (!(node.getValue() instanceof Number) || node.getDouble(-1) < 0) { node.setValue(def); } }
Example #24
Source File: ConfigHandler.java From Nations with MIT License | 5 votes |
public static void ensureString(CommentedConfigurationNode node, String def) { if (node.getString() == null) { node.setValue(def); } }
Example #25
Source File: ConfigHandler.java From Nations with MIT License | 5 votes |
public static boolean isWhitelisted(String type, String id) { if (id.equals("minecraft:air")) return true; if (!config.getNode("whitelist", type).hasListChildren()) return false; for (CommentedConfigurationNode item : config.getNode("whitelist", type).getChildrenList()) { if (id.startsWith(item.getString())) { return true; } } return false; }
Example #26
Source File: ConfigHandler.java From Nations with MIT License | 5 votes |
public static CommentedConfigurationNode getNationRank(int numCitizens) { CommentedConfigurationNode rank = config.getNode("nationRanks") .getChildrenList() .stream() .filter(node -> node.getNode("numCitizens").getInt() <= numCitizens) .max((CommentedConfigurationNode a, CommentedConfigurationNode b) -> Integer.compare(a.getNode("numCitizens").getInt(), b.getNode("numCitizens").getInt())) .get(); return rank; }
Example #27
Source File: Config.java From ChatUI with MIT License | 5 votes |
public static ConfigurationNode playerConfig(UUID uuid) { CommentedConfigurationNode settings = config.getNode("player-settings", uuid.toString()); if (settings.isVirtual()) { settings.getNode("enabled").setValue(true); } return settings; }
Example #28
Source File: Config.java From ChatUI with MIT License | 5 votes |
public static void loadConfig() { try { config = confLoader.load(); } catch (IOException e) { logger.error("Error while loading config", e); config = confLoader.createEmptyNode(); } CommentedConfigurationNode playerSettings = config.getNode("player-settings"); if (playerSettings.isVirtual()) { playerSettings.setValue(Collections.emptyMap()); } }
Example #29
Source File: LibConfig.java From ChatUI with MIT License | 5 votes |
public static PlayerSettings playerConfig(UUID uuid) { CommentedConfigurationNode settings = config.getNode("player-settings", uuid.toString()); try { // Save defaults to config file dirty |= settings.isVirtual(); return settingsMapper.bindToNew().populate(settings); } catch (ObjectMappingException e) { throw new RuntimeException(e); } }
Example #30
Source File: Utils.java From EssentialCmds with MIT License | 5 votes |
public static boolean unsafeEnchanmentsEnabled() { CommentedConfigurationNode node = Configs.getConfig(mainConfig).getNode("unsafeenchantments", "enabled"); if (configManager.getBoolean(node).isPresent()) return node.getBoolean(); setUnsafeEnchanmentsEnabled(false); return false; }