don't use gson's reflection serialization on non RuneLite classes
java >=16 disallows access to most private fields which makes these fail with the reflection type adapter
This commit is contained in:
@@ -25,10 +25,16 @@
|
|||||||
package net.runelite.http.api;
|
package net.runelite.http.api;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import net.runelite.http.api.gson.ColorTypeAdapter;
|
||||||
|
import net.runelite.http.api.gson.InstantTypeAdapter;
|
||||||
|
import net.runelite.http.api.gson.IllegalReflectionExclusion;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
@@ -46,7 +52,7 @@ public class RuneLiteAPI
|
|||||||
public static final String RUNELITE_MACHINEID = "RUNELITE-MACHINEID";
|
public static final String RUNELITE_MACHINEID = "RUNELITE-MACHINEID";
|
||||||
|
|
||||||
public static final OkHttpClient CLIENT;
|
public static final OkHttpClient CLIENT;
|
||||||
public static final Gson GSON = new Gson();
|
public static final Gson GSON;
|
||||||
public static final MediaType JSON = MediaType.parse("application/json");
|
public static final MediaType JSON = MediaType.parse("application/json");
|
||||||
public static String userAgent;
|
public static String userAgent;
|
||||||
|
|
||||||
@@ -96,6 +102,23 @@ public class RuneLiteAPI
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
|
|
||||||
|
gsonBuilder
|
||||||
|
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
|
||||||
|
.registerTypeAdapter(Color.class, new ColorTypeAdapter());
|
||||||
|
|
||||||
|
boolean assertionsEnabled = false;
|
||||||
|
assert assertionsEnabled = true;
|
||||||
|
if (assertionsEnabled)
|
||||||
|
{
|
||||||
|
IllegalReflectionExclusion jbe = new IllegalReflectionExclusion();
|
||||||
|
gsonBuilder.addSerializationExclusionStrategy(jbe);
|
||||||
|
gsonBuilder.addDeserializationExclusionStrategy(jbe);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSON = gsonBuilder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl getSessionBase()
|
public static HttpUrl getSessionBase()
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.api.gson;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ColorTypeAdapter extends TypeAdapter<Color>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Color value) throws IOException
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
out.nullValue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rgba = value.getRGB();
|
||||||
|
out.beginObject()
|
||||||
|
.name("value")
|
||||||
|
.value(rgba)
|
||||||
|
.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color read(JsonReader in) throws IOException
|
||||||
|
{
|
||||||
|
switch (in.peek())
|
||||||
|
{
|
||||||
|
case NULL:
|
||||||
|
in.nextNull();
|
||||||
|
return null;
|
||||||
|
case BEGIN_OBJECT:
|
||||||
|
in.beginObject();
|
||||||
|
double value = 0;
|
||||||
|
while (in.peek() != JsonToken.END_OBJECT)
|
||||||
|
{
|
||||||
|
switch (in.nextName())
|
||||||
|
{
|
||||||
|
case "value":
|
||||||
|
value = in.nextDouble();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
in.skipValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in.endObject();
|
||||||
|
return new Color((int) value, true);
|
||||||
|
}
|
||||||
|
return null; // throws
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.api.gson;
|
||||||
|
|
||||||
|
import com.google.gson.ExclusionStrategy;
|
||||||
|
import com.google.gson.FieldAttributes;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
public class IllegalReflectionExclusion implements ExclusionStrategy
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean shouldSkipField(FieldAttributes f)
|
||||||
|
{
|
||||||
|
if (f.getDeclaringClass().getName().startsWith("net.runelite"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert !Modifier.isPrivate(f.getDeclaringClass().getModifiers()) : "gsoning private class " + f.getDeclaringClass().getName();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f.getDeclaringClass().getField(f.getName());
|
||||||
|
}
|
||||||
|
catch (NoSuchFieldException e)
|
||||||
|
{
|
||||||
|
throw new AssertionError("gsoning private field " + f.getDeclaringClass() + "." + f.getName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldSkipClass(Class<?> clazz)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.api.gson;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
// Just add water!
|
||||||
|
public class InstantTypeAdapter extends TypeAdapter<Instant>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Instant value) throws IOException
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
out.nullValue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.beginObject()
|
||||||
|
.name("seconds")
|
||||||
|
.value(value.getEpochSecond())
|
||||||
|
.name("nanos")
|
||||||
|
.value(value.getNano())
|
||||||
|
.endObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instant read(JsonReader in) throws IOException
|
||||||
|
{
|
||||||
|
if (in.peek() == JsonToken.NULL)
|
||||||
|
{
|
||||||
|
in.nextNull();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
long seconds = 0;
|
||||||
|
int nanos = 0;
|
||||||
|
in.beginObject();
|
||||||
|
while (in.peek() != JsonToken.END_OBJECT)
|
||||||
|
{
|
||||||
|
switch (in.nextName())
|
||||||
|
{
|
||||||
|
case "nanos":
|
||||||
|
nanos = in.nextInt();
|
||||||
|
break;
|
||||||
|
case "seconds":
|
||||||
|
seconds = in.nextLong();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in.endObject();
|
||||||
|
|
||||||
|
return Instant.ofEpochSecond(seconds, nanos);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
package net.runelite.http.api.ws;
|
package net.runelite.http.api.ws;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
import net.runelite.http.api.ws.messages.Handshake;
|
import net.runelite.http.api.ws.messages.Handshake;
|
||||||
import net.runelite.http.api.ws.messages.LoginResponse;
|
import net.runelite.http.api.ws.messages.LoginResponse;
|
||||||
import net.runelite.http.api.ws.messages.party.Join;
|
import net.runelite.http.api.ws.messages.party.Join;
|
||||||
@@ -76,7 +76,7 @@ public class WebsocketGsonFactory
|
|||||||
|
|
||||||
public static Gson build(final RuntimeTypeAdapterFactory<WebsocketMessage> factory)
|
public static Gson build(final RuntimeTypeAdapterFactory<WebsocketMessage> factory)
|
||||||
{
|
{
|
||||||
return new GsonBuilder()
|
return RuneLiteAPI.GSON.newBuilder()
|
||||||
.registerTypeAdapterFactory(factory)
|
.registerTypeAdapterFactory(factory)
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.api.gson;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ColorTypeAdapterTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void test()
|
||||||
|
{
|
||||||
|
test("null", null);
|
||||||
|
test("{\"value\":-13347208,\"falpha\":0.0}", new Color(0x12345678, false));
|
||||||
|
test("{\"value\":305419896,\"falpha\":0.0}", new Color(0x12345678, true));
|
||||||
|
test("{\"value\":-1.4221317E7,\"falpha\":0.0}", new Color(0xFF26FFFB, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test(String json, Color object)
|
||||||
|
{
|
||||||
|
Color parsed = RuneLiteAPI.GSON.fromJson(json, Color.class);
|
||||||
|
Assert.assertEquals(object, parsed);
|
||||||
|
String serialized = RuneLiteAPI.GSON.toJson(object);
|
||||||
|
Color roundTripped = RuneLiteAPI.GSON.fromJson(serialized, Color.class);
|
||||||
|
Assert.assertEquals(object, roundTripped);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.http.api.gson;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class InstantTypeAdapterTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void test()
|
||||||
|
{
|
||||||
|
test("null", null);
|
||||||
|
test("{\"seconds\":1609538310,\"nanos\":291698903}", Instant.ofEpochSecond(1609538310, 291698903));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void test(String json, Instant object)
|
||||||
|
{
|
||||||
|
Instant parsed = RuneLiteAPI.GSON.fromJson(json, Instant.class);
|
||||||
|
Assert.assertEquals(object, parsed);
|
||||||
|
String serialized = RuneLiteAPI.GSON.toJson(object);
|
||||||
|
Instant roundTripped = RuneLiteAPI.GSON.fromJson(serialized, Instant.class);
|
||||||
|
Assert.assertEquals(object, roundTripped);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client;
|
package net.runelite.client;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
@@ -51,6 +52,7 @@ import net.runelite.client.plugins.PluginManager;
|
|||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
import net.runelite.client.util.DeferredEventBus;
|
import net.runelite.client.util.DeferredEventBus;
|
||||||
import net.runelite.client.util.ExecutorServiceExceptionLogger;
|
import net.runelite.client.util.ExecutorServiceExceptionLogger;
|
||||||
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
import net.runelite.http.api.chat.ChatClient;
|
import net.runelite.http.api.chat.ChatClient;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
@@ -86,6 +88,8 @@ public class RuneLiteModule extends AbstractModule
|
|||||||
bind(PluginManager.class);
|
bind(PluginManager.class);
|
||||||
bind(SessionManager.class);
|
bind(SessionManager.class);
|
||||||
|
|
||||||
|
bind(Gson.class).toInstance(RuneLiteAPI.GSON);
|
||||||
|
|
||||||
bind(Callbacks.class).to(Hooks.class);
|
bind(Callbacks.class).to(Hooks.class);
|
||||||
|
|
||||||
bind(EventBus.class)
|
bind(EventBus.class)
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class SessionManager
|
|||||||
private final WSClient wsClient;
|
private final WSClient wsClient;
|
||||||
private final File sessionFile;
|
private final File sessionFile;
|
||||||
private final AccountClient accountClient;
|
private final AccountClient accountClient;
|
||||||
|
private final Gson gson;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SessionManager(
|
private SessionManager(
|
||||||
@@ -71,13 +72,15 @@ public class SessionManager
|
|||||||
ConfigManager configManager,
|
ConfigManager configManager,
|
||||||
EventBus eventBus,
|
EventBus eventBus,
|
||||||
WSClient wsClient,
|
WSClient wsClient,
|
||||||
OkHttpClient okHttpClient)
|
OkHttpClient okHttpClient,
|
||||||
|
Gson gson)
|
||||||
{
|
{
|
||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.wsClient = wsClient;
|
this.wsClient = wsClient;
|
||||||
this.sessionFile = sessionfile;
|
this.sessionFile = sessionfile;
|
||||||
this.accountClient = new AccountClient(okHttpClient);
|
this.accountClient = new AccountClient(okHttpClient);
|
||||||
|
this.gson = gson;
|
||||||
|
|
||||||
eventBus.register(this);
|
eventBus.register(this);
|
||||||
}
|
}
|
||||||
@@ -94,7 +97,7 @@ public class SessionManager
|
|||||||
|
|
||||||
try (FileInputStream in = new FileInputStream(sessionFile))
|
try (FileInputStream in = new FileInputStream(sessionFile))
|
||||||
{
|
{
|
||||||
session = new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
|
session = gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
|
||||||
|
|
||||||
log.debug("Loaded session for {}", session.getUsername());
|
log.debug("Loaded session for {}", session.getUsername());
|
||||||
}
|
}
|
||||||
@@ -124,7 +127,7 @@ public class SessionManager
|
|||||||
|
|
||||||
try (Writer fw = new OutputStreamWriter(new FileOutputStream(sessionFile), StandardCharsets.UTF_8))
|
try (Writer fw = new OutputStreamWriter(new FileOutputStream(sessionFile), StandardCharsets.UTF_8))
|
||||||
{
|
{
|
||||||
new Gson().toJson(accountSession, fw);
|
gson.toJson(accountSession, fw);
|
||||||
|
|
||||||
log.debug("Saved session to {}", sessionFile);
|
log.debug("Saved session to {}", sessionFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.externalplugins;
|
package net.runelite.client.externalplugins;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -59,11 +60,13 @@ import okio.BufferedSource;
|
|||||||
public class ExternalPluginClient
|
public class ExternalPluginClient
|
||||||
{
|
{
|
||||||
private final OkHttpClient okHttpClient;
|
private final OkHttpClient okHttpClient;
|
||||||
|
private final Gson gson;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ExternalPluginClient(OkHttpClient okHttpClient)
|
private ExternalPluginClient(OkHttpClient okHttpClient, Gson gson)
|
||||||
{
|
{
|
||||||
this.okHttpClient = okHttpClient;
|
this.okHttpClient = okHttpClient;
|
||||||
|
this.gson = gson;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExternalPluginManifest> downloadManifest() throws IOException, VerificationException
|
public List<ExternalPluginManifest> downloadManifest() throws IOException, VerificationException
|
||||||
@@ -94,7 +97,7 @@ public class ExternalPluginClient
|
|||||||
throw new VerificationException("Unable to verify external plugin manifest");
|
throw new VerificationException("Unable to verify external plugin manifest");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RuneLiteAPI.GSON.fromJson(new String(data, StandardCharsets.UTF_8),
|
return gson.fromJson(new String(data, StandardCharsets.UTF_8),
|
||||||
new TypeToken<List<ExternalPluginManifest>>()
|
new TypeToken<List<ExternalPluginManifest>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
@@ -156,7 +159,7 @@ public class ExternalPluginClient
|
|||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(RequestBody.create(RuneLiteAPI.JSON, RuneLiteAPI.GSON.toJson(plugins)))
|
.post(RequestBody.create(RuneLiteAPI.JSON, gson.toJson(plugins)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
okHttpClient.newCall(request).enqueue(new Callback()
|
okHttpClient.newCall(request).enqueue(new Callback()
|
||||||
@@ -190,7 +193,7 @@ public class ExternalPluginClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
|
return gson.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
}
|
}
|
||||||
catch (JsonSyntaxException ex)
|
catch (JsonSyntaxException ex)
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Callback;
|
import okhttp3.Callback;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
@@ -47,11 +46,13 @@ public class CrowdsourcingManager
|
|||||||
{
|
{
|
||||||
private static final String CROWDSOURCING_BASE = "https://crowdsource.runescape.wiki/runelite";
|
private static final String CROWDSOURCING_BASE = "https://crowdsource.runescape.wiki/runelite";
|
||||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OkHttpClient okHttpClient;
|
private OkHttpClient okHttpClient;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
private List<Object> data = new ArrayList<>();
|
private List<Object> data = new ArrayList<>();
|
||||||
|
|
||||||
public void storeEvent(Object event)
|
public void storeEvent(Object event)
|
||||||
@@ -77,7 +78,7 @@ public class CrowdsourcingManager
|
|||||||
|
|
||||||
Request r = new Request.Builder()
|
Request r = new Request.Builder()
|
||||||
.url(CROWDSOURCING_BASE)
|
.url(CROWDSOURCING_BASE)
|
||||||
.post(RequestBody.create(JSON, GSON.toJson(temp)))
|
.post(RequestBody.create(JSON, gson.toJson(temp)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
okHttpClient.newCall(r).enqueue(new Callback()
|
okHttpClient.newCall(r).enqueue(new Callback()
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
|
|
||||||
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
||||||
private static final String BUY_LIMIT_KEY = "buylimit";
|
private static final String BUY_LIMIT_KEY = "buylimit";
|
||||||
private static final Gson GSON = new Gson();
|
|
||||||
private static final Duration BUY_LIMIT_RESET = Duration.ofHours(4);
|
private static final Duration BUY_LIMIT_RESET = Duration.ofHours(4);
|
||||||
|
|
||||||
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
|
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
|
||||||
@@ -183,6 +182,9 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ConfigManager configManager;
|
private ConfigManager configManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
private Widget grandExchangeText;
|
private Widget grandExchangeText;
|
||||||
private Widget grandExchangeItem;
|
private Widget grandExchangeItem;
|
||||||
private String grandExchangeExamine;
|
private String grandExchangeExamine;
|
||||||
@@ -253,12 +255,12 @@ public class GrandExchangePlugin extends Plugin
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return GSON.fromJson(offer, SavedOffer.class);
|
return gson.fromJson(offer, SavedOffer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOffer(int slot, SavedOffer offer)
|
private void setOffer(int slot, SavedOffer offer)
|
||||||
{
|
{
|
||||||
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), GSON.toJson(offer));
|
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), gson.toJson(offer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteOffer(int slot)
|
private void deleteOffer(int slot)
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
private static final String WALK_HERE = "Walk here";
|
private static final String WALK_HERE = "Walk here";
|
||||||
private static final String REGION_PREFIX = "region_";
|
private static final String REGION_PREFIX = "region_";
|
||||||
|
|
||||||
private static final Gson GSON = new Gson();
|
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final List<ColorTileMarker> points = new ArrayList<>();
|
private final List<ColorTileMarker> points = new ArrayList<>();
|
||||||
|
|
||||||
@@ -105,6 +103,9 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private GroundMarkerSharingManager sharingManager;
|
private GroundMarkerSharingManager sharingManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
void savePoints(int regionId, Collection<GroundMarkerPoint> points)
|
void savePoints(int regionId, Collection<GroundMarkerPoint> points)
|
||||||
{
|
{
|
||||||
if (points == null || points.isEmpty())
|
if (points == null || points.isEmpty())
|
||||||
@@ -113,7 +114,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String json = GSON.toJson(points);
|
String json = gson.toJson(points);
|
||||||
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
|
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ public class GroundMarkerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
return GSON.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
return gson.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import net.runelite.client.eventbus.Subscribe;
|
|||||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
import net.runelite.client.menus.WidgetMenuOption;
|
import net.runelite.client.menus.WidgetMenuOption;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class GroundMarkerSharingManager
|
class GroundMarkerSharingManager
|
||||||
@@ -61,22 +60,23 @@ class GroundMarkerSharingManager
|
|||||||
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
|
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
|
||||||
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
|
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
|
||||||
|
|
||||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
|
||||||
|
|
||||||
private final GroundMarkerPlugin plugin;
|
private final GroundMarkerPlugin plugin;
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final MenuManager menuManager;
|
private final MenuManager menuManager;
|
||||||
private final ChatMessageManager chatMessageManager;
|
private final ChatMessageManager chatMessageManager;
|
||||||
private final ChatboxPanelManager chatboxPanelManager;
|
private final ChatboxPanelManager chatboxPanelManager;
|
||||||
|
private final Gson gson;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GroundMarkerSharingManager(GroundMarkerPlugin plugin, Client client, MenuManager menuManager, ChatMessageManager chatMessageManager, ChatboxPanelManager chatboxPanelManager)
|
private GroundMarkerSharingManager(GroundMarkerPlugin plugin, Client client, MenuManager menuManager,
|
||||||
|
ChatMessageManager chatMessageManager, ChatboxPanelManager chatboxPanelManager, Gson gson)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.menuManager = menuManager;
|
this.menuManager = menuManager;
|
||||||
this.chatMessageManager = chatMessageManager;
|
this.chatMessageManager = chatMessageManager;
|
||||||
this.chatboxPanelManager = chatboxPanelManager;
|
this.chatboxPanelManager = chatboxPanelManager;
|
||||||
|
this.gson = gson;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMenuOptions()
|
void addMenuOptions()
|
||||||
@@ -135,7 +135,7 @@ class GroundMarkerSharingManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String exportDump = GSON.toJson(activePoints);
|
final String exportDump = gson.toJson(activePoints);
|
||||||
|
|
||||||
log.debug("Exported ground markers: {}", exportDump);
|
log.debug("Exported ground markers: {}", exportDump);
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ class GroundMarkerSharingManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
importPoints = GSON.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
importPoints = gson.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
}
|
}
|
||||||
catch (JsonSyntaxException e)
|
catch (JsonSyntaxException e)
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ public class ObjectIndicatorsPlugin extends Plugin
|
|||||||
private static final String MARK = "Mark object";
|
private static final String MARK = "Mark object";
|
||||||
private static final String UNMARK = "Unmark object";
|
private static final String UNMARK = "Unmark object";
|
||||||
|
|
||||||
private final Gson GSON = new Gson();
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final List<ColorTileObject> objects = new ArrayList<>();
|
private final List<ColorTileObject> objects = new ArrayList<>();
|
||||||
private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>();
|
private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>();
|
||||||
@@ -108,6 +107,9 @@ public class ObjectIndicatorsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ObjectIndicatorsConfig config;
|
private ObjectIndicatorsConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ObjectIndicatorsConfig provideConfig(ConfigManager configManager)
|
ObjectIndicatorsConfig provideConfig(ConfigManager configManager)
|
||||||
{
|
{
|
||||||
@@ -428,7 +430,7 @@ public class ObjectIndicatorsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final String json = GSON.toJson(points);
|
final String json = gson.toJson(points);
|
||||||
configManager.setConfiguration(CONFIG_GROUP, "region_" + id, json);
|
configManager.setConfiguration(CONFIG_GROUP, "region_" + id, json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -442,7 +444,7 @@ public class ObjectIndicatorsPlugin extends Plugin
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ObjectPoint> points = GSON.fromJson(json, new TypeToken<Set<ObjectPoint>>()
|
Set<ObjectPoint> points = gson.fromJson(json, new TypeToken<Set<ObjectPoint>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
// Prior to multiloc support the plugin would mark objects named "null", which breaks
|
// Prior to multiloc support the plugin would mark objects named "null", which breaks
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ public class ScreenMarkerPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private ScreenMarkerCreationOverlay overlay;
|
private ScreenMarkerCreationOverlay overlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Inject
|
@Inject
|
||||||
private ColorPickerManager colorPickerManager;
|
private ColorPickerManager colorPickerManager;
|
||||||
@@ -266,7 +269,6 @@ public class ScreenMarkerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Gson gson = new Gson();
|
|
||||||
final String json = gson
|
final String json = gson
|
||||||
.toJson(screenMarkers.stream().map(ScreenMarkerOverlay::getMarker).collect(Collectors.toList()));
|
.toJson(screenMarkers.stream().map(ScreenMarkerOverlay::getMarker).collect(Collectors.toList()));
|
||||||
configManager.setConfiguration(CONFIG_GROUP, CONFIG_KEY, json);
|
configManager.setConfiguration(CONFIG_GROUP, CONFIG_KEY, json);
|
||||||
@@ -279,7 +281,6 @@ public class ScreenMarkerPlugin extends Plugin
|
|||||||
return Stream.empty();
|
return Stream.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Gson gson = new Gson();
|
|
||||||
final List<ScreenMarker> screenMarkerData = gson.fromJson(json, new TypeToken<ArrayList<ScreenMarker>>()
|
final List<ScreenMarker> screenMarkerData = gson.fromJson(json, new TypeToken<ArrayList<ScreenMarker>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ public class ClockManager
|
|||||||
@Inject
|
@Inject
|
||||||
private Notifier notifier;
|
private Notifier notifier;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Gson gson;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final List<Timer> timers = new CopyOnWriteArrayList<>();
|
private final List<Timer> timers = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@@ -183,7 +186,6 @@ public class ClockManager
|
|||||||
|
|
||||||
if (!Strings.isNullOrEmpty(timersJson))
|
if (!Strings.isNullOrEmpty(timersJson))
|
||||||
{
|
{
|
||||||
final Gson gson = new Gson();
|
|
||||||
final List<Timer> timers = gson.fromJson(timersJson, new TypeToken<ArrayList<Timer>>()
|
final List<Timer> timers = gson.fromJson(timersJson, new TypeToken<ArrayList<Timer>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
@@ -200,7 +202,6 @@ public class ClockManager
|
|||||||
|
|
||||||
if (!Strings.isNullOrEmpty(stopwatchesJson))
|
if (!Strings.isNullOrEmpty(stopwatchesJson))
|
||||||
{
|
{
|
||||||
final Gson gson = new Gson();
|
|
||||||
final List<Stopwatch> stopwatches = gson.fromJson(stopwatchesJson, new TypeToken<ArrayList<Stopwatch>>()
|
final List<Stopwatch> stopwatches = gson.fromJson(stopwatchesJson, new TypeToken<ArrayList<Stopwatch>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
@@ -227,14 +228,12 @@ public class ClockManager
|
|||||||
|
|
||||||
void saveTimers()
|
void saveTimers()
|
||||||
{
|
{
|
||||||
final Gson gson = new Gson();
|
|
||||||
final String json = gson.toJson(timers);
|
final String json = gson.toJson(timers);
|
||||||
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS, json);
|
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveStopwatches()
|
void saveStopwatches()
|
||||||
{
|
{
|
||||||
final Gson gson = new Gson();
|
|
||||||
final String json = gson.toJson(stopwatches);
|
final String json = gson.toJson(stopwatches);
|
||||||
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.STOPWATCHES, json);
|
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.STOPWATCHES, json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
|
|||||||
private static final int PREDICTION_DEBOUNCE_DELAY_MS = 200;
|
private static final int PREDICTION_DEBOUNCE_DELAY_MS = 200;
|
||||||
|
|
||||||
private final ChatboxPanelManager chatboxPanelManager;
|
private final ChatboxPanelManager chatboxPanelManager;
|
||||||
private final Gson gson = new Gson();
|
|
||||||
|
|
||||||
private Future<?> runningRequest = null;
|
private Future<?> runningRequest = null;
|
||||||
private List<String> predictions = ImmutableList.of();
|
private List<String> predictions = ImmutableList.of();
|
||||||
@@ -78,7 +77,7 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
|
|||||||
@Inject
|
@Inject
|
||||||
public WikiSearchChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread,
|
public WikiSearchChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread,
|
||||||
ScheduledExecutorService scheduledExecutorService, @Named("developerMode") final boolean developerMode,
|
ScheduledExecutorService scheduledExecutorService, @Named("developerMode") final boolean developerMode,
|
||||||
OkHttpClient okHttpClient)
|
OkHttpClient okHttpClient, Gson gson)
|
||||||
{
|
{
|
||||||
super(chatboxPanelManager, clientThread);
|
super(chatboxPanelManager, clientThread);
|
||||||
this.chatboxPanelManager = chatboxPanelManager;
|
this.chatboxPanelManager = chatboxPanelManager;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
package net.runelite.client.util;
|
package net.runelite.client.util;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.gson.Gson;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.awt.datatransfer.Clipboard;
|
import java.awt.datatransfer.Clipboard;
|
||||||
@@ -54,7 +55,6 @@ import net.runelite.api.GameState;
|
|||||||
import net.runelite.api.WorldType;
|
import net.runelite.api.WorldType;
|
||||||
import net.runelite.client.Notifier;
|
import net.runelite.client.Notifier;
|
||||||
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
|
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Callback;
|
import okhttp3.Callback;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
@@ -75,6 +75,7 @@ public class ImageCapture
|
|||||||
private final Client client;
|
private final Client client;
|
||||||
private final Notifier notifier;
|
private final Notifier notifier;
|
||||||
private final OkHttpClient okHttpClient;
|
private final OkHttpClient okHttpClient;
|
||||||
|
private final Gson gson;
|
||||||
private final String imgurClientId;
|
private final String imgurClientId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -82,12 +83,14 @@ public class ImageCapture
|
|||||||
final Client client,
|
final Client client,
|
||||||
final Notifier notifier,
|
final Notifier notifier,
|
||||||
final OkHttpClient okHttpClient,
|
final OkHttpClient okHttpClient,
|
||||||
|
final Gson gson,
|
||||||
@Named("runelite.imgur.client.id") final String imgurClientId
|
@Named("runelite.imgur.client.id") final String imgurClientId
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.notifier = notifier;
|
this.notifier = notifier;
|
||||||
this.okHttpClient = okHttpClient;
|
this.okHttpClient = okHttpClient;
|
||||||
|
this.gson = gson;
|
||||||
this.imgurClientId = imgurClientId;
|
this.imgurClientId = imgurClientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +207,7 @@ public class ImageCapture
|
|||||||
*/
|
*/
|
||||||
private void uploadScreenshot(File screenshotFile, boolean notify) throws IOException
|
private void uploadScreenshot(File screenshotFile, boolean notify) throws IOException
|
||||||
{
|
{
|
||||||
String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile));
|
String json = gson.toJson(new ImageUploadRequest(screenshotFile));
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(IMGUR_IMAGE_UPLOAD_URL)
|
.url(IMGUR_IMAGE_UPLOAD_URL)
|
||||||
@@ -225,8 +228,8 @@ public class ImageCapture
|
|||||||
{
|
{
|
||||||
try (InputStream in = response.body().byteStream())
|
try (InputStream in = response.body().byteStream())
|
||||||
{
|
{
|
||||||
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
|
ImageUploadResponse imageUploadResponse =
|
||||||
.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
|
gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
|
||||||
|
|
||||||
if (imageUploadResponse.isSuccess())
|
if (imageUploadResponse.isSuccess())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user