crwdns39943:0crwdne39943:0

crwdns39944:0crwdne39944:0

import org.spongepowered.api.Sponge;

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

crwdns39945:0crwdne39945:0

crwdns39946:0crwdne39946:0

  • crwdns39947:0crwdne39947:0

  • crwdns39948:0crwdne39948:0

crwdns39949:0:doc:crwdne39949:0

Note

crwdns39950:0crwdne39950:0

crwdns39951:0crwdne39951:0

crwdns39952:0:javadoc:crwdne39952:0

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

crwdns39953:0crwdne39953:0

crwdns39954:0crwdne39954:0

Note

crwdns39955:0crwdne39955:0

crwdns39956:0crwdne39956:0

crwdns39957:0crwdne39957: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);
}

crwdns39958:0crwdne39958: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);
    }
}

crwdns39959:0crwdne39959:0

crwdns39960:0crwdne39960:0

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

crwdns39961:0crwdne39961:0

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

Tip

crwdns39962:0crwdne39962:0