Tabnine Logo
DataContainer.get
Code IndexAdd Tabnine to your IDE (free)

How to use
get
method
in
org.spongepowered.api.data.DataContainer

Best Java code snippets using org.spongepowered.api.data.DataContainer.get (Showing top 13 results out of 315)

origin: SpongePowered/SpongeAPI

@Override
public void serialize(TypeToken<?> type, Text obj, ConfigurationNode value) throws ObjectMappingException {
  String json = (String) obj.toContainer().get(Queries.JSON).get();
  GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder()
      .setSource(() -> new BufferedReader(new StringReader(json)))
      .build();
  try {
    value.setValue(gsonLoader.load());
  } catch (IOException e) {
    throw new ObjectMappingException(e);
  }
}
origin: SpongePowered/SpongeAPI

@Test
public void testAbsents() {
  DataContainer container = DataContainer.createNew();
  DataQuery testQuery = of("foo", "bar", "baz");
  assertTrue(!container.get(testQuery).isPresent());
  assertTrue(!container.getBoolean(testQuery).isPresent());
  assertTrue(!container.getBooleanList(testQuery).isPresent());
  assertTrue(!container.getByteList(testQuery).isPresent());
  assertTrue(!container.getCharacterList(testQuery).isPresent());
  assertTrue(!container.getDouble(testQuery).isPresent());
  assertTrue(!container.getDoubleList(testQuery).isPresent());
  assertTrue(!container.getFloatList(testQuery).isPresent());
  assertTrue(!container.getInt(testQuery).isPresent());
  assertTrue(!container.getIntegerList(testQuery).isPresent());
  assertTrue(!container.getList(testQuery).isPresent());
  assertTrue(!container.getLong(testQuery).isPresent());
  assertTrue(!container.getLongList(testQuery).isPresent());
  assertTrue(!container.getMapList(testQuery).isPresent());
  assertTrue(!container.getShortList(testQuery).isPresent());
  assertTrue(!container.getString(testQuery).isPresent());
  assertTrue(!container.getStringList(testQuery).isPresent());
  assertTrue(!container.getView(testQuery).isPresent());
}
origin: prism/Prism

/**
 * Helper method for formatting entity container data.
 * @param entity
 */
private void writeEntity(Entity entity) {
  checkNotNull(entity);
  DataContainer entityData = entity.toContainer();
  Optional<DataView> position = entityData.getView(DataQueries.Position);
  if (position.isPresent()) {
    position.get().set(DataQueries.WorldUuid, entityData.get(DataQueries.WorldUuid).get());
    data.set(DataQueries.Location, position.get());
    entityData.remove(DataQueries.Position);
    entityData.remove(DataQueries.WorldUuid);
  }
  Optional<DataView> optionalUnsafeData = entityData.getView(DataQueries.UnsafeData);
  if (optionalUnsafeData.isPresent()) {
    DataView unsafeData = optionalUnsafeData.get();
    unsafeData.remove(DataQueries.Rotation);
    unsafeData.remove(DataQueries.Pos);
    entityData.set(DataQueries.UnsafeData, unsafeData);
  }
  data.set(DataQueries.Target, entity.getType().getId().replace("_", " "));
  data.set(DataQueries.Entity, entityData);
}
origin: prism/Prism

hoverMessage.append(Text.of(TextColors.DARK_GRAY, "Time: ", TextColors.WHITE, resultComplete.getTime(), Text.NEW_LINE));
DataView location = (DataView) resultComplete.data.get(DataQueries.Location).orElse(null);
if (location != null) {
  int x = location.getInt(DataQueries.X).orElse(0);
origin: SpongePowered/SpongeAPI

@Test
public void testEmptyQuery() {
  DataContainer container = DataContainer.createNew();
  DataQuery query = of("");
  container.set(query, "foo");
  assertTrue(container.get(query).isPresent());
  assertTrue(container.get(query).get().equals("foo"));
}
origin: prism/Prism

  /**
   * Returns a full timestamp.
   *
   * @return String timestamp
   */
  public String getTime() {
    Optional<Object> date = data.get(DataQueries.Created);
    String time = "";

    if (date.isPresent()) {
      if (date.get() instanceof Date) {
        time = dateFormatter.format((Date) date.get());
      }
      else if (date.get() instanceof Long) {
        time = dateFormatter.format(new Date(((Long) date.get()) * 1000));
      }
    }

    return time;
  }
}
origin: prism/Prism

/**
 * Returns a user-friendly relative "time since" value.
 *
 * @return String "time since" value.
 */
public String getRelativeTime() {
  Optional<Object> date = data.get(DataQueries.Created);
  String relativeTime = "";
  if (date.isPresent()) {
    Date created = null;
    if (date.get() instanceof Date) {
      created = (Date) date.get();
    }
    else if (date.get() instanceof Long) {
      created = new Date(((Long) date.get()) * 1000);
    }
    if (created != null) {
      relativeTime = DateUtil.getTimeSince(created);
    }
  }
  return relativeTime;
}
origin: org.spongepowered/spongeapi

@Override
public void serialize(TypeToken<?> type, Text obj, ConfigurationNode value) throws ObjectMappingException {
  String json = (String) obj.toContainer().get(Queries.JSON).get();
  GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder()
      .setSource(() -> new BufferedReader(new StringReader(json)))
      .build();
  try {
    value.setValue(gsonLoader.load());
  } catch (IOException e) {
    throw new ObjectMappingException(e);
  }
}
origin: prism/Prism

  /**
   * Helper method to translate Player UUIDs to names.
   *
   * @param results List of results
   * @param uuidsPendingLookup Lists of UUIDs pending lookup
   * @return CompletableFuture
   */
  public static CompletableFuture<List<Result>> translateUuidsToNames(List<Result> results, List<UUID> uuidsPendingLookup) {
    CompletableFuture<List<Result>> future = new CompletableFuture<>();

    CompletableFuture<Collection<GameProfile>> futures = Sponge.getServer().getGameProfileManager().getAllById(uuidsPendingLookup, true);
    futures.thenAccept((profiles) -> {
      for (GameProfile profile : profiles) {
        for (Result r : results) {
          Optional<Object> cause = r.data.get(DataQueries.Cause);
          if (cause.isPresent() && cause.get().equals(profile.getUniqueId().toString())) {
            r.data.set(DataQueries.Cause, profile.getName().orElse("unknown"));
          }
        }
      }

      future.complete(results);
    });

    return future;
  }
}
origin: prism/Prism

  /**
   * Removes unnecessary/duplicate data from a BlockSnapshot's DataContainer.
   *
   * @param blockSnapshot Block Snapshot.
   * @return DataContainer Formatted Data Container.
   */
  private DataContainer formatBlockDataContainer(BlockSnapshot blockSnapshot) {
    DataContainer block = blockSnapshot.toContainer();
    block.remove(DataQueries.WorldUuid);
    block.remove(DataQueries.Position);
    Optional<Object> optionalUnsafeData = block.get(DataQueries.UnsafeData);
    if (optionalUnsafeData.isPresent()) {
      DataView unsafeData = (DataView) optionalUnsafeData.get();
      unsafeData.remove(DataQueries.X);
      unsafeData.remove(DataQueries.Y);
      unsafeData.remove(DataQueries.Z);
      block.set(DataQueries.UnsafeData, unsafeData);
    }
    return block;
  }
}
origin: prism/Prism

@Override
public ActionableResult restore() throws Exception {
  Optional<Object> optionalFinal = data.get(DataQueries.ReplacementBlock);
  if (!optionalFinal.isPresent()) {
    return ActionableResult.skipped(SkipReason.INVALID);
  Optional<Object> optionalLocation = data.get(DataQueries.Location);
  if (!optionalLocation.isPresent()) {
    return ActionableResult.skipped(SkipReason.INVALID_LOCATION);
origin: prism/Prism

@Override
public ActionableResult rollback() throws Exception {
  Optional<Object> optionalOriginal = data.get(DataQueries.OriginalBlock);
  Optional<Object> optionalLocation = data.get(DataQueries.Location);
  if (!optionalLocation.isPresent()) {
    return ActionableResult.skipped(SkipReason.INVALID_LOCATION);
origin: prism/Prism

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;
org.spongepowered.api.dataDataContainerget

Popular methods of DataContainer

  • set
  • createNew
    Creates a new DataContainer with the provided org.spongepowered.api.data.DataView.SafetyMode.
  • contains
  • getInt
  • getSerializable
  • getString
  • getView
  • createView
  • getLong
  • copy
  • getBoolean
  • getBooleanList
  • getBoolean,
  • getBooleanList,
  • getByteList,
  • getCharacterList,
  • getDouble,
  • getDoubleList,
  • getFloatList,
  • getIntegerList,
  • getList

Popular in Java

  • Reading from database using SQL prepared statement
  • runOnUiThread (Activity)
  • startActivity (Activity)
  • scheduleAtFixedRate (Timer)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now