diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index ac58b0c..3fa1c18 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -396,7 +396,7 @@ this.field_147147_p.func_151321_a(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.7.2", 4)); this.func_147138_a(this.field_147147_p); - WatchdogThread.doStart(); + if(!isSinglePlayer()) WatchdogThread.doStart(); for (long lastTick = 0L; this.serverRunning; this.serverIsRunning = true) { @@ -418,7 +418,7 @@ lastTick = curTime; this.tick(); - WatchdogThread.tick(); + if(!isSinglePlayer()) WatchdogThread.tick(); } FMLCommonHandler.instance().handleServerStopping(); @@ -515,7 +515,7 @@ protected File getDataDirectory() { - return ConfigurationHandler.getSettingDir(); + return new File("."); } protected void finalTick(CrashReport par1CrashReport) {} @@ -900,6 +900,8 @@ public void func_147139_a(EnumDifficulty p_147139_1_) { + if(!isSinglePlayer()) return; + for (int i = 0; i < this.worldServers.length; ++i) { WorldServer worldserver = this.worldServers[i]; @@ -910,11 +912,13 @@ { worldserver.difficultySetting = EnumDifficulty.HARD; worldserver.setAllowedSpawnTypes(true, true); + worldserver.getConfig().mobSpawn.spawnMonsters = true; } else if (this.isSinglePlayer()) { worldserver.difficultySetting = p_147139_1_; worldserver.setAllowedSpawnTypes(worldserver.difficultySetting != EnumDifficulty.PEACEFUL, true); + worldserver.getConfig().mobSpawn.spawnMonsters = worldserver.difficultySetting != EnumDifficulty.PEACEFUL; } else { diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index 5bafafb..f7baf53 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -495,4 +495,9 @@ getConfigurationManager().setPlayerManager(new WorldServer[]{ getMultiWorld().getWorldByID(0) }); initialWorldChunkLoad(); } + + protected File getDataDirectory() + { + return ConfigurationHandler.getSettingDir(); + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/integrated/IntegratedServer.java b/src/main/java/net/minecraft/server/integrated/IntegratedServer.java index 62f32ba..3e1c59b 100644 --- a/src/main/java/net/minecraft/server/integrated/IntegratedServer.java +++ b/src/main/java/net/minecraft/server/integrated/IntegratedServer.java @@ -1,272 +1,274 @@ -package net.minecraft.server.integrated; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import java.io.File; -import java.io.IOException; -import java.net.InetAddress; -import java.util.concurrent.Callable; -import net.minecraft.client.ClientBrandRetriever; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ThreadLanServerPing; -import net.minecraft.crash.CrashReport; -import net.minecraft.profiler.PlayerUsageSnooper; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.CryptManager; -import net.minecraft.util.HttpUtil; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.WorldManager; -import net.minecraft.world.WorldServer; -import net.minecraft.world.WorldServerMulti; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.WorldType; -import net.minecraft.world.demo.DemoWorldServer; -import net.minecraft.world.storage.ISaveHandler; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.world.WorldEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.ultramine.permission.PermissionRepository; -import org.ultramine.permission.internal.ClientPermissionManager; - -@SideOnly(Side.CLIENT) -public class IntegratedServer extends MinecraftServer -{ - private static final Logger logger = LogManager.getLogger(); - private final Minecraft mc; - private final WorldSettings theWorldSettings; - private boolean isGamePaused; - private boolean isPublic; - private ThreadLanServerPing lanServerPing; - private static final String __OBFID = "CL_00001129"; - - public IntegratedServer(Minecraft par1Minecraft, String par2Str, String par3Str, WorldSettings par4WorldSettings) - { - super(new File(par1Minecraft.mcDataDir, "saves"), par1Minecraft.getProxy()); - this.setServerOwner(par1Minecraft.getSession().getUsername()); - this.setFolderName(par2Str); - this.setWorldName(par3Str); - this.setDemo(par1Minecraft.isDemo()); - this.canCreateBonusChest(par4WorldSettings.isBonusChestEnabled()); - this.setBuildLimit(256); - this.setConfigurationManager(new IntegratedPlayerList(this)); - this.mc = par1Minecraft; - this.theWorldSettings = par4WorldSettings; - } - - protected void loadAllWorlds(String par1Str, String par2Str, long par3, WorldType par5WorldType, String par6Str) - { - this.convertMapIfNeeded(par1Str); - ISaveHandler isavehandler = this.getActiveAnvilConverter().getSaveLoader(par1Str, true); - - WorldServer overWorld = (isDemo() ? new DemoWorldServer(this, isavehandler, par2Str, 0, theProfiler) : new WorldServer(this, isavehandler, par2Str, 0, theWorldSettings, theProfiler)); - for (int dim : DimensionManager.getStaticDimensionIDs()) - { - WorldServer world = (dim == 0 ? overWorld : new WorldServerMulti(this, isavehandler, par2Str, dim, theWorldSettings, overWorld, theProfiler)); - world.addWorldAccess(new WorldManager(this, world)); - - if (!this.isSinglePlayer()) - { - world.getWorldInfo().setGameType(getGameType()); - } - - MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world)); - } - - this.getConfigurationManager().setPlayerManager(new WorldServer[]{ overWorld }); - this.func_147139_a(this.func_147135_j()); - this.initialWorldChunkLoad(); - } - - protected boolean startServer() throws IOException - { - logger.info("Starting integrated minecraft server version 1.7.2"); - this.setOnlineMode(false); - this.setCanSpawnAnimals(true); - this.setCanSpawnNPCs(true); - this.setAllowPvp(true); - this.setAllowFlight(true); - logger.info("Generating keypair"); - this.setKeyPair(CryptManager.createNewKeyPair()); - this.setPermissionManager(new ClientPermissionManager(getServerOwner(), new PermissionRepository())); // ultramine - if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; } - this.loadAllWorlds(this.getFolderName(), this.getWorldName(), this.theWorldSettings.getSeed(), this.theWorldSettings.getTerrainType(), this.theWorldSettings.func_82749_j()); - this.setMOTD(this.getServerOwner() + " - " + this.worldServers[0].getWorldInfo().getWorldName()); - return FMLCommonHandler.instance().handleServerStarting(this); - } - - public void tick() - { - boolean flag = this.isGamePaused; - this.isGamePaused = Minecraft.getMinecraft().getNetHandler() != null && Minecraft.getMinecraft().isGamePaused(); - - if (!flag && this.isGamePaused) - { - logger.info("Saving and pausing game..."); - this.getConfigurationManager().saveAllPlayerData(); - this.saveAllWorlds(false); - } - - if (!this.isGamePaused) - { - super.tick(); - } - } - - public boolean canStructuresSpawn() - { - return false; - } - - public WorldSettings.GameType getGameType() - { - return this.theWorldSettings.getGameType(); - } - - public EnumDifficulty func_147135_j() - { - return this.mc.gameSettings.difficulty; - } - - public boolean isHardcore() - { - return this.theWorldSettings.getHardcoreEnabled(); - } - - protected File getDataDirectory() - { - return this.mc.mcDataDir; - } - - public boolean isDedicatedServer() - { - return false; - } - - protected void finalTick(CrashReport par1CrashReport) - { - this.mc.crashed(par1CrashReport); - } - - public CrashReport addServerInfoToCrashReport(CrashReport par1CrashReport) - { - par1CrashReport = super.addServerInfoToCrashReport(par1CrashReport); - par1CrashReport.getCategory().addCrashSectionCallable("Type", new Callable() - { - private static final String __OBFID = "CL_00001130"; - public String call() - { - return "Integrated Server (map_client.txt)"; - } - }); - par1CrashReport.getCategory().addCrashSectionCallable("Is Modded", new Callable() - { - private static final String __OBFID = "CL_00001131"; - public String call() - { - String s = ClientBrandRetriever.getClientModName(); - - if (!s.equals("vanilla")) - { - return "Definitely; Client brand changed to \'" + s + "\'"; - } - else - { - s = IntegratedServer.this.getServerModName(); - return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : (Minecraft.class.getSigners() == null ? "Very likely; Jar signature invalidated" : "Probably not. Jar signature remains and both client + server brands are untouched."); - } - } - }); - return par1CrashReport; - } - - public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) - { - super.addServerStatsToSnooper(par1PlayerUsageSnooper); - par1PlayerUsageSnooper.addData("snooper_partner", this.mc.getPlayerUsageSnooper().getUniqueID()); - } - - public boolean isSnooperEnabled() - { - return Minecraft.getMinecraft().isSnooperEnabled(); - } - - public String shareToLAN(WorldSettings.GameType par1EnumGameType, boolean par2) - { - try - { - int i = -1; - - try - { - i = HttpUtil.func_76181_a(); - } - catch (IOException ioexception) - { - ; - } - - if (i <= 0) - { - i = 25564; - } - - this.func_147137_ag().addLanEndpoint((InetAddress)null, i); - logger.info("Started on " + i); - this.isPublic = true; - this.lanServerPing = new ThreadLanServerPing(this.getMOTD(), i + ""); - this.lanServerPing.start(); - this.getConfigurationManager().setGameType(par1EnumGameType); - this.getConfigurationManager().setCommandsAllowedForAll(par2); - return i + ""; - } - catch (IOException ioexception1) - { - return null; - } - } - - public void stopServer() - { - super.stopServer(); - - if (this.lanServerPing != null) - { - this.lanServerPing.interrupt(); - this.lanServerPing = null; - } - } - - public void initiateShutdown() - { - super.initiateShutdown(); - - if (this.lanServerPing != null) - { - this.lanServerPing.interrupt(); - this.lanServerPing = null; - } - } - - public boolean getPublic() - { - return this.isPublic; - } - - public void setGameType(WorldSettings.GameType par1EnumGameType) - { - this.getConfigurationManager().setGameType(par1EnumGameType); - } - - public boolean isCommandBlockEnabled() - { - return true; - } - - public int getOpPermissionLevel() - { - return 4; - } +package net.minecraft.server.integrated; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.util.concurrent.Callable; +import net.minecraft.client.ClientBrandRetriever; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ThreadLanServerPing; +import net.minecraft.crash.CrashReport; +import net.minecraft.profiler.PlayerUsageSnooper; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.CryptManager; +import net.minecraft.util.HttpUtil; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.WorldManager; +import net.minecraft.world.WorldServer; +import net.minecraft.world.WorldServerMulti; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.WorldType; +import net.minecraft.world.demo.DemoWorldServer; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.ultramine.permission.PermissionRepository; +import org.ultramine.permission.internal.ClientPermissionManager; + +@SideOnly(Side.CLIENT) +public class IntegratedServer extends MinecraftServer +{ + private static final Logger logger = LogManager.getLogger(); + private final Minecraft mc; + private final WorldSettings theWorldSettings; + private boolean isGamePaused; + private boolean isPublic; + private ThreadLanServerPing lanServerPing; + private static final String __OBFID = "CL_00001129"; + + public IntegratedServer(Minecraft par1Minecraft, String par2Str, String par3Str, WorldSettings par4WorldSettings) + { + super(new File(par1Minecraft.mcDataDir, "saves"), par1Minecraft.getProxy()); + this.setServerOwner(par1Minecraft.getSession().getUsername()); + this.setFolderName(par2Str); + this.setWorldName(par3Str); + this.setDemo(par1Minecraft.isDemo()); + this.canCreateBonusChest(par4WorldSettings.isBonusChestEnabled()); + this.setBuildLimit(256); + this.mc = par1Minecraft; + this.setConfigurationManager(new IntegratedPlayerList(this)); + this.theWorldSettings = par4WorldSettings; + } + + protected void loadAllWorlds(String par1Str, String par2Str, long par3, WorldType par5WorldType, String par6Str) + { + this.convertMapIfNeeded(par1Str); + ISaveHandler isavehandler = this.getActiveAnvilConverter().getSaveLoader(par1Str, true); + + WorldServer overWorld = (isDemo() ? new DemoWorldServer(this, isavehandler, par2Str, 0, theProfiler) : new WorldServer(this, isavehandler, par2Str, 0, theWorldSettings, theProfiler)); + for (int dim : DimensionManager.getStaticDimensionIDs()) + { + WorldServer world = (dim == 0 ? overWorld : new WorldServerMulti(this, isavehandler, par2Str, dim, theWorldSettings, overWorld, theProfiler)); + world.addWorldAccess(new WorldManager(this, world)); + + if (!this.isSinglePlayer()) + { + world.getWorldInfo().setGameType(getGameType()); + } + + MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world)); + } + + getMultiWorld().handleClientWorldsInit(); + + this.getConfigurationManager().setPlayerManager(new WorldServer[]{ overWorld }); + this.func_147139_a(this.func_147135_j()); + this.initialWorldChunkLoad(); + } + + protected boolean startServer() throws IOException + { + logger.info("Starting integrated minecraft server version 1.7.2"); + this.setOnlineMode(false); + this.setCanSpawnAnimals(true); + this.setCanSpawnNPCs(true); + this.setAllowPvp(true); + this.setAllowFlight(true); + logger.info("Generating keypair"); + this.setKeyPair(CryptManager.createNewKeyPair()); + this.setPermissionManager(new ClientPermissionManager(getServerOwner(), new PermissionRepository())); // ultramine + if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; } + this.loadAllWorlds(this.getFolderName(), this.getWorldName(), this.theWorldSettings.getSeed(), this.theWorldSettings.getTerrainType(), this.theWorldSettings.func_82749_j()); + this.setMOTD(this.getServerOwner() + " - " + this.worldServers[0].getWorldInfo().getWorldName()); + return FMLCommonHandler.instance().handleServerStarting(this); + } + + public void tick() + { + boolean flag = this.isGamePaused; + this.isGamePaused = Minecraft.getMinecraft().getNetHandler() != null && Minecraft.getMinecraft().isGamePaused(); + + if (!flag && this.isGamePaused) + { + logger.info("Saving and pausing game..."); + this.getConfigurationManager().saveAllPlayerData(); + this.saveAllWorlds(false); + } + + if (!this.isGamePaused) + { + super.tick(); + } + } + + public boolean canStructuresSpawn() + { + return false; + } + + public WorldSettings.GameType getGameType() + { + return this.theWorldSettings.getGameType(); + } + + public EnumDifficulty func_147135_j() + { + return this.mc.gameSettings.difficulty; + } + + public boolean isHardcore() + { + return this.theWorldSettings.getHardcoreEnabled(); + } + + protected File getDataDirectory() + { + return this.mc.mcDataDir; + } + + public boolean isDedicatedServer() + { + return false; + } + + protected void finalTick(CrashReport par1CrashReport) + { + this.mc.crashed(par1CrashReport); + } + + public CrashReport addServerInfoToCrashReport(CrashReport par1CrashReport) + { + par1CrashReport = super.addServerInfoToCrashReport(par1CrashReport); + par1CrashReport.getCategory().addCrashSectionCallable("Type", new Callable() + { + private static final String __OBFID = "CL_00001130"; + public String call() + { + return "Integrated Server (map_client.txt)"; + } + }); + par1CrashReport.getCategory().addCrashSectionCallable("Is Modded", new Callable() + { + private static final String __OBFID = "CL_00001131"; + public String call() + { + String s = ClientBrandRetriever.getClientModName(); + + if (!s.equals("vanilla")) + { + return "Definitely; Client brand changed to \'" + s + "\'"; + } + else + { + s = IntegratedServer.this.getServerModName(); + return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : (Minecraft.class.getSigners() == null ? "Very likely; Jar signature invalidated" : "Probably not. Jar signature remains and both client + server brands are untouched."); + } + } + }); + return par1CrashReport; + } + + public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) + { + super.addServerStatsToSnooper(par1PlayerUsageSnooper); + par1PlayerUsageSnooper.addData("snooper_partner", this.mc.getPlayerUsageSnooper().getUniqueID()); + } + + public boolean isSnooperEnabled() + { + return Minecraft.getMinecraft().isSnooperEnabled(); + } + + public String shareToLAN(WorldSettings.GameType par1EnumGameType, boolean par2) + { + try + { + int i = -1; + + try + { + i = HttpUtil.func_76181_a(); + } + catch (IOException ioexception) + { + ; + } + + if (i <= 0) + { + i = 25564; + } + + this.func_147137_ag().addLanEndpoint((InetAddress)null, i); + logger.info("Started on " + i); + this.isPublic = true; + this.lanServerPing = new ThreadLanServerPing(this.getMOTD(), i + ""); + this.lanServerPing.start(); + this.getConfigurationManager().setGameType(par1EnumGameType); + this.getConfigurationManager().setCommandsAllowedForAll(par2); + return i + ""; + } + catch (IOException ioexception1) + { + return null; + } + } + + public void stopServer() + { + super.stopServer(); + + if (this.lanServerPing != null) + { + this.lanServerPing.interrupt(); + this.lanServerPing = null; + } + } + + public void initiateShutdown() + { + super.initiateShutdown(); + + if (this.lanServerPing != null) + { + this.lanServerPing.interrupt(); + this.lanServerPing = null; + } + } + + public boolean getPublic() + { + return this.isPublic; + } + + public void setGameType(WorldSettings.GameType par1EnumGameType) + { + this.getConfigurationManager().setGameType(par1EnumGameType); + } + + public boolean isCommandBlockEnabled() + { + return true; + } + + public int getOpPermissionLevel() + { + return 4; + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/management/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/management/ServerConfigurationManager.java index ed57fbe..ecc0448 100644 --- a/src/main/java/net/minecraft/server/management/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/management/ServerConfigurationManager.java @@ -78,8 +78,8 @@ private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); private final MinecraftServer mcServer; public final List playerEntityList = new ArrayList(); - private final BanList bannedPlayers = new BanList(new File(ConfigurationHandler.getSettingDir(), "banned-players.txt")); - private final BanList bannedIPs = new BanList(new File(ConfigurationHandler.getSettingDir(), "banned-ips.txt")); + private final BanList bannedPlayers; + private final BanList bannedIPs; private final Set ops = new HashSet(); private final Set whiteListedPlayers = new HashSet(); private final Map field_148547_k = Maps.newHashMap(); @@ -95,6 +95,8 @@ public ServerConfigurationManager(MinecraftServer par1MinecraftServer) { this.mcServer = par1MinecraftServer; + this.bannedPlayers = new BanList(mcServer.getFile("banned-players.txt")); + this.bannedIPs = new BanList(mcServer.getFile("banned-ips.txt")); this.bannedPlayers.setListActive(false); this.bannedIPs.setListActive(false); this.maxPlayers = 8; diff --git a/src/main/java/org/ultramine/server/ConfigurationHandler.java b/src/main/java/org/ultramine/server/ConfigurationHandler.java index 99fb251..364f2ab 100644 --- a/src/main/java/org/ultramine/server/ConfigurationHandler.java +++ b/src/main/java/org/ultramine/server/ConfigurationHandler.java @@ -9,7 +9,10 @@ import org.ultramine.server.util.YamlConfigProvider; import cpw.mods.fml.relauncher.FMLLaunchHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +@SideOnly(Side.SERVER) public class ConfigurationHandler { public static Logger log = LogManager.getLogger(); diff --git a/src/main/java/org/ultramine/server/MultiWorld.java b/src/main/java/org/ultramine/server/MultiWorld.java index ecb20f6..9bceef1 100644 --- a/src/main/java/org/ultramine/server/MultiWorld.java +++ b/src/main/java/org/ultramine/server/MultiWorld.java @@ -18,10 +18,10 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.handshake.NetworkDispatcher; import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; import net.minecraft.server.MinecraftServer; -import net.minecraft.world.EnumDifficulty; import net.minecraft.world.WorldManager; import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServerMulti; @@ -69,6 +69,7 @@ nameToWorldMap.remove(event.world.getWorldInfo().getWorldName()); } + @SideOnly(Side.SERVER) public void handleServerWorldsInit() { DimensionManager.registerProviderType(-10, org.ultramine.server.wempty.WorldProviderEmpty.class, false); @@ -126,6 +127,18 @@ } } + @SideOnly(Side.CLIENT) + public void handleClientWorldsInit() + { + WorldConfig conf = new WorldConfig(); + conf.mobSpawn = new WorldConfig.MobSpawn(); + conf.settings = new WorldConfig.Settings(); + conf.chunkLoading = new WorldConfig.ChunkLoading(); + for(WorldServer world : server.worldServers) + world.setConfig(conf); + } + + @SideOnly(Side.SERVER) public void initDimension(int dim) { ISaveFormat format = server.getActiveAnvilConverter(); @@ -152,6 +165,7 @@ initWorld(world, conf); } + @SideOnly(Side.SERVER) private WorldSettings makeSettings(ISaveHandler save, WorldConfig conf) { WorldInfo mainWorldInfo = save.loadWorldInfo(); @@ -183,6 +197,7 @@ } } + @SideOnly(Side.SERVER) private void initWorld(WorldServer world, WorldConfig conf) { world.addWorldAccess(new WorldManager(server, world)); diff --git a/src/main/java/org/ultramine/server/UltramineServerModContainer.java b/src/main/java/org/ultramine/server/UltramineServerModContainer.java index 35c5490..ea0154c 100644 --- a/src/main/java/org/ultramine/server/UltramineServerModContainer.java +++ b/src/main/java/org/ultramine/server/UltramineServerModContainer.java @@ -54,13 +54,15 @@ @Subscribe public void preInit(FMLPreInitializationEvent e) { - ConfigurationHandler.load(); + if(e.getSide().isServer()) + ConfigurationHandler.load(); } @Subscribe public void postInit(FMLPostInitializationEvent e) { - ConfigurationHandler.saveServerConfig(); + if(e.getSide().isServer()) + ConfigurationHandler.saveServerConfig(); } @Subscribe diff --git a/src/main/java/org/ultramine/server/WatchdogThread.java b/src/main/java/org/ultramine/server/WatchdogThread.java index d188207..8cabd84 100644 --- a/src/main/java/org/ultramine/server/WatchdogThread.java +++ b/src/main/java/org/ultramine/server/WatchdogThread.java @@ -1,118 +1,122 @@ -package org.ultramine.server; - -import java.lang.management.ManagementFactory; -import java.lang.management.MonitorInfo; -import java.lang.management.ThreadInfo; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class WatchdogThread extends Thread -{ - Logger log = LogManager.getLogger(); - - private static WatchdogThread instance; - private final long timeoutTime; - private final boolean restart; - private volatile long lastTick; - private volatile boolean stopping; - - private WatchdogThread(long timeoutTime, boolean restart) - { - super("Spigot Watchdog Thread"); - this.timeoutTime = timeoutTime; - this.restart = restart; - } - - public static void doStart(int timeoutTime, boolean restart) - { - if(instance == null) - { - instance = new WatchdogThread(timeoutTime * 1000L, restart); - instance.start(); - } - } - - public static void doStart() - { - doStart(ConfigurationHandler.getServerConfig().watchdogThread.timeout, ConfigurationHandler.getServerConfig().watchdogThread.restart); - } - - public static void tick() - { - instance.lastTick = System.currentTimeMillis(); - } - - public static void doStop() - { - if(instance != null) - { - instance.stopping = true; - } - } - - @Override - public void run() - { - while(!stopping) - { - // - if(lastTick != 0 && System.currentTimeMillis() > lastTick + timeoutTime) - { - log.log(Level.FATAL, "The server has stopped responding!"); - - log.log(Level.FATAL, "Current Thread State:"); - ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true); - - for(ThreadInfo thread : threads) - { - if(thread.getThreadState() != State.WAITING) - { - log.log(Level.FATAL, "------------------------------"); - // - log.log(Level.FATAL, "Current Thread: " + thread.getThreadName()); - log.log(Level.FATAL, "\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " - + thread.getThreadState()); - - if(thread.getLockedMonitors().length != 0) - { - log.log(Level.FATAL, "\tThread is waiting on monitor(s):"); - - for(MonitorInfo monitor : thread.getLockedMonitors()) - { - log.log(Level.FATAL, "\t\tLocked on:" + monitor.getLockedStackFrame()); - } - } - - log.log(Level.FATAL, "\tStack:"); - // - StackTraceElement[] stack = thread.getStackTrace(); - - for(int line = 0; line < stack.length; line++) - { - log.log(Level.FATAL, "\t\t" + stack[line].toString()); - } - } - } - - log.log(Level.FATAL, "------------------------------"); - - if(restart) - { - System.exit(0); - } - - break; - } - - try - { - sleep(10000); - } catch (InterruptedException ex) - { - // interrupt(); - } - } - } -} +package org.ultramine.server; + +import java.lang.management.ManagementFactory; +import java.lang.management.MonitorInfo; +import java.lang.management.ThreadInfo; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.SERVER) +public class WatchdogThread extends Thread +{ + Logger log = LogManager.getLogger(); + + private static WatchdogThread instance; + private final long timeoutTime; + private final boolean restart; + private volatile long lastTick; + private volatile boolean stopping; + + private WatchdogThread(long timeoutTime, boolean restart) + { + super("Spigot Watchdog Thread"); + this.timeoutTime = timeoutTime; + this.restart = restart; + } + + public static void doStart(int timeoutTime, boolean restart) + { + if(instance == null) + { + instance = new WatchdogThread(timeoutTime * 1000L, restart); + instance.start(); + } + } + + public static void doStart() + { + doStart(ConfigurationHandler.getServerConfig().watchdogThread.timeout, ConfigurationHandler.getServerConfig().watchdogThread.restart); + } + + public static void tick() + { + instance.lastTick = System.currentTimeMillis(); + } + + public static void doStop() + { + if(instance != null) + { + instance.stopping = true; + } + } + + @Override + public void run() + { + while(!stopping) + { + // + if(lastTick != 0 && System.currentTimeMillis() > lastTick + timeoutTime) + { + log.log(Level.FATAL, "The server has stopped responding!"); + + log.log(Level.FATAL, "Current Thread State:"); + ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true); + + for(ThreadInfo thread : threads) + { + if(thread.getThreadState() != State.WAITING) + { + log.log(Level.FATAL, "------------------------------"); + // + log.log(Level.FATAL, "Current Thread: " + thread.getThreadName()); + log.log(Level.FATAL, "\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " + + thread.getThreadState()); + + if(thread.getLockedMonitors().length != 0) + { + log.log(Level.FATAL, "\tThread is waiting on monitor(s):"); + + for(MonitorInfo monitor : thread.getLockedMonitors()) + { + log.log(Level.FATAL, "\t\tLocked on:" + monitor.getLockedStackFrame()); + } + } + + log.log(Level.FATAL, "\tStack:"); + // + StackTraceElement[] stack = thread.getStackTrace(); + + for(int line = 0; line < stack.length; line++) + { + log.log(Level.FATAL, "\t\t" + stack[line].toString()); + } + } + } + + log.log(Level.FATAL, "------------------------------"); + + if(restart) + { + System.exit(0); + } + + break; + } + + try + { + sleep(10000); + } catch (InterruptedException ex) + { + // interrupt(); + } + } + } +} diff --git a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java index 9511792..6d5d5dd 100644 --- a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java +++ b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java @@ -13,7 +13,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; -import org.ultramine.server.ConfigurationHandler; import org.ultramine.server.util.BlockFace; import org.ultramine.server.util.ChunkCoordComparator; import org.ultramine.server.util.TIntArrayListImpl; @@ -43,7 +42,7 @@ private PlayerManager manager; private BlockFace lastFace; - private final TIntArrayListImpl toSend = new TIntArrayListImpl((int)Math.pow(ConfigurationHandler.getWorldsConfig().global.chunkLoading.viewDistance, 2)); + private final TIntArrayListImpl toSend = new TIntArrayListImpl(441); private final TIntSet sending = TCollections.synchronizedSet(new TIntHashSet()); private final TIntSet sended = new TIntHashSet(); private final Queue toUpdate = Queues.newConcurrentLinkedQueue();