3
0

Finally fix #67

This commit is contained in:
Prototik 2015-06-27 16:32:21 +07:00
parent 9fdf330495
commit 8c50b9899f
19 changed files with 737 additions and 704 deletions

View File

@ -73,7 +73,7 @@
if (this.players.isEmpty())
{
+ if (this.theWorldServer.loadedEntityList.size() == 0 || this.theWorldServer.theChunkProviderServer.loadedChunkHashMap.size() == 0)
+ if (this.theWorldServer.loadedEntityList.size() == 0 || this.theWorldServer.theChunkProviderServer.loadedChunkHashMap_KC.size() == 0)
+ {
+ return; // CraftBukkit - Only do unload when we go from non-empty to empty
+ }

View File

@ -67,11 +67,11 @@
- public List loadedChunks = new ArrayList();
+ public boolean loadChunkOnProvideRequest = MinecraftServer.getServer().cauldronConfig.loadChunkOnRequest.getValue(); // Cauldron - if true, allows mods to force load chunks. to disable, set load-chunk-on-request in cauldron.yml to false
+ public int initialTick; // Cauldron counter to keep track of when this loader was created
+ public TLongObjectMap<Chunk> loadedChunkHashMap = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>());
+ public TLongObjectMap<Chunk> loadedChunkHashMap_KC = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>());
+ public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility
public WorldServer worldObj;
private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet();
+ public LongHashMap loadedChunkHashMap_vanilla = new LongHashMap(); // Cauldron - vanilla/mystcraft compatibility
+ public LongHashMap loadedChunkHashMap = new kcauldron.wrapper.VanillaChunkHashMap(loadedChunkHashMap_KC); // KCauldron - vanilla/mystcraft compatibility
private static final String __OBFID = "CL_00001436";
public ChunkProviderServer(WorldServer p_i1520_1_, IChunkLoader p_i1520_2_, IChunkProvider p_i1520_3_)
@ -85,7 +85,7 @@
public boolean chunkExists(int p_73149_1_, int p_73149_2_)
{
- return this.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(p_73149_1_, p_73149_2_));
+ return this.loadedChunkHashMap.containsKey(LongHash.toLong(p_73149_1_, p_73149_2_)); // CraftBukkit
+ return this.loadedChunkHashMap_KC.containsKey(LongHash.toLong(p_73149_1_, p_73149_2_)); // CraftBukkit
}
- public List func_152380_a()
@ -102,7 +102,7 @@
{
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ Chunk c = this.loadedChunkHashMap.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+
+ if (c != null)
+ {
@ -118,7 +118,7 @@
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ // CraftBukkit start
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ Chunk c = this.loadedChunkHashMap.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+
+ if (c != null)
+ {
@ -138,7 +138,7 @@
- Chunk chunk = (Chunk)iterator.next();
- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
- }
+ this.loadedChunkHashMap.forEachValue(new TObjectProcedure<Chunk>() {
+ this.loadedChunkHashMap_KC.forEachValue(new TObjectProcedure<Chunk>() {
+ @Override
+ public boolean execute(Chunk chunk) {
+ unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
@ -156,7 +156,7 @@
- this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(par1, par2);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap.get(LongHash.toLong(par1, par2));
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(par1, par2));
+ boolean newChunk = false;
AnvilChunkLoader loader = null;
@ -178,7 +178,7 @@
- this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(p_73158_1_, p_73158_2_);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap.get(LongHash.toLong(p_73158_1_, p_73158_2_));
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73158_1_, p_73158_2_));
+ boolean newChunk = false; // CraftBukkit
if (chunk == null)
@ -195,7 +195,7 @@
if (chunk == null)
{
chunk = this.safeLoadChunk(p_73158_1_, p_73158_2_);
@@ -176,18 +235,40 @@
@@ -176,18 +235,39 @@
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception generating new chunk");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Chunk to be generated");
crashreportcategory.addCrashSection("Location", String.format("%d,%d", new Object[] {Integer.valueOf(p_73158_1_), Integer.valueOf(p_73158_2_)}));
@ -213,9 +213,8 @@
- this.loadedChunks.add(chunk);
- loadingChunks.remove(k);
- chunk.onChunkLoad();
+ this.loadedChunkHashMap.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit
+ this.loadedChunkHashMap_KC.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit
+ this.loadedChunks.add(chunk); // Cauldron - vanilla compatibility
+ this.loadedChunkHashMap_vanilla.add(ChunkCoordIntPair.chunkXZ2Int(p_73158_1_, p_73158_2_), chunk); // Cauldron - vanilla/mystcraft compatibility
+ loadingChunks.remove(LongHash.toLong(p_73158_1_, p_73158_2_)); // Cauldron - LongHash
+
+ if (chunk != null)
@ -241,14 +240,14 @@
}
return chunk;
@@ -195,11 +276,29 @@
@@ -195,11 +275,29 @@
public Chunk provideChunk(int p_73154_1_, int p_73154_2_)
{
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(p_73154_1_, p_73154_2_));
- return chunk == null ? (!this.worldObj.findingSpawnPoint && !this.loadChunkOnProvideRequest ? this.defaultEmptyChunk : this.loadChunk(p_73154_1_, p_73154_2_)) : chunk;
+ // CraftBukkit start
+ Chunk chunk = (Chunk) this.loadedChunkHashMap.get(LongHash.toLong(p_73154_1_, p_73154_2_));
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73154_1_, p_73154_2_));
+ chunk = chunk == null ? (shouldLoadChunk() ? this.loadChunk(p_73154_1_, p_73154_2_) : this.defaultEmptyChunk) : chunk; // Cauldron handle forge server tick events and load the chunk within 5 seconds of the world being loaded (for chunk loaders)
+
+ if (chunk == this.defaultEmptyChunk)
@ -274,7 +273,7 @@
{
if (this.currentChunkLoader == null)
{
@@ -209,6 +308,7 @@
@@ -209,6 +307,7 @@
{
try
{
@ -282,7 +281,7 @@
Chunk chunk = this.currentChunkLoader.loadChunk(this.worldObj, p_73239_1_, p_73239_2_);
if (chunk != null)
@@ -217,8 +317,11 @@
@@ -217,8 +316,11 @@
if (this.currentChunkProvider != null)
{
@ -294,7 +293,7 @@
}
return chunk;
@@ -231,7 +334,7 @@
@@ -231,7 +333,7 @@
}
}
@ -303,7 +302,7 @@
{
if (this.currentChunkLoader != null)
{
@@ -246,7 +349,7 @@
@@ -246,7 +348,7 @@
}
}
@ -312,7 +311,7 @@
{
if (this.currentChunkLoader != null)
{
@@ -254,15 +357,18 @@
@@ -254,15 +356,18 @@
{
p_73242_1_.lastSaveTime = this.worldObj.getTotalWorldTime();
this.currentChunkLoader.saveChunk(this.worldObj, p_73242_1_);
@ -332,7 +331,7 @@
}
}
@@ -277,6 +383,35 @@
@@ -277,6 +382,35 @@
if (this.currentChunkProvider != null)
{
this.currentChunkProvider.populate(p_73153_1_, p_73153_2_, p_73153_3_);
@ -368,7 +367,7 @@
GameRegistry.generateWorld(p_73153_2_, p_73153_3_, worldObj, currentChunkProvider, p_73153_1_);
chunk.setChunkModified();
}
@@ -286,11 +421,13 @@
@@ -286,11 +420,13 @@
public boolean saveChunks(boolean p_73151_1_, IProgressUpdate p_73151_2_)
{
int i = 0;
@ -385,7 +384,7 @@
if (p_73151_1_)
{
@@ -325,36 +462,61 @@
@@ -325,36 +461,60 @@
{
if (!this.worldObj.levelSaving)
{
@ -408,7 +407,7 @@
{
- if (!this.chunksToUnload.isEmpty())
+ long chunkcoordinates = this.chunksToUnload.popFirst();
+ Chunk chunk = this.loadedChunkHashMap.get(chunkcoordinates);
+ Chunk chunk = this.loadedChunkHashMap_KC.get(chunkcoordinates);
+
+ if (chunk == null)
{
@ -451,11 +450,10 @@
+ this.safeSaveChunk(chunk);
+ this.safeSaveExtraChunkData(chunk);
+ // this.unloadQueue.remove(olong);
+ this.loadedChunkHashMap.remove(chunkcoordinates); // CraftBukkit
+ this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit
+ this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility
+ this.loadedChunkHashMap_vanilla.remove(ChunkCoordIntPair.chunkXZ2Int(LongHash.msw(chunkcoordinates), LongHash.lsw(chunkcoordinates))); // Cauldron - vanilla/mystcraft compatibility
+ ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk);
+ if(this.loadedChunkHashMap.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
+ if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
+ DimensionManager.unloadWorld(this.worldObj.provider.dimensionId);
+ return currentChunkProvider.unloadQueuedChunks();
+ }
@ -467,21 +465,21 @@
if (this.currentChunkLoader != null)
{
this.currentChunkLoader.chunkTick();
@@ -371,7 +533,7 @@
@@ -371,7 +531,7 @@
public String makeString()
{
- return "ServerChunkCache: " + this.loadedChunkHashMap.getNumHashElements() + " Drop: " + this.chunksToUnload.size();
+ return "ServerChunkCache: " + this.loadedChunkHashMap.size() + " Drop: " + this.chunksToUnload.size(); // Cauldron
+ return "ServerChunkCache: " + this.loadedChunkHashMap_KC.size() + " Drop: " + this.chunksToUnload.size(); // Cauldron
}
public List getPossibleCreatures(EnumCreatureType p_73155_1_, int p_73155_2_, int p_73155_3_, int p_73155_4_)
@@ -386,8 +548,31 @@
@@ -386,8 +546,31 @@
public int getLoadedChunkCount()
{
- return this.loadedChunkHashMap.getNumHashElements();
+ return this.loadedChunkHashMap.size(); // Cauldron
+ return this.loadedChunkHashMap_KC.size(); // Cauldron
}
public void recreateStructures(int p_82695_1_, int p_82695_2_) {}
@ -498,8 +496,8 @@
+ public long lastAccessed(int x, int z)
+ {
+ long chunkHash = LongHash.toLong(x, z);
+ if (!loadedChunkHashMap.containsKey(chunkHash)) return 0;
+ return loadedChunkHashMap.get(chunkHash).lastAccessedTick;
+ if (!loadedChunkHashMap_KC.containsKey(chunkHash)) return 0;
+ return loadedChunkHashMap_KC.get(chunkHash).lastAccessedTick;
+ }
+
+ /*private boolean shouldUnloadChunk(Chunk chunk)

View File

@ -10,14 +10,13 @@
class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChunk, net.minecraft.world.chunk.Chunk, Runnable, RuntimeException> {
private final AtomicInteger threadNumber = new AtomicInteger(1);
@@ -41,13 +44,21 @@
@@ -41,13 +44,20 @@
queuedChunk.loader.loadEntities(queuedChunk.world, queuedChunk.compound.getCompoundTag("Level"), chunk);
MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(chunk, queuedChunk.compound)); // Don't call ChunkDataEvent.Load async
chunk.lastSaveTime = queuedChunk.provider.worldObj.getTotalWorldTime();
- queuedChunk.provider.loadedChunkHashMap.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk);
+ queuedChunk.provider.loadedChunkHashMap.put(LongHash.toLong(queuedChunk.x, queuedChunk.z), chunk);
+ queuedChunk.provider.loadedChunkHashMap_KC.put(LongHash.toLong(queuedChunk.x, queuedChunk.z), chunk);
queuedChunk.provider.loadedChunks.add(chunk);
+ queuedChunk.provider.loadedChunkHashMap_vanilla.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk); // Cauldron - vanilla/mystcraft compatibility
chunk.onChunkLoad();
if (queuedChunk.provider.currentChunkProvider != null) {

View File

@ -9,96 +9,96 @@ import java.util.Properties;
import org.spigotmc.RestartCommand;
public class KCauldron {
private static boolean sManifestParsed = false;
private static boolean sManifestParsed = false;
private static void parseManifest() {
if (sManifestParsed)
return;
sManifestParsed = true;
private static void parseManifest() {
if (sManifestParsed)
return;
sManifestParsed = true;
try {
Enumeration<URL> resources = KCauldron.class.getClassLoader()
.getResources("META-INF/MANIFEST.MF");
Properties manifest = new Properties();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
manifest.load(url.openStream());
String version = manifest.getProperty("KCauldron-Version");
if (version != null) {
String path = url.getPath();
String jarFilePath = path.substring(path.indexOf(":") + 1,
path.indexOf("!"));
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
try {
Enumeration<URL> resources = KCauldron.class.getClassLoader()
.getResources("META-INF/MANIFEST.MF");
Properties manifest = new Properties();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
manifest.load(url.openStream());
String version = manifest.getProperty("KCauldron-Version");
if (version != null) {
String path = url.getPath();
String jarFilePath = path.substring(path.indexOf(":") + 1,
path.indexOf("!"));
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
sCurrentVersion = version;
sGroup = manifest.getProperty("KCauldron-Group");
sBranch = manifest.getProperty("KCauldron-Branch");
sChannel = manifest.getProperty("KCauldron-Channel");
break;
}
manifest.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
}
sCurrentVersion = version;
sGroup = manifest.getProperty("KCauldron-Group");
sBranch = manifest.getProperty("KCauldron-Branch");
sChannel = manifest.getProperty("KCauldron-Channel");
break;
}
manifest.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String sCurrentVersion;
private static String sCurrentVersion;
public static String getCurrentVersion() {
parseManifest();
return sCurrentVersion;
}
public static String getCurrentVersion() {
parseManifest();
return sCurrentVersion;
}
private static File sServerLocation;
private static File sServerLocation;
public static File getServerLocation() {
parseManifest();
return sServerLocation;
}
public static File getServerLocation() {
parseManifest();
return sServerLocation;
}
private static File sServerHome;
private static File sServerHome;
public static File getServerHome() {
if (sServerHome == null) {
String home = System.getenv("KCAULDRON_HOME");
if (home != null) {
sServerHome = new File(home);
} else {
parseManifest();
sServerHome = sServerLocation.getParentFile();
}
}
return sServerHome;
}
public static File getServerHome() {
if (sServerHome == null) {
String home = System.getenv("KCAULDRON_HOME");
if (home != null) {
sServerHome = new File(home);
} else {
parseManifest();
sServerHome = sServerLocation.getParentFile();
}
}
return sServerHome;
}
private static String sGroup;
private static String sGroup;
public static String getGroup() {
parseManifest();
return sGroup;
}
public static String getGroup() {
parseManifest();
return sGroup;
}
private static String sBranch;
private static String sBranch;
public static String getBranch() {
parseManifest();
return sBranch;
}
public static String getBranch() {
parseManifest();
return sBranch;
}
private static String sChannel;
private static String sChannel;
public static String getChannel() {
parseManifest();
return sChannel;
}
public static String getChannel() {
parseManifest();
return sChannel;
}
public static File sNewServerLocation;
public static String sNewServerVersion;
public static boolean sUpdateInProgress;
public static File sNewServerLocation;
public static String sNewServerVersion;
public static boolean sUpdateInProgress;
public static void restart() {
RestartCommand.restart(true);
}
public static void restart() {
RestartCommand.restart(true);
}
}

View File

@ -1,13 +1,10 @@
package kcauldron;
import static org.objectweb.asm.Opcodes.*;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.GETFIELD;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
@ -19,64 +16,28 @@ import cpw.mods.fml.common.FMLLog;
@Transformer.RegisterTransformer
public class KCauldronClassTransformer implements Transformer {
@Override
public void transform(final ImagineASM asm) {
if (asm.is("net.minecraft.world.gen.ChunkProviderServer")
|| asm.is("net.minecraftforge.common.chunkio.ChunkIOProvider")
|| asm.is("org.bukkit.craftbukkit.CraftWorld")
|| asm.is("org.bukkit.craftbukkit.v1_7_R4.CraftWorld")) {
FMLLog.log(Level.INFO, "KCauldron: Patching " + asm.getActualName() + " for compatibility with Mystcraft");
ClassReader reader = new ClassReader(asm.build());
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(new ClassVisitor(ASM5, writer) {
@Override
public FieldVisitor visitField(int access, String name,
String desc, String signature, Object value) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = asm.isDev() ? "loadedChunkHashMap" : "field_73244_f";
}
return super.visitField(access, name, desc, signature,
value);
}
@Override
public void transform(final ImagineASM asm) {
if (asm.is("climateControl.utils.ChunkGeneratorExtractor")) {
boolean undergroundBiomesInstalled = false;
try {
Class.forName("exterminatorJeff.undergroundBiomes.worldGen.ChunkProviderWrapper");
undergroundBiomesInstalled = true;
} catch (Exception ignored) {
}
if (!undergroundBiomesInstalled) {
FMLLog.log(Level.INFO, "KCauldron: Patching " + asm.getActualName() + " for compatibility with Climate Control");
extractFrom(asm, asm.method("extractFrom",
"(Lnet/minecraft/world/WorldServer;)Lnet/minecraft/world/chunk/IChunkProvider;").instructions());
}
}
}
@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new MethodVisitor(api, super.visitMethod(access,
name, desc, signature, exceptions)) {
@Override
public void visitFieldInsn(int opcode, String owner,
String name, String desc) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = asm.isDev() ? "loadedChunkHashMap" : "field_73244_f";
}
super.visitFieldInsn(opcode, owner, name, desc);
}
};
}
}, 0);
asm.loadClass(writer.toByteArray());
}
if (asm.is("climateControl.utils.ChunkGeneratorExtractor")) {
boolean undergroundBiomesInstalled = false;
try {
Class.forName("exterminatorJeff.undergroundBiomes.worldGen.ChunkProviderWrapper");
undergroundBiomesInstalled = true;
} catch (Exception ignored) {
}
if (!undergroundBiomesInstalled) {
FMLLog.log(Level.INFO, "KCauldron: Patching " + asm.getActualName() + " for compatibility with Climate Control");
extractFrom(asm, asm.method("extractFrom",
"(Lnet/minecraft/world/WorldServer;)Lnet/minecraft/world/chunk/IChunkProvider;").instructions());
}
}
}
public void extractFrom(ImagineASM asm, InsnList list) {
//Pair<String, String> fieldChunkProvider = asm.field("net/minecraft/world/World", "chunkProvider");
list.clear();
list.add(new IntInsnNode(ALOAD, 1));
list.add(new FieldInsnNode(GETFIELD, "ahb", "v", "Lapu;"));
list.add(new InsnNode(ARETURN));
}
public void extractFrom(ImagineASM asm, InsnList list) {
//Pair<String, String> fieldChunkProvider = asm.field("net/minecraft/world/World", "chunkProvider");
list.clear();
list.add(new IntInsnNode(ALOAD, 1));
list.add(new FieldInsnNode(GETFIELD, "ahb", "v", "Lapu;"));
list.add(new InsnNode(ARETURN));
}
}

View File

@ -9,72 +9,72 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
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 RESTART = NAME + ".restart";
public static final String NAME = "kc";
public static final String CHECK = NAME + ".check";
public static final String UPDATE = NAME + ".update";
public static final String RESTART = NAME + ".restart";
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 restart - Restart server\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 restart - Restart server\n", NAME));
setUsage(builder.toString());
setPermission("kcauldron");
}
setPermission("kcauldron");
}
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 ("restart".equals(action)) {
if (!testPermission(sender, RESTART))
return true;
KCauldron.restart();
} else {
sender.sendMessage(ChatColor.RED + "Unknown action");
}
return true;
}
@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 ("restart".equals(action)) {
if (!testPermission(sender, RESTART))
return true;
KCauldron.restart();
} else {
sender.sendMessage(ChatColor.RED + "Unknown action");
}
return true;
}
}

View File

@ -9,71 +9,71 @@ import net.minecraftforge.cauldron.configuration.Setting;
import net.minecraftforge.cauldron.configuration.StringSetting;
public class KCauldronConfig extends ConfigBase {
public BoolSetting commandEnable = new BoolSetting(this, "command.enable",
true, "Enable KCauldron command");
public BoolSetting updatecheckerEnable = new BoolSetting(this,
"updatechecker.enable", true, "Enable KCauldron update checker");
public StringSetting updatecheckerSymlinks = new StringSetting(this,
"updatechecker.symlinks", "KCauldron.jar", "(Re)create symlinks after update");
public BoolSetting updatecheckerAutoinstall = new BoolSetting(this,
"updatechecker.autoinstall", false, "Install updates without confirming");
public BoolSetting updatecheckerAutorestart = new BoolSetting(this,
"updatechecker.autorestart", false, "Restart server after updating without confirming (set restart script in spigot.yml)");
public BoolSetting updatecheckerQuite = new BoolSetting(this,
"updatechecker.quite", false, "Print less info during update");
public BoolSetting commandEnable = new BoolSetting(this, "command.enable",
true, "Enable KCauldron command");
public BoolSetting updatecheckerEnable = new BoolSetting(this,
"updatechecker.enable", true, "Enable KCauldron update checker");
public StringSetting updatecheckerSymlinks = new StringSetting(this,
"updatechecker.symlinks", "KCauldron.jar", "(Re)create symlinks after update");
public BoolSetting updatecheckerAutoinstall = new BoolSetting(this,
"updatechecker.autoinstall", false, "Install updates without confirming");
public BoolSetting updatecheckerAutorestart = new BoolSetting(this,
"updatechecker.autorestart", false, "Restart server after updating without confirming (set restart script in spigot.yml)");
public BoolSetting updatecheckerQuite = new BoolSetting(this,
"updatechecker.quite", false, "Print less info during update");
public BoolSetting loggingMaterialInjection = new BoolSetting(this,
"logging.materialInjection", false, "Log material injection event");
public BoolSetting loggingMaterialInjection = new BoolSetting(this,
"logging.materialInjection", false, "Log material injection event");
public KCauldronConfig() {
super("kcauldron.yml", "kc");
register(commandEnable);
register(updatecheckerEnable);
register(updatecheckerSymlinks);
register(updatecheckerAutoinstall);
register(updatecheckerAutorestart);
register(updatecheckerQuite);
register(loggingMaterialInjection);
load();
}
public KCauldronConfig() {
super("kcauldron.yml", "kc");
register(commandEnable);
register(updatecheckerEnable);
register(updatecheckerSymlinks);
register(updatecheckerAutoinstall);
register(updatecheckerAutorestart);
register(updatecheckerQuite);
register(loggingMaterialInjection);
load();
}
private void register(Setting<?> setting) {
settings.put(setting.path, setting);
}
private void register(Setting<?> setting) {
settings.put(setting.path, setting);
}
@Override
public void registerCommands() {
if (commandEnable.getValue()) {
super.registerCommands();
}
}
@Override
public void registerCommands() {
if (commandEnable.getValue()) {
super.registerCommands();
}
}
@Override
protected void addCommands() {
commands.put(commandName, new KCauldronCommand());
}
@Override
protected void addCommands() {
commands.put(commandName, new KCauldronCommand());
}
@Override
protected void load() {
try {
config = YamlConfiguration.loadConfiguration(configFile);
String header = "";
for (Setting<?> toggle : settings.values()) {
if (!toggle.description.equals(""))
header += "Setting: " + toggle.path + " Default: "
+ toggle.def + " # " + toggle.description + "\n";
@Override
protected void load() {
try {
config = YamlConfiguration.loadConfiguration(configFile);
String header = "";
for (Setting<?> toggle : settings.values()) {
if (!toggle.description.equals(""))
header += "Setting: " + toggle.path + " Default: "
+ toggle.def + " # " + toggle.description + "\n";
config.addDefault(toggle.path, toggle.def);
settings.get(toggle.path).setValue(
config.getString(toggle.path));
}
config.options().header(header);
config.options().copyDefaults(true);
save();
} catch (Exception ex) {
MinecraftServer.getServer().logSevere(
"Could not load " + this.configFile);
ex.printStackTrace();
}
}
config.addDefault(toggle.path, toggle.def);
settings.get(toggle.path).setValue(
config.getString(toggle.path));
}
config.options().header(header);
config.options().copyDefaults(true);
save();
} catch (Exception ex) {
MinecraftServer.getServer().logSevere(
"Could not load " + this.configFile);
ex.printStackTrace();
}
}
}

View File

@ -4,16 +4,16 @@ import net.md_5.specialsource.JarMapping;
import net.md_5.specialsource.JarRemapper;
public class KCauldronRemapper extends JarRemapper {
public KCauldronRemapper(JarMapping jarMapping) {
super(jarMapping);
}
public KCauldronRemapper(JarMapping jarMapping) {
super(jarMapping);
}
@Override
public String mapSignature(String signature, boolean typeSignature) {
try {
return super.mapSignature(signature, typeSignature);
} catch (Exception e) {
return signature;
}
}
@Override
public String mapSignature(String signature, boolean typeSignature) {
try {
return super.mapSignature(signature, typeSignature);
} catch (Exception e) {
return signature;
}
}
}

View File

@ -5,48 +5,48 @@ import org.apache.logging.log4j.Level;
import cpw.mods.fml.common.FMLLog;
public class KLog {
private static final KLog DEFAULT_LOGGER = new KLog("KCauldron");
private static final KLog DEFAULT_LOGGER = new KLog("KCauldron");
public static KLog get() {
return DEFAULT_LOGGER;
}
public static KLog get() {
return DEFAULT_LOGGER;
}
public static KLog get(String tag) {
return new KLog("KCauldron: " + tag);
}
public static KLog get(String tag) {
return new KLog("KCauldron: " + tag);
}
private final String mTag;
private final String mTag;
public KLog(String tag) {
mTag = tag;
}
public KLog(String tag) {
mTag = tag;
}
public void log(Level level, Throwable throwable, String message,
Object... args) {
Throwable t = null;
if (throwable != null) {
t = new Throwable();
t.initCause(throwable);
t.fillInStackTrace();
}
FMLLog.log(mTag, level, t, String.format(message, args));
}
public void log(Level level, Throwable throwable, String message,
Object... args) {
Throwable t = null;
if (throwable != null) {
t = new Throwable();
t.initCause(throwable);
t.fillInStackTrace();
}
FMLLog.log(mTag, level, t, String.format(message, args));
}
public void warning(String message, Object... args) {
log(Level.WARN, null, message, args);
}
public void warning(String message, Object... args) {
log(Level.WARN, null, message, args);
}
public void warning(Throwable throwable, String message,
Object... args) {
log(Level.WARN, throwable, message, args);
}
public void warning(Throwable throwable, String message,
Object... args) {
log(Level.WARN, throwable, message, args);
}
public void info(String message, Object... args) {
log(Level.INFO, null, message, args);
}
public void info(String message, Object... args) {
log(Level.INFO, null, message, args);
}
public void info(Throwable throwable, String message,
Object... args) {
log(Level.INFO, throwable, message, args);
}
public void info(Throwable throwable, String message,
Object... args) {
log(Level.INFO, throwable, message, args);
}
}

View File

@ -10,52 +10,52 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
public class CommandSenderUpdateCallback implements IVersionCheckCallback {
private Reference<CommandSender> mSender;
private Reference<CommandSender> mSender;
public CommandSenderUpdateCallback(CommandSender sender) {
mSender = new WeakReference<CommandSender>(sender);
}
public CommandSenderUpdateCallback(CommandSender sender) {
mSender = new WeakReference<CommandSender>(sender);
}
protected CommandSender getSender() {
return mSender.get();
}
protected CommandSender getSender() {
return mSender.get();
}
@Override
public void upToDate() {
CommandSender sender = mSender.get();
if (sender != null) {
sender.sendMessage(ChatColor.GREEN
+ "Running version of KCauldron is up-to-date: "
+ KCauldron.getCurrentVersion());
}
DefaultUpdateCallback.INSTANCE.upToDate();
}
@Override
public void upToDate() {
CommandSender sender = mSender.get();
if (sender != null) {
sender.sendMessage(ChatColor.GREEN
+ "Running version of KCauldron is up-to-date: "
+ KCauldron.getCurrentVersion());
}
DefaultUpdateCallback.INSTANCE.upToDate();
}
@Override
public void newVersion(String newVersion) {
CommandSender sender = mSender.get();
if (sender != null) {
newVersion(sender, KCauldron.getCurrentVersion(), newVersion);
}
DefaultUpdateCallback.INSTANCE.newVersion(newVersion);
}
@Override
public void newVersion(String newVersion) {
CommandSender sender = mSender.get();
if (sender != null) {
newVersion(sender, KCauldron.getCurrentVersion(), newVersion);
}
DefaultUpdateCallback.INSTANCE.newVersion(newVersion);
}
public static void newVersion(CommandSender sender, String currentVersion,
String newVersion) {
sender.sendMessage(new String[] {
ChatColor.YELLOW + "Found new version of KCauldron: "
+ newVersion,
ChatColor.YELLOW + "Current is " + currentVersion,
ChatColor.YELLOW + "Type '" + ChatColor.BLUE + "/kc update"
+ ChatColor.YELLOW + "' to update" });
}
public static void newVersion(CommandSender sender, String currentVersion,
String newVersion) {
sender.sendMessage(new String[] {
ChatColor.YELLOW + "Found new version of KCauldron: "
+ newVersion,
ChatColor.YELLOW + "Current is " + currentVersion,
ChatColor.YELLOW + "Type '" + ChatColor.BLUE + "/kc update"
+ ChatColor.YELLOW + "' to update" });
}
@Override
public void error(Throwable t) {
CommandSender sender = mSender.get();
if (sender != null) {
sender.sendMessage(ChatColor.RED
+ "Error ocurred durring version check, see details in server log");
}
}
@Override
public void error(Throwable t) {
CommandSender sender = mSender.get();
if (sender != null) {
sender.sendMessage(ChatColor.RED
+ "Error ocurred durring version check, see details in server log");
}
}
}

View File

@ -11,66 +11,66 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
public class DefaultUpdateCallback implements IVersionCheckCallback {
public static DefaultUpdateCallback INSTANCE;
public static DefaultUpdateCallback INSTANCE;
static {
INSTANCE = new DefaultUpdateCallback();
}
static {
INSTANCE = new DefaultUpdateCallback();
}
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (mHasUpdate && hasPermission(player)) {
sendUpdate(player);
}
}
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (mHasUpdate && hasPermission(player)) {
sendUpdate(player);
}
}
private boolean hasPermission(CommandSender player) {
return player.hasPermission(KCauldronCommand.UPDATE);
}
private boolean hasPermission(CommandSender player) {
return player.hasPermission(KCauldronCommand.UPDATE);
}
private void sendUpdate(CommandSender player) {
CommandSenderUpdateCallback.newVersion(player, mCurrentVersion,
mNewVersion);
}
private void sendUpdate(CommandSender player) {
CommandSenderUpdateCallback.newVersion(player, mCurrentVersion,
mNewVersion);
}
private boolean mHasUpdate;
private String mCurrentVersion;
private String mNewVersion;
private boolean mHasUpdate;
private String mCurrentVersion;
private String mNewVersion;
private DefaultUpdateCallback() {
}
private DefaultUpdateCallback() {
}
@Override
public void upToDate() {
mHasUpdate = false;
mCurrentVersion = KCauldron.getCurrentVersion();
mNewVersion = null;
}
@Override
public void upToDate() {
mHasUpdate = false;
mCurrentVersion = KCauldron.getCurrentVersion();
mNewVersion = null;
}
@Override
public void newVersion(String newVersion) {
mCurrentVersion = KCauldron.getCurrentVersion();
mNewVersion = newVersion;
if (!mHasUpdate) {
Bukkit.getConsoleSender().sendMessage(
"New version of KCauldron avaiable: " + newVersion);
for (Player player : Bukkit.getOnlinePlayers()) {
if (hasPermission(player)) {
sendUpdate(player);
}
}
}
mHasUpdate = true;
if (MinecraftServer.kcauldronConfig.updatecheckerAutoinstall.getValue()
&& !mNewVersion.equals(KCauldron.sNewServerVersion)
&& !KCauldron.sUpdateInProgress) {
Bukkit.getConsoleSender().sendMessage("Triggering auto update");
KCauldronUpdater.initUpdate(Bukkit.getConsoleSender(), newVersion);
}
}
@Override
public void newVersion(String newVersion) {
mCurrentVersion = KCauldron.getCurrentVersion();
mNewVersion = newVersion;
if (!mHasUpdate) {
Bukkit.getConsoleSender().sendMessage(
"New version of KCauldron avaiable: " + newVersion);
for (Player player : Bukkit.getOnlinePlayers()) {
if (hasPermission(player)) {
sendUpdate(player);
}
}
}
mHasUpdate = true;
if (MinecraftServer.kcauldronConfig.updatecheckerAutoinstall.getValue()
&& !mNewVersion.equals(KCauldron.sNewServerVersion)
&& !KCauldron.sUpdateInProgress) {
Bukkit.getConsoleSender().sendMessage("Triggering auto update");
KCauldronUpdater.initUpdate(Bukkit.getConsoleSender(), newVersion);
}
}
@Override
public void error(Throwable t) {
@Override
public void error(Throwable t) {
}
}
}

View File

@ -26,181 +26,181 @@ import org.bukkit.command.CommandSender;
import com.google.common.base.Joiner;
public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
private static final class LatestVersionCallback extends
CommandSenderUpdateCallback {
public LatestVersionCallback(CommandSender sender) {
super(sender);
}
private static final class LatestVersionCallback extends
CommandSenderUpdateCallback {
public LatestVersionCallback(CommandSender sender) {
super(sender);
}
@Override
public void newVersion(String newVersion) {
startUpdate(getSender(), newVersion);
}
@Override
public void newVersion(String newVersion) {
startUpdate(getSender(), newVersion);
}
@Override
public void upToDate() {
KCauldron.sUpdateInProgress = false;
CommandSender sender = getSender();
if (sender != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Current version ("
+ KCauldron.getCurrentVersion() + ") is up to date");
}
}
@Override
public void upToDate() {
KCauldron.sUpdateInProgress = false;
CommandSender sender = getSender();
if (sender != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Current version ("
+ KCauldron.getCurrentVersion() + ") is up to date");
}
}
@Override
public void error(Throwable t) {
super.error(t);
KCauldron.sUpdateInProgress = false;
}
}
@Override
public void error(Throwable t) {
super.error(t);
KCauldron.sUpdateInProgress = false;
}
}
public static void initUpdate(CommandSender sender, String version) {
if (KCauldron.sUpdateInProgress) {
sender.sendMessage(ChatColor.RED
+ "Update stopped: another update in progress");
return;
}
KCauldron.sUpdateInProgress = true;
if (version == null) {
sender.sendMessage(ChatColor.DARK_PURPLE
+ "Fetching latest version...");
KVersionRetriever.startServer(new LatestVersionCallback(sender),
false);
} else {
startUpdate(sender, version);
}
}
public static void initUpdate(CommandSender sender, String version) {
if (KCauldron.sUpdateInProgress) {
sender.sendMessage(ChatColor.RED
+ "Update stopped: another update in progress");
return;
}
KCauldron.sUpdateInProgress = true;
if (version == null) {
sender.sendMessage(ChatColor.DARK_PURPLE
+ "Fetching latest version...");
KVersionRetriever.startServer(new LatestVersionCallback(sender),
false);
} else {
startUpdate(sender, version);
}
}
private static void startUpdate(CommandSender sender, String version) {
if (sender != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Starting update to "
+ version + "...");
}
new KCauldronUpdater(sender, version);
}
private static void startUpdate(CommandSender sender, String version) {
if (sender != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Starting update to "
+ version + "...");
}
new KCauldronUpdater(sender, version);
}
private final CommandSender mSender;
private final String mVersion;
private final Thread mThread;
private final CommandSender mSender;
private final String mVersion;
private final Thread mThread;
public KCauldronUpdater(CommandSender sender, String version) {
mSender = sender;
mVersion = version;
mThread = new Thread(this);
mThread.setName("KCauldron updater");
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.start();
}
public KCauldronUpdater(CommandSender sender, String version) {
mSender = sender;
mVersion = version;
mThread = new Thread(this);
mThread.setName("KCauldron updater");
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.start();
}
@Override
public void run() {
if (!MinecraftServer.kcauldronConfig.updatecheckerQuite.getValue()) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Retrieving latest KBootstrap version...");
}
new KVersionRetriever(this, false, false, "pw.prok", "KBootstrap");
}
@Override
public void run() {
if (!MinecraftServer.kcauldronConfig.updatecheckerQuite.getValue()) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Retrieving latest KBootstrap version...");
}
new KVersionRetriever(this, false, false, "pw.prok", "KBootstrap");
}
@Override
public void upToDate() {
@Override
public void upToDate() {
}
}
@Override
public void newVersion(String kbootstrapVersion) {
boolean quite = MinecraftServer.kcauldronConfig.updatecheckerQuite
.getValue();
try {
if (!quite) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Downloading KBootstrap " + kbootstrapVersion + "...");
}
File kbootstrap = File.createTempFile("kbootstrap",
String.valueOf(System.currentTimeMillis()));
download(
"https://api.prok.pw/repo/blob/pw.prok/KBootstrap/latest/app",
kbootstrap);
if (!quite) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Installing KCauldron " + mVersion
+ " via KBootstrap " + kbootstrapVersion + "...");
}
@Override
public void newVersion(String kbootstrapVersion) {
boolean quite = MinecraftServer.kcauldronConfig.updatecheckerQuite
.getValue();
try {
if (!quite) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Downloading KBootstrap " + kbootstrapVersion + "...");
}
File kbootstrap = File.createTempFile("kbootstrap",
String.valueOf(System.currentTimeMillis()));
download(
"https://api.prok.pw/repo/blob/pw.prok/KBootstrap/latest/app",
kbootstrap);
if (!quite) {
mSender.sendMessage(ChatColor.DARK_PURPLE
+ "Installing KCauldron " + mVersion
+ " via KBootstrap " + kbootstrapVersion + "...");
}
String javahome = System.getProperty("java.home");
String javapath = javahome + "/bin/java";
String javahome = System.getProperty("java.home");
String javapath = javahome + "/bin/java";
List<String> command = new ArrayList<String>();
command.add(javapath);
command.add("-jar");
command.add(kbootstrap.getCanonicalPath());
command.add("--serverDir");
command.add(KCauldron.getServerHome().getCanonicalPath());
command.add("--installKCauldron");
command.add(String.format("%s:%s:%s", KCauldron.getGroup(), KCauldron.getChannel(), mVersion));
final String[] symlinks = MinecraftServer.kcauldronConfig.updatecheckerSymlinks
.getValue().trim().split(File.pathSeparator);
for (String symlink : symlinks) {
command.add("--serverSymlinks");
command.add(symlink);
}
List<String> command = new ArrayList<String>();
command.add(javapath);
command.add("-jar");
command.add(kbootstrap.getCanonicalPath());
command.add("--serverDir");
command.add(KCauldron.getServerHome().getCanonicalPath());
command.add("--installKCauldron");
command.add(String.format("%s:%s:%s", KCauldron.getGroup(), KCauldron.getChannel(), mVersion));
final String[] symlinks = MinecraftServer.kcauldronConfig.updatecheckerSymlinks
.getValue().trim().split(File.pathSeparator);
for (String symlink : symlinks) {
command.add("--serverSymlinks");
command.add(symlink);
}
Bukkit.getConsoleSender().sendMessage(
"Starting command: " + Joiner.on(' ').join(command));
Bukkit.getConsoleSender().sendMessage(
"Starting command: " + Joiner.on(' ').join(command));
ProcessBuilder builder = new ProcessBuilder(command);
builder.environment().put("JAVA_HOME", javahome);
switch (builder.start().waitFor()) {
case 0:
mSender.sendMessage(ChatColor.GREEN + "KCauldron " + mVersion
+ " installed");
break;
default:
mSender.sendMessage(ChatColor.RED
+ "Failed to install KCauldron " + mVersion);
}
} catch (Exception e) {
if (!quite) {
e.printStackTrace();
}
if (mSender != null) {
mSender.sendMessage(ChatColor.RED + "Failed update to "
+ mVersion);
}
} finally {
KCauldron.sUpdateInProgress = false;
}
}
ProcessBuilder builder = new ProcessBuilder(command);
builder.environment().put("JAVA_HOME", javahome);
switch (builder.start().waitFor()) {
case 0:
mSender.sendMessage(ChatColor.GREEN + "KCauldron " + mVersion
+ " installed");
break;
default:
mSender.sendMessage(ChatColor.RED
+ "Failed to install KCauldron " + mVersion);
}
} catch (Exception e) {
if (!quite) {
e.printStackTrace();
}
if (mSender != null) {
mSender.sendMessage(ChatColor.RED + "Failed update to "
+ mVersion);
}
} finally {
KCauldron.sUpdateInProgress = false;
}
}
@Override
public void error(Throwable t) {
KCauldron.sUpdateInProgress = false;
t.printStackTrace();
}
@Override
public void error(Throwable t) {
KCauldron.sUpdateInProgress = false;
t.printStackTrace();
}
private static void download(String url, File destination)
throws IOException {
HttpUriRequest request = RequestBuilder
.get()
.setUri(url)
.addParameter("hostname",
MinecraftServer.getServer().getHostname())
.addParameter("port",
String.valueOf(MinecraftServer.getServer().getPort()))
.build();
CloseableHttpClient client = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent("KCauldron Updater").build();
private static void download(String url, File destination)
throws IOException {
HttpUriRequest request = RequestBuilder
.get()
.setUri(url)
.addParameter("hostname",
MinecraftServer.getServer().getHostname())
.addParameter("port",
String.valueOf(MinecraftServer.getServer().getPort()))
.build();
CloseableHttpClient client = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.setUserAgent("KCauldron Updater").build();
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
client.close();
throw new IllegalStateException("Could not download " + url);
}
InputStream is = response.getEntity().getContent();
OutputStream os = new FileOutputStream(destination);
IOUtils.copy(is, os);
is.close();
os.close();
client.close();
}
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
client.close();
throw new IllegalStateException("Could not download " + url);
}
InputStream is = response.getEntity().getContent();
OutputStream os = new FileOutputStream(destination);
IOUtils.copy(is, os);
is.close();
os.close();
client.close();
}
}

View File

@ -16,112 +16,112 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class KVersionRetriever implements Runnable, UncaughtExceptionHandler {
private static final boolean DEBUG;
private static final KLog sLogger;
private static final JSONParser sParser;
private static MinecraftServer sServer;
private static final boolean DEBUG;
private static final KLog sLogger;
private static final JSONParser sParser;
private static MinecraftServer sServer;
static {
DEBUG = false;
sLogger = KLog.get(KVersionRetriever.class.getSimpleName());
static {
DEBUG = false;
sLogger = KLog.get(KVersionRetriever.class.getSimpleName());
sParser = new JSONParser();
}
sParser = new JSONParser();
}
public static void init(MinecraftServer server) {
sServer = server;
if (MinecraftServer.kcauldronConfig.updatecheckerEnable.getValue()) {
startServer(DefaultUpdateCallback.INSTANCE, true);
}
}
public static void init(MinecraftServer server) {
sServer = server;
if (MinecraftServer.kcauldronConfig.updatecheckerEnable.getValue()) {
startServer(DefaultUpdateCallback.INSTANCE, true);
}
}
public static void startServer(IVersionCheckCallback callback, boolean loop) {
new KVersionRetriever(callback, loop, true, KCauldron.getGroup(),
KCauldron.getChannel());
}
public static void startServer(IVersionCheckCallback callback, boolean loop) {
new KVersionRetriever(callback, loop, true, KCauldron.getGroup(),
KCauldron.getChannel());
}
private final IVersionCheckCallback mCallback;
private final boolean mLoop;
private final Thread mThread;
private final String mGroup;
private final String mName;
private final boolean mUpToDateSupport;
private final IVersionCheckCallback mCallback;
private final boolean mLoop;
private final Thread mThread;
private final String mGroup;
private final String mName;
private final boolean mUpToDateSupport;
public KVersionRetriever(IVersionCheckCallback callback, boolean loop,
boolean upToDateSupport, String group, String name) {
if (DEBUG)
sLogger.info("Created new version retrivier");
mCallback = callback;
mLoop = loop;
mUpToDateSupport = upToDateSupport;
mGroup = group;
mName = name;
mThread = new Thread(this);
mThread.setName("KCauldron version retrievier");
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.setDaemon(true);
mThread.setUncaughtExceptionHandler(this);
mThread.start();
}
public KVersionRetriever(IVersionCheckCallback callback, boolean loop,
boolean upToDateSupport, String group, String name) {
if (DEBUG)
sLogger.info("Created new version retrivier");
mCallback = callback;
mLoop = loop;
mUpToDateSupport = upToDateSupport;
mGroup = group;
mName = name;
mThread = new Thread(this);
mThread.setName("KCauldron version retrievier");
mThread.setPriority(Thread.MIN_PRIORITY);
mThread.setDaemon(true);
mThread.setUncaughtExceptionHandler(this);
mThread.start();
}
@Override
public void run() {
while (!mThread.isInterrupted()) {
check();
if (!mLoop)
break;
try {
Thread.sleep(1000 * 60 * 10);// Sleep ten minutes
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void run() {
while (!mThread.isInterrupted()) {
check();
if (!mLoop)
break;
try {
Thread.sleep(1000 * 60 * 10);// Sleep ten minutes
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void check() {
try {
HttpUriRequest request = RequestBuilder
.get()
.setUri("https://api.prok.pw/repo/version/" + mGroup + "/"
+ mName)
.addParameter("hostname", sServer.getHostname())
.addParameter("port", "" + sServer.getPort()).build();
HttpResponse response = HttpClientBuilder.create()
.setUserAgent("KCauldron Version Retriever")
.setRedirectStrategy(new LaxRedirectStrategy()).build()
.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
uncaughtException(mThread, new IllegalStateException(
"Status code isn't OK"));
return;
}
JSONObject json = (JSONObject) sParser.parse(new InputStreamReader(
response.getEntity().getContent()));
String version = (String) json.get("version");
if (!mUpToDateSupport || KCauldron.getCurrentVersion() == null
|| !version.equals(KCauldron.getCurrentVersion())) {
mCallback.newVersion(version);
} else {
mCallback.upToDate();
}
} catch (Exception e) {
uncaughtException(null, e);
}
}
private void check() {
try {
HttpUriRequest request = RequestBuilder
.get()
.setUri("https://api.prok.pw/repo/version/" + mGroup + "/"
+ mName)
.addParameter("hostname", sServer.getHostname())
.addParameter("port", "" + sServer.getPort()).build();
HttpResponse response = HttpClientBuilder.create()
.setUserAgent("KCauldron Version Retriever")
.setRedirectStrategy(new LaxRedirectStrategy()).build()
.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
uncaughtException(mThread, new IllegalStateException(
"Status code isn't OK"));
return;
}
JSONObject json = (JSONObject) sParser.parse(new InputStreamReader(
response.getEntity().getContent()));
String version = (String) json.get("version");
if (!mUpToDateSupport || KCauldron.getCurrentVersion() == null
|| !version.equals(KCauldron.getCurrentVersion())) {
mCallback.newVersion(version);
} else {
mCallback.upToDate();
}
} catch (Exception e) {
uncaughtException(null, e);
}
}
@Override
public void uncaughtException(Thread t, Throwable e) {
sLogger.warning(e, "Error occured during retriving version");
if (mCallback != null) {
mCallback.error(e);
}
}
@Override
public void uncaughtException(Thread t, Throwable e) {
sLogger.warning(e, "Error occured during retriving version");
if (mCallback != null) {
mCallback.error(e);
}
}
public interface IVersionCheckCallback {
void upToDate();
public interface IVersionCheckCallback {
void upToDate();
void newVersion(String newVersion);
void newVersion(String newVersion);
void error(Throwable t);
}
void error(Throwable t);
}
}

View File

@ -0,0 +1,40 @@
package kcauldron.wrapper;
import gnu.trove.map.TLongObjectMap;
import net.minecraft.util.LongHashMap;
public class LongHashMapTrove<T> extends LongHashMap {
private final TLongObjectMap<T> mMap;
public LongHashMapTrove(TLongObjectMap<T> map) {
mMap = map;
}
@SuppressWarnings("unchecked")
@Override
public void add(long key, Object value) {
mMap.put(key, (T) value);
}
@Override
public int getNumHashElements() {
return mMap.size();
}
@Override
public Object getValueByKey(long key) {
return mMap.get(key);
}
@Override
public boolean containsItem(long key) {
return mMap.containsKey(key);
}
@Override
public Object remove(long key) {
return mMap.remove(key);
}
}

View File

@ -0,0 +1,36 @@
package kcauldron.wrapper;
import gnu.trove.map.TLongObjectMap;
import net.minecraft.world.chunk.Chunk;
import org.bukkit.craftbukkit.util.LongHash;
public class VanillaChunkHashMap extends LongHashMapTrove<Chunk> {
public VanillaChunkHashMap(TLongObjectMap<Chunk> map) {
super(map);
}
private static long V2B(long key) {
return LongHash.toLong((int) (key & 0xFFFFFFFFL), (int) (key >>> 32));
}
@Override
public void add(long key, Object value) {
super.add(V2B(key), value);
}
@Override
public boolean containsItem(long key) {
return super.containsItem(V2B(key));
}
@Override
public Object getValueByKey(long key) {
return super.getValueByKey(V2B(key));
}
@Override
public Object remove(long key) {
return super.remove(V2B(key));
}
}

View File

@ -332,7 +332,7 @@ public class CauldronHooks
writer.name("name").value(world.getWorld().getName());
writer.name("dimensionId").value(world.provider.dimensionId);
writer.name("players").value(world.playerEntities.size());
writer.name("loadedChunks").value(world.theChunkProviderServer.loadedChunkHashMap.size());
writer.name("loadedChunks").value(world.theChunkProviderServer.loadedChunkHashMap_KC.size());
writer.name("activeChunks").value(world.activeChunkSet.size());
writer.name("entities").value(world.loadedEntityList.size());
writer.name("tiles").value(world.loadedTileEntityList.size());

View File

@ -110,7 +110,7 @@ public class CauldronCommand extends Command
for (net.minecraft.world.WorldServer world : MinecraftServer.getServer().worlds)
{
sender.sendMessage(ChatColor.GOLD + "Dimension: " + ChatColor.GRAY + world.provider.dimensionId +
ChatColor.GOLD + " Loaded Chunks: " + ChatColor.GRAY + world.theChunkProviderServer.loadedChunkHashMap.size() +
ChatColor.GOLD + " Loaded Chunks: " + ChatColor.GRAY + world.theChunkProviderServer.loadedChunkHashMap_KC.size() +
ChatColor.GOLD + " Active Chunks: " + ChatColor.GRAY + world.activeChunkSet.size() +
ChatColor.GOLD + " Entities: " + ChatColor.GRAY + world.loadedEntityList.size() +
ChatColor.GOLD + " Tile Entities: " + ChatColor.GRAY + world.loadedTileEntityList.size()

View File

@ -138,7 +138,7 @@ public class CraftWorld implements World {
}
public Chunk[] getLoadedChunks() {
Object[] chunks = world.theChunkProviderServer.loadedChunkHashMap.values();
Object[] chunks = world.theChunkProviderServer.loadedChunkHashMap_KC.values();
org.bukkit.Chunk[] craftChunks = new CraftChunk[chunks.length];
for (int i = 0; i < chunks.length; i++) {
@ -262,7 +262,7 @@ public class CraftWorld implements World {
}
world.theChunkProviderServer.chunksToUnload.remove(x, z);
net.minecraft.world.chunk.Chunk chunk = world.theChunkProviderServer.loadedChunkHashMap.get(LongHash.toLong(x, z));
net.minecraft.world.chunk.Chunk chunk = world.theChunkProviderServer.loadedChunkHashMap_KC.get(LongHash.toLong(x, z));
if (chunk == null) {
world.timings.syncChunkLoadTimer.startTiming(); // Spigot
@ -276,9 +276,8 @@ public class CraftWorld implements World {
private void chunkLoadPostProcess(net.minecraft.world.chunk.Chunk chunk, int x, int z) {
if (chunk != null) {
world.theChunkProviderServer.loadedChunkHashMap.put(LongHash.toLong(x, z), chunk);
world.theChunkProviderServer.loadedChunkHashMap_KC.put(LongHash.toLong(x, z), chunk);
world.theChunkProviderServer.loadedChunks.add(chunk); // Cauldron - vanilla compatibility
world.theChunkProviderServer.loadedChunkHashMap_vanilla.add(ChunkCoordIntPair.chunkXZ2Int(x, z), chunk);
chunk.onChunkLoad();
@ -1395,7 +1394,7 @@ public class CraftWorld implements World {
}
final net.minecraft.world.gen.ChunkProviderServer cps = world.theChunkProviderServer;
cps.loadedChunkHashMap.forEachValue(new TObjectProcedure<net.minecraft.world.chunk.Chunk>() {
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

View File

@ -89,7 +89,7 @@ public class WatchdogThread extends Thread
{
log.log(Level.SEVERE, " Dimension:" + world.provider.dimensionId);
log.log(Level.SEVERE,
" Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap.size() + " Active Chunks: " + world.activeChunkSet.size()
" Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap_KC.size() + " Active Chunks: " + world.activeChunkSet.size()
+ " Entities: " + world.loadedEntityList.size() + " Tile Entities: " + world.loadedTileEntityList.size());
log.log(Level.SEVERE, " Entities Last Tick: " + world.entitiesTicked);
log.log(Level.SEVERE, " Tiles Last Tick: " + world.tilesTicked);
@ -153,7 +153,7 @@ public class WatchdogThread extends Thread
for (net.minecraft.world.WorldServer world : MinecraftServer.getServer().worlds)
{
log.log(Level.WARNING, " Dimension:" + world.provider.dimensionId);
log.log(Level.WARNING, " Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap.size() +
log.log(Level.WARNING, " Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap_KC.size() +
" Active Chunks: " + world.activeChunkSet.size() +
" Entities: " + world.loadedEntityList.size() +
" Tile Entities: " + world.loadedTileEntityList.size());