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);
}
}
}
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();
}
}
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();
}
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"));
}
Aggregations