org.spongepowered.api.Server Java Examples

The following examples show how to use org.spongepowered.api.Server. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onClientConnectionJoin(ClientConnectionEvent.Join event)
{
    Server server = Sponge.getServer();
    if (server.getOnlineMode())
    {
        // prefetch the profile when a player joins the server
        // TODO: maybe we should also prefetch player profiles in offline mode
        GameProfile profile = event.getTargetEntity().getProfile();
        server.getGameProfileManager().fill(profile).thenRun(() ->
        {
            String message = "Successfully loaded the game profile for {} (player {})";
            this.logger.debug(message, profile.getUniqueId(), profile.getName().orElse("null"));
        });
    }
}
 
Example #2
Source File: PlanSpongeMocker.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Server mockServer() {
    Server server = Mockito.mock(Server.class);

    Text motd = Mockito.mock(Text.class);
    doReturn("Motd").when(motd).toPlain();
    Optional<InetSocketAddress> ip = Optional.of(new InetSocketAddress(25565));
    int maxPlayers = 20;
    List<Player> online = new ArrayList<>();

    doReturn(motd).when(server).getMotd();
    doReturn(ip).when(server).getBoundAddress();
    doReturn(maxPlayers).when(server).getMaxPlayers();
    doReturn(online).when(server).getOnlinePlayers();

    return server;
}
 
Example #3
Source File: InfoServlet.java    From Web-API with MIT License 6 votes vote down vote up
public ServerInfo() {
    Server server = Sponge.getServer();
    Platform platform = Sponge.getPlatform();

    this.motd = server.getMotd().toBuilder().build();
    this.players = server.getOnlinePlayers().size();
    this.maxPlayers = server.getMaxPlayers();
    if (server.getBoundAddress().isPresent()) {
        InetSocketAddress addr = server.getBoundAddress().get();
        this.address = addr.getHostName() + (addr.getPort() == 25565 ? "" : ":" + addr.getPort());
    }
    this.onlineMode = server.getOnlineMode();
    this.resourcePack = server.getDefaultResourcePack().map(ResourcePack::getName).orElse(null);
    this.hasWhitelist = server.hasWhitelist();

    this.uptimeTicks = server.getRunningTimeTicks();
    this.tps = server.getTicksPerSecond();
    this.minecraftVersion = platform.getMinecraftVersion().getName();

    this.game = new CachedPluginContainer(platform.getContainer(Platform.Component.GAME));
    this.api = new CachedPluginContainer(platform.getContainer(Platform.Component.API));
    this.implementation = new CachedPluginContainer(platform.getContainer(Platform.Component.IMPLEMENTATION));
}
 
Example #4
Source File: SpongePlugin.java    From BungeeTabListPlus with GNU General Public License v3.0 6 votes vote down vote up
private String resolveServerVariable(Server server, DataKey<String> key) {
    apiLock.readLock().lock();
    try {
        ServerVariable variable = serverVariablesByName.get(key.getParameter());
        if (variable != null) {
            String replacement = null;
            try {
                replacement = variable.getReplacement();
            } catch (Throwable th) {
                logger.warn("An exception occurred while resolving a variable provided by a third party plugin", th);
            }
            return replacement;
        }
        return null;
    } finally {
        apiLock.readLock().unlock();
    }
}
 
Example #5
Source File: PlanSpongeMocker.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
PlanSpongeMocker withGame() {
    Game game = Mockito.mock(Game.class);

    Platform platform = mockPlatform();
    Server server = mockServer();
    doReturn(platform).when(game).getPlatform();
    doReturn(server).when(game).getServer();

    doReturn(game).when(planMock).getGame();
    return this;
}
 
Example #6
Source File: KickExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Server server = game.getServer();
	Player player = ctx.<Player> getOne("player").get();
	Optional<String> reason = ctx.<String> getOne("reason");

	if (server.getPlayer(player.getUniqueId()).isPresent())
	{
		Text finalKickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName());

		if (reason.isPresent())
		{
			Text reas = TextSerializers.formattingCode('&').deserialize(reason.get());
			Text kickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName() + " for ", TextColors.RED);
			finalKickMessage = Text.builder().append(kickMessage).append(reas).build();
			player.kick(reas);
		}
		else
		{
			player.kick();
		}

		MessageChannel.TO_ALL.send(finalKickMessage);
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player kicked."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player doesn't appear to be online!"));
	}

	return CommandResult.success();
}
 
Example #7
Source File: MotdExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext args)
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Server server = game.getServer();
	src.sendMessage(Text.of(TextColors.GOLD, "[MOTD]: ", server.getMotd()));
}
 
Example #8
Source File: TeleportConfig.java    From FlexibleLogin with MIT License 5 votes vote down vote up
public Optional<Location<World>> getSpawnLocation() {
    Server server = Sponge.getServer();
    if (worldName == null) {
        worldName = server.getDefaultWorldName();
    }

    return server.getWorld(worldName).map(world -> {
        if (defaultSpawn) {
            return world.getSpawnLocation();
        }

        return world.getLocation(coordX, coordY, coordZ);
    });
}
 
Example #9
Source File: UCLogger.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
public UCLogger(Server serv) {
    this.console = serv.getConsole();
}
 
Example #10
Source File: LPSpongeBootstrap.java    From LuckPerms with MIT License 4 votes vote down vote up
public Optional<Server> getServer() {
    return this.game.isServerAvailable() ? Optional.of(this.game.getServer()) : Optional.empty();
}
 
Example #11
Source File: SpongeMain.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public Server getServer() {
    return this.server;
}
 
Example #12
Source File: SpongeMain.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public Server getServer() {
    return this.server;
}
 
Example #13
Source File: RedProtect.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public Server getServer() {
    return Sponge.getServer();
}