Java Code Examples for ninja.leaping.configurate.commented.CommentedConfigurationNode#getNode()
The following examples show how to use
ninja.leaping.configurate.commented.CommentedConfigurationNode#getNode() .
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: 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 2
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 3
Source File: CommandtimerModule.java From UltimateCore with MIT License | 6 votes |
@Override public void onPostInit(GamePostInitializationEvent event) { CommandsConfig config = UltimateCore.get().getCommandsConfig(); CommentedConfigurationNode node = config.get(); boolean modified = false; for (Command cmd : UltimateCore.get().getCommandService().getCommands()) { CommentedConfigurationNode cmdnode = node.getNode("commands", cmd.getIdentifier()); if (cmdnode.getNode("cooldown").getValue() == null) { modified = true; cmdnode.getNode("cooldown").setComment("Time in seconds that a player has to wait between uses of the command. (0 to disable)"); cmdnode.getNode("cooldown").setValue("0s"); } if (cmdnode.getNode("warmup").getValue() == null) { modified = true; cmdnode.getNode("warmup").setComment("Time in seconds that a player has to wait before the command is executed. (0 to disable)"); cmdnode.getNode("warmup").setValue("0s"); } } if (modified) { config.save(node); } onReload(null); new CommandtimerPermissions(); }
Example 4
Source File: CommandtimerModule.java From UltimateCore with MIT License | 6 votes |
@Override public void onReload(GameReloadEvent event) { HashMap<Command, Long> cooldowns = new HashMap<>(); HashMap<Command, Long> warmups = new HashMap<>(); CommandsConfig config = UltimateCore.get().getCommandsConfig(); CommentedConfigurationNode node = config.get(); for (Command cmd : UltimateCore.get().getCommandService().getCommands()) { CommentedConfigurationNode cmdnode = node.getNode("commands", cmd.getIdentifier()); if (!cmdnode.getNode("cooldown").isVirtual()) { cooldowns.put(cmd, TimeUtil.parse(cmdnode.getNode("cooldown").getString())); } if (!cmdnode.getNode("warmup").isVirtual()) { warmups.put(cmd, TimeUtil.parse(cmdnode.getNode("warmup").getString())); } } GlobalData.offer(CommandtimerKeys.COOLDOWNS, cooldowns); GlobalData.offer(CommandtimerKeys.WARMUPS, warmups); }
Example 5
Source File: ConfigCompleter.java From UltimateCore with MIT License | 6 votes |
private static boolean complete(CommentedConfigurationNode assetnode, CommentedConfigurationNode sourcenode) { boolean changed = false; //Children of sourcenode && assetnode Map<Object, ? extends CommentedConfigurationNode> sourcenodes = sourcenode.getChildrenMap(); Map<Object, ? extends CommentedConfigurationNode> assetnodes = assetnode.getChildrenMap(); //For each child of assetnode for (Object name : new ArrayList<>(assetnode.getChildrenMap().keySet())) { //The current child of assetnode which is being tested CommentedConfigurationNode node = assetnode.getNode(name); //If it doesnt contain the current key if (!sourcenodes.containsKey(name)) { CommentedConfigurationNode newnode = sourcenode.getNode(name); newnode.setValue(node.getValue()); newnode.setComment(node.getComment().orElse(null)); changed = true; } } return changed; }
Example 6
Source File: ItemListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onPickup(ChangeInventoryEvent.Pickup event, @First Player p) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for(SlotTransaction trans : event.getTransactions()){ ItemStack item = trans.getSlot().peek(); CommentedConfigurationNode node = hnode.getNode("items", item.getType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-drop").getBoolean()) { trans.setValid(false); } } } }
Example 7
Source File: ItemListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onInteract(InteractItemEvent event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); ItemStackSnapshot item = event.getItemStack(); CommentedConfigurationNode node = hnode.getNode("items", item.getType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-use").getBoolean()) { event.setCancelled(true); } } }
Example 8
Source File: BlockListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onBreak(ChangeBlockEvent.Break event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Transaction<BlockSnapshot> trans : event.getTransactions()) { if (!trans.isValid()) continue; CommentedConfigurationNode node = hnode.getNode("blocks", trans.getOriginal().getState().getType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-break").getBoolean()) { trans.setValid(false); } } } }
Example 9
Source File: BlockListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onPlace(ChangeBlockEvent.Place event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Transaction<BlockSnapshot> trans : event.getTransactions()) { if (!trans.isValid()) continue; CommentedConfigurationNode node = hnode.getNode("blocks", trans.getFinal().getState().getType().getId()); if (!node.isVirtual() && node.getNode("deny-place").getBoolean()) { trans.setValid(false); } } }
Example 10
Source File: BloodModule.java From UltimateCore with MIT License | 5 votes |
@Override public void onInit(GameInitializationEvent event) { //Config TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(BloodEffect.class), new BloodEffect.BloodEffectSerializer()); config = new RawModuleConfig("blood"); //Check if all entity types are in the config CommentedConfigurationNode node = config.get(); boolean modified = false; //For every entitytype, if it doesnt exist in the config add it for (EntityType type : Sponge.getRegistry().getAllOf(CatalogTypes.ENTITY_TYPE)) { if (!Living.class.isAssignableFrom(type.getEntityClass())) { continue; } //If entitytype is not in config if (node.getNode("types", type.getId(), "enabled").getValue() == null) { modified = true; CommentedConfigurationNode typenode = node.getNode("types", type.getId()); try { typenode.setValue(TypeToken.of(BloodEffect.class), BloodEffects.DEFAULT); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to set default blood effect."); } } } if (modified) { config.save(node); } //Load blood effects from config BloodEffects.reload(); //Listeners Sponge.getEventManager().registerListeners(UltimateCore.get(), new BloodListener()); }
Example 11
Source File: NamesHandler.java From UltimateCore with MIT License | 4 votes |
private Tuples.Tri<Text, Text, Text> getDetails(Player p) { ModuleConfig config = Modules.TABLIST.get().getConfig().get(); CommentedConfigurationNode node = config.get(); boolean compatibility = config.get().getNode("names", "compatibility-mode").getBoolean(); Text prefix = Messages.toText(node.getNode("names", "default", "prefix").getString("")); Text suffix = Messages.toText(node.getNode("names", "default", "suffix").getString("")); Text name = Messages.toText(node.getNode("names", "default", "format").getString("")); //Check if the uc.tablist.group property is set, in that case override name. String group = TablistPermissions.UC_TABLIST_GROUP.getFor(p); if (group != null && !node.getNode("names", "groups", group).isVirtual()) { CommentedConfigurationNode subnode = node.getNode("names", "groups", group); name = Messages.toText(subnode.getNode("format").getString("")); prefix = Messages.toText(subnode.getNode("prefix").getString("")); suffix = Messages.toText(subnode.getNode("suffix").getString("")); } //Afk suffix if (Modules.AFK.isPresent()) { UltimateUser up = UltimateCore.get().getUserService().getUser(p); if (up.get(AfkKeys.IS_AFK).get()) { Text afksuffix = Messages.toText(config.get().getNode("afk-suffix").getString()); suffix = Text.of(suffix, afksuffix); } } prefix = VariableUtil.replaceVariables(prefix, p); suffix = VariableUtil.replaceVariables(suffix, p); name = VariableUtil.replaceVariables(name, p); //Max length check for prefix & suffix if (compatibility) { if (TextSerializers.FORMATTING_CODE.serialize(name).length() > 16) { name = TextSerializers.FORMATTING_CODE.deserialize(TextSerializers.FORMATTING_CODE.serialize(name).substring(0, 16)); } if (TextSerializers.FORMATTING_CODE.serialize(prefix).length() > 16) { prefix = TextSerializers.FORMATTING_CODE.deserialize(TextSerializers.FORMATTING_CODE.serialize(prefix).substring(0, 16)); } if (TextSerializers.FORMATTING_CODE.serialize(suffix).length() > 16) { suffix = TextSerializers.FORMATTING_CODE.deserialize(TextSerializers.FORMATTING_CODE.serialize(suffix).substring(0, 16)); } } return Tuples.of(prefix, name, suffix); }