Introduced World Save Thread and some refractoring
This commit is contained in:
@ -13,6 +13,8 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class KCauldron {
|
||||
public static final ThreadGroup sKCauldronThreadGroup = new ThreadGroup("KCauldron");
|
||||
|
||||
private static boolean sManifestParsed = false;
|
||||
|
||||
private static void parseManifest() {
|
||||
|
@ -26,155 +26,155 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class KCauldronCommand extends Command {
|
||||
public static final String NAME = "kc";
|
||||
public static final String CHECK = NAME + ".check";
|
||||
public static final String UPDATE = NAME + ".update";
|
||||
public static final String TPS = NAME + ".tps";
|
||||
public static final String RESTART = NAME + ".restart";
|
||||
public static final String DUMP = NAME + ".dump";
|
||||
public static final String NAME = "kc";
|
||||
public static final String CHECK = NAME + ".check";
|
||||
public static final String UPDATE = NAME + ".update";
|
||||
public static final String TPS = NAME + ".tps";
|
||||
public static final String RESTART = NAME + ".restart";
|
||||
public static final String DUMP = NAME + ".dump";
|
||||
|
||||
public KCauldronCommand() {
|
||||
super(NAME);
|
||||
public KCauldronCommand() {
|
||||
super(NAME);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(String.format("/%s check - Check to update\n", NAME));
|
||||
builder.append(String.format("/%s update [version] - Update to specified or latest version\n", NAME));
|
||||
builder.append(String.format("/%s tps - Show tps statistics\n", NAME));
|
||||
builder.append(String.format("/%s restart - Restart server\n", NAME));
|
||||
builder.append(String.format("/%s dump - Dump statistics into kcauldron.dump file\n", NAME));
|
||||
setUsage(builder.toString());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(String.format("/%s check - Check to update\n", NAME));
|
||||
builder.append(String.format("/%s update [version] - Update to specified or latest version\n", NAME));
|
||||
builder.append(String.format("/%s tps - Show tps statistics\n", NAME));
|
||||
builder.append(String.format("/%s restart - Restart server\n", NAME));
|
||||
builder.append(String.format("/%s dump - Dump statistics into kcauldron.dump file\n", NAME));
|
||||
setUsage(builder.toString());
|
||||
|
||||
setPermission("kc");
|
||||
}
|
||||
setPermission("kc");
|
||||
}
|
||||
|
||||
public boolean testPermission(CommandSender target, String permission) {
|
||||
if (testPermissionSilent(target, permission)) {
|
||||
return true;
|
||||
}
|
||||
target.sendMessage(ChatColor.RED
|
||||
+ "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
|
||||
return false;
|
||||
}
|
||||
public boolean testPermission(CommandSender target, String permission) {
|
||||
if (testPermissionSilent(target, permission)) {
|
||||
return true;
|
||||
}
|
||||
target.sendMessage(ChatColor.RED
|
||||
+ "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean testPermissionSilent(CommandSender target, String permission) {
|
||||
if (!super.testPermissionSilent(target)) {
|
||||
return false;
|
||||
}
|
||||
for (String p : permission.split(";"))
|
||||
if (target.hasPermission(p))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public boolean testPermissionSilent(CommandSender target, String permission) {
|
||||
if (!super.testPermissionSilent(target)) {
|
||||
return false;
|
||||
}
|
||||
for (String p : permission.split(";"))
|
||||
if (target.hasPermission(p))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender))
|
||||
return true;
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Please specify action");
|
||||
sender.sendMessage(ChatColor.AQUA + usageMessage);
|
||||
return true;
|
||||
}
|
||||
String action = args[0];
|
||||
if ("check".equals(action)) {
|
||||
if (!testPermission(sender, CHECK))
|
||||
return true;
|
||||
sender.sendMessage(ChatColor.GREEN + "Initiated version check...");
|
||||
KVersionRetriever.startServer(new CommandSenderUpdateCallback(sender), false);
|
||||
} else if ("update".equals(action)) {
|
||||
KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1] : null);
|
||||
} else if ("tps".equals(action)) {
|
||||
if (!testPermission(sender, TPS))
|
||||
return true;
|
||||
World currentWorld = null;
|
||||
if (sender instanceof CraftPlayer) {
|
||||
currentWorld = ((CraftPlayer) sender).getWorld();
|
||||
}
|
||||
sender.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
|
||||
final MinecraftServer server = MinecraftServer.getServer();
|
||||
for (World world : server.server.getWorlds()) {
|
||||
if (world instanceof CraftWorld) {
|
||||
boolean current = currentWorld != null && currentWorld == world;
|
||||
net.minecraft.world.World mcWorld = ((CraftWorld) world).getHandle();
|
||||
String bukkitName = world.getName();
|
||||
int dimensionId = mcWorld.provider.dimensionId;
|
||||
String name = mcWorld.provider.getDimensionName();
|
||||
String displayName = name.equals(bukkitName) ? name : String.format("%s | %s", name, bukkitName);
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender))
|
||||
return true;
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Please specify action");
|
||||
sender.sendMessage(ChatColor.AQUA + usageMessage);
|
||||
return true;
|
||||
}
|
||||
String action = args[0];
|
||||
if ("check".equals(action)) {
|
||||
if (!testPermission(sender, CHECK))
|
||||
return true;
|
||||
sender.sendMessage(ChatColor.GREEN + "Initiated version check...");
|
||||
KVersionRetriever.startServer(new CommandSenderUpdateCallback(sender), false);
|
||||
} else if ("update".equals(action)) {
|
||||
KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1] : null);
|
||||
} else if ("tps".equals(action)) {
|
||||
if (!testPermission(sender, TPS))
|
||||
return true;
|
||||
World currentWorld = null;
|
||||
if (sender instanceof CraftPlayer) {
|
||||
currentWorld = ((CraftPlayer) sender).getWorld();
|
||||
}
|
||||
sender.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
|
||||
final MinecraftServer server = MinecraftServer.getServer();
|
||||
for (World world : server.server.getWorlds()) {
|
||||
if (world instanceof CraftWorld) {
|
||||
boolean current = currentWorld != null && currentWorld == world;
|
||||
net.minecraft.world.World mcWorld = ((CraftWorld) world).getHandle();
|
||||
String bukkitName = world.getName();
|
||||
int dimensionId = mcWorld.provider.dimensionId;
|
||||
String name = mcWorld.provider.getDimensionName();
|
||||
String displayName = name.equals(bukkitName) ? name : String.format("%s | %s", name, bukkitName);
|
||||
|
||||
double worldTickTime = mean(server.worldTickTimes.get(dimensionId)) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
double worldTickTime = mean(server.worldTickTimes.get(dimensionId)) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
|
||||
sender.sendMessage(String.format("%s[%d] %s%s %s- %s%.2fms / %.2ftps", ChatColor.GOLD, dimensionId,
|
||||
current ? ChatColor.GREEN : ChatColor.YELLOW, displayName, ChatColor.RESET,
|
||||
ChatColor.DARK_RED, worldTickTime, worldTPS));
|
||||
}
|
||||
}
|
||||
double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0 / meanTickTime, 20);
|
||||
sender.sendMessage(String.format("%sOverall - %s%s%.2fms / %.2ftps", ChatColor.BLUE, ChatColor.RESET,
|
||||
ChatColor.DARK_RED, meanTickTime, meanTPS));
|
||||
} else if ("restart".equals(action)) {
|
||||
if (!testPermission(sender, RESTART))
|
||||
return true;
|
||||
KCauldron.restart();
|
||||
} else if ("dump".equals(action)) {
|
||||
if (!testPermission(sender, DUMP))
|
||||
return true;
|
||||
try {
|
||||
File outputFile = new File("kcauldron.dump");
|
||||
OutputStream os = new FileOutputStream(outputFile);
|
||||
Writer writer = new OutputStreamWriter(os);
|
||||
for (WorldServer world : DimensionManager.getWorlds()) {
|
||||
writer.write(String.format("Stats for %s [%s] with id %d\n", world,
|
||||
world.provider.getDimensionName(), world.dimension));
|
||||
writer.write("Current tick: " + world.worldInfo.getWorldTotalTime() + "\n");
|
||||
writer.write("\nEntities: ");
|
||||
writer.write("count - " + world.loadedEntityList_KC.size() + "\n");
|
||||
for (Entity entity : world.loadedEntityList_KC) {
|
||||
writer.write(String.format(" %s at (%.4f;%.4f;%.4f)\n", entity.getClass().getName(),
|
||||
entity.posX, entity.posY, entity.posZ));
|
||||
}
|
||||
writer.write("\nTileEntities: ");
|
||||
writer.write("count - " + world.loadedTileEntityList_KC.size() + "\n");
|
||||
for (TileEntity entity : world.loadedTileEntityList_KC) {
|
||||
writer.write(String.format(" %s at (%d;%d;%d)\n", entity.getClass().getName(), entity.xCoord,
|
||||
entity.yCoord, entity.zCoord));
|
||||
}
|
||||
writer.write("\nLoaded chunks: ");
|
||||
writer.write("count - " + world.activeChunkSet_CB.size() + "\n");
|
||||
for (long chunkKey : world.activeChunkSet_CB.keys()) {
|
||||
final int x = WorldServer.keyToX(chunkKey);
|
||||
final int z = WorldServer.keyToZ(chunkKey);
|
||||
Chunk chunk = world.chunkProvider.provideChunk(x, z);
|
||||
if (chunk == null)
|
||||
continue;
|
||||
writer.write(String.format("Chunk at (%d;%d)\n", x, z));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<NextTickListEntry> updates = world.getPendingBlockUpdates(chunk, false);
|
||||
writer.write("Pending block updates [" + updates.size() + "]:\n");
|
||||
for (NextTickListEntry entry : updates) {
|
||||
writer.write(String.format("(%d;%d;%d) at %d with priority %d\n", entry.xCoord,
|
||||
entry.yCoord, entry.zCoord, entry.scheduledTime, entry.priority));
|
||||
}
|
||||
}
|
||||
writer.write("-------------------------\n");
|
||||
}
|
||||
writer.close();
|
||||
sender.sendMessage(ChatColor.RED + "Dump saved!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown action");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(String.format("%s[%d] %s%s %s- %s%.2fms / %.2ftps", ChatColor.GOLD, dimensionId,
|
||||
current ? ChatColor.GREEN : ChatColor.YELLOW, displayName, ChatColor.RESET,
|
||||
ChatColor.DARK_RED, worldTickTime, worldTPS));
|
||||
}
|
||||
}
|
||||
double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0 / meanTickTime, 20);
|
||||
sender.sendMessage(String.format("%sOverall - %s%s%.2fms / %.2ftps", ChatColor.BLUE, ChatColor.RESET,
|
||||
ChatColor.DARK_RED, meanTickTime, meanTPS));
|
||||
} else if ("restart".equals(action)) {
|
||||
if (!testPermission(sender, RESTART))
|
||||
return true;
|
||||
KCauldron.restart();
|
||||
} else if ("dump".equals(action)) {
|
||||
if (!testPermission(sender, DUMP))
|
||||
return true;
|
||||
try {
|
||||
File outputFile = new File("kcauldron.dump");
|
||||
OutputStream os = new FileOutputStream(outputFile);
|
||||
Writer writer = new OutputStreamWriter(os);
|
||||
for (WorldServer world : DimensionManager.getWorlds()) {
|
||||
writer.write(String.format("Stats for %s [%s] with id %d\n", world,
|
||||
world.provider.getDimensionName(), world.dimension));
|
||||
writer.write("Current tick: " + world.worldInfo.getWorldTotalTime() + "\n");
|
||||
writer.write("\nEntities: ");
|
||||
writer.write("count - " + world.loadedEntityList_KC.size() + "\n");
|
||||
for (Entity entity : world.loadedEntityList_KC) {
|
||||
writer.write(String.format(" %s at (%.4f;%.4f;%.4f)\n", entity.getClass().getName(),
|
||||
entity.posX, entity.posY, entity.posZ));
|
||||
}
|
||||
writer.write("\nTileEntities: ");
|
||||
writer.write("count - " + world.loadedTileEntityList_KC.size() + "\n");
|
||||
for (TileEntity entity : world.loadedTileEntityList_KC) {
|
||||
writer.write(String.format(" %s at (%d;%d;%d)\n", entity.getClass().getName(), entity.xCoord,
|
||||
entity.yCoord, entity.zCoord));
|
||||
}
|
||||
writer.write("\nLoaded chunks: ");
|
||||
writer.write("count - " + world.activeChunkSet_CB.size() + "\n");
|
||||
for (long chunkKey : world.activeChunkSet_CB.keys()) {
|
||||
final int x = WorldServer.keyToX(chunkKey);
|
||||
final int z = WorldServer.keyToZ(chunkKey);
|
||||
Chunk chunk = world.chunkProvider.provideChunk(x, z);
|
||||
if (chunk == null)
|
||||
continue;
|
||||
writer.write(String.format("Chunk at (%d;%d)\n", x, z));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<NextTickListEntry> updates = world.getPendingBlockUpdates(chunk, false);
|
||||
writer.write("Pending block updates [" + updates.size() + "]:\n");
|
||||
for (NextTickListEntry entry : updates) {
|
||||
writer.write(String.format("(%d;%d;%d) at %d with priority %d\n", entry.xCoord,
|
||||
entry.yCoord, entry.zCoord, entry.scheduledTime, entry.priority));
|
||||
}
|
||||
}
|
||||
writer.write("-------------------------\n");
|
||||
}
|
||||
writer.close();
|
||||
sender.sendMessage(ChatColor.RED + "Dump saved!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown action");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final long mean(long[] array) {
|
||||
long r = 0;
|
||||
for (long i : array)
|
||||
r += i;
|
||||
return r / array.length;
|
||||
}
|
||||
private static final long mean(long[] array) {
|
||||
long r = 0;
|
||||
for (long i : array)
|
||||
r += i;
|
||||
return r / array.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
57
src/main/java/kcauldron/KCauldronWorldSaveThread.java
Normal file
57
src/main/java/kcauldron/KCauldronWorldSaveThread.java
Normal file
@ -0,0 +1,57 @@
|
||||
package kcauldron;
|
||||
|
||||
import org.bukkit.craftbukkit.SpigotTimings;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.MinecraftException;
|
||||
|
||||
public class KCauldronWorldSaveThread extends Thread {
|
||||
private final MinecraftServer mServer;
|
||||
private int mLastSaveTick = -1;
|
||||
private int mNextSaveTick = -1;
|
||||
|
||||
public KCauldronWorldSaveThread(MinecraftServer server) {
|
||||
super(KCauldron.sKCauldronThreadGroup, "KCauldron World Save");
|
||||
mServer = server;
|
||||
setPriority(Thread.MIN_PRIORITY);
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
KLog.get().info("Starting KCauldron World Saver thread...");
|
||||
try {
|
||||
while (!isInterrupted()) {
|
||||
if (mLastSaveTick < 0) {
|
||||
mLastSaveTick = mServer.tickCounter;
|
||||
}
|
||||
mNextSaveTick = mLastSaveTick + mServer.autosavePeriod;
|
||||
while (mNextSaveTick > mServer.tickCounter) {
|
||||
try {
|
||||
sleep((mNextSaveTick - mServer.tickCounter) * 50);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
SpigotTimings.worldSaveTimer.startTiming();
|
||||
try {
|
||||
mServer.serverConfigManager.saveAllPlayerData();
|
||||
mServer.saveAllWorlds(true);
|
||||
} catch (MinecraftException e) {
|
||||
new RuntimeException("Error occurred during save world", e).printStackTrace();
|
||||
}
|
||||
SpigotTimings.worldSaveTimer.stopTiming();
|
||||
mLastSaveTick = mServer.tickCounter;
|
||||
}
|
||||
} finally {
|
||||
KLog.get().info("Stopping KCauldron World Saver thread...");
|
||||
}
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
interrupt();
|
||||
while(isAlive()) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
@ -86,8 +86,7 @@ public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
|
||||
public KCauldronUpdater(CommandSender sender, String version) {
|
||||
mSender = sender;
|
||||
mVersion = version;
|
||||
mThread = new Thread(this);
|
||||
mThread.setName("KCauldron updater");
|
||||
mThread = new Thread(KCauldron.sKCauldronThreadGroup, this, "KCauldron updated");
|
||||
mThread.setPriority(Thread.MIN_PRIORITY);
|
||||
mThread.start();
|
||||
}
|
||||
|
@ -56,8 +56,7 @@ public class KVersionRetriever implements Runnable, UncaughtExceptionHandler {
|
||||
mUpToDateSupport = upToDateSupport;
|
||||
mGroup = group;
|
||||
mName = name;
|
||||
mThread = new Thread(this);
|
||||
mThread.setName("KCauldron version retrievier");
|
||||
mThread = new Thread(KCauldron.sKCauldronThreadGroup, this, "KCauldron version retrievier");
|
||||
mThread.setPriority(Thread.MIN_PRIORITY);
|
||||
mThread.setDaemon(true);
|
||||
mThread.setUncaughtExceptionHandler(this);
|
||||
|
@ -44,7 +44,7 @@ class ThreadPlayerLookupUUID extends Thread
|
||||
String s = (new BigInteger(CryptManager.getServerIdHash(NetHandlerLoginServer.getLoginServerId(this.field_151292_a), this.mcServer.getKeyPair().getPublic(), NetHandlerLoginServer.getSecretKey(this.field_151292_a)))).toString(16);
|
||||
GameProfile profile = this.mcServer.func_147130_as().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s);
|
||||
if (profile != null) {
|
||||
NetHandlerLoginServer.processPlayerLoginGameProfile(this.field_151292_a, profile);
|
||||
NetHandlerLoginServer.processPlayerLoginGameProfile(this.field_151292_a, profile);
|
||||
fireLoginEvents(); // Spigot
|
||||
}
|
||||
else if (this.mcServer.isSinglePlayer())
|
||||
|
@ -134,7 +134,7 @@ public class CauldronCommand extends Command
|
||||
sender.sendMessage("Chunk info complete");
|
||||
}
|
||||
|
||||
private boolean getToggle(CommandSender sender, String[] args)
|
||||
private boolean getToggle(CommandSender sender, String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1,23 +1,23 @@
|
||||
package net.minecraftforge.cauldron.configuration;
|
||||
|
||||
public class StringSetting extends Setting<String> {
|
||||
private String value;
|
||||
private ConfigBase config;
|
||||
private String value;
|
||||
private ConfigBase config;
|
||||
|
||||
public StringSetting(ConfigBase config, String path, String def,
|
||||
String description) {
|
||||
super(path, def, description);
|
||||
this.value = def;
|
||||
this.config = config;
|
||||
}
|
||||
public StringSetting(ConfigBase config, String path, String def,
|
||||
String description) {
|
||||
super(path, def, description);
|
||||
this.value = def;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
config.set(path, this.value = value);
|
||||
}
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
config.set(path, this.value = value);
|
||||
}
|
||||
}
|
||||
|
@ -263,6 +263,7 @@ public final class CraftServer implements Server {
|
||||
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
|
||||
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||
console.invalidateWorldSaver();
|
||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||
loadIcon();
|
||||
chunkGCEnabled = configuration.getBoolean("chunk-gc.enabled"); // Cauldron
|
||||
@ -764,6 +765,7 @@ public final class CraftServer implements Server {
|
||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||
printSaveWarning = false;
|
||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||
console.invalidateWorldSaver();
|
||||
chunkGCPeriod = configuration.getInt("chunk-gc.period-in-ticks");
|
||||
chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
|
||||
loadIcon();
|
||||
@ -1307,7 +1309,7 @@ public final class CraftServer implements Server {
|
||||
// Spigot start
|
||||
GameProfile profile = null;
|
||||
if (MinecraftServer.getServer().isServerInOnlineMode() || org.spigotmc.SpigotConfig.bungee) {
|
||||
profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(name);
|
||||
profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(name);
|
||||
}
|
||||
if (profile == null) {
|
||||
// Make an OfflinePlayer using an offline mode UUID since the name has no profile
|
||||
|
@ -88,7 +88,7 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
Chunk chunk = getChunkAt(x >> 4, z >> 4);
|
||||
Chunk chunk = getChunkAt(x >> 4, z >> 4);
|
||||
return chunk == null ? null : chunk.getBlock(x & 0xF, y & 0xFF, z & 0xF);
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ public class CraftWorld implements World {
|
||||
}
|
||||
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
net.minecraft.world.chunk.Chunk chunk = this.world.theChunkProviderServer.loadChunk(x, z);
|
||||
net.minecraft.world.chunk.Chunk chunk = this.world.theChunkProviderServer.loadChunk(x, z);
|
||||
return chunk == null ? null : chunk.bukkitChunk;
|
||||
}
|
||||
|
||||
@ -1395,23 +1395,23 @@ public class CraftWorld implements World {
|
||||
|
||||
final net.minecraft.world.gen.ChunkProviderServer cps = world.theChunkProviderServer;
|
||||
cps.loadedChunkHashMap_KC.forEachValue(new TObjectProcedure<net.minecraft.world.chunk.Chunk>() {
|
||||
@Override
|
||||
public boolean execute(net.minecraft.world.chunk.Chunk chunk) {
|
||||
// If in use, skip it
|
||||
if (isChunkInUse(chunk.xPosition, chunk.zPosition)) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean execute(net.minecraft.world.chunk.Chunk chunk) {
|
||||
// If in use, skip it
|
||||
if (isChunkInUse(chunk.xPosition, chunk.zPosition)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Already unloading?
|
||||
if (cps.chunksToUnload.contains(chunk.xPosition, chunk.zPosition)) {
|
||||
return true;
|
||||
}
|
||||
// Already unloading?
|
||||
if (cps.chunksToUnload.contains(chunk.xPosition, chunk.zPosition)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add unload request
|
||||
cps.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// Add unload request
|
||||
cps.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Spigot start
|
||||
|
@ -166,7 +166,7 @@ public class CraftSkull extends CraftBlockState implements Skull {
|
||||
}
|
||||
|
||||
public BlockFace getRotation() {
|
||||
return getBlockFace(rotation);
|
||||
return getBlockFace(rotation);
|
||||
}
|
||||
|
||||
public void setRotation(BlockFace rotation) {
|
||||
|
@ -416,7 +416,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
// Spigot start
|
||||
net.minecraft.world.WorldServer newWorld = ((CraftWorld) location.getWorld()).getHandle();
|
||||
if (newWorld != entity.worldObj) {
|
||||
entity.teleportTo(location, cause.isPortal());
|
||||
entity.teleportTo(location, cause.isPortal());
|
||||
return true;
|
||||
}
|
||||
// Spigot
|
||||
|
@ -44,7 +44,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
}
|
||||
|
||||
public PlayerInventory getInventory() {
|
||||
if (inventory == null) inventory = new CraftInventoryPlayer(((net.minecraft.entity.player.EntityPlayer) entity).inventory);
|
||||
if (inventory == null) inventory = new CraftInventoryPlayer(((net.minecraft.entity.player.EntityPlayer) entity).inventory);
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
}
|
||||
|
||||
public Inventory getEnderChest() {
|
||||
if (enderChest == null) enderChest = new CraftInventory(((net.minecraft.entity.player.EntityPlayer) entity).getInventoryEnderChest());
|
||||
if (enderChest == null) enderChest = new CraftInventory(((net.minecraft.entity.player.EntityPlayer) entity).getInventoryEnderChest());
|
||||
return enderChest;
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
firstPlayed = System.currentTimeMillis();
|
||||
double maxHealth = entity.getEntityAttribute(SharedMonsterAttributes.maxHealth).getBaseValue();
|
||||
if (maxHealth != health) {
|
||||
healthScale = maxHealth;
|
||||
scaledHealth = true;
|
||||
healthScale = maxHealth;
|
||||
scaledHealth = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,9 +80,9 @@ public final class CraftChatMessage {
|
||||
currentChatComponent = null;
|
||||
break;
|
||||
case 3:
|
||||
if (match.indexOf("://") < 0) {
|
||||
match = "http://" + match;
|
||||
}
|
||||
if (match.indexOf("://") < 0) {
|
||||
match = "http://" + match;
|
||||
}
|
||||
modifier.setChatClickEvent(new net.minecraft.event.ClickEvent(net.minecraft.event.ClickEvent.Action.OPEN_URL, match)); // Should be setChatClickable
|
||||
appendNewComponent(matcher.end(groupId));
|
||||
modifier.setChatClickEvent((net.minecraft.event.ClickEvent) null);
|
||||
|
@ -188,7 +188,7 @@ public class LongHashSet implements Set<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void clear() {
|
||||
elements = 0;
|
||||
for (int ix = 0; ix < values.length; ix++) {
|
||||
@ -214,9 +214,9 @@ public class LongHashSet implements Set<Long> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public Long[] toArray() {
|
||||
Long[] result = new Long[elements];
|
||||
Long[] result = new Long[elements];
|
||||
long[] values = Java15Compat.Arrays_copyOf(this.values, this.values.length);
|
||||
int pos = 0;
|
||||
|
||||
@ -229,10 +229,10 @@ public class LongHashSet implements Set<Long> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public <T> T[] toArray(T[] arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public long popFirst() {
|
||||
for (long value : values) {
|
||||
@ -359,52 +359,52 @@ public class LongHashSet implements Set<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Long value) {
|
||||
return add(value.longValue());
|
||||
}
|
||||
@Override
|
||||
public boolean add(Long value) {
|
||||
return add(value.longValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Long> collection) {
|
||||
boolean result = false;
|
||||
for (Long value : collection) result |= add(value.longValue());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Long> collection) {
|
||||
boolean result = false;
|
||||
for (Long value : collection) result |= add(value.longValue());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o instanceof Long ? contains(((Long) o).longValue()) : false;
|
||||
}
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o instanceof Long ? contains(((Long) o).longValue()) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> collection) {
|
||||
for (Object value : collection) if (!contains(value)) return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> collection) {
|
||||
for (Object value : collection) if (!contains(value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return o instanceof Long ? remove(((Long) o).longValue()) : false;
|
||||
}
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return o instanceof Long ? remove(((Long) o).longValue()) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> collection) {
|
||||
boolean result = false;
|
||||
for (Object value : collection) result |= remove(value);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> collection) {
|
||||
boolean result = false;
|
||||
for (Object value : collection) result |= remove(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> collection) {
|
||||
boolean result = false;
|
||||
Iterator<Long> iterator = iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Long l = iterator.next();
|
||||
if (!collection.contains(l)) {
|
||||
iterator.remove();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> collection) {
|
||||
boolean result = false;
|
||||
Iterator<Long> iterator = iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Long l = iterator.next();
|
||||
if (!collection.contains(l)) {
|
||||
iterator.remove();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class LongObjectHashMap<V> implements Cloneable, Serializable {
|
||||
* @return Set of Entry objects
|
||||
*/
|
||||
public Set<Map.Entry<Long, V>> entrySet() {
|
||||
return new EntrySet();
|
||||
return new EntrySet();
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
@ -425,40 +425,40 @@ public class LongObjectHashMap<V> implements Cloneable, Serializable {
|
||||
}
|
||||
|
||||
private void bind(long key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class EntrySet extends AbstractSet<Map.Entry<Long, V>> {
|
||||
@Override
|
||||
public Iterator<Map.Entry<Long, V>> iterator() {
|
||||
return new Iterator<Map.Entry<Long, V>>() {
|
||||
final Entry entry = new Entry();
|
||||
final ValueIterator valueIterator = new ValueIterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return valueIterator.hasNext();
|
||||
}
|
||||
@Override
|
||||
public Iterator<Map.Entry<Long, V>> iterator() {
|
||||
return new Iterator<Map.Entry<Long, V>>() {
|
||||
final Entry entry = new Entry();
|
||||
final ValueIterator valueIterator = new ValueIterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return valueIterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongObjectHashMap<V>.Entry next() {
|
||||
V value = valueIterator.next();
|
||||
entry.bind(valueIterator.prevKey, value);
|
||||
return entry;
|
||||
}
|
||||
@Override
|
||||
public LongObjectHashMap<V>.Entry next() {
|
||||
V value = valueIterator.next();
|
||||
entry.bind(valueIterator.prevKey, value);
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
valueIterator.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
valueIterator.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return LongObjectHashMap.this.size;
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return LongObjectHashMap.this.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class RestartCommand extends Command
|
||||
}
|
||||
|
||||
public static void restart() {
|
||||
restart(false);
|
||||
restart(false);
|
||||
}
|
||||
|
||||
public static void restart(boolean forbidShutdown)
|
||||
@ -102,10 +102,10 @@ public class RestartCommand extends Command
|
||||
Runtime.getRuntime().addShutdownHook( shutdownHook );
|
||||
} else
|
||||
{
|
||||
if (forbidShutdown) {
|
||||
System.out.println("Attempt to restart server without restart script, decline request");
|
||||
return;
|
||||
}
|
||||
if (forbidShutdown) {
|
||||
System.out.println("Attempt to restart server without restart script, decline request");
|
||||
return;
|
||||
}
|
||||
System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||
}
|
||||
cpw.mods.fml.common.FMLCommonHandler.instance().exitJava(0, false);
|
||||
|
@ -271,6 +271,6 @@ public class SpigotConfig
|
||||
public static int fullMatchRate;
|
||||
private static void fullMatchRate()
|
||||
{
|
||||
fullMatchRate = getInt( "settings.fullMatchRate", 10);
|
||||
fullMatchRate = getInt( "settings.fullMatchRate", 10);
|
||||
}
|
||||
}
|
||||
|
@ -283,8 +283,8 @@ public class SpigotWorldConfig
|
||||
public int entityMaxTickTime;
|
||||
private void maxTickTimes()
|
||||
{
|
||||
tileMaxTickTime = getInt("max-tick-time.tile", 50);
|
||||
entityMaxTickTime = getInt("max-tick-time.entity", 50);
|
||||
log("Tile Max Tick Time: " + tileMaxTickTime + "ms Entity max Tick Time: " + entityMaxTickTime + "ms");
|
||||
tileMaxTickTime = getInt("max-tick-time.tile", 50);
|
||||
entityMaxTickTime = getInt("max-tick-time.entity", 50);
|
||||
log("Tile Max Tick Time: " + tileMaxTickTime + "ms Entity max Tick Time: " + entityMaxTickTime + "ms");
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package org.spigotmc;
|
||||
|
||||
public class TickLimiter {
|
||||
private final int maxTime;
|
||||
private long startTime;
|
||||
private int tick;
|
||||
private boolean shouldContinue;
|
||||
public TickLimiter(int maxTime) {
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
public void initTick() {
|
||||
startTime = System.currentTimeMillis();
|
||||
tick = 0;
|
||||
shouldContinue = true;
|
||||
}
|
||||
|
||||
public boolean shouldContinue() {
|
||||
if (++tick >= 300 && shouldContinue) {
|
||||
tick = 0;
|
||||
shouldContinue = System.currentTimeMillis() - startTime < maxTime;
|
||||
}
|
||||
return shouldContinue;
|
||||
}
|
||||
private final int maxTime;
|
||||
private long startTime;
|
||||
private int tick;
|
||||
private boolean shouldContinue;
|
||||
public TickLimiter(int maxTime) {
|
||||
this.maxTime = maxTime;
|
||||
}
|
||||
|
||||
public void initTick() {
|
||||
startTime = System.currentTimeMillis();
|
||||
tick = 0;
|
||||
shouldContinue = true;
|
||||
}
|
||||
|
||||
public boolean shouldContinue() {
|
||||
if (++tick >= 300 && shouldContinue) {
|
||||
tick = 0;
|
||||
shouldContinue = System.currentTimeMillis() - startTime < maxTime;
|
||||
}
|
||||
return shouldContinue;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user