crwdns120745:0crwdne120745:0

crwdns120747:0crwdne120747:0

import org.spongepowered.api.Sponge;

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

crwdns120749:0crwdne120749:0

crwdns120751:0crwdne120751:0

  • crwdns120753:0crwdne120753:0

  • crwdns120755:0crwdne120755:0

crwdns120757:0:doc:crwdne120757:0

Note

crwdns120759:0crwdne120759:0

crwdns120761:0crwdne120761:0

crwdns120763:0:javadoc:crwdne120763:0

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

crwdns120765:0crwdne120765:0

crwdns120767:0crwdne120767:0

Note

crwdns120769:0crwdne120769:0

crwdns120771:0crwdne120771:0

crwdns120773:0crwdne120773: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);
}

crwdns120775:0crwdne120775: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);
    }
}

crwdns120777:0crwdne120777:0

crwdns120779:0crwdne120779:0

PluginContainer plugin = ...;

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

crwdns120781:0crwdne120781:0

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

Tip

crwdns120783:0crwdne120783:0