crwdns129531:0crwdne129531:0

crwdns129533:0:javadoc:crwdne129533:0

crwdns129535:0:javadoc:crwdnd129535:0:javadoc:crwdnd129535:0:javadoc:crwdnd129535:0:javadoc:crwdnd129535:0:javadoc:crwdnd129535:0:javadoc:crwdne129535:0

crwdns129537:0:javadoc:crwdnd129537:0:javadoc:crwdnd129537:0:ref:crwdnd129537:0:ref:crwdne129537:0

crwdns129539:0:javadoc:crwdnd129539:0:javadoc:crwdne129539:0

Note

crwdns129541:0crwdne129541:0

crwdns129543:0:javadoc:crwdnd129543:0:javadoc:crwdne129543:0

crwdns129545:0crwdne129545:0

crwdns129547:0:javadoc:crwdne129547:0

crwdns129549:0crwdne129549:0

import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.value.ValueFactory;
import org.spongepowered.api.data.value.mutable.Value;

import org.spongepowered.cookbook.myhomes.data.home.Home;
import org.spongepowered.cookbook.myhomes.data.Keys;

@Override
protected Value<Home> defaultHome() {
    return Sponge.getRegistry().getValueFactory()
            .createValue(Keys.DEFAULT_HOME, getValue(), null);
}

crwdns129551:0crwdne129551:0

crwdns129553:0:javadoc:crwdnd129553:0:javadoc:crwdne129553:0

crwdns129555:0:javadoc:crwdne129555:0

crwdns129557:0crwdne129557:0

import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.data.key.KeyFactory;
import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.data.value.mutable.Value;

import com.google.common.reflect.TypeToken;

import org.spongepowered.cookbook.myhomes.data.home.Home;

public static final Key<Value<Home>> DEFAULT_HOME = KeyFactory.makeSingleKey(
        TypeToken.of(Home.class),
        new TypeToken<Value<Home>>() {},
        DataQuery.of("DefaultHome"), "myhomes:default_home", "Default Home");

Note

crwdns129559:0:javadoc:crwdne129559:0

  • crwdns129561:0crwdne129561:0

  • crwdns129563:0crwdne129563:0

crwdns129565:0crwdne129565:0

crwdns129567:0:doc:crwdnd129567:0:javadoc:crwdnd129567:0:javadoc:crwdnd129567:0:javadoc:crwdnd129567:0:ref:crwdne129567:0

Note

crwdns129569:0crwdne129569:0

crwdns129571:0crwdne129571:0

import org.spongepowered.api.data.DataContainer;

import org.spongepowered.cookbook.myhomes.data.Keys;

@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    // This is the simplest, but use whatever structure you want!
    container.set(Keys.DEFAULT_HOME.getQuery(), this.defaultHome);
    container.set(Keys.HOMES, this.homes);

    return container;
}

crwdns129573:0crwdne129573:0

crwdns129575:0crwdne129575:0

crwdns129577:0crwdne129577:0

  • crwdns129579:0crwdne129579:0

  • crwdns129581:0crwdne129581:0

  • crwdns129583:0crwdne129583:0

  • crwdns129585:0crwdne129585:0

  • crwdns129587:0crwdne129587:0

  • crwdns129589:0crwdne129589:0

  • crwdns129591:0crwdne129591:0

crwdns129593:0crwdne129593:0

Tip

crwdns129595:0crwdne129595:0

crwdns129597:0crwdne129597:0

crwdns129599:0crwdne129599:0

  • crwdns129601:0crwdne129601:0

  • crwdns129603:0crwdne129603:0

crwdns129605:0:javadoc:crwdnd129605:0:javadoc:crwdne129605:0

Note

crwdns129607:0crwdne129607:0

crwdns129609:0crwdne129609:0

crwdns129611:0crwdne129611:0

import org.spongepowered.api.data.DataHolder;
import org.spongepowered.api.data.merge.MergeFunction;

import org.spongepowered.cookbook.myhomes.data.friends.FriendsData;

import java.util.Optional;

@Override
public Optional<FriendsData> fill(DataHolder dataHolder, MergeFunction overlap) {
    FriendsData merged = overlap.merge(this, dataHolder.get(FriendsData.class).orElse(null));
    setValue(merged.friends().get());

    return Optional.of(this);
}

crwdns129613:0crwdne129613:0

import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.DataQuery;

import org.spongepowered.cookbook.myhomes.data.Keys;
import org.spongepowered.cookbook.myhomes.data.friends.FriendsData;
import org.spongepowered.cookbook.myhomes.data.friends.ImmutableFriendsData;

import com.google.common.collect.Maps;

import java.util.Optional;
import java.util.UUID;

@Override
public Optional<FriendsData> from(DataContainer container) {
    if(container.contains(Keys.FRIENDS)) {
        List<UUID> friends = container.getObjectList(Keys.FRIENDS.getQuery(), UUID.class).get();
        return Optional.of(setValue(friends));
    }

    return Optional.empty();
}

crwdns129615:0crwdne129615:0

import org.spongepowered.cookbook.myhomes.data.friends.FriendsData;

@Override
public FriendsData copy() {
    return new FriendsDataImpl(getValue());
}

crwdns129617:0crwdne129617:0

crwdns129619:0crwdne129619:0

crwdns129621:0crwdne129621:0

crwdns129623:0crwdne129623:0

crwdns129625:0crwdne129625:0

crwdns129627:0:javadoc:crwdne129627:0

crwdns129629:0crwdne129629:0

crwdns129631:0crwdne129631:0

crwdns129633:0:doc:crwdnd129633:0:javadoc:crwdnd129633:0:javadoc:crwdne129633:0

crwdns129635:0crwdne129635:0

  • crwdns129637:0crwdne129637:0

  • crwdns129639:0crwdne129639:0

  • crwdns129641:0crwdne129641:0

crwdns129643:0crwdne129643:0

crwdns129645:0crwdne129645:0

import org.spongepowered.cookbook.myhomes.data.Keys

// registerGetters() for immutable implementation
@Override
protected void registerGettersAndSetters() {
    registerKeyValue(Keys.DEFAULT_HOME, this::defaultHome);
    registerKeyValue(Keys.HOMES, this::homes);

    registerFieldGetter(Keys.DEFAULT_HOME, this::getDefaultHome);
    registerFieldGetter(Keys.HOMES, this::getHomes);

    // Only on mutable implementation
    registerFieldSetter(Keys.DEFAULT_HOME, this::setDefaultHome);
    registerFieldSetter(Keys.HOMES, this::setHomes);
}

crwdns129647:0crwdne129647:0