| 1 | package net.minecraft.server;
|
| 2 |
|
| 3 | import com.google.common.base.Charsets;
|
| 4 | import com.google.common.collect.Lists;
|
| 5 | import com.google.common.collect.Queues;
|
| 6 | import com.google.common.util.concurrent.Futures;
|
| 7 | import com.google.common.util.concurrent.ListenableFuture;
|
| 8 | import com.google.common.util.concurrent.ListenableFutureTask;
|
| 9 | import com.mojang.authlib.GameProfile;
|
| 10 | import com.mojang.authlib.GameProfileRepository;
|
| 11 | import com.mojang.authlib.minecraft.MinecraftSessionService;
|
| 12 | import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
|
| 13 | import io.netty.buffer.ByteBuf;
|
| 14 | import io.netty.buffer.ByteBufOutputStream;
|
| 15 | import io.netty.buffer.Unpooled;
|
| 16 | import io.netty.handler.codec.base64.Base64;
|
| 17 | import java.awt.GraphicsEnvironment;
|
| 18 | import java.awt.image.BufferedImage;
|
| 19 | import java.io.File;
|
| 20 | import java.io.IOException;
|
| 21 | import java.io.OutputStream;
|
| 22 | import java.net.Proxy;
|
| 23 | import java.security.KeyPair;
|
| 24 | import java.text.SimpleDateFormat;
|
| 25 | import java.util.Arrays;
|
| 26 | import java.util.Collections;
|
| 27 | import java.util.Date;
|
| 28 | import java.util.List;
|
| 29 | import java.util.Queue;
|
| 30 | import java.util.Random;
|
| 31 | import java.util.UUID;
|
| 32 | import java.util.concurrent.Callable;
|
| 33 | import java.util.concurrent.Executors;
|
| 34 | import java.util.concurrent.FutureTask;
|
| 35 | import javax.imageio.ImageIO;
|
| 36 | import net.minecraft.command.CommandBase;
|
| 37 | import net.minecraft.command.CommandResultStats;
|
| 38 | import net.minecraft.command.ICommandManager;
|
| 39 | import net.minecraft.command.ICommandSender;
|
| 40 | import net.minecraft.command.ServerCommandManager;
|
| 41 | import net.minecraft.crash.CrashReport;
|
| 42 | import net.minecraft.entity.Entity;
|
| 43 | import net.minecraft.entity.player.EntityPlayer;
|
| 44 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 45 | import net.minecraft.network.NetworkSystem;
|
| 46 | import net.minecraft.network.ServerStatusResponse;
|
| 47 | import net.minecraft.network.play.server.S03PacketTimeUpdate;
|
| 48 | import net.minecraft.profiler.IPlayerUsage;
|
| 49 | import net.minecraft.profiler.PlayerUsageSnooper;
|
| 50 | import net.minecraft.profiler.Profiler;
|
| 51 | import net.minecraft.server.management.PlayerProfileCache;
|
| 52 | import net.minecraft.server.management.ServerConfigurationManager;
|
| 53 | import net.minecraft.util.BlockPos;
|
| 54 | import net.minecraft.util.ChatComponentText;
|
| 55 | import net.minecraft.util.IChatComponent;
|
| 56 | import net.minecraft.util.IProgressUpdate;
|
| 57 | import net.minecraft.util.IThreadListener;
|
| 58 | import net.minecraft.util.ITickable;
|
| 59 | import net.minecraft.util.MathHelper;
|
| 60 | import net.minecraft.util.ReportedException;
|
| 61 | import net.minecraft.util.Util;
|
| 62 | import net.minecraft.util.Vec3;
|
| 63 | import net.minecraft.world.EnumDifficulty;
|
| 64 | import net.minecraft.world.MinecraftException;
|
| 65 | import net.minecraft.world.World;
|
| 66 | import net.minecraft.world.WorldManager;
|
| 67 | import net.minecraft.world.WorldServer;
|
| 68 | import net.minecraft.world.WorldServerMulti;
|
| 69 | import net.minecraft.world.WorldSettings;
|
| 70 | import net.minecraft.world.WorldType;
|
| 71 | import net.minecraft.world.chunk.storage.AnvilSaveConverter;
|
| 72 | import net.minecraft.world.demo.DemoWorldServer;
|
| 73 | import net.minecraft.world.storage.ISaveFormat;
|
| 74 | import net.minecraft.world.storage.ISaveHandler;
|
| 75 | import net.minecraft.world.storage.WorldInfo;
|
| 76 | import org.apache.commons.lang3.Validate;
|
| 77 | import org.apache.logging.log4j.LogManager;
|
| 78 | import org.apache.logging.log4j.Logger;
|
| 79 |
|
| 80 | public abstract class MinecraftServer implements Runnable, ICommandSender, IThreadListener, IPlayerUsage
|
| 81 | {
|
| 82 | private static final Logger logger = LogManager.getLogger();
|
| 83 | public static final File USER_CACHE_FILE = new File("usercache.json");
|
| 84 |
|
| 85 | /** Instance of Minecraft Server. */
|
| 86 | private static MinecraftServer mcServer;
|
| 87 | private final ISaveFormat anvilConverterForAnvilFile;
|
| 88 |
|
| 89 | /** The PlayerUsageSnooper instance. */
|
| 90 | private final PlayerUsageSnooper usageSnooper = new PlayerUsageSnooper("server", this, getCurrentTimeMillis());
|
| 91 | private final File anvilFile;
|
| 92 | private final List<ITickable> playersOnline = Lists.<ITickable>newArrayList();
|
| 93 | protected final ICommandManager commandManager;
|
| 94 | public final Profiler theProfiler = new Profiler();
|
| 95 | private final NetworkSystem networkSystem;
|
| 96 | private final ServerStatusResponse statusResponse = new ServerStatusResponse();
|
| 97 | private final Random random = new Random();
|
| 98 |
|
| 99 | /** The server's port. */
|
| 100 | private int serverPort = -1;
|
| 101 |
|
| 102 | /** The server world instances. */
|
| 103 | public WorldServer[] worldServers;
|
| 104 |
|
| 105 | /** The ServerConfigurationManager instance. */
|
| 106 | private ServerConfigurationManager serverConfigManager;
|
| 107 |
|
| 108 | /**
|
| 109 | * Indicates whether the server is running or not. Set to false to initiate a shutdown.
|
| 110 | */
|
| 111 | private boolean serverRunning = true;
|
| 112 |
|
| 113 | /** Indicates to other classes that the server is safely stopped. */
|
| 114 | private boolean serverStopped;
|
| 115 |
|
| 116 | /** Incremented every tick. */
|
| 117 | private int tickCounter;
|
| 118 | protected final Proxy serverProxy;
|
| 119 |
|
| 120 | /**
|
| 121 | * The task the server is currently working on(and will output on outputPercentRemaining).
|
| 122 | */
|
| 123 | public String currentTask;
|
| 124 |
|
| 125 | /** The percentage of the current task finished so far. */
|
| 126 | public int percentDone;
|
| 127 |
|
| 128 | /** True if the server is in online mode. */
|
| 129 | private boolean onlineMode;
|
| 130 |
|
| 131 | /** True if the server has animals turned on. */
|
| 132 | private boolean canSpawnAnimals;
|
| 133 | private boolean canSpawnNPCs;
|
| 134 |
|
| 135 | /** Indicates whether PvP is active on the server or not. */
|
| 136 | private boolean pvpEnabled;
|
| 137 |
|
| 138 | /** Determines if flight is allowed or not. */
|
| 139 | private boolean allowFlight;
|
| 140 |
|
| 141 | /** The server MOTD string. */
|
| 142 | private String motd;
|
| 143 |
|
| 144 | /** Maximum build height. */
|
| 145 | private int buildLimit;
|
| 146 | private int maxPlayerIdleMinutes = 0;
|
| 147 | public final long[] tickTimeArray = new long[100];
|
| 148 |
|
| 149 | /** Stats are [dimension][tick%100] system.nanoTime is stored. */
|
| 150 | public long[][] timeOfLastDimensionTick;
|
| 151 | private KeyPair serverKeyPair;
|
| 152 |
|
| 153 | /** Username of the server owner (for integrated servers) */
|
| 154 | private String serverOwner;
|
| 155 | private String folderName;
|
| 156 | private String worldName;
|
| 157 | private boolean isDemo;
|
| 158 | private boolean enableBonusChest;
|
| 159 |
|
| 160 | /**
|
| 161 | * If true, there is no need to save chunks or stop the server, because that is already being done.
|
| 162 | */
|
| 163 | private boolean worldIsBeingDeleted;
|
| 164 |
|
| 165 | /** The texture pack for the server */
|
| 166 | private String resourcePackUrl = "";
|
| 167 | private String resourcePackHash = "";
|
| 168 | private boolean serverIsRunning;
|
| 169 |
|
| 170 | /**
|
| 171 | * Set when warned for "Can't keep up", which triggers again after 15 seconds.
|
| 172 | */
|
| 173 | private long timeOfLastWarning;
|
| 174 | private String userMessage;
|
| 175 | private boolean startProfiling;
|
| 176 | private boolean isGamemodeForced;
|
| 177 | private final YggdrasilAuthenticationService authService;
|
| 178 | private final MinecraftSessionService sessionService;
|
| 179 | private long nanoTimeSinceStatusRefresh = 0L;
|
| 180 | private final GameProfileRepository profileRepo;
|
| 181 | private final PlayerProfileCache profileCache;
|
| 182 | protected final Queue < FutureTask<? >> futureTaskQueue = Queues. < FutureTask<? >> newArrayDeque();
|
| 183 | private Thread serverThread;
|
| 184 | private long currentTime = getCurrentTimeMillis();
|
| 185 |
|
| 186 | public MinecraftServer(Proxy proxy, File workDir)
|
| 187 | {
|
| 188 | this.serverProxy = proxy;
|
| 189 | mcServer = this;
|
| 190 | this.anvilFile = null;
|
| 191 | this.networkSystem = null;
|
| 192 | this.profileCache = new PlayerProfileCache(this, workDir);
|
| 193 | this.commandManager = null;
|
| 194 | this.anvilConverterForAnvilFile = null;
|
| 195 | this.authService = new YggdrasilAuthenticationService(proxy, UUID.randomUUID().toString());
|
| 196 | this.sessionService = this.authService.createMinecraftSessionService();
|
| 197 | this.profileRepo = this.authService.createProfileRepository();
|
| 198 | }
|
| 199 |
|
| 200 | public MinecraftServer(File workDir, Proxy proxy, File profileCacheDir)
|
| 201 | {
|
| 202 | this.serverProxy = proxy;
|
| 203 | mcServer = this;
|
| 204 | this.anvilFile = workDir;
|
| 205 | this.networkSystem = new NetworkSystem(this);
|
| 206 | this.profileCache = new PlayerProfileCache(this, profileCacheDir);
|
| 207 | this.commandManager = this.createNewCommandManager();
|
| 208 | this.anvilConverterForAnvilFile = new AnvilSaveConverter(workDir);
|
| 209 | this.authService = new YggdrasilAuthenticationService(proxy, UUID.randomUUID().toString());
|
| 210 | this.sessionService = this.authService.createMinecraftSessionService();
|
| 211 | this.profileRepo = this.authService.createProfileRepository();
|
| 212 | }
|
| 213 |
|
| 214 | protected ServerCommandManager createNewCommandManager()
|
| 215 | {
|
| 216 | return new ServerCommandManager();
|
| 217 | }
|
| 218 |
|
| 219 | /**
|
| 220 | * Initialises the server and starts it.
|
| 221 | */
|
| 222 | protected abstract boolean startServer() throws IOException;
|
| 223 |
|
| 224 | protected void convertMapIfNeeded(String worldNameIn)
|
| 225 | {
|
| 226 | if (this.getActiveAnvilConverter().isOldMapFormat(worldNameIn))
|
| 227 | {
|
| 228 | logger.info("Converting map!");
|
| 229 | this.setUserMessage("menu.convertingLevel");
|
| 230 | this.getActiveAnvilConverter().convertMapFormat(worldNameIn, new IProgressUpdate()
|
| 231 | {
|
| 232 | private long startTime = System.currentTimeMillis();
|
| 233 | public void displaySavingString(String message)
|
| 234 | {
|
| 235 | }
|
| 236 | public void resetProgressAndMessage(String message)
|
| 237 | {
|
| 238 | }
|
| 239 | public void setLoadingProgress(int progress)
|
| 240 | {
|
| 241 | if (System.currentTimeMillis() - this.startTime >= 1000L)
|
| 242 | {
|
| 243 | this.startTime = System.currentTimeMillis();
|
| 244 | MinecraftServer.logger.info("Converting... " + progress + "%");
|
| 245 | }
|
| 246 | }
|
| 247 | public void setDoneWorking()
|
| 248 | {
|
| 249 | }
|
| 250 | public void displayLoadingString(String message)
|
| 251 | {
|
| 252 | }
|
| 253 | });
|
| 254 | }
|
| 255 | }
|
| 256 |
|
| 257 | /**
|
| 258 | * Typically "menu.convertingLevel", "menu.loadingLevel" or others.
|
| 259 | */
|
| 260 | protected synchronized void setUserMessage(String message)
|
| 261 | {
|
| 262 | this.userMessage = message;
|
| 263 | }
|
| 264 |
|
| 265 | public synchronized String getUserMessage()
|
| 266 | {
|
| 267 | return this.userMessage;
|
| 268 | }
|
| 269 |
|
| 270 | protected void loadAllWorlds(String saveName, String worldNameIn, long seed, WorldType type, String worldNameIn2)
|
| 271 | {
|
| 272 | this.convertMapIfNeeded(saveName);
|
| 273 | this.setUserMessage("menu.loadingLevel");
|
| 274 | this.worldServers = new WorldServer[3];
|
| 275 | this.timeOfLastDimensionTick = new long[this.worldServers.length][100];
|
| 276 | ISaveHandler isavehandler = this.anvilConverterForAnvilFile.getSaveLoader(saveName, true);
|
| 277 | this.setResourcePackFromWorld(this.getFolderName(), isavehandler);
|
| 278 | WorldInfo worldinfo = isavehandler.loadWorldInfo();
|
| 279 | WorldSettings worldsettings;
|
| 280 |
|
| 281 | if (worldinfo == null)
|
| 282 | {
|
| 283 | if (this.isDemo())
|
| 284 | {
|
| 285 | worldsettings = DemoWorldServer.demoWorldSettings;
|
| 286 | }
|
| 287 | else
|
| 288 | {
|
| 289 | worldsettings = new WorldSettings(seed, this.getGameType(), this.canStructuresSpawn(), this.isHardcore(), type);
|
| 290 | worldsettings.setWorldName(worldNameIn2);
|
| 291 |
|
| 292 | if (this.enableBonusChest)
|
| 293 | {
|
| 294 | worldsettings.enableBonusChest();
|
| 295 | }
|
| 296 | }
|
| 297 |
|
| 298 | worldinfo = new WorldInfo(worldsettings, worldNameIn);
|
| 299 | }
|
| 300 | else
|
| 301 | {
|
| 302 | worldinfo.setWorldName(worldNameIn);
|
| 303 | worldsettings = new WorldSettings(worldinfo);
|
| 304 | }
|
| 305 |
|
| 306 | for (int i = 0; i < this.worldServers.length; ++i)
|
| 307 | {
|
| 308 | int j = 0;
|
| 309 |
|
| 310 | if (i == 1)
|
| 311 | {
|
| 312 | j = -1;
|
| 313 | }
|
| 314 |
|
| 315 | if (i == 2)
|
| 316 | {
|
| 317 | j = 1;
|
| 318 | }
|
| 319 |
|
| 320 | if (i == 0)
|
| 321 | {
|
| 322 | if (this.isDemo())
|
| 323 | {
|
| 324 | this.worldServers[i] = (WorldServer)(new DemoWorldServer(this, isavehandler, worldinfo, j, this.theProfiler)).init();
|
| 325 | }
|
| 326 | else
|
| 327 | {
|
| 328 | this.worldServers[i] = (WorldServer)(new WorldServer(this, isavehandler, worldinfo, j, this.theProfiler)).init();
|
| 329 | }
|
| 330 |
|
| 331 | this.worldServers[i].initialize(worldsettings);
|
| 332 | }
|
| 333 | else
|
| 334 | {
|
| 335 | this.worldServers[i] = (WorldServer)(new WorldServerMulti(this, isavehandler, j, this.worldServers[0], this.theProfiler)).init();
|
| 336 | }
|
| 337 |
|
| 338 | this.worldServers[i].addWorldAccess(new WorldManager(this, this.worldServers[i]));
|
| 339 |
|
| 340 | if (!this.isSinglePlayer())
|
| 341 | {
|
| 342 | this.worldServers[i].getWorldInfo().setGameType(this.getGameType());
|
| 343 | }
|
| 344 | }
|
| 345 |
|
| 346 | this.serverConfigManager.setPlayerManager(this.worldServers);
|
| 347 | this.setDifficultyForAllWorlds(this.getDifficulty());
|
| 348 | this.initialWorldChunkLoad();
|
| 349 | }
|
| 350 |
|
| 351 | protected void initialWorldChunkLoad()
|
| 352 | {
|
| 353 | int i = 16;
|
| 354 | int j = 4;
|
| 355 | int k = 192;
|
| 356 | int l = 625;
|
| 357 | int i1 = 0;
|
| 358 | this.setUserMessage("menu.generatingTerrain");
|
| 359 | int j1 = 0;
|
| 360 | logger.info("Preparing start region for level " + j1);
|
| 361 | WorldServer worldserver = this.worldServers[j1];
|
| 362 | BlockPos blockpos = worldserver.getSpawnPoint();
|
| 363 | long k1 = getCurrentTimeMillis();
|
| 364 |
|
| 365 | for (int l1 = -192; l1 <= 192 && this.isServerRunning(); l1 += 16)
|
| 366 | {
|
| 367 | for (int i2 = -192; i2 <= 192 && this.isServerRunning(); i2 += 16)
|
| 368 | {
|
| 369 | long j2 = getCurrentTimeMillis();
|
| 370 |
|
| 371 | if (j2 - k1 > 1000L)
|
| 372 | {
|
| 373 | this.outputPercentRemaining("Preparing spawn area", i1 * 100 / 625);
|
| 374 | k1 = j2;
|
| 375 | }
|
| 376 |
|
| 377 | ++i1;
|
| 378 | worldserver.theChunkProviderServer.loadChunk(blockpos.getX() + l1 >> 4, blockpos.getZ() + i2 >> 4);
|
| 379 | }
|
| 380 | }
|
| 381 |
|
| 382 | this.clearCurrentTask();
|
| 383 | }
|
| 384 |
|
| 385 | protected void setResourcePackFromWorld(String worldNameIn, ISaveHandler saveHandlerIn)
|
| 386 | {
|
| 387 | File file1 = new File(saveHandlerIn.getWorldDirectory(), "resources.zip");
|
| 388 |
|
| 389 | if (file1.isFile())
|
| 390 | {
|
| 391 | this.setResourcePack("level://" + worldNameIn + "/" + file1.getName(), "");
|
| 392 | }
|
| 393 | }
|
| 394 |
|
| 395 | public abstract boolean canStructuresSpawn();
|
| 396 |
|
| 397 | public abstract WorldSettings.GameType getGameType();
|
| 398 |
|
| 399 | /**
|
| 400 | * Get the server's difficulty
|
| 401 | */
|
| 402 | public abstract EnumDifficulty getDifficulty();
|
| 403 |
|
| 404 | /**
|
| 405 | * Defaults to false.
|
| 406 | */
|
| 407 | public abstract boolean isHardcore();
|
| 408 |
|
| 409 | public abstract int getOpPermissionLevel();
|
| 410 |
|
| 411 | /**
|
| 412 | * Get if RCON command events should be broadcast to ops
|
| 413 | */
|
| 414 | public abstract boolean shouldBroadcastRconToOps();
|
| 415 |
|
| 416 | /**
|
| 417 | * Get if console command events should be broadcast to ops
|
| 418 | */
|
| 419 | public abstract boolean shouldBroadcastConsoleToOps();
|
| 420 |
|
| 421 | /**
|
| 422 | * Used to display a percent remaining given text and the percentage.
|
| 423 | */
|
| 424 | protected void outputPercentRemaining(String message, int percent)
|
| 425 | {
|
| 426 | this.currentTask = message;
|
| 427 | this.percentDone = percent;
|
| 428 | logger.info(message + ": " + percent + "%");
|
| 429 | }
|
| 430 |
|
| 431 | /**
|
| 432 | * Set current task to null and set its percentage to 0.
|
| 433 | */
|
| 434 | protected void clearCurrentTask()
|
| 435 | {
|
| 436 | this.currentTask = null;
|
| 437 | this.percentDone = 0;
|
| 438 | }
|
| 439 |
|
| 440 | /**
|
| 441 | * par1 indicates if a log message should be output.
|
| 442 | */
|
| 443 | protected void saveAllWorlds(boolean dontLog)
|
| 444 | {
|
| 445 | if (!this.worldIsBeingDeleted)
|
| 446 | {
|
| 447 | for (WorldServer worldserver : this.worldServers)
|
| 448 | {
|
| 449 | if (worldserver != null)
|
| 450 | {
|
| 451 | if (!dontLog)
|
| 452 | {
|
| 453 | logger.info("Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName());
|
| 454 | }
|
| 455 |
|
| 456 | try
|
| 457 | {
|
| 458 | worldserver.saveAllChunks(true, (IProgressUpdate)null);
|
| 459 | }
|
| 460 | catch (MinecraftException minecraftexception)
|
| 461 | {
|
| 462 | logger.warn(minecraftexception.getMessage());
|
| 463 | }
|
| 464 | }
|
| 465 | }
|
| 466 | }
|
| 467 | }
|
| 468 |
|
| 469 | /**
|
| 470 | * Saves all necessary data as preparation for stopping the server.
|
| 471 | */
|
| 472 | public void stopServer()
|
| 473 | {
|
| 474 | if (!this.worldIsBeingDeleted)
|
| 475 | {
|
| 476 | logger.info("Stopping server");
|
| 477 |
|
| 478 | if (this.getNetworkSystem() != null)
|
| 479 | {
|
| 480 | this.getNetworkSystem().terminateEndpoints();
|
| 481 | }
|
| 482 |
|
| 483 | if (this.serverConfigManager != null)
|
| 484 | {
|
| 485 | logger.info("Saving players");
|
| 486 | this.serverConfigManager.saveAllPlayerData();
|
| 487 | this.serverConfigManager.removeAllPlayers();
|
| 488 | }
|
| 489 |
|
| 490 | if (this.worldServers != null)
|
| 491 | {
|
| 492 | logger.info("Saving worlds");
|
| 493 | this.saveAllWorlds(false);
|
| 494 |
|
| 495 | for (int i = 0; i < this.worldServers.length; ++i)
|
| 496 | {
|
| 497 | WorldServer worldserver = this.worldServers[i];
|
| 498 | worldserver.flush();
|
| 499 | }
|
| 500 | }
|
| 501 |
|
| 502 | if (this.usageSnooper.isSnooperRunning())
|
| 503 | {
|
| 504 | this.usageSnooper.stopSnooper();
|
| 505 | }
|
| 506 | }
|
| 507 | }
|
| 508 |
|
| 509 | public boolean isServerRunning()
|
| 510 | {
|
| 511 | return this.serverRunning;
|
| 512 | }
|
| 513 |
|
| 514 | /**
|
| 515 | * Sets the serverRunning variable to false, in order to get the server to shut down.
|
| 516 | */
|
| 517 | public void initiateShutdown()
|
| 518 | {
|
| 519 | this.serverRunning = false;
|
| 520 | }
|
| 521 |
|
| 522 | protected void setInstance()
|
| 523 | {
|
| 524 | mcServer = this;
|
| 525 | }
|
| 526 |
|
| 527 | public void run()
|
| 528 | {
|
| 529 | try
|
| 530 | {
|
| 531 | if (this.startServer())
|
| 532 | {
|
| 533 | this.currentTime = getCurrentTimeMillis();
|
| 534 | long i = 0L;
|
| 535 | this.statusResponse.setServerDescription(new ChatComponentText(this.motd));
|
| 536 | this.statusResponse.setProtocolVersionInfo(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.8.9", 47));
|
| 537 | this.addFaviconToStatusResponse(this.statusResponse);
|
| 538 |
|
| 539 | while (this.serverRunning)
|
| 540 | {
|
| 541 | long k = getCurrentTimeMillis();
|
| 542 | long j = k - this.currentTime;
|
| 543 |
|
| 544 | if (j > 2000L && this.currentTime - this.timeOfLastWarning >= 15000L)
|
| 545 | {
|
| 546 | logger.warn("Can\'t keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)", new Object[] {Long.valueOf(j), Long.valueOf(j / 50L)});
|
| 547 | j = 2000L;
|
| 548 | this.timeOfLastWarning = this.currentTime;
|
| 549 | }
|
| 550 |
|
| 551 | if (j < 0L)
|
| 552 | {
|
| 553 | logger.warn("Time ran backwards! Did the system time change?");
|
| 554 | j = 0L;
|
| 555 | }
|
| 556 |
|
| 557 | i += j;
|
| 558 | this.currentTime = k;
|
| 559 |
|
| 560 | if (this.worldServers[0].areAllPlayersAsleep())
|
| 561 | {
|
| 562 | this.tick();
|
| 563 | i = 0L;
|
| 564 | }
|
| 565 | else
|
| 566 | {
|
| 567 | while (i > 50L)
|
| 568 | {
|
| 569 | i -= 50L;
|
| 570 | this.tick();
|
| 571 | }
|
| 572 | }
|
| 573 |
|
| 574 | Thread.sleep(Math.max(1L, 50L - i));
|
| 575 | this.serverIsRunning = true;
|
| 576 | }
|
| 577 | }
|
| 578 | else
|
| 579 | {
|
| 580 | this.finalTick((CrashReport)null);
|
| 581 | }
|
| 582 | }
|
| 583 | catch (Throwable throwable1)
|
| 584 | {
|
| 585 | logger.error("Encountered an unexpected exception", throwable1);
|
| 586 | CrashReport crashreport = null;
|
| 587 |
|
| 588 | if (throwable1 instanceof ReportedException)
|
| 589 | {
|
| 590 | crashreport = this.addServerInfoToCrashReport(((ReportedException)throwable1).getCrashReport());
|
| 591 | }
|
| 592 | else
|
| 593 | {
|
| 594 | crashreport = this.addServerInfoToCrashReport(new CrashReport("Exception in server tick loop", throwable1));
|
| 595 | }
|
| 596 |
|
| 597 | File file1 = new File(new File(this.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
|
| 598 |
|
| 599 | if (crashreport.saveToFile(file1))
|
| 600 | {
|
| 601 | logger.error("This crash report has been saved to: " + file1.getAbsolutePath());
|
| 602 | }
|
| 603 | else
|
| 604 | {
|
| 605 | logger.error("We were unable to save this crash report to disk.");
|
| 606 | }
|
| 607 |
|
| 608 | this.finalTick(crashreport);
|
| 609 | }
|
| 610 | finally
|
| 611 | {
|
| 612 | try
|
| 613 | {
|
| 614 | this.serverStopped = true;
|
| 615 | this.stopServer();
|
| 616 | }
|
| 617 | catch (Throwable throwable)
|
| 618 | {
|
| 619 | logger.error("Exception stopping the server", throwable);
|
| 620 | }
|
| 621 | finally
|
| 622 | {
|
| 623 | this.systemExitNow();
|
| 624 | }
|
| 625 | }
|
| 626 | }
|
| 627 |
|
| 628 | private void addFaviconToStatusResponse(ServerStatusResponse response)
|
| 629 | {
|
| 630 | File file1 = this.getFile("server-icon.png");
|
| 631 |
|
| 632 | if (file1.isFile())
|
| 633 | {
|
| 634 | ByteBuf bytebuf = Unpooled.buffer();
|
| 635 |
|
| 636 | try
|
| 637 | {
|
| 638 | BufferedImage bufferedimage = ImageIO.read(file1);
|
| 639 | Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
|
| 640 | Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
|
| 641 | ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
|
| 642 | ByteBuf bytebuf1 = Base64.encode(bytebuf);
|
| 643 | response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
|
| 644 | }
|
| 645 | catch (Exception exception)
|
| 646 | {
|
| 647 | logger.error((String)"Couldn\'t load server icon", (Throwable)exception);
|
| 648 | }
|
| 649 | finally
|
| 650 | {
|
| 651 | bytebuf.release();
|
| 652 | }
|
| 653 | }
|
| 654 | }
|
| 655 |
|
| 656 | public File getDataDirectory()
|
| 657 | {
|
| 658 | return new File(".");
|
| 659 | }
|
| 660 |
|
| 661 | /**
|
| 662 | * Called on exit from the main run() loop.
|
| 663 | */
|
| 664 | protected void finalTick(CrashReport report)
|
| 665 | {
|
| 666 | }
|
| 667 |
|
| 668 | /**
|
| 669 | * Directly calls System.exit(0), instantly killing the program.
|
| 670 | */
|
| 671 | protected void systemExitNow()
|
| 672 | {
|
| 673 | }
|
| 674 |
|
| 675 | /**
|
| 676 | * Main function called by run() every loop.
|
| 677 | */
|
| 678 | public void tick()
|
| 679 | {
|
| 680 | long i = System.nanoTime();
|
| 681 | ++this.tickCounter;
|
| 682 |
|
| 683 | if (this.startProfiling)
|
| 684 | {
|
| 685 | this.startProfiling = false;
|
| 686 | this.theProfiler.profilingEnabled = true;
|
| 687 | this.theProfiler.clearProfiling();
|
| 688 | }
|
| 689 |
|
| 690 | this.theProfiler.startSection("root");
|
| 691 | this.updateTimeLightAndEntities();
|
| 692 |
|
| 693 | if (i - this.nanoTimeSinceStatusRefresh >= 5000000000L)
|
| 694 | {
|
| 695 | this.nanoTimeSinceStatusRefresh = i;
|
| 696 | this.statusResponse.setPlayerCountData(new ServerStatusResponse.PlayerCountData(this.getMaxPlayers(), this.getCurrentPlayerCount()));
|
| 697 | GameProfile[] agameprofile = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)];
|
| 698 | int j = MathHelper.getRandomIntegerInRange(this.random, 0, this.getCurrentPlayerCount() - agameprofile.length);
|
| 699 |
|
| 700 | for (int k = 0; k < agameprofile.length; ++k)
|
| 701 | {
|
| 702 | agameprofile[k] = ((EntityPlayerMP)this.serverConfigManager.getPlayerList().get(j + k)).getGameProfile();
|
| 703 | }
|
| 704 |
|
| 705 | Collections.shuffle(Arrays.asList(agameprofile));
|
| 706 | this.statusResponse.getPlayerCountData().setPlayers(agameprofile);
|
| 707 | }
|
| 708 |
|
| 709 | if (this.tickCounter % 900 == 0)
|
| 710 | {
|
| 711 | this.theProfiler.startSection("save");
|
| 712 | this.serverConfigManager.saveAllPlayerData();
|
| 713 | this.saveAllWorlds(true);
|
| 714 | this.theProfiler.endSection();
|
| 715 | }
|
| 716 |
|
| 717 | this.theProfiler.startSection("tallying");
|
| 718 | this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i;
|
| 719 | this.theProfiler.endSection();
|
| 720 | this.theProfiler.startSection("snooper");
|
| 721 |
|
| 722 | if (!this.usageSnooper.isSnooperRunning() && this.tickCounter > 100)
|
| 723 | {
|
| 724 | this.usageSnooper.startSnooper();
|
| 725 | }
|
| 726 |
|
| 727 | if (this.tickCounter % 6000 == 0)
|
| 728 | {
|
| 729 | this.usageSnooper.addMemoryStatsToSnooper();
|
| 730 | }
|
| 731 |
|
| 732 | this.theProfiler.endSection();
|
| 733 | this.theProfiler.endSection();
|
| 734 | }
|
| 735 |
|
| 736 | public void updateTimeLightAndEntities()
|
| 737 | {
|
| 738 | this.theProfiler.startSection("jobs");
|
| 739 |
|
| 740 | synchronized (this.futureTaskQueue)
|
| 741 | {
|
| 742 | while (!this.futureTaskQueue.isEmpty())
|
| 743 | {
|
| 744 | Util.runTask((FutureTask)this.futureTaskQueue.poll(), logger);
|
| 745 | }
|
| 746 | }
|
| 747 |
|
| 748 | this.theProfiler.endStartSection("levels");
|
| 749 |
|
| 750 | for (int j = 0; j < this.worldServers.length; ++j)
|
| 751 | {
|
| 752 | long i = System.nanoTime();
|
| 753 |
|
| 754 | if (j == 0 || this.getAllowNether())
|
| 755 | {
|
| 756 | WorldServer worldserver = this.worldServers[j];
|
| 757 | this.theProfiler.startSection(worldserver.getWorldInfo().getWorldName());
|
| 758 |
|
| 759 | if (this.tickCounter % 20 == 0)
|
| 760 | {
|
| 761 | this.theProfiler.startSection("timeSync");
|
| 762 | this.serverConfigManager.sendPacketToAllPlayersInDimension(new S03PacketTimeUpdate(worldserver.getTotalWorldTime(), worldserver.getWorldTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")), worldserver.provider.getDimensionId());
|
| 763 | this.theProfiler.endSection();
|
| 764 | }
|
| 765 |
|
| 766 | this.theProfiler.startSection("tick");
|
| 767 |
|
| 768 | try
|
| 769 | {
|
| 770 | worldserver.tick();
|
| 771 | }
|
| 772 | catch (Throwable throwable1)
|
| 773 | {
|
| 774 | CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world");
|
| 775 | worldserver.addWorldInfoToCrashReport(crashreport);
|
| 776 | throw new ReportedException(crashreport);
|
| 777 | }
|
| 778 |
|
| 779 | try
|
| 780 | {
|
| 781 | worldserver.updateEntities();
|
| 782 | }
|
| 783 | catch (Throwable throwable)
|
| 784 | {
|
| 785 | CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Exception ticking world entities");
|
| 786 | worldserver.addWorldInfoToCrashReport(crashreport1);
|
| 787 | throw new ReportedException(crashreport1);
|
| 788 | }
|
| 789 |
|
| 790 | this.theProfiler.endSection();
|
| 791 | this.theProfiler.startSection("tracker");
|
| 792 | worldserver.getEntityTracker().updateTrackedEntities();
|
| 793 | this.theProfiler.endSection();
|
| 794 | this.theProfiler.endSection();
|
| 795 | }
|
| 796 |
|
| 797 | this.timeOfLastDimensionTick[j][this.tickCounter % 100] = System.nanoTime() - i;
|
| 798 | }
|
| 799 |
|
| 800 | this.theProfiler.endStartSection("connection");
|
| 801 | this.getNetworkSystem().networkTick();
|
| 802 | this.theProfiler.endStartSection("players");
|
| 803 | this.serverConfigManager.onTick();
|
| 804 | this.theProfiler.endStartSection("tickables");
|
| 805 |
|
| 806 | for (int k = 0; k < this.playersOnline.size(); ++k)
|
| 807 | {
|
| 808 | ((ITickable)this.playersOnline.get(k)).update();
|
| 809 | }
|
| 810 |
|
| 811 | this.theProfiler.endSection();
|
| 812 | }
|
| 813 |
|
| 814 | public boolean getAllowNether()
|
| 815 | {
|
| 816 | return true;
|
| 817 | }
|
| 818 |
|
| 819 | public void startServerThread()
|
| 820 | {
|
| 821 | this.serverThread = new Thread(this, "Server thread");
|
| 822 | this.serverThread.start();
|
| 823 | }
|
| 824 |
|
| 825 | /**
|
| 826 | * Returns a File object from the specified string.
|
| 827 | */
|
| 828 | public File getFile(String fileName)
|
| 829 | {
|
| 830 | return new File(this.getDataDirectory(), fileName);
|
| 831 | }
|
| 832 |
|
| 833 | /**
|
| 834 | * Logs the message with a level of WARN.
|
| 835 | */
|
| 836 | public void logWarning(String msg)
|
| 837 | {
|
| 838 | logger.warn(msg);
|
| 839 | }
|
| 840 |
|
| 841 | /**
|
| 842 | * Gets the worldServer by the given dimension.
|
| 843 | */
|
| 844 | public WorldServer worldServerForDimension(int dimension)
|
| 845 | {
|
| 846 | return dimension == -1 ? this.worldServers[1] : (dimension == 1 ? this.worldServers[2] : this.worldServers[0]);
|
| 847 | }
|
| 848 |
|
| 849 | /**
|
| 850 | * Returns the server's Minecraft version as string.
|
| 851 | */
|
| 852 | public String getMinecraftVersion()
|
| 853 | {
|
| 854 | return "1.8.9";
|
| 855 | }
|
| 856 |
|
| 857 | /**
|
| 858 | * Returns the number of players currently on the server.
|
| 859 | */
|
| 860 | public int getCurrentPlayerCount()
|
| 861 | {
|
| 862 | return this.serverConfigManager.getCurrentPlayerCount();
|
| 863 | }
|
| 864 |
|
| 865 | /**
|
| 866 | * Returns the maximum number of players allowed on the server.
|
| 867 | */
|
| 868 | public int getMaxPlayers()
|
| 869 | {
|
| 870 | return this.serverConfigManager.getMaxPlayers();
|
| 871 | }
|
| 872 |
|
| 873 | /**
|
| 874 | * Returns an array of the usernames of all the connected players.
|
| 875 | */
|
| 876 | public String[] getAllUsernames()
|
| 877 | {
|
| 878 | return this.serverConfigManager.getAllUsernames();
|
| 879 | }
|
| 880 |
|
| 881 | /**
|
| 882 | * Returns an array of the GameProfiles of all the connected players
|
| 883 | */
|
| 884 | public GameProfile[] getGameProfiles()
|
| 885 | {
|
| 886 | return this.serverConfigManager.getAllProfiles();
|
| 887 | }
|
| 888 |
|
| 889 | public String getServerModName()
|
| 890 | {
|
| 891 | return "vanilla";
|
| 892 | }
|
| 893 |
|
| 894 | /**
|
| 895 | * Adds the server info, including from theWorldServer, to the crash report.
|
| 896 | */
|
| 897 | public CrashReport addServerInfoToCrashReport(CrashReport report)
|
| 898 | {
|
| 899 | report.getCategory().addCrashSectionCallable("Profiler Position", new Callable<String>()
|
| 900 | {
|
| 901 | public String call() throws Exception
|
| 902 | {
|
| 903 | return MinecraftServer.this.theProfiler.profilingEnabled ? MinecraftServer.this.theProfiler.getNameOfLastSection() : "N/A (disabled)";
|
| 904 | }
|
| 905 | });
|
| 906 |
|
| 907 | if (this.serverConfigManager != null)
|
| 908 | {
|
| 909 | report.getCategory().addCrashSectionCallable("Player Count", new Callable<String>()
|
| 910 | {
|
| 911 | public String call()
|
| 912 | {
|
| 913 | return MinecraftServer.this.serverConfigManager.getCurrentPlayerCount() + " / " + MinecraftServer.this.serverConfigManager.getMaxPlayers() + "; " + MinecraftServer.this.serverConfigManager.getPlayerList();
|
| 914 | }
|
| 915 | });
|
| 916 | }
|
| 917 |
|
| 918 | return report;
|
| 919 | }
|
| 920 |
|
| 921 | public List<String> getTabCompletions(ICommandSender sender, String input, BlockPos pos)
|
| 922 | {
|
| 923 | List<String> list = Lists.<String>newArrayList();
|
| 924 |
|
| 925 | if (input.startsWith("/"))
|
| 926 | {
|
| 927 | input = input.substring(1);
|
| 928 | boolean flag = !input.contains(" ");
|
| 929 | List<String> list1 = this.commandManager.getTabCompletionOptions(sender, input, pos);
|
| 930 |
|
| 931 | if (list1 != null)
|
| 932 | {
|
| 933 | for (String s2 : list1)
|
| 934 | {
|
| 935 | if (flag)
|
| 936 | {
|
| 937 | list.add("/" + s2);
|
| 938 | }
|
| 939 | else
|
| 940 | {
|
| 941 | list.add(s2);
|
| 942 | }
|
| 943 | }
|
| 944 | }
|
| 945 |
|
| 946 | return list;
|
| 947 | }
|
| 948 | else
|
| 949 | {
|
| 950 | String[] astring = input.split(" ", -1);
|
| 951 | String s = astring[astring.length - 1];
|
| 952 |
|
| 953 | for (String s1 : this.serverConfigManager.getAllUsernames())
|
| 954 | {
|
| 955 | if (CommandBase.doesStringStartWith(s, s1))
|
| 956 | {
|
| 957 | list.add(s1);
|
| 958 | }
|
| 959 | }
|
| 960 |
|
| 961 | return list;
|
| 962 | }
|
| 963 | }
|
| 964 |
|
| 965 | /**
|
| 966 | * Gets mcServer.
|
| 967 | */
|
| 968 | public static MinecraftServer getServer()
|
| 969 | {
|
| 970 | return mcServer;
|
| 971 | }
|
| 972 |
|
| 973 | public boolean isAnvilFileSet()
|
| 974 | {
|
| 975 | return this.anvilFile != null;
|
| 976 | }
|
| 977 |
|
| 978 | /**
|
| 979 | * Get the name of this object. For players this returns their username
|
| 980 | */
|
| 981 | public String getName()
|
| 982 | {
|
| 983 | return "Server";
|
| 984 | }
|
| 985 |
|
| 986 | /**
|
| 987 | * Send a chat message to the CommandSender
|
| 988 | */
|
| 989 | public void addChatMessage(IChatComponent component)
|
| 990 | {
|
| 991 | logger.info(component.getUnformattedText());
|
| 992 | }
|
| 993 |
|
| 994 | /**
|
| 995 | * Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
|
| 996 | */
|
| 997 | public boolean canCommandSenderUseCommand(int permLevel, String commandName)
|
| 998 | {
|
| 999 | return true;
|
| 1000 | }
|
| 1001 |
|
| 1002 | public ICommandManager getCommandManager()
|
| 1003 | {
|
| 1004 | return this.commandManager;
|
| 1005 | }
|
| 1006 |
|
| 1007 | /**
|
| 1008 | * Gets KeyPair instanced in MinecraftServer.
|
| 1009 | */
|
| 1010 | public KeyPair getKeyPair()
|
| 1011 | {
|
| 1012 | return this.serverKeyPair;
|
| 1013 | }
|
| 1014 |
|
| 1015 | /**
|
| 1016 | * Returns the username of the server owner (for integrated servers)
|
| 1017 | */
|
| 1018 | public String getServerOwner()
|
| 1019 | {
|
| 1020 | return this.serverOwner;
|
| 1021 | }
|
| 1022 |
|
| 1023 | /**
|
| 1024 | * Sets the username of the owner of this server (in the case of an integrated server)
|
| 1025 | */
|
| 1026 | public void setServerOwner(String owner)
|
| 1027 | {
|
| 1028 | this.serverOwner = owner;
|
| 1029 | }
|
| 1030 |
|
| 1031 | public boolean isSinglePlayer()
|
| 1032 | {
|
| 1033 | return this.serverOwner != null;
|
| 1034 | }
|
| 1035 |
|
| 1036 | public String getFolderName()
|
| 1037 | {
|
| 1038 | return this.folderName;
|
| 1039 | }
|
| 1040 |
|
| 1041 | public void setFolderName(String name)
|
| 1042 | {
|
| 1043 | this.folderName = name;
|
| 1044 | }
|
| 1045 |
|
| 1046 | public void setWorldName(String p_71246_1_)
|
| 1047 | {
|
| 1048 | this.worldName = p_71246_1_;
|
| 1049 | }
|
| 1050 |
|
| 1051 | public String getWorldName()
|
| 1052 | {
|
| 1053 | return this.worldName;
|
| 1054 | }
|
| 1055 |
|
| 1056 | public void setKeyPair(KeyPair keyPair)
|
| 1057 | {
|
| 1058 | this.serverKeyPair = keyPair;
|
| 1059 | }
|
| 1060 |
|
| 1061 | public void setDifficultyForAllWorlds(EnumDifficulty difficulty)
|
| 1062 | {
|
| 1063 | for (int i = 0; i < this.worldServers.length; ++i)
|
| 1064 | {
|
| 1065 | World world = this.worldServers[i];
|
| 1066 |
|
| 1067 | if (world != null)
|
| 1068 | {
|
| 1069 | if (world.getWorldInfo().isHardcoreModeEnabled())
|
| 1070 | {
|
| 1071 | world.getWorldInfo().setDifficulty(EnumDifficulty.HARD);
|
| 1072 | world.setAllowedSpawnTypes(true, true);
|
| 1073 | }
|
| 1074 | else if (this.isSinglePlayer())
|
| 1075 | {
|
| 1076 | world.getWorldInfo().setDifficulty(difficulty);
|
| 1077 | world.setAllowedSpawnTypes(world.getDifficulty() != EnumDifficulty.PEACEFUL, true);
|
| 1078 | }
|
| 1079 | else
|
| 1080 | {
|
| 1081 | world.getWorldInfo().setDifficulty(difficulty);
|
| 1082 | world.setAllowedSpawnTypes(this.allowSpawnMonsters(), this.canSpawnAnimals);
|
| 1083 | }
|
| 1084 | }
|
| 1085 | }
|
| 1086 | }
|
| 1087 |
|
| 1088 | protected boolean allowSpawnMonsters()
|
| 1089 | {
|
| 1090 | return true;
|
| 1091 | }
|
| 1092 |
|
| 1093 | /**
|
| 1094 | * Gets whether this is a demo or not.
|
| 1095 | */
|
| 1096 | public boolean isDemo()
|
| 1097 | {
|
| 1098 | return this.isDemo;
|
| 1099 | }
|
| 1100 |
|
| 1101 | /**
|
| 1102 | * Sets whether this is a demo or not.
|
| 1103 | */
|
| 1104 | public void setDemo(boolean demo)
|
| 1105 | {
|
| 1106 | this.isDemo = demo;
|
| 1107 | }
|
| 1108 |
|
| 1109 | public void canCreateBonusChest(boolean enable)
|
| 1110 | {
|
| 1111 | this.enableBonusChest = enable;
|
| 1112 | }
|
| 1113 |
|
| 1114 | public ISaveFormat getActiveAnvilConverter()
|
| 1115 | {
|
| 1116 | return this.anvilConverterForAnvilFile;
|
| 1117 | }
|
| 1118 |
|
| 1119 | /**
|
| 1120 | * WARNING : directly calls
|
| 1121 | * getActiveAnvilConverter().deleteWorldDirectory(theWorldServer[0].getSaveHandler().getWorldDirectoryName());
|
| 1122 | */
|
| 1123 | public void deleteWorldAndStopServer()
|
| 1124 | {
|
| 1125 | this.worldIsBeingDeleted = true;
|
| 1126 | this.getActiveAnvilConverter().flushCache();
|
| 1127 |
|
| 1128 | for (int i = 0; i < this.worldServers.length; ++i)
|
| 1129 | {
|
| 1130 | WorldServer worldserver = this.worldServers[i];
|
| 1131 |
|
| 1132 | if (worldserver != null)
|
| 1133 | {
|
| 1134 | worldserver.flush();
|
| 1135 | }
|
| 1136 | }
|
| 1137 |
|
| 1138 | this.getActiveAnvilConverter().deleteWorldDirectory(this.worldServers[0].getSaveHandler().getWorldDirectoryName());
|
| 1139 | this.initiateShutdown();
|
| 1140 | }
|
| 1141 |
|
| 1142 | public String getResourcePackUrl()
|
| 1143 | {
|
| 1144 | return this.resourcePackUrl;
|
| 1145 | }
|
| 1146 |
|
| 1147 | public String getResourcePackHash()
|
| 1148 | {
|
| 1149 | return this.resourcePackHash;
|
| 1150 | }
|
| 1151 |
|
| 1152 | public void setResourcePack(String url, String hash)
|
| 1153 | {
|
| 1154 | this.resourcePackUrl = url;
|
| 1155 | this.resourcePackHash = hash;
|
| 1156 | }
|
| 1157 |
|
| 1158 | public void addServerStatsToSnooper(PlayerUsageSnooper playerSnooper)
|
| 1159 | {
|
| 1160 | playerSnooper.addClientStat("whitelist_enabled", Boolean.valueOf(false));
|
| 1161 | playerSnooper.addClientStat("whitelist_count", Integer.valueOf(0));
|
| 1162 |
|
| 1163 | if (this.serverConfigManager != null)
|
| 1164 | {
|
| 1165 | playerSnooper.addClientStat("players_current", Integer.valueOf(this.getCurrentPlayerCount()));
|
| 1166 | playerSnooper.addClientStat("players_max", Integer.valueOf(this.getMaxPlayers()));
|
| 1167 | playerSnooper.addClientStat("players_seen", Integer.valueOf(this.serverConfigManager.getAvailablePlayerDat().length));
|
| 1168 | }
|
| 1169 |
|
| 1170 | playerSnooper.addClientStat("uses_auth", Boolean.valueOf(this.onlineMode));
|
| 1171 | playerSnooper.addClientStat("gui_state", this.getGuiEnabled() ? "enabled" : "disabled");
|
| 1172 | playerSnooper.addClientStat("run_time", Long.valueOf((getCurrentTimeMillis() - playerSnooper.getMinecraftStartTimeMillis()) / 60L * 1000L));
|
| 1173 | playerSnooper.addClientStat("avg_tick_ms", Integer.valueOf((int)(MathHelper.average(this.tickTimeArray) * 1.0E-6D)));
|
| 1174 | int i = 0;
|
| 1175 |
|
| 1176 | if (this.worldServers != null)
|
| 1177 | {
|
| 1178 | for (int j = 0; j < this.worldServers.length; ++j)
|
| 1179 | {
|
| 1180 | if (this.worldServers[j] != null)
|
| 1181 | {
|
| 1182 | WorldServer worldserver = this.worldServers[j];
|
| 1183 | WorldInfo worldinfo = worldserver.getWorldInfo();
|
| 1184 | playerSnooper.addClientStat("world[" + i + "][dimension]", Integer.valueOf(worldserver.provider.getDimensionId()));
|
| 1185 | playerSnooper.addClientStat("world[" + i + "][mode]", worldinfo.getGameType());
|
| 1186 | playerSnooper.addClientStat("world[" + i + "][difficulty]", worldserver.getDifficulty());
|
| 1187 | playerSnooper.addClientStat("world[" + i + "][hardcore]", Boolean.valueOf(worldinfo.isHardcoreModeEnabled()));
|
| 1188 | playerSnooper.addClientStat("world[" + i + "][generator_name]", worldinfo.getTerrainType().getWorldTypeName());
|
| 1189 | playerSnooper.addClientStat("world[" + i + "][generator_version]", Integer.valueOf(worldinfo.getTerrainType().getGeneratorVersion()));
|
| 1190 | playerSnooper.addClientStat("world[" + i + "][height]", Integer.valueOf(this.buildLimit));
|
| 1191 | playerSnooper.addClientStat("world[" + i + "][chunks_loaded]", Integer.valueOf(worldserver.getChunkProvider().getLoadedChunkCount()));
|
| 1192 | ++i;
|
| 1193 | }
|
| 1194 | }
|
| 1195 | }
|
| 1196 |
|
| 1197 | playerSnooper.addClientStat("worlds", Integer.valueOf(i));
|
| 1198 | }
|
| 1199 |
|
| 1200 | public void addServerTypeToSnooper(PlayerUsageSnooper playerSnooper)
|
| 1201 | {
|
| 1202 | playerSnooper.addStatToSnooper("singleplayer", Boolean.valueOf(this.isSinglePlayer()));
|
| 1203 | playerSnooper.addStatToSnooper("server_brand", this.getServerModName());
|
| 1204 | playerSnooper.addStatToSnooper("gui_supported", GraphicsEnvironment.isHeadless() ? "headless" : "supported");
|
| 1205 | playerSnooper.addStatToSnooper("dedicated", Boolean.valueOf(this.isDedicatedServer()));
|
| 1206 | }
|
| 1207 |
|
| 1208 | /**
|
| 1209 | * Returns whether snooping is enabled or not.
|
| 1210 | */
|
| 1211 | public boolean isSnooperEnabled()
|
| 1212 | {
|
| 1213 | return true;
|
| 1214 | }
|
| 1215 |
|
| 1216 | public abstract boolean isDedicatedServer();
|
| 1217 |
|
| 1218 | public boolean isServerInOnlineMode()
|
| 1219 | {
|
| 1220 | return this.onlineMode;
|
| 1221 | }
|
| 1222 |
|
| 1223 | public void setOnlineMode(boolean online)
|
| 1224 | {
|
| 1225 | this.onlineMode = online;
|
| 1226 | }
|
| 1227 |
|
| 1228 | public boolean getCanSpawnAnimals()
|
| 1229 | {
|
| 1230 | return this.canSpawnAnimals;
|
| 1231 | }
|
| 1232 |
|
| 1233 | public void setCanSpawnAnimals(boolean spawnAnimals)
|
| 1234 | {
|
| 1235 | this.canSpawnAnimals = spawnAnimals;
|
| 1236 | }
|
| 1237 |
|
| 1238 | public boolean getCanSpawnNPCs()
|
| 1239 | {
|
| 1240 | return this.canSpawnNPCs;
|
| 1241 | }
|
| 1242 |
|
| 1243 | /**
|
| 1244 | * Get if native transport should be used. Native transport means linux server performance improvements and
|
| 1245 | * optimized packet sending/receiving on linux
|
| 1246 | */
|
| 1247 | public abstract boolean shouldUseNativeTransport();
|
| 1248 |
|
| 1249 | public void setCanSpawnNPCs(boolean spawnNpcs)
|
| 1250 | {
|
| 1251 | this.canSpawnNPCs = spawnNpcs;
|
| 1252 | }
|
| 1253 |
|
| 1254 | public boolean isPVPEnabled()
|
| 1255 | {
|
| 1256 | return this.pvpEnabled;
|
| 1257 | }
|
| 1258 |
|
| 1259 | public void setAllowPvp(boolean allowPvp)
|
| 1260 | {
|
| 1261 | this.pvpEnabled = allowPvp;
|
| 1262 | }
|
| 1263 |
|
| 1264 | public boolean isFlightAllowed()
|
| 1265 | {
|
| 1266 | return this.allowFlight;
|
| 1267 | }
|
| 1268 |
|
| 1269 | public void setAllowFlight(boolean allow)
|
| 1270 | {
|
| 1271 | this.allowFlight = allow;
|
| 1272 | }
|
| 1273 |
|
| 1274 | /**
|
| 1275 | * Return whether command blocks are enabled.
|
| 1276 | */
|
| 1277 | public abstract boolean isCommandBlockEnabled();
|
| 1278 |
|
| 1279 | public String getMOTD()
|
| 1280 | {
|
| 1281 | return this.motd;
|
| 1282 | }
|
| 1283 |
|
| 1284 | public void setMOTD(String motdIn)
|
| 1285 | {
|
| 1286 | this.motd = motdIn;
|
| 1287 | }
|
| 1288 |
|
| 1289 | public int getBuildLimit()
|
| 1290 | {
|
| 1291 | return this.buildLimit;
|
| 1292 | }
|
| 1293 |
|
| 1294 | public void setBuildLimit(int maxBuildHeight)
|
| 1295 | {
|
| 1296 | this.buildLimit = maxBuildHeight;
|
| 1297 | }
|
| 1298 |
|
| 1299 | public boolean isServerStopped()
|
| 1300 | {
|
| 1301 | return this.serverStopped;
|
| 1302 | }
|
| 1303 |
|
| 1304 | public ServerConfigurationManager getConfigurationManager()
|
| 1305 | {
|
| 1306 | return this.serverConfigManager;
|
| 1307 | }
|
| 1308 |
|
| 1309 | public void setConfigManager(ServerConfigurationManager configManager)
|
| 1310 | {
|
| 1311 | this.serverConfigManager = configManager;
|
| 1312 | }
|
| 1313 |
|
| 1314 | /**
|
| 1315 | * Sets the game type for all worlds.
|
| 1316 | */
|
| 1317 | public void setGameType(WorldSettings.GameType gameMode)
|
| 1318 | {
|
| 1319 | for (int i = 0; i < this.worldServers.length; ++i)
|
| 1320 | {
|
| 1321 | getServer().worldServers[i].getWorldInfo().setGameType(gameMode);
|
| 1322 | }
|
| 1323 | }
|
| 1324 |
|
| 1325 | public NetworkSystem getNetworkSystem()
|
| 1326 | {
|
| 1327 | return this.networkSystem;
|
| 1328 | }
|
| 1329 |
|
| 1330 | public boolean serverIsInRunLoop()
|
| 1331 | {
|
| 1332 | return this.serverIsRunning;
|
| 1333 | }
|
| 1334 |
|
| 1335 | public boolean getGuiEnabled()
|
| 1336 | {
|
| 1337 | return false;
|
| 1338 | }
|
| 1339 |
|
| 1340 | /**
|
| 1341 | * On dedicated does nothing. On integrated, sets commandsAllowedForAll, gameType and allows external connections.
|
| 1342 | */
|
| 1343 | public abstract String shareToLAN(WorldSettings.GameType type, boolean allowCheats);
|
| 1344 |
|
| 1345 | public int getTickCounter()
|
| 1346 | {
|
| 1347 | return this.tickCounter;
|
| 1348 | }
|
| 1349 |
|
| 1350 | public void enableProfiling()
|
| 1351 | {
|
| 1352 | this.startProfiling = true;
|
| 1353 | }
|
| 1354 |
|
| 1355 | public PlayerUsageSnooper getPlayerUsageSnooper()
|
| 1356 | {
|
| 1357 | return this.usageSnooper;
|
| 1358 | }
|
| 1359 |
|
| 1360 | /**
|
| 1361 | * Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
|
| 1362 | * the coordinates 0, 0, 0
|
| 1363 | */
|
| 1364 | public BlockPos getPosition()
|
| 1365 | {
|
| 1366 | return BlockPos.ORIGIN;
|
| 1367 | }
|
| 1368 |
|
| 1369 | /**
|
| 1370 | * Get the position vector. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return 0.0D,
|
| 1371 | * 0.0D, 0.0D
|
| 1372 | */
|
| 1373 | public Vec3 getPositionVector()
|
| 1374 | {
|
| 1375 | return new Vec3(0.0D, 0.0D, 0.0D);
|
| 1376 | }
|
| 1377 |
|
| 1378 | /**
|
| 1379 | * Get the world, if available. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
|
| 1380 | * the overworld
|
| 1381 | */
|
| 1382 | public World getEntityWorld()
|
| 1383 | {
|
| 1384 | return this.worldServers[0];
|
| 1385 | }
|
| 1386 |
|
| 1387 | /**
|
| 1388 | * Returns the entity associated with the command sender. MAY BE NULL!
|
| 1389 | */
|
| 1390 | public Entity getCommandSenderEntity()
|
| 1391 | {
|
| 1392 | return null;
|
| 1393 | }
|
| 1394 |
|
| 1395 | /**
|
| 1396 | * Return the spawn protection area's size.
|
| 1397 | */
|
| 1398 | public int getSpawnProtectionSize()
|
| 1399 | {
|
| 1400 | return 16;
|
| 1401 | }
|
| 1402 |
|
| 1403 | public boolean isBlockProtected(World worldIn, BlockPos pos, EntityPlayer playerIn)
|
| 1404 | {
|
| 1405 | return false;
|
| 1406 | }
|
| 1407 |
|
| 1408 | public boolean getForceGamemode()
|
| 1409 | {
|
| 1410 | return this.isGamemodeForced;
|
| 1411 | }
|
| 1412 |
|
| 1413 | public Proxy getServerProxy()
|
| 1414 | {
|
| 1415 | return this.serverProxy;
|
| 1416 | }
|
| 1417 |
|
| 1418 | public static long getCurrentTimeMillis()
|
| 1419 | {
|
| 1420 | return System.currentTimeMillis();
|
| 1421 | }
|
| 1422 |
|
| 1423 | public int getMaxPlayerIdleMinutes()
|
| 1424 | {
|
| 1425 | return this.maxPlayerIdleMinutes;
|
| 1426 | }
|
| 1427 |
|
| 1428 | public void setPlayerIdleTimeout(int idleTimeout)
|
| 1429 | {
|
| 1430 | this.maxPlayerIdleMinutes = idleTimeout;
|
| 1431 | }
|
| 1432 |
|
| 1433 | /**
|
| 1434 | * Get the formatted ChatComponent that will be used for the sender's username in chat
|
| 1435 | */
|
| 1436 | public IChatComponent getDisplayName()
|
| 1437 | {
|
| 1438 | return new ChatComponentText(this.getName());
|
| 1439 | }
|
| 1440 |
|
| 1441 | public boolean isAnnouncingPlayerAchievements()
|
| 1442 | {
|
| 1443 | return true;
|
| 1444 | }
|
| 1445 |
|
| 1446 | public MinecraftSessionService getMinecraftSessionService()
|
| 1447 | {
|
| 1448 | return this.sessionService;
|
| 1449 | }
|
| 1450 |
|
| 1451 | public GameProfileRepository getGameProfileRepository()
|
| 1452 | {
|
| 1453 | return this.profileRepo;
|
| 1454 | }
|
| 1455 |
|
| 1456 | public PlayerProfileCache getPlayerProfileCache()
|
| 1457 | {
|
| 1458 | return this.profileCache;
|
| 1459 | }
|
| 1460 |
|
| 1461 | public ServerStatusResponse getServerStatusResponse()
|
| 1462 | {
|
| 1463 | return this.statusResponse;
|
| 1464 | }
|
| 1465 |
|
| 1466 | public void refreshStatusNextTick()
|
| 1467 | {
|
| 1468 | this.nanoTimeSinceStatusRefresh = 0L;
|
| 1469 | }
|
| 1470 |
|
| 1471 | public Entity getEntityFromUuid(UUID uuid)
|
| 1472 | {
|
| 1473 | for (WorldServer worldserver : this.worldServers)
|
| 1474 | {
|
| 1475 | if (worldserver != null)
|
| 1476 | {
|
| 1477 | Entity entity = worldserver.getEntityFromUuid(uuid);
|
| 1478 |
|
| 1479 | if (entity != null)
|
| 1480 | {
|
| 1481 | return entity;
|
| 1482 | }
|
| 1483 | }
|
| 1484 | }
|
| 1485 |
|
| 1486 | return null;
|
| 1487 | }
|
| 1488 |
|
| 1489 | /**
|
| 1490 | * Returns true if the command sender should be sent feedback about executed commands
|
| 1491 | */
|
| 1492 | public boolean sendCommandFeedback()
|
| 1493 | {
|
| 1494 | return getServer().worldServers[0].getGameRules().getBoolean("sendCommandFeedback");
|
| 1495 | }
|
| 1496 |
|
| 1497 | public void setCommandStat(CommandResultStats.Type type, int amount)
|
| 1498 | {
|
| 1499 | }
|
| 1500 |
|
| 1501 | public int getMaxWorldSize()
|
| 1502 | {
|
| 1503 | return 29999984;
|
| 1504 | }
|
| 1505 |
|
| 1506 | public <V> ListenableFuture<V> callFromMainThread(Callable<V> callable)
|
| 1507 | {
|
| 1508 | Validate.notNull(callable);
|
| 1509 |
|
| 1510 | if (!this.isCallingFromMinecraftThread() && !this.isServerStopped())
|
| 1511 | {
|
| 1512 | ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callable);
|
| 1513 |
|
| 1514 | synchronized (this.futureTaskQueue)
|
| 1515 | {
|
| 1516 | this.futureTaskQueue.add(listenablefuturetask);
|
| 1517 | return listenablefuturetask;
|
| 1518 | }
|
| 1519 | }
|
| 1520 | else
|
| 1521 | {
|
| 1522 | try
|
| 1523 | {
|
| 1524 | return Futures.<V>immediateFuture(callable.call());
|
| 1525 | }
|
| 1526 | catch (Exception exception)
|
| 1527 | {
|
| 1528 | return Futures.immediateFailedCheckedFuture(exception);
|
| 1529 | }
|
| 1530 | }
|
| 1531 | }
|
| 1532 |
|
| 1533 | public ListenableFuture<Object> addScheduledTask(Runnable runnableToSchedule)
|
| 1534 | {
|
| 1535 | Validate.notNull(runnableToSchedule);
|
| 1536 | return this.<Object>callFromMainThread(Executors.callable(runnableToSchedule));
|
| 1537 | }
|
| 1538 |
|
| 1539 | public boolean isCallingFromMinecraftThread()
|
| 1540 | {
|
| 1541 | return Thread.currentThread() == this.serverThread;
|
| 1542 | }
|
| 1543 |
|
| 1544 | /**
|
| 1545 | * The compression treshold. If the packet is larger than the specified amount of bytes, it will be compressed
|
| 1546 | */
|
| 1547 | public int getNetworkCompressionTreshold()
|
| 1548 | {
|
| 1549 | return 256;
|
| 1550 | }
|
| 1551 | }
|
| 1552 |
|