Java Code Examples for org.spongepowered.api.data.DataQuery#toString()
The following examples show how to use
org.spongepowered.api.data.DataQuery#toString() .
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: DataUtil.java From Prism with MIT License | 6 votes |
/** * Helper method for writing values to a {@link DataView DataView}. * * @param dataView DataView * @param path DataQuery * @param value Object * @throws IllegalArgumentException If an attempt is made to change an existing value. */ public static void writeToDataView(DataView dataView, DataQuery path, Object value) throws IllegalArgumentException { Preconditions.checkNotNull(dataView); Preconditions.checkNotNull(path); Object currentValue = dataView.get(path).orElse(null); if (currentValue != null) { if (!currentValue.equals(value)) { throw new IllegalArgumentException("Attempted to overwrite " + path.toString()); } Prism.getInstance().getLogger().warn("Attempted to overwrite {} with the same value", path.toString(), new Exception()); return; } dataView.set(path, value); }
Example 2
Source File: VirtualChestInventoryBuilder.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Optional<VirtualChestInventory> buildContent(DataView view) throws InvalidDataException { this.items.clear(); for (DataQuery key : view.getKeys(false)) { String keyString = key.toString(); if (keyString.startsWith(VirtualChestInventory.KEY_PREFIX)) { SlotIndex slotIndex = SlotIndex.of(VirtualChestInventory.keyToSlotIndex(keyString)); for (DataView dataView : VirtualChestItem.getViewListOrSingletonList(key, view)) { VirtualChestItem item = VirtualChestItem.deserialize(plugin, dataView); this.items.put(slotIndex, item); } } } this.title = view.getString(VirtualChestInventory.TITLE) .map(TextSerializers.FORMATTING_CODE::deserialize) .orElseThrow(() -> new InvalidDataException("Expected title")); this.height = view.getInt(VirtualChestInventory.HEIGHT) .orElseThrow(() -> new InvalidDataException("Expected height")); this.triggerItems.clear(); VirtualChestItem.getViewListOrSingletonList(VirtualChestInventory.TRIGGER_ITEM, view) .forEach(dataView -> this.triggerItems.add(new VirtualChestTriggerItem(dataView))); this.openActionCommand = view.getString(VirtualChestInventory.OPEN_ACTION_COMMAND); this.closeActionCommand = view.getString(VirtualChestInventory.CLOSE_ACTION_COMMAND); this.updateIntervalTick = view.getInt(VirtualChestInventory.UPDATE_INTERVAL_TICK).orElse(0); this.actionIntervalTick = view.getInt(VirtualChestInventory.ACCEPTABLE_ACTION_INTERVAL_TICK); return Optional.of(new VirtualChestInventory(this.plugin, this)); }