@Override public Set<DataQuery> getKeys(boolean deep) { ImmutableSet.Builder<DataQuery> builder = ImmutableSet.builder(); for (Map.Entry<String, Object> entry : this.map.entrySet()) { builder.add(of(entry.getKey())); } if (deep) { for (Map.Entry<String, Object> entry : this.map.entrySet()) { if (entry.getValue() instanceof DataView) { for (DataQuery query : ((DataView) entry.getValue()).getKeys(true)) { builder.add(of(entry.getKey()).then(query)); } } } } return builder.build(); }
protected MemoryDataView(DataView parent, DataQuery path, DataView.SafetyMode safety) { checkArgument(path.getParts().size() >= 1, "Path must have at least one part"); this.parent = parent; this.container = parent.getContainer(); this.path = parent.getCurrentPath().then(path); this.safety = checkNotNull(safety, "Safety mode"); }
private void copyDataView(DataQuery path, DataView value) { Collection<DataQuery> valueKeys = value.getKeys(true); for (DataQuery oldKey : valueKeys) { set(path.then(oldKey), value.get(oldKey).get()); } }
/** * Method: then(DataQuery that) */ @Test public void testThen() { final DataQuery query = DataQuery.of("this", "testing"); final DataQuery other = DataQuery.of("this"); final DataQuery test = other.then(DataQuery.of("testing")); assertThat(query.equals(test), is(true)); assertThat(test.equals(query), is(true)); }
@Override public Set<DataQuery> getKeys(boolean deep) { ImmutableSet.Builder<DataQuery> builder = ImmutableSet.builder(); for (Map.Entry<String, Object> entry : this.map.entrySet()) { builder.add(of(entry.getKey())); } if (deep) { for (Map.Entry<String, Object> entry : this.map.entrySet()) { if (entry.getValue() instanceof DataView) { for (DataQuery query : ((DataView) entry.getValue()).getKeys(true)) { builder.add(of(entry.getKey()).then(query)); } } } } return builder.build(); }
protected MemoryDataView(DataView parent, DataQuery path, DataView.SafetyMode safety) { checkArgument(path.getParts().size() >= 1, "Path must have at least one part"); this.parent = parent; this.container = parent.getContainer(); this.path = parent.getCurrentPath().then(path); this.safety = checkNotNull(safety, "Safety mode"); }
private void copyDataView(DataQuery path, DataView value) { Collection<DataQuery> valueKeys = value.getKeys(true); for (DataQuery oldKey : valueKeys) { set(path.then(oldKey), value.get(oldKey).get()); } }
/** * Convenience method to build conditions for a single location. * * @param location Location<?> * @return ConditionGroup */ public static ConditionGroup from(Location<?> location) { ConditionGroup conditions = new ConditionGroup(Operator.AND); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.WorldUuid), MatchRule.EQUALS, location.getExtent().getUniqueId().toString())); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.X), MatchRule.EQUALS, location.getBlockX())); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.Y), MatchRule.EQUALS, location.getBlockY())); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.Z), MatchRule.EQUALS, location.getBlockZ())); return conditions; }
public DataView formatBlockData(DataView finalBlock, @Nonnull Object optionalLocation) { Preconditions.checkNotNull(optionalLocation, "The location you are formatting cannot be null."); DataView location = (DataView) optionalLocation; DataView position = DataContainer.createNew(); position.set(DataQueries.X, location.get(DataQueries.X).get()); position.set(DataQueries.Y, location.get(DataQueries.Y).get()); position.set(DataQueries.Z, location.get(DataQueries.Z).get()); finalBlock.set(DataQueries.Position, position); finalBlock.set(DataQueries.WorldUuid, location.get(DataQueries.WorldUuid).get()); int blockStateVersion = finalBlock.getInt(DataQueries.BlockState.then(DataQueries.ContentVersion)).orElse(1); if (blockStateVersion == 1) { // Unsafe data includes coordinates Optional<Object> optionalUnsafeData = finalBlock.get(DataQueries.UnsafeData); if (optionalUnsafeData.isPresent()) { DataView unsafeData = (DataView) optionalUnsafeData.get(); unsafeData.set(DataQueries.X, location.get(DataQueries.X).get()); unsafeData.set(DataQueries.Y, location.get(DataQueries.Y).get()); unsafeData.set(DataQueries.Z, location.get(DataQueries.Z).get()); finalBlock.set(DataQueries.UnsafeData, unsafeData); } } return finalBlock; }
/** * Convenience method to build conditions for a region of radius around a central location. * * @param location Location<?> * @param radius Integer * @return ConditionGroup */ public static ConditionGroup from(Location<?> location, int radius) { ConditionGroup conditions = new ConditionGroup(Operator.AND); // World conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.WorldUuid), MatchRule.EQUALS, location.getExtent().getUniqueId().toString())); // X Range<Integer> xRange = Range.open(location.getBlockX() - radius, location.getBlockX() + radius); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.X), xRange)); // Y Range<Integer> yRange = Range.open(location.getBlockY() - radius, location.getBlockY() + radius); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.Y), yRange)); // Z Range<Integer> zRange = Range.open(location.getBlockZ() - radius, location.getBlockZ() + radius); conditions.add(FieldCondition.of(DataQueries.Location.then(DataQueries.Z), zRange)); return conditions; } }
Optional<Object> optionalOriginalBlock = event.getData().get(DataQueries.OriginalBlock.then(DataQueries.BlockState).then(DataQueries.BlockType)); if (optionalOriginalBlock.isPresent() && !Prism.getInstance().getFilterList().allowsBlock((String) optionalOriginalBlock.get())) { return; Optional<Object> optionalReplacementBlock = event.getData().get(DataQueries.ReplacementBlock.then(DataQueries.BlockState).then(DataQueries.BlockType)); if (optionalReplacementBlock.isPresent() && !Prism.getInstance().getFilterList().allowsBlock((String) optionalReplacementBlock.get())) { return;
groupFields.put(DataQueries.Target.toString(), "$" + DataQueries.Target); groupFields.put(DataQueries.Entity.toString(), "$" + DataQueries.Entity.then(DataQueries.EntityType));
/** * Constructs a MySQL SQL query from a given QuerySession. * * @param session QuerySession * @return SQLQuery */ public static SQLQuery from(QuerySession session) { Builder builder = SQLQuery.builder().select().from(tablePrefix + "records AS r"); if (!session.hasFlag(Flag.NO_GROUP)) { builder.group( DataQueries.EventName.toString(), DataQueries.Target.toString(), DataQueries.Player.toString(), DataQueries.Cause.toString(), "DATE_FORMAT(created, '%Y-%m-%d')" ).col("COUNT(*) AS total").col("DATE_FORMAT(created, '%Y-%m-%d') as created"); } else { builder.col("*").leftJoin(tablePrefix + "extra AS e", "r.id = e.record_id"); } builder.hex(DataQueries.Player.toString(), DataQueries.WorldUuid.toString()).conditions(session.getQuery().getConditions()); builder.valueMutator(DataQueries.Player, value -> "UNHEX('" + TypeUtil.uuidStringToDbString(value) + "')"); builder.valueMutator(DataQueries.Location.then(DataQueries.WorldUuid), value -> "UNHEX('" + TypeUtil.uuidStringToDbString(value) + "')"); // Get Sorting order. builder.order("created " + session.getSortBy().getString()); return builder.build(); } }