Update OpenNBT

This commit is contained in:
Myles 2016-12-24 17:27:59 +00:00
parent ea4487e33f
commit 528a8e5587
4 changed files with 33 additions and 8 deletions

View File

@ -13,7 +13,6 @@
<artifactId>viaversion-common</artifactId>
<dependencies>
<!-- Snake YAML -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>

View File

@ -8,7 +8,9 @@ import org.spacehq.opennbt.NBTIO;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.type.Type;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
public class NBTType extends Type<CompoundTag> {
@ -28,7 +30,7 @@ public class NBTType extends Type<CompoundTag> {
buffer.readerIndex(readerIndex);
ByteBufInputStream bytebufStream = new ByteBufInputStream(buffer);
try (DataInputStream dataInputStream = new DataInputStream(bytebufStream)) {
return (CompoundTag) NBTIO.readTag(dataInputStream);
return (CompoundTag) NBTIO.readTag((DataInput) dataInputStream);
}
}
}
@ -41,7 +43,7 @@ public class NBTType extends Type<CompoundTag> {
ByteBufOutputStream bytebufStream = new ByteBufOutputStream(buffer);
DataOutputStream dataOutputStream = new DataOutputStream(bytebufStream);
NBTIO.writeTag(dataOutputStream, object);
NBTIO.writeTag((DataOutput) dataOutputStream, object);
dataOutputStream.close();
}

View File

@ -1,5 +1,6 @@
package us.myles.ViaVersion.commands.defaultsubs;
import com.google.common.io.CharStreams;
import com.google.gson.JsonObject;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.Via;
@ -10,6 +11,7 @@ import us.myles.ViaVersion.dump.DumpTemplate;
import us.myles.ViaVersion.dump.VersionInfo;
import us.myles.ViaVersion.util.GsonUtil;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InvalidObjectException;
import java.io.OutputStream;
@ -50,10 +52,19 @@ public class DumpSubCmd extends ViaSubCommand {
Via.getPlatform().runAsync(new Runnable() {
@Override
public void run() {
try {
HttpURLConnection con = (HttpURLConnection) new URL("http://hastebin.com/documents").openConnection();
HttpURLConnection con = null;
try {
con = (HttpURLConnection) new URL("http://hastebin.com/documents").openConnection();
} catch (IOException e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
return;
}
try {
con.setRequestProperty("Content-Type", "text/plain");
// Bypass cloudflare :(
con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
con.setRequestMethod("POST");
con.setDoOutput(true);
@ -61,8 +72,11 @@ public class DumpSubCmd extends ViaSubCommand {
out.write(GsonUtil.getGsonBuilder().setPrettyPrinting().create().toJson(template).getBytes(Charset.forName("UTF-8")));
out.close();
JsonObject output = GsonUtil.getGson().fromJson(new InputStreamReader(con.getInputStream()), JsonObject.class);
String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream()));
con.getInputStream().close();
System.out.println("Raw output: " + rawOutput);
JsonObject output = GsonUtil.getGson().fromJson(rawOutput, JsonObject.class);
if (!output.has("key"))
throw new InvalidObjectException("Key is not given in Hastebin output");
@ -71,6 +85,15 @@ public class DumpSubCmd extends ViaSubCommand {
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
try {
if (con.getResponseCode() < 200 || con.getResponseCode() > 400) {
String rawOutput = CharStreams.toString(new InputStreamReader(con.getErrorStream()));
con.getErrorStream().close();
Via.getPlatform().getLogger().log(Level.WARNING, "Page returned: " + rawOutput);
}
} catch (IOException e1) {
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to capture further info", e1);
}
}
}
});

View File

@ -65,6 +65,7 @@
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
<!-- Javassist (Bytecode Library) -->
<dependency>
<groupId>org.javassist</groupId>
@ -74,11 +75,11 @@
<optional>true</optional>
</dependency>
<!-- NBT Edit Library -->
<!-- OpenNBT Library -->
<dependency>
<groupId>org.spacehq</groupId>
<artifactId>opennbt</artifactId>
<version>1.0</version>
<version>1.1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>