crwdns20018:0crwdne20018:0

crwdns20019:0crwdne20019:0

import org.spongepowered.api.Sponge;

Sponge.getServiceManager().provide(EventManager.class);

crwdns20020:0crwdne20020:0

crwdns20021:0crwdne20021:0

  • crwdns20022:0crwdne20022:0

  • crwdns20023:0crwdne20023:0

crwdns20024:0:doc:crwdne20024:0

Note

crwdns20025:0crwdne20025:0

crwdns20026:0crwdne20026:0

crwdns42100:0:javadoc:crwdne42100:0

Sponge.getServiceManager().setProvider(Object plugin, Class<T> service, T provider);

crwdns20028:0crwdne20028:0

crwdns20029:0crwdne20029:0

Note

crwdns20030:0crwdne20030:0

crwdns20031:0crwdne20031:0

crwdns20032:0crwdne20032:0

import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import java.util.Optional;

public interface WarpService {
    void setWarp(String name, Location<World> location);
    Optional<Location<World>> getWarp(String name);
}

crwdns20033:0crwdne20033:0

import java.util.HashMap;

public class SimpleWarpService implements WarpService {
    HashMap<String, Location<World>> warpMap = new HashMap<String, Location<World>>();

    @Override
    public Optional<Location<World>> getWarp(String name) {
        if(!warpMap.containsKey(name)) {
            return Optional.empty();
        } else {
            return Optional.of(warpMap.get(name));
        }
    }

    @Override
    public void setWarp(String name, Location<World> location) {
        warpMap.put(name, location);
    }
}

crwdns20034:0crwdne20034:0

crwdns20035:0crwdne20035:0

PluginContainer plugin = ...;

Sponge.getServiceManager().setProvider(plugin, WarpService.class, new SimpleWarpService());

crwdns20036:0crwdne20036:0

Sponge.getServiceManager().provide(WarpService.class);

Tip

crwdns20037:0crwdne20037:0