Search in sources :

Example 1 with DedicatedServer

use of net.minecraft.server.dedicated.DedicatedServer in project Cavern2 by kegare.

the class WorldProviderCavern method onWorldUpdateEntities.

@Override
public void onWorldUpdateEntities() {
    if (getMonsterSpawn() > 0 && world instanceof WorldServer) {
        WorldServer worldServer = (WorldServer) world;
        if (worldServer.getGameRules().getBoolean("doMobSpawning") && worldServer.getWorldInfo().getTerrainType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
            MinecraftServer server = worldServer.getMinecraftServer();
            boolean spawnHostileMobs = worldServer.getDifficulty() != EnumDifficulty.PEACEFUL;
            if (server != null && !server.isSinglePlayer() && server.isDedicatedServer() && server instanceof DedicatedServer) {
                spawnHostileMobs = ((DedicatedServer) server).allowSpawnMonsters();
            }
            entitySpawner.findChunksForSpawning(worldServer, spawnHostileMobs, false, worldServer.getWorldInfo().getWorldTotalTime() % 400L == 0L);
        }
    }
}
Also used : WorldServer(net.minecraft.world.WorldServer) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with DedicatedServer

use of net.minecraft.server.dedicated.DedicatedServer in project MinecraftForge by MinecraftForge.

the class FMLServerHandler method queryUser.

@Override
public void queryUser(StartupQuery query) throws InterruptedException {
    if (query.getResult() == null) {
        FMLLog.warning("%s", query.getText());
        query.finish();
    } else {
        String text = query.getText() + "\n\nRun the command /fml confirm or or /fml cancel to proceed." + "\nAlternatively start the server with -Dfml.queryResult=confirm or -Dfml.queryResult=cancel to preselect the answer.";
        FMLLog.warning("%s", text);
        // no-op until mc does commands in another thread (if ever)
        if (!query.isSynchronous())
            return;
        boolean done = false;
        while (!done && server.isServerRunning()) {
            if (Thread.interrupted())
                throw new InterruptedException();
            DedicatedServer dedServer = (DedicatedServer) server;
            // rudimentary command processing, check for fml confirm/cancel and stop commands
            synchronized (dedServer.pendingCommandList) {
                for (Iterator<PendingCommand> it = GenericIterableFactory.newCastingIterable(dedServer.pendingCommandList, PendingCommand.class).iterator(); it.hasNext(); ) {
                    String cmd = it.next().command.trim().toLowerCase();
                    if (cmd.equals("/fml confirm")) {
                        FMLLog.info("confirmed");
                        query.setResult(true);
                        done = true;
                        it.remove();
                    } else if (cmd.equals("/fml cancel")) {
                        FMLLog.info("cancelled");
                        query.setResult(false);
                        done = true;
                        it.remove();
                    } else if (cmd.equals("/stop")) {
                        StartupQuery.abort();
                    }
                }
            }
            Thread.sleep(10L);
        }
        query.finish();
    }
}
Also used : DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) PendingCommand(net.minecraft.server.dedicated.PendingCommand)

Example 3 with DedicatedServer

use of net.minecraft.server.dedicated.DedicatedServer in project SpongeCommon by SpongePowered.

the class SpongeBootstrap method initializeServices.

public static void initializeServices() {
    registerService(SqlService.class, new SqlServiceImpl());
    registerService(PaginationService.class, new SpongePaginationService());
    if (SpongeImpl.getGame().getPlatform().getType() == Platform.Type.SERVER) {
        registerService(RconService.class, new MinecraftRconService((DedicatedServer) Sponge.getServer()));
    }
    registerService(UserStorageService.class, new SpongeUserStorageService());
    registerService(BanService.class, new SpongeBanService());
    registerService(WhitelistService.class, new SpongeWhitelistService());
    SpongeInternalListeners.getInstance().registerServiceCallback(PermissionService.class, input -> {
        if (Sponge.isServerAvailable()) {
            Sponge.getServer().getConsole().getContainingCollection();
        }
    });
    SpongeUsernameCache.load();
}
Also used : SqlServiceImpl(org.spongepowered.common.service.sql.SqlServiceImpl) SpongeWhitelistService(org.spongepowered.common.service.whitelist.SpongeWhitelistService) MinecraftRconService(org.spongepowered.common.service.rcon.MinecraftRconService) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) SpongeUserStorageService(org.spongepowered.common.service.user.SpongeUserStorageService) SpongePaginationService(org.spongepowered.common.service.pagination.SpongePaginationService) SpongeBanService(org.spongepowered.common.service.ban.SpongeBanService)

Example 4 with DedicatedServer

use of net.minecraft.server.dedicated.DedicatedServer in project SpongeVanilla by SpongePowered.

the class SpongeVanilla method start.

private static void start(String[] args) {
    // Attempt to load metadata
    MetadataContainer metadata = MetadataContainer.load();
    // Register Minecraft plugin container
    MinecraftPluginContainer.register();
    OptionSet options = VanillaCommandLine.parse(args);
    // Note: This launches the server instead of MinecraftServer.main
    // Keep command line options up-to-date with Vanilla
    Bootstrap.register();
    File worldDir = options.has(WORLD_DIR) ? options.valueOf(WORLD_DIR) : new File(".");
    YggdrasilAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
    MinecraftSessionService sessionService = authenticationService.createMinecraftSessionService();
    GameProfileRepository profileRepository = authenticationService.createProfileRepository();
    PlayerProfileCache profileCache = new PlayerProfileCache(profileRepository, new File(worldDir, USER_CACHE_FILE.getName()));
    DedicatedServer server = new DedicatedServer(worldDir, DataFixesManager.createFixer(), authenticationService, sessionService, profileRepository, profileCache);
    // We force-load NetHandlerPlayServer here.
    // Otherwise, VanillaChannelRegistrar causes it to be loaded from
    // within the Guice injector (see SpongeVanillaModule), thus swallowing
    // any Mixin exception that occurs.
    // 
    // See https://github.com/SpongePowered/SpongeVanilla/issues/235 for a more
    // in-depth explanation
    NetHandlerPlayServer.class.getName();
    final Stage stage = SpongeGuice.getInjectorStage(VanillaLaunch.ENVIRONMENT == DEVELOPMENT ? Stage.DEVELOPMENT : Stage.PRODUCTION);
    SpongeImpl.getLogger().debug("Creating injector in stage '{}'", stage);
    Guice.createInjector(stage, new SpongeModule(), new SpongeVanillaModule(server, metadata));
    if (options.has(WORLD_NAME)) {
        server.setFolderName(options.valueOf(WORLD_NAME));
    }
    if (options.has(PORT)) {
        server.setServerPort(options.valueOf(PORT));
    }
    if (options.has(BONUS_CHEST)) {
        server.canCreateBonusChest(true);
    }
    server.startServerThread();
    Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer, "Server Shutdown Thread"));
}
Also used : MetadataContainer(org.spongepowered.server.plugin.MetadataContainer) SpongeModule(org.spongepowered.common.inject.SpongeModule) PlayerProfileCache(net.minecraft.server.management.PlayerProfileCache) GameProfileRepository(com.mojang.authlib.GameProfileRepository) Stage(com.google.inject.Stage) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) OptionSet(joptsimple.OptionSet) File(java.io.File) SpongeVanillaModule(org.spongepowered.server.inject.SpongeVanillaModule)

Aggregations

DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)4 Stage (com.google.inject.Stage)1 GameProfileRepository (com.mojang.authlib.GameProfileRepository)1 MinecraftSessionService (com.mojang.authlib.minecraft.MinecraftSessionService)1 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)1 File (java.io.File)1 OptionSet (joptsimple.OptionSet)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 PendingCommand (net.minecraft.server.dedicated.PendingCommand)1 PlayerProfileCache (net.minecraft.server.management.PlayerProfileCache)1 WorldServer (net.minecraft.world.WorldServer)1 SpongeModule (org.spongepowered.common.inject.SpongeModule)1 SpongeBanService (org.spongepowered.common.service.ban.SpongeBanService)1 SpongePaginationService (org.spongepowered.common.service.pagination.SpongePaginationService)1 MinecraftRconService (org.spongepowered.common.service.rcon.MinecraftRconService)1 SqlServiceImpl (org.spongepowered.common.service.sql.SqlServiceImpl)1 SpongeUserStorageService (org.spongepowered.common.service.user.SpongeUserStorageService)1 SpongeWhitelistService (org.spongepowered.common.service.whitelist.SpongeWhitelistService)1 SpongeVanillaModule (org.spongepowered.server.inject.SpongeVanillaModule)1 MetadataContainer (org.spongepowered.server.plugin.MetadataContainer)1