project: Fix deprecations and supress unchecked warnings

This commit is contained in:
Owain van Brakel
2019-07-25 20:08:45 +02:00
parent 481831359b
commit 17b35205fd
40 changed files with 113 additions and 263 deletions

View File

@@ -12,7 +12,7 @@ allprojects {
gradle.projectsEvaluated { gradle.projectsEvaluated {
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
} }
} }
} }

View File

@@ -56,7 +56,7 @@ public class ScriptLoader
int numSwitches = in.readUnsignedByte(); int numSwitches = in.readUnsignedByte();
if (numSwitches > 0) if (numSwitches > 0)
{ {
Map<Integer, Integer>[] switches = new Map[numSwitches]; @SuppressWarnings("unchecked") Map<Integer, Integer>[] switches = new Map[numSwitches];
def.setSwitches(switches); def.setSwitches(switches);
for (int i = 0; i < numSwitches; ++i) for (int i = 0; i < numSwitches; ++i)

View File

@@ -36,6 +36,7 @@ import net.runelite.cache.region.Position;
public class WorldMapLoader public class WorldMapLoader
{ {
@SuppressWarnings("unchecked")
public WorldMapDefinition load(byte[] b, int fileId) public WorldMapDefinition load(byte[] b, int fileId)
{ {
WorldMapDefinition def = new WorldMapDefinition(); WorldMapDefinition def = new WorldMapDefinition();

View File

@@ -29,7 +29,7 @@ import java.io.InputStream;
import net.runelite.cache.definitions.ScriptDefinition; import net.runelite.cache.definitions.ScriptDefinition;
import net.runelite.cache.script.Instructions; import net.runelite.cache.script.Instructions;
import net.runelite.cache.script.assembler.rs2asmParser.ProgContext; import net.runelite.cache.script.assembler.rs2asmParser.ProgContext;
import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.antlr.v4.runtime.tree.ParseTreeWalker;
@@ -45,7 +45,7 @@ public class Assembler
public ScriptDefinition assemble(InputStream in) throws IOException public ScriptDefinition assemble(InputStream in) throws IOException
{ {
// Get our lexer // Get our lexer
rs2asmLexer lexer = new rs2asmLexer(new ANTLRInputStream(in)); rs2asmLexer lexer = new rs2asmLexer(CharStreams.fromStream(in));
LexerErrorListener errorListener = new LexerErrorListener(); LexerErrorListener errorListener = new LexerErrorListener();
lexer.addErrorListener(errorListener); lexer.addErrorListener(errorListener);

View File

@@ -259,7 +259,7 @@ public class ScriptWriter extends rs2asmBaseListener
} }
int index = 0; int index = 0;
Map<Integer, Integer>[] maps = new Map[count]; @SuppressWarnings("unchecked") Map<Integer, Integer>[] maps = new Map[count];
for (LookupSwitch lswitch : switches) for (LookupSwitch lswitch : switches)
{ {
if (lswitch == null) if (lswitch == null)

View File

@@ -24,6 +24,7 @@
*/ */
package net.runelite.cache; package net.runelite.cache;
import com.google.common.io.FileWriteMode;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@@ -81,7 +82,7 @@ public class SoundEffectsDumperTest
SoundEffectTrackLoader setLoader = new SoundEffectTrackLoader(); SoundEffectTrackLoader setLoader = new SoundEffectTrackLoader();
SoundEffectTrackDefinition soundEffect = setLoader.load(contents); SoundEffectTrackDefinition soundEffect = setLoader.load(contents);
Files.write(gson.toJson(soundEffect), new File(dumpDir, archive.getArchiveId() + ".json"), Charset.defaultCharset()); Files.asCharSink(new File(dumpDir, archive.getArchiveId() + ".json"), Charset.defaultCharset()).write(gson.toJson(soundEffect));
++count; ++count;
} }
} }

View File

@@ -66,6 +66,7 @@ public class InvokeDynamic extends Instruction implements InvokeInstruction
} }
@Override @Override
@SuppressWarnings("unchecked")
public List<net.runelite.asm.Method> getMethods() public List<net.runelite.asm.Method> getMethods()
{ {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;

View File

@@ -75,6 +75,7 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
} }
@Override @Override
@SuppressWarnings("unchecked")
public List<net.runelite.asm.Method> getMethods() public List<net.runelite.asm.Method> getMethods()
{ {
return myMethod != null ? Arrays.asList(myMethod) : Collections.EMPTY_LIST; return myMethod != null ? Arrays.asList(myMethod) : Collections.EMPTY_LIST;

View File

@@ -83,6 +83,7 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
} }
@Override @Override
@SuppressWarnings("unchecked")
public List<net.runelite.asm.Method> getMethods() public List<net.runelite.asm.Method> getMethods()
{ {
return myMethod != null ? Arrays.asList(myMethod) : Collections.EMPTY_LIST; return myMethod != null ? Arrays.asList(myMethod) : Collections.EMPTY_LIST;

View File

@@ -70,6 +70,7 @@ public class MethodContext
return contexts.get(i); return contexts.get(i);
} }
@SuppressWarnings("unchecked")
public Collection<InstructionContext> getInstructionContexts() public Collection<InstructionContext> getInstructionContexts()
{ {
return (Collection) contexts.values(); return (Collection) contexts.values();

View File

@@ -167,7 +167,7 @@ public class ModArith implements Deobfuscator
FieldInfo fieldInfo = getFieldInfo(fi.getMyField()); FieldInfo fieldInfo = getFieldInfo(fi.getMyField());
List<InstructionContext> l = getInsInExpr(ctx, new HashSet(), false); @SuppressWarnings("unchecked") List<InstructionContext> l = getInsInExpr(ctx, new HashSet(), false);
boolean other = false; // check if this contains another field boolean other = false; // check if this contains another field
boolean getter = false, setter = false; boolean getter = false, setter = false;
for (InstructionContext i : l) for (InstructionContext i : l)
@@ -272,7 +272,7 @@ public class ModArith implements Deobfuscator
// parse the full multiplication expression to // parse the full multiplication expression to
// get all associated constants // get all associated constants
List<InstructionContext> insInExpr = getInsInExpr(ctx, new HashSet(), true); @SuppressWarnings("unchecked") List<InstructionContext> insInExpr = getInsInExpr(ctx, new HashSet(), true);
for (InstructionContext ctx2 : insInExpr) for (InstructionContext ctx2 : insInExpr)
{ {

View File

@@ -171,6 +171,7 @@ public class ConstantParameter implements Deobfuscator
findConstantParameter(methods, ins); findConstantParameter(methods, ins);
} }
@SuppressWarnings("unchecked")
private List<ConstantMethodParameter> findParametersForMethod(Method m) private List<ConstantMethodParameter> findParametersForMethod(Method m)
{ {
Collection<ConstantMethodParameter> c = mparams.get(m); Collection<ConstantMethodParameter> c = mparams.get(m);

View File

@@ -52,7 +52,7 @@ public class CheckExports
@Before @Before
public void before() throws MalformedURLException, ClassNotFoundException public void before() throws MalformedURLException, ClassNotFoundException
{ {
ClassLoader loader = new URLClassLoader(new URL[]{CLIENT.toURL()}); ClassLoader loader = new URLClassLoader(new URL[]{CLIENT.toURI().toURL()});
Class c = loader.loadClass("net.runelite.rs.client.client"); Class c = loader.loadClass("net.runelite.rs.client.client");
classes.add(c); classes.add(c);
@@ -70,6 +70,7 @@ public class CheckExports
} }
} }
@SuppressWarnings("unchecked")
private Class<?> findClassWithObfuscatedName(String name) private Class<?> findClassWithObfuscatedName(String name)
{ {
for (Class c : classes) for (Class c : classes)

View File

@@ -53,7 +53,7 @@ public class CheckMappings
@Before @Before
public void before() throws MalformedURLException, ClassNotFoundException public void before() throws MalformedURLException, ClassNotFoundException
{ {
ClassLoader loader = new URLClassLoader(new URL[]{CLIENT.toURL()}); ClassLoader loader = new URLClassLoader(new URL[]{CLIENT.toURI().toURL()});
Class c = loader.loadClass("client"); Class c = loader.loadClass("client");
classes.add(c); classes.add(c);
@@ -71,6 +71,7 @@ public class CheckMappings
} }
} }
@SuppressWarnings("unchecked")
private Class<?> findClassWithObfuscatedName(String name) private Class<?> findClassWithObfuscatedName(String name)
{ {
for (Class c : classes) for (Class c : classes)

View File

@@ -57,8 +57,9 @@ public class AnimationClient
logger.debug("Built URI: {}", url); logger.debug("Built URI: {}", url);
RequestBody body = RequestBody.Companion.create(json, JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(JSON, json)) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -38,6 +38,8 @@ import okhttp3.Response;
public class ChatClient public class ChatClient
{ {
private static final RequestBody body = RequestBody.Companion.create(new byte[0], null);
private static final Predicate<String> LAYOUT_VALIDATOR = Pattern private static final Predicate<String> LAYOUT_VALIDATOR = Pattern
.compile("\\[[A-Z]+]:(\\s*\\w+\\s*(\\([A-Za-z]+\\))?,?)+") .compile("\\[[A-Z]+]:(\\s*\\w+\\s*(\\([A-Za-z]+\\))?,?)+")
.asPredicate(); .asPredicate();
@@ -52,8 +54,9 @@ public class ChatClient
.addQueryParameter("kc", Integer.toString(kc)) .addQueryParameter("kc", Integer.toString(kc))
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -96,7 +99,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -141,7 +144,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -190,7 +193,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -233,7 +236,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -280,7 +283,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -303,7 +306,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -424,7 +427,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();
@@ -453,7 +456,7 @@ public class ChatClient
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -52,8 +52,9 @@ public class DiscordClient
private void message(HttpUrl url, DiscordMessage discordMessage, int retryAttempt, int maxAttempts) private void message(HttpUrl url, DiscordMessage discordMessage, int retryAttempt, int maxAttempts)
{ {
RequestBody body = RequestBody.Companion.create(gson.toJson(discordMessage), JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(JSON, gson.toJson(discordMessage))) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -67,9 +67,10 @@ public class ExamineClient
logger.debug("Built URI: {}", url); logger.debug("Built URI: {}", url);
RequestBody body = RequestBody.Companion.create(text, TEXT);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
.post(RequestBody.create(TEXT, text)) .post(body)
.build(); .build();
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback()

View File

@@ -53,9 +53,10 @@ public class GrandExchangeClient
.addPathSegment("ge") .addPathSegment("ge")
.build(); .build();
RequestBody body = RequestBody.Companion.create(GSON.toJson(grandExchangeTrade), JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
.post(RequestBody.create(JSON, GSON.toJson(grandExchangeTrade))) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -59,9 +59,10 @@ public class LootTrackerClient
.addPathSegment("loottracker") .addPathSegment("loottracker")
.build(); .build();
RequestBody body = RequestBody.Companion.create(GSON.toJson(lootRecord), JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString()) .header(RuneLiteAPI.RUNELITE_AUTH, uuid.toString())
.post(RequestBody.create(JSON, GSON.toJson(lootRecord))) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -57,8 +57,9 @@ public class XteaClient
logger.debug("Built URI: {}", url); logger.debug("Built URI: {}", url);
RequestBody body = RequestBody.Companion.create(json, JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(JSON, json)) .post(body)
.url(url) .url(url)
.build(); .build();

View File

@@ -33,11 +33,11 @@ import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
@EnableWebMvc @EnableWebMvc
public class SpringWebMvcConfigurer extends WebMvcConfigurerAdapter public class SpringWebMvcConfigurer implements WebMvcConfigurer
{ {
/** /**
* Configure .js as application/json to trick Cloudflare into caching json responses * Configure .js as application/json to trick Cloudflare into caching json responses

View File

@@ -43,7 +43,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@@ -108,7 +108,7 @@ public class ConfigManager
final Properties properties = new Properties(); final Properties properties = new Properties();
try (FileInputStream in = new FileInputStream(propertiesFile)) try (FileInputStream in = new FileInputStream(propertiesFile))
{ {
properties.load(new InputStreamReader(in, Charset.forName("UTF-8"))); properties.load(new InputStreamReader(in, StandardCharsets.UTF_8));
} }
catch (Exception e) catch (Exception e)
{ {
@@ -116,7 +116,7 @@ public class ConfigManager
return; return;
} }
final Map<String, String> copy = (Map) ImmutableMap.copyOf(this.properties); @SuppressWarnings("unchecked") final Map<String, String> copy = (Map) ImmutableMap.copyOf(this.properties);
copy.forEach((groupAndKey, value) -> copy.forEach((groupAndKey, value) ->
{ {
if (!properties.containsKey(groupAndKey)) if (!properties.containsKey(groupAndKey))
@@ -160,7 +160,7 @@ public class ConfigManager
try (FileInputStream in = new FileInputStream(SETTINGS_FILE)) try (FileInputStream in = new FileInputStream(SETTINGS_FILE))
{ {
properties.load(new InputStreamReader(in, Charset.forName("UTF-8"))); properties.load(new InputStreamReader(in, StandardCharsets.UTF_8));
} }
catch (FileNotFoundException ex) catch (FileNotFoundException ex)
{ {
@@ -174,7 +174,7 @@ public class ConfigManager
try try
{ {
Map<String, String> copy = (Map) ImmutableMap.copyOf(properties); @SuppressWarnings("unchecked") Map<String, String> copy = (Map) ImmutableMap.copyOf(properties);
copy.forEach((groupAndKey, value) -> copy.forEach((groupAndKey, value) ->
{ {
final String[] split = groupAndKey.split("\\.", 2); final String[] split = groupAndKey.split("\\.", 2);
@@ -212,7 +212,7 @@ public class ConfigManager
try try
{ {
properties.store(new OutputStreamWriter(out, Charset.forName("UTF-8")), "RuneLite configuration"); properties.store(new OutputStreamWriter(out, StandardCharsets.UTF_8), "RuneLite configuration");
} }
finally finally
{ {
@@ -235,6 +235,7 @@ public class ConfigManager
eventBus.post(ConfigChanged.class, configChanged); eventBus.post(ConfigChanged.class, configChanged);
} }
@SuppressWarnings("unchecked")
public <T> T getConfig(Class<T> clazz) public <T> T getConfig(Class<T> clazz)
{ {
if (!Modifier.isPublic(clazz.getModifiers())) if (!Modifier.isPublic(clazz.getModifiers()))
@@ -263,6 +264,7 @@ public class ConfigManager
return properties.getProperty(propertyKey); return properties.getProperty(propertyKey);
} }
@SuppressWarnings("unchecked")
public <T> T getConfiguration(String groupName, String key, Class<T> clazz) public <T> T getConfiguration(String groupName, String key, Class<T> clazz)
{ {
String value = getConfiguration(groupName, key); String value = getConfiguration(groupName, key);
@@ -464,6 +466,7 @@ public class ConfigManager
} }
} }
@SuppressWarnings("unchecked")
static Object stringToObject(String str, Class<?> type) static Object stringToObject(String str, Class<?> type)
{ {
if (type == boolean.class || type == Boolean.class) if (type == boolean.class || type == Boolean.class)
@@ -633,22 +636,34 @@ public class ConfigManager
newestFile = STANDARD_SETTINGS_FILE; newestFile = STANDARD_SETTINGS_FILE;
for (File profileDir : PROFILES_DIR.listFiles()) File[] profileDirFiles = PROFILES_DIR.listFiles();
{
if (!profileDir.isDirectory())
{
continue;
}
for (File settings : profileDir.listFiles()) if (profileDirFiles != null)
{
for (File profileDir : profileDirFiles)
{ {
if (!settings.getName().equals(STANDARD_SETTINGS_FILE_NAME) || if (!profileDir.isDirectory())
settings.lastModified() < newestFile.lastModified())
{ {
continue; continue;
} }
newestFile = settings; File[] settingsFiles = profileDir.listFiles();
if (settingsFiles == null)
{
continue;
}
for (File settings : settingsFiles)
{
if (!settings.getName().equals(STANDARD_SETTINGS_FILE_NAME) ||
settings.lastModified() < newestFile.lastModified())
{
continue;
}
newestFile = settings;
}
} }
} }

View File

@@ -118,6 +118,9 @@ public class PluginManager
this.configManager = configManager; this.configManager = configManager;
this.executor = executor; this.executor = executor;
this.sceneTileManager = sceneTileManager; this.sceneTileManager = sceneTileManager;
eventBus.subscribe(SessionOpen.class, this, this::onSessionOpen);
eventBus.subscribe(SessionClose.class, this, this::onSessionClose);
} }
public void watch() public void watch()
@@ -171,7 +174,7 @@ public class PluginManager
return null; return null;
} }
public List<Config> getPluginConfigProxies() private List<Config> getPluginConfigProxies()
{ {
List<Injector> injectors = new ArrayList<>(); List<Injector> injectors = new ArrayList<>();
injectors.add(RuneLite.getInjector()); injectors.add(RuneLite.getInjector());
@@ -224,6 +227,7 @@ public class PluginManager
} }
} }
@SuppressWarnings("unchecked")
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
{ {
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder MutableGraph<Class<? extends Plugin>> graph = GraphBuilder
@@ -266,7 +270,7 @@ public class PluginManager
continue; continue;
} }
Class<Plugin> pluginClass = (Class<Plugin>) clazz; @SuppressWarnings("unchecked") Class<Plugin> pluginClass = (Class<Plugin>) clazz;
graph.addNode(pluginClass); graph.addNode(pluginClass);
} }
@@ -428,13 +432,14 @@ public class PluginManager
if (value != null) if (value != null)
{ {
return Boolean.valueOf(value); return Boolean.parseBoolean(value);
} }
final PluginDescriptor pluginDescriptor = plugin.getClass().getAnnotation(PluginDescriptor.class); final PluginDescriptor pluginDescriptor = plugin.getClass().getAnnotation(PluginDescriptor.class);
return pluginDescriptor == null || pluginDescriptor.enabledByDefault(); return pluginDescriptor == null || pluginDescriptor.enabledByDefault();
} }
@SuppressWarnings("unchecked")
private Plugin instantiate(List<Plugin> scannedPlugins, Class<Plugin> clazz) throws PluginInstantiationException private Plugin instantiate(List<Plugin> scannedPlugins, Class<Plugin> clazz) throws PluginInstantiationException
{ {
PluginDependency[] pluginDependencies = clazz.getAnnotationsByType(PluginDependency.class); PluginDependency[] pluginDependencies = clazz.getAnnotationsByType(PluginDependency.class);

View File

@@ -119,6 +119,7 @@ public class ClanChatPlugin extends Plugin
private List<String> chats = new ArrayList<>(); private List<String> chats = new ArrayList<>();
@SuppressWarnings("unchecked")
public static CopyOnWriteArrayList<Player> getClanMembers() public static CopyOnWriteArrayList<Player> getClanMembers()
{ {
return (CopyOnWriteArrayList<Player>) clanMembers.clone(); return (CopyOnWriteArrayList<Player>) clanMembers.clone();

View File

@@ -526,6 +526,7 @@ public class ConfigPanel extends PluginPanel
openGroupConfigPanel(listItem, config, cd, false); openGroupConfigPanel(listItem, config, cd, false);
} }
@SuppressWarnings("unchecked")
private void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd, boolean refresh) private void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd, boolean refresh)
{ {
showingPluginList = false; showingPluginList = false;
@@ -657,10 +658,10 @@ public class ConfigPanel extends PluginPanel
} }
else if (cid2.getType().isEnum()) else if (cid2.getType().isEnum())
{ {
Class<? extends Enum> type = (Class<? extends Enum>) cid2.getType(); @SuppressWarnings("unchecked") Class<? extends Enum> type = (Class<? extends Enum>) cid2.getType();
try try
{ {
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName())); @SuppressWarnings("unchecked") Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
if (!cid.getItem().unhideValue().equals("")) if (!cid.getItem().unhideValue().equals(""))
{ {
show = selectedItem.toString().equals(cid.getItem().unhideValue()); show = selectedItem.toString().equals(cid.getItem().unhideValue());
@@ -1307,7 +1308,7 @@ public class ConfigPanel extends PluginPanel
return new Dimension(PANEL_WIDTH + SCROLLBAR_WIDTH, super.getPreferredSize().height); return new Dimension(PANEL_WIDTH + SCROLLBAR_WIDTH, super.getPreferredSize().height);
} }
private class FixedWidthPanel extends JPanel private static class FixedWidthPanel extends JPanel
{ {
@Override @Override
public Dimension getPreferredSize() public Dimension getPreferredSize()

View File

@@ -67,6 +67,7 @@ public class WidgetField<T>
return MessageFormatter.format("{}", value).getMessage(); return MessageFormatter.format("{}", value).getMessage();
} }
@SuppressWarnings("unchecked")
void setValue(Widget widget, Object inValue) void setValue(Widget widget, Object inValue)
{ {
Object value = null; Object value = null;

View File

@@ -190,6 +190,7 @@ public class GroundMarkerPlugin extends Plugin
* @param points * @param points
* @return * @return
*/ */
@SuppressWarnings("unchecked")
private Collection<GroundMarkerWorldPoint> translateToWorld(Collection<GroundMarkerPoint> points) private Collection<GroundMarkerWorldPoint> translateToWorld(Collection<GroundMarkerPoint> points)
{ {
if (points.isEmpty()) if (points.isEmpty())

View File

@@ -714,7 +714,7 @@ public class LootTrackerPlugin extends Plugin
break; break;
} }
int killCount = Integer.valueOf(m.group(1)); int killCount = Integer.parseInt(m.group(1));
killCountMap.put(eventType.toUpperCase(), killCount); killCountMap.put(eventType.toUpperCase(), killCount);
return; return;
} }
@@ -755,11 +755,12 @@ public class LootTrackerPlugin extends Plugin
if (boss.find()) if (boss.find())
{ {
String bossName = boss.group(1); String bossName = boss.group(1);
int killCount = Integer.valueOf(boss.group(2)); int killCount = Integer.parseInt(boss.group(2));
killCountMap.put(bossName.toUpperCase(), killCount); killCountMap.put(bossName.toUpperCase(), killCount);
} }
} }
@SuppressWarnings("unchecked")
public void onItemContainerChanged(ItemContainerChanged event) public void onItemContainerChanged(ItemContainerChanged event)
{ {
if (pvpDeath && RESPAWN_REGIONS.contains(client.getLocalPlayer().getWorldLocation().getRegionID())) if (pvpDeath && RESPAWN_REGIONS.contains(client.getLocalPlayer().getWorldLocation().getRegionID()))
@@ -849,7 +850,7 @@ public class LootTrackerPlugin extends Plugin
} }
} }
public void deleteLocalRecords() void deleteLocalRecords()
{ {
try try
{ {
@@ -960,7 +961,7 @@ public class LootTrackerPlugin extends Plugin
* @param name - The String name of the record to toggle the hidden status of * @param name - The String name of the record to toggle the hidden status of
* @param ignore - true to ignore, false to remove * @param ignore - true to ignore, false to remove
*/ */
public void toggleNPC(String name, boolean ignore) void toggleNPC(String name, boolean ignore)
{ {
final Set<String> ignoredNPCSet = new HashSet<>(ignoredNPCs); final Set<String> ignoredNPCSet = new HashSet<>(ignoredNPCs);
if (ignore) if (ignore)
@@ -981,7 +982,7 @@ public class LootTrackerPlugin extends Plugin
* @param name - The String of the name to check * @param name - The String of the name to check
* @return - true if it is being ignored, false otherwise * @return - true if it is being ignored, false otherwise
*/ */
public boolean isIgnoredNPC(String name) boolean isIgnoredNPC(String name)
{ {
return ignoredNPCs.contains(name); return ignoredNPCs.contains(name);
} }

View File

@@ -35,11 +35,17 @@ import net.runelite.api.Constants;
public class MapLocations public class MapLocations
{ {
@SuppressWarnings("unchecked")
private static final List<Shape>[] MULTICOMBAT = new List[Constants.MAX_Z]; private static final List<Shape>[] MULTICOMBAT = new List[Constants.MAX_Z];
@SuppressWarnings("unchecked")
private static final List<Shape>[] NOT_MULTICOMBAT = new List[Constants.MAX_Z]; private static final List<Shape>[] NOT_MULTICOMBAT = new List[Constants.MAX_Z];
@SuppressWarnings("unchecked")
private static final List<Shape>[] ROUGH_WILDERNESS = new List[Constants.MAX_Z]; private static final List<Shape>[] ROUGH_WILDERNESS = new List[Constants.MAX_Z];
@SuppressWarnings("unchecked")
private static final List<Shape>[] WILDERNESS_LEVEL_LINES = new List[Constants.MAX_Z]; private static final List<Shape>[] WILDERNESS_LEVEL_LINES = new List[Constants.MAX_Z];
@SuppressWarnings("unchecked")
private static final List<Shape>[] DEADMAN_SAFE_ZONES = new List[Constants.MAX_Z]; private static final List<Shape>[] DEADMAN_SAFE_ZONES = new List[Constants.MAX_Z];
@SuppressWarnings("unchecked")
private static final List<Shape>[] PVP_WORLD_SAFE_ZONES = new List[Constants.MAX_Z]; private static final List<Shape>[] PVP_WORLD_SAFE_ZONES = new List[Constants.MAX_Z];
private static Area getArea(List<Shape> shapes) private static Area getArea(List<Shape> shapes)

View File

@@ -824,10 +824,11 @@ public class ScreenshotPlugin extends Plugin
Request request = null; Request request = null;
if (IMGUR_IMAGE_UPLOAD_URL != null) if (IMGUR_IMAGE_UPLOAD_URL != null)
{ {
RequestBody body = RequestBody.Companion.create(json, JSON);
request = new Request.Builder() request = new Request.Builder()
.url(IMGUR_IMAGE_UPLOAD_URL) .url(IMGUR_IMAGE_UPLOAD_URL)
.addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID) .addHeader("Authorization", "Client-ID " + IMGUR_CLIENT_ID)
.post(RequestBody.create(JSON, json)) .post(body)
.build(); .build();
} }

View File

@@ -219,6 +219,7 @@ public class ModifyPanel extends JPanel
labelContainer.repaint(); labelContainer.repaint();
} }
@SuppressWarnings("unchecked")
private void updateAdjustContainer() private void updateAdjustContainer()
{ {
adjustContainer.removeAll(); adjustContainer.removeAll();

View File

@@ -76,13 +76,13 @@ import net.runelite.client.eventbus.EventBus;
import net.runelite.client.input.KeyManager; import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.worldhopper.ping.Ping;
import net.runelite.client.ui.ClientToolbar; import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ExecutorServiceExceptionLogger; import net.runelite.client.util.ExecutorServiceExceptionLogger;
import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.HotkeyListener;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
import net.runelite.client.util.WorldUtil; import net.runelite.client.util.WorldUtil;
import net.runelite.client.util.ping.Ping;
import net.runelite.http.api.worlds.World; import net.runelite.http.api.worlds.World;
import net.runelite.http.api.worlds.WorldClient; import net.runelite.http.api.worlds.WorldClient;
import net.runelite.http.api.worlds.WorldResult; import net.runelite.http.api.worlds.WorldResult;

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.client.plugins.worldhopper.ping;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
interface IPHlpAPI extends Library
{
IPHlpAPI INSTANCE = Native.loadLibrary("IPHlpAPI", IPHlpAPI.class);
Pointer IcmpCreateFile();
boolean IcmpCloseHandle(Pointer handle);
int IcmpSendEcho(Pointer IcmpHandle, int DestinationAddress, Pointer RequestData, short RequestSize, Pointer RequestOptions, IcmpEchoReply ReplyBuffer, int ReplySize, int Timeout);
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.client.plugins.worldhopper.ping;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.platform.win32.WinDef;
import java.util.Arrays;
import java.util.List;
public class IcmpEchoReply extends Structure
{
private static final int IP_OPTION_INFO_SIZE = 1 + 1 + 1 + 1 + (Native.POINTER_SIZE == 8 ? 12 : 4); // on 64bit vms add 4 byte padding
public static final int SIZE = 4 + 4 + 4 + 2 + 2 + Native.POINTER_SIZE + IP_OPTION_INFO_SIZE;
public WinDef.ULONG address;
public WinDef.ULONG status;
public WinDef.ULONG roundTripTime;
public WinDef.USHORT dataSize;
public WinDef.USHORT reserved;
public WinDef.PVOID data;
public WinDef.UCHAR ttl;
public WinDef.UCHAR tos;
public WinDef.UCHAR flags;
public WinDef.UCHAR optionsSize;
public WinDef.PVOID optionsData;
IcmpEchoReply(final Pointer p)
{
super(p);
}
@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("address", "status", "roundTripTime", "dataSize", "reserved", "data", "ttl", "tos", "flags", "optionsSize", "optionsData");
}
}

View File

@@ -1,101 +0,0 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.client.plugins.worldhopper.ping;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.util.OSType;
import net.runelite.http.api.worlds.World;
@Slf4j
public class Ping
{
private static final String RUNELITE_PING = "RuneLitePing";
private static final int TIMEOUT = 2000;
private static final int PORT = 43594;
public static int ping(World world)
{
try
{
if (OSType.getOSType() == OSType.Windows)
{
return windowsPing(world);
}
return tcpPing(world);
}
catch (IOException ex)
{
log.warn("error pinging", ex);
return -1;
}
}
private static int windowsPing(World world) throws UnknownHostException
{
IPHlpAPI ipHlpAPI = IPHlpAPI.INSTANCE;
Pointer ptr = ipHlpAPI.IcmpCreateFile();
InetAddress inetAddress = InetAddress.getByName(world.getAddress());
byte[] address = inetAddress.getAddress();
String dataStr = RUNELITE_PING;
int dataLength = dataStr.length() + 1;
Pointer data = new Memory(dataLength);
data.setString(0L, dataStr);
IcmpEchoReply icmpEchoReply = new IcmpEchoReply(new Memory(IcmpEchoReply.SIZE + dataLength));
assert icmpEchoReply.size() == IcmpEchoReply.SIZE;
int packed = (address[0] & 0xff) | ((address[1] & 0xff) << 8) | ((address[2] & 0xff) << 16) | ((address[3] & 0xff) << 24);
int ret = ipHlpAPI.IcmpSendEcho(ptr, packed, data, (short) (dataLength), Pointer.NULL, icmpEchoReply, IcmpEchoReply.SIZE + dataLength, TIMEOUT);
if (ret != 1)
{
ipHlpAPI.IcmpCloseHandle(ptr);
return -1;
}
int rtt = Math.toIntExact(icmpEchoReply.roundTripTime.longValue());
ipHlpAPI.IcmpCloseHandle(ptr);
return rtt;
}
private static int tcpPing(World world) throws IOException
{
try (Socket socket = new Socket())
{
socket.setSoTimeout(TIMEOUT);
InetAddress inetAddress = InetAddress.getByName(world.getAddress());
long start = System.nanoTime();
socket.connect(new InetSocketAddress(inetAddress, PORT));
long end = System.nanoTime();
return (int) ((end - start) / 1000000L);
}
}
}

View File

@@ -51,6 +51,7 @@ public class DeferredEventBus extends EventBus
pendingEvents.add(new ImmutablePair<>(eventClass, event)); pendingEvents.add(new ImmutablePair<>(eventClass, event));
} }
@SuppressWarnings("unchecked")
public void replay() public void replay()
{ {
int size = pendingEvents.size(); int size = pendingEvents.size();

View File

@@ -30,7 +30,7 @@ import com.sun.jna.Pointer;
interface IPHlpAPI extends Library interface IPHlpAPI extends Library
{ {
IPHlpAPI INSTANCE = Native.loadLibrary("IPHlpAPI", IPHlpAPI.class); IPHlpAPI INSTANCE = Native.load("IPHlpAPI", IPHlpAPI.class);
Pointer IcmpCreateFile(); Pointer IcmpCreateFile();

View File

@@ -1410,7 +1410,7 @@ public abstract class RSClientMixin implements RSClient
} }
// Get the message node which was added // Get the message node which was added
Map<Integer, RSChatChannel> chatLineMap = client.getChatLineMap(); @SuppressWarnings("unchecked") Map<Integer, RSChatChannel> chatLineMap = client.getChatLineMap();
RSChatChannel chatLineBuffer = chatLineMap.get(type); RSChatChannel chatLineBuffer = chatLineMap.get(type);
MessageNode messageNode = chatLineBuffer.getLines()[0]; MessageNode messageNode = chatLineBuffer.getLines()[0];
@@ -1431,7 +1431,7 @@ public abstract class RSClientMixin implements RSClient
public static void renderWidgetLayer(Widget[] widgets, int parentId, int minX, int minY, int maxX, int maxY, int x, int y, int var8) public static void renderWidgetLayer(Widget[] widgets, int parentId, int minX, int minY, int maxX, int maxY, int x, int y, int var8)
{ {
Callbacks callbacks = client.getCallbacks(); Callbacks callbacks = client.getCallbacks();
HashTable<WidgetNode> componentTable = client.getComponentTable(); @SuppressWarnings("unchecked") HashTable<WidgetNode> componentTable = client.getComponentTable();
for (Widget rlWidget : widgets) for (Widget rlWidget : widgets)
{ {

View File

@@ -143,7 +143,7 @@ public abstract class RSWidgetMixin implements RSWidget
// parent id potentially incorrect // parent id potentially incorrect
// check the parent in the component table // check the parent in the component table
HashTable<WidgetNode> componentTable = client.getComponentTable(); @SuppressWarnings("unchecked") HashTable<WidgetNode> componentTable = client.getComponentTable();
WidgetNode widgetNode = componentTable.get(parentId); WidgetNode widgetNode = componentTable.get(parentId);
if (widgetNode == null || widgetNode.getId() != TO_GROUP(id)) if (widgetNode == null || widgetNode.getId() != TO_GROUP(id))
{ {
@@ -380,7 +380,7 @@ public abstract class RSWidgetMixin implements RSWidget
return new Widget[0]; return new Widget[0];
} }
HashTable<WidgetNode> componentTable = client.getComponentTable(); @SuppressWarnings("unchecked") HashTable<WidgetNode> componentTable = client.getComponentTable();
WidgetNode wn = componentTable.get(getId()); WidgetNode wn = componentTable.get(getId());
if (wn == null) if (wn == null)