Fix timings

This commit is contained in:
samczsun 2016-09-17 00:18:05 -04:00 committed by Shaun Bennett
parent ec4add259d
commit 92a0d606d4
3 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,104 @@
package mineplex.core;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import sun.net.www.protocol.http.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
@ReflectivelyCreateMiniPlugin
public class TimingsFix extends MiniPlugin
{
private static final Gson GSON = new Gson();
private TimingsFix()
{
super("Timings Fix");
URL.setURLStreamHandlerFactory(protocol ->
{
if (protocol.equals("http"))
{
return new sun.net.www.protocol.http.Handler()
{
@Override
protected URLConnection openConnection(URL u) throws IOException
{
if (u.getHost().contains("paste.ubuntu.com"))
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
return new HttpURLConnection(u, null, this)
{
@Override
public OutputStream getOutputStream()
{
return baos;
}
@Override
public InputStream getInputStream()
{
return bais;
}
@Override
public String getHeaderField(String name)
{
if (name.equals("Location"))
{
try
{
String request = new String(baos.toByteArray(), StandardCharsets.UTF_8);
request = request.substring("poster=Spigot&syntax=text&content=".length());
request = URLDecoder.decode(request, "UTF-8");
URL url = new URL("https://timings.spigotmc.org/paste");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setInstanceFollowRedirects(false);
connection.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
connection.getOutputStream().close();
JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream()), JsonObject.class);
return "http://paste.ubuntu.com/" + object.get("key").getAsString() + "/";
}
catch (Throwable e)
{
e.printStackTrace();
return "http://paste.ubuntu.com/0/";
}
}
return null;
}
};
}
return super.openConnection(u);
}
@Override
protected URLConnection openConnection(URL u, Proxy p) throws IOException
{
return super.openConnection(u, p);
}
};
}
return null;
});
}
}

View File

@ -2,6 +2,7 @@ package mineplex.game.clans;
import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix;
import mineplex.core.TimingsFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
@ -91,6 +92,8 @@ public class Clans extends JavaPlugin
_clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(_clientManager);
require(TimingsFix.class);
ItemStackFactory.Initialize(this, false);
DelayedTask.Initialize(this);

View File

@ -3,6 +3,7 @@ package nautilus.game.arcade;
import mineplex.core.CustomTagFix;
import mineplex.core.FoodDupeFix;
import mineplex.core.PacketsInteractionFix;
import mineplex.core.TimingsFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
@ -102,6 +103,8 @@ public class Arcade extends JavaPlugin
CommandCenter.Instance.setClientManager(_clientManager);
require(ProfileCacheManager.class);
require(TimingsFix.class);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);