Merge pull request #941 from sdburns1998/code-cleanup

api: client: code clean up
This commit is contained in:
Tyler Bochard
2019-07-08 19:20:39 -04:00
committed by GitHub
25 changed files with 89 additions and 104 deletions

View File

@@ -27,9 +27,9 @@ package net.runelite.api;
import java.awt.Canvas; import java.awt.Canvas;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
@@ -1677,7 +1677,7 @@ public interface Client extends GameShell
/** /**
* Set spells excluded from above hiding * Set spells excluded from above hiding
*/ */
void setUnhiddenCasts(HashSet<String> casts); void setUnhiddenCasts(Set<String> casts);
/** /**
* Sorts the current menu entries in the same way the client does this. * Sorts the current menu entries in the same way the client does this.

View File

@@ -317,12 +317,6 @@ public class Perspective
final int neX = localLocation.getX() + (size * LOCAL_TILE_SIZE / 2); final int neX = localLocation.getX() + (size * LOCAL_TILE_SIZE / 2);
final int neY = localLocation.getY() + (size * LOCAL_TILE_SIZE / 2); final int neY = localLocation.getY() + (size * LOCAL_TILE_SIZE / 2);
final int seX = swX;
final int seY = neY;
final int nwX = neX;
final int nwY = swY;
final byte[][][] tileSettings = client.getTileSettings(); final byte[][][] tileSettings = client.getTileSettings();
final int sceneX = localLocation.getSceneX(); final int sceneX = localLocation.getSceneX();
@@ -340,14 +334,14 @@ public class Perspective
} }
final int swHeight = getHeight(client, swX, swY, tilePlane); final int swHeight = getHeight(client, swX, swY, tilePlane);
final int nwHeight = getHeight(client, nwX, nwY, tilePlane); final int nwHeight = getHeight(client, neX, swY, tilePlane);
final int neHeight = getHeight(client, neX, neY, tilePlane); final int neHeight = getHeight(client, neX, neY, tilePlane);
final int seHeight = getHeight(client, seX, seY, tilePlane); final int seHeight = getHeight(client, swX, neY, tilePlane);
Point p1 = localToCanvas(client, swX, swY, swHeight); Point p1 = localToCanvas(client, swX, swY, swHeight);
Point p2 = localToCanvas(client, nwX, nwY, nwHeight); Point p2 = localToCanvas(client, neX, swY, nwHeight);
Point p3 = localToCanvas(client, neX, neY, neHeight); Point p3 = localToCanvas(client, neX, neY, neHeight);
Point p4 = localToCanvas(client, seX, seY, seHeight); Point p4 = localToCanvas(client, swX, neY, seHeight);
if (p1 == null || p2 == null || p3 == null || p4 == null) if (p1 == null || p2 == null || p3 == null || p4 == null)
{ {

View File

@@ -104,10 +104,6 @@ public class Point
{ {
return false; return false;
} }
if (this.y != other.y) return this.y == other.y;
{
return false;
}
return true;
} }
} }

View File

@@ -271,8 +271,16 @@ public class WorldArea
LocalPoint lp = LocalPoint.fromWorld(client, x, y); LocalPoint lp = LocalPoint.fromWorld(client, x, y);
int startX = lp.getSceneX() + dx; int startX = 0;
int startY = lp.getSceneY() + dy; if (lp != null)
{
startX = lp.getSceneX() + dx;
}
int startY = 0;
if (lp != null)
{
startY = lp.getSceneY() + dy;
}
int checkX = startX + (dx > 0 ? width - 1 : 0); int checkX = startX + (dx > 0 ? width - 1 : 0);
int checkY = startY + (dy > 0 ? height - 1 : 0); int checkY = startY + (dy > 0 ? height - 1 : 0);
int endX = startX + width - 1; int endX = startX + width - 1;
@@ -427,11 +435,8 @@ public class WorldArea
} }
if (height == 1) if (height == 1)
{ {
if ((collisionDataFlags[checkX - dx][checkY] & yFlags) != 0 && return (collisionDataFlags[checkX - dx][checkY] & yFlags) == 0 ||
extraCondition.test(WorldPoint.fromScene(client, startX, checkY, client.getPlane()))) !extraCondition.test(WorldPoint.fromScene(client, startX, checkY, client.getPlane()));
{
return false;
}
} }
} }

View File

@@ -370,16 +370,12 @@ public class WorldPoint
*/ */
public static boolean isInZone(WorldPoint lowerBound, WorldPoint upperBound, WorldPoint userLocation) public static boolean isInZone(WorldPoint lowerBound, WorldPoint upperBound, WorldPoint userLocation)
{ {
if (userLocation.getX() < lowerBound.getX() return userLocation.getX() >= lowerBound.getX()
|| userLocation.getX() > upperBound.getX() && userLocation.getX() <= upperBound.getX()
|| userLocation.getY() < lowerBound.getY() && userLocation.getY() >= lowerBound.getY()
|| userLocation.getY() > upperBound.getY() && userLocation.getY() <= upperBound.getY()
|| userLocation.getPlane() < lowerBound.getPlane() && userLocation.getPlane() >= lowerBound.getPlane()
|| userLocation.getPlane() > upperBound.getPlane()) && userLocation.getPlane() <= upperBound.getPlane();
{
return false;
}
return true;
} }
/** /**

View File

@@ -125,8 +125,7 @@ public class Jarvis
private static long crossProduct(Point p, Point q, Point r) private static long crossProduct(Point p, Point q, Point r)
{ {
long val = (long)(q.getY() - p.getY()) * (r.getX() - q.getX()) return (long)(q.getY() - p.getY()) * (r.getX() - q.getX())
- (long)(q.getX() - p.getX()) * (r.getY() - q.getY()); - (long)(q.getX() - p.getX()) * (r.getY() - q.getY());
return val;
} }
} }

View File

@@ -36,7 +36,7 @@ import net.runelite.api.Client;
@Slf4j @Slf4j
public class ClientThread public class ClientThread
{ {
private ConcurrentLinkedQueue<BooleanSupplier> invokes = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<BooleanSupplier> invokes = new ConcurrentLinkedQueue<>();
@Inject @Inject
private Client client; private Client client;

View File

@@ -115,7 +115,7 @@ public class ChatMessageManager
boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1; boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1;
Color usernameColor = null; Color usernameColor = null;
Color senderColor = null; Color senderColor;
switch (chatMessageType) switch (chatMessageType)
{ {

View File

@@ -49,7 +49,7 @@ import net.runelite.discord.DiscordUser;
public class DiscordService implements AutoCloseable public class DiscordService implements AutoCloseable
{ {
private final EventBus eventBus; private final EventBus eventBus;
public final RuneLiteProperties runeLiteProperties; private final RuneLiteProperties runeLiteProperties;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
private final DiscordRPC discordRPC; private final DiscordRPC discordRPC;

View File

@@ -36,6 +36,7 @@ import static net.runelite.client.game.HiscoreManager.NONE;
import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreEndpoint;
import net.runelite.http.api.hiscore.HiscoreResult; import net.runelite.http.api.hiscore.HiscoreResult;
import org.jetbrains.annotations.NotNull;
@Slf4j @Slf4j
class HiscoreLoader extends CacheLoader<HiscoreManager.HiscoreKey, HiscoreResult> class HiscoreLoader extends CacheLoader<HiscoreManager.HiscoreKey, HiscoreResult>
@@ -50,7 +51,7 @@ class HiscoreLoader extends CacheLoader<HiscoreManager.HiscoreKey, HiscoreResult
} }
@Override @Override
public HiscoreResult load(HiscoreManager.HiscoreKey hiscoreKey) throws Exception public HiscoreResult load(@NotNull HiscoreManager.HiscoreKey hiscoreKey) throws Exception
{ {
return EMPTY; return EMPTY;
} }

View File

@@ -168,6 +168,7 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.http.api.item.ItemClient; import net.runelite.http.api.item.ItemClient;
import net.runelite.http.api.item.ItemPrice; import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.item.ItemStats; import net.runelite.http.api.item.ItemStats;
import org.jetbrains.annotations.NotNull;
@Singleton @Singleton
@Slf4j @Slf4j
@@ -279,7 +280,7 @@ public class ItemManager
.build(new CacheLoader<ImageKey, AsyncBufferedImage>() .build(new CacheLoader<ImageKey, AsyncBufferedImage>()
{ {
@Override @Override
public AsyncBufferedImage load(ImageKey key) throws Exception public AsyncBufferedImage load(@NotNull ImageKey key) throws Exception
{ {
return loadImage(key.itemId, key.itemQuantity, key.stackable); return loadImage(key.itemId, key.itemQuantity, key.stackable);
} }
@@ -291,7 +292,7 @@ public class ItemManager
.build(new CacheLoader<Integer, ItemDefinition>() .build(new CacheLoader<Integer, ItemDefinition>()
{ {
@Override @Override
public ItemDefinition load(Integer key) throws Exception public ItemDefinition load(@NotNull Integer key) throws Exception
{ {
return client.getItemDefinition(key); return client.getItemDefinition(key);
} }
@@ -303,7 +304,7 @@ public class ItemManager
.build(new CacheLoader<OutlineKey, BufferedImage>() .build(new CacheLoader<OutlineKey, BufferedImage>()
{ {
@Override @Override
public BufferedImage load(OutlineKey key) throws Exception public BufferedImage load(@NotNull OutlineKey key) throws Exception
{ {
return loadItemOutline(key.itemId, key.itemQuantity, key.outlineColor); return loadItemOutline(key.itemId, key.itemQuantity, key.outlineColor);
} }

View File

@@ -40,7 +40,7 @@ public class SkillIconManager
public BufferedImage getSkillImage(Skill skill, boolean small) public BufferedImage getSkillImage(Skill skill, boolean small)
{ {
int skillIdx = skill.ordinal() + (small ? Skill.values().length : 0); int skillIdx = skill.ordinal() + (small ? Skill.values().length : 0);
BufferedImage skillImage = null; BufferedImage skillImage;
if (imgCache[skillIdx] != null) if (imgCache[skillIdx] != null)
{ {

View File

@@ -20,10 +20,10 @@ public enum Sound
RESTORED_SPECIAL_ATTACK(16, "net/runelite/client/game/sounds/restorespec.wav"), RESTORED_SPECIAL_ATTACK(16, "net/runelite/client/game/sounds/restorespec.wav"),
IDLE(17, "net/runelite/client/game/sounds/idle.wav"); IDLE(17, "net/runelite/client/game/sounds/idle.wav");
private String filePath; private final String filePath;
private int id; private final int id;
private Sound(int id, String filePath) Sound(int id, String filePath)
{ {
this.id = id; this.id = id;
this.filePath = filePath; this.filePath = filePath;

View File

@@ -54,7 +54,7 @@ public class SpriteManager
@Inject @Inject
private ClientThread clientThread; private ClientThread clientThread;
public Cache<Long, BufferedImage> cache = CacheBuilder.newBuilder() private final Cache<Long, BufferedImage> cache = CacheBuilder.newBuilder()
.maximumSize(128L) .maximumSize(128L)
.expireAfterAccess(1, TimeUnit.HOURS) .expireAfterAccess(1, TimeUnit.HOURS)
.build(); .build();
@@ -110,12 +110,8 @@ public class SpriteManager
public void addSpriteTo(JButton c, int archive, int file) public void addSpriteTo(JButton c, int archive, int file)
{ {
getSpriteAsync(archive, file, img -> getSpriteAsync(archive, file, img ->
{
SwingUtilities.invokeLater(() -> SwingUtilities.invokeLater(() ->
{ c.setIcon(new ImageIcon(img))));
c.setIcon(new ImageIcon(img));
});
});
} }
/** /**
@@ -124,12 +120,8 @@ public class SpriteManager
public void addSpriteTo(JLabel c, int archive, int file) public void addSpriteTo(JLabel c, int archive, int file)
{ {
getSpriteAsync(archive, file, img -> getSpriteAsync(archive, file, img ->
{
SwingUtilities.invokeLater(() -> SwingUtilities.invokeLater(() ->
{ c.setIcon(new ImageIcon(img))));
c.setIcon(new ImageIcon(img));
});
});
} }
public void addSpriteOverrides(SpriteOverride[] add) public void addSpriteOverrides(SpriteOverride[] add)

View File

@@ -27,13 +27,13 @@ package net.runelite.client.game.chatbox;
/** /**
* A modal input that lives in the chatbox panel. * A modal input that lives in the chatbox panel.
*/ */
public abstract class ChatboxInput abstract class ChatboxInput
{ {
protected void open() void open()
{ {
} }
protected void close() void close()
{ {
} }
} }

View File

@@ -156,12 +156,12 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
return this; return this;
} }
public ChatboxTextInput cursorAt(int index) private ChatboxTextInput cursorAt(int index)
{ {
return cursorAt(index, index); return cursorAt(index, index);
} }
public ChatboxTextInput cursorAt(int indexA, int indexB) private ChatboxTextInput cursorAt(int indexA, int indexB)
{ {
if (indexA < 0) if (indexA < 0)
{ {
@@ -722,9 +722,6 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
newPos++; newPos++;
break; break;
case KeyEvent.VK_UP: case KeyEvent.VK_UP:
ev.consume();
newPos = getLineOffset.applyAsInt(code);
break;
case KeyEvent.VK_DOWN: case KeyEvent.VK_DOWN:
ev.consume(); ev.consume();
newPos = getLineOffset.applyAsInt(code); newPos = getLineOffset.applyAsInt(code);

View File

@@ -40,7 +40,7 @@ import lombok.extern.slf4j.Slf4j;
public class ClientLoader public class ClientLoader
{ {
private final ClientConfigLoader clientConfigLoader; private final ClientConfigLoader clientConfigLoader;
private ClientUpdateCheckMode updateCheckMode; private final ClientUpdateCheckMode updateCheckMode;
public static boolean useLocalInjected = false; public static boolean useLocalInjected = false;
@Inject @Inject
@@ -69,14 +69,16 @@ public class ClientLoader
return null; return null;
} }
} }
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) catch (IOException | InstantiationException | IllegalAccessException e)
{ {
if (e instanceof ClassNotFoundException) log.error("Error loading RS!", e);
{ return null;
log.error("Unable to load client - class not found. This means you" }
+ " are not running RuneLite with Maven as the injected client" catch (ClassNotFoundException e)
+ " is not in your classpath."); {
} log.error("Unable to load client - class not found. This means you"
+ " are not running RuneLite with Maven as the injected client"
+ " is not in your classpath.");
log.error("Error loading RS!", e); log.error("Error loading RS!", e);
return null; return null;

View File

@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;
@Singleton @Singleton
public class DeferredEventBus extends EventBus public class DeferredEventBus extends EventBus
@@ -43,19 +44,19 @@ public class DeferredEventBus extends EventBus
} }
@Override @Override
public void register(Object object) public void register(@NotNull Object object)
{ {
eventBus.register(object); eventBus.register(object);
} }
@Override @Override
public void unregister(Object object) public void unregister(@NotNull Object object)
{ {
eventBus.unregister(object); eventBus.unregister(object);
} }
@Override @Override
public void post(Object object) public void post(@NotNull Object object)
{ {
pendingEvents.add(object); pendingEvents.add(object);
} }
@@ -66,7 +67,10 @@ public class DeferredEventBus extends EventBus
while (size-- > 0) while (size-- > 0)
{ {
Object object = pendingEvents.poll(); Object object = pendingEvents.poll();
eventBus.post(object); if (object != null)
{
eventBus.post(object);
}
} }
} }
} }

View File

@@ -8,13 +8,13 @@ import net.runelite.api.coords.WorldPoint;
public class MiscUtils public class MiscUtils
{ {
private static int[] abovePointsX = {2944, 3392, 3392, 2944}; private static final int[] abovePointsX = {2944, 3392, 3392, 2944};
private static int[] abovePointsY = {3523, 3523, 3971, 3971}; private static final int[] abovePointsY = {3523, 3523, 3971, 3971};
private static int[] belowPointsX = {2944, 2944, 3264, 3264}; private static final int[] belowPointsX = {2944, 2944, 3264, 3264};
private static int[] belowPointsY = {9918, 10360, 10360, 9918}; private static final int[] belowPointsY = {9918, 10360, 10360, 9918};
private static Polygon abovePoly = new Polygon(abovePointsX, abovePointsY, abovePointsX.length); private static final Polygon abovePoly = new Polygon(abovePointsX, abovePointsY, abovePointsX.length);
private static Polygon belowPoly = new Polygon(belowPointsX, belowPointsY, belowPointsX.length); private static final Polygon belowPoly = new Polygon(belowPointsX, belowPointsY, belowPointsX.length);
//test replacement so private for now //test replacement so private for now
private static boolean inWildy(WorldPoint point) private static boolean inWildy(WorldPoint point)
@@ -50,12 +50,9 @@ public class MiscUtils
//v underground //v above ground //v underground //v above ground
int wildernessLevel = clamp(y > 6400 ? ((y - 9920) / 8) + 1 : ((y - 3520) / 8) + 1, 0, 56); int wildernessLevel = clamp(y > 6400 ? ((y - 9920) / 8) + 1 : ((y - 3520) / 8) + 1, 0, 56);
if (point.getPlane() > 0) if (point.getPlane() > 0 && y < 9920)
{ {
if (y < 9920) wildernessLevel = 0;
{
wildernessLevel = 0;
}
} }
if (client.getWorldType().stream().anyMatch(worldType -> worldType == WorldType.PVP || worldType == WorldType.HIGH_RISK)) if (client.getWorldType().stream().anyMatch(worldType -> worldType == WorldType.PVP || worldType == WorldType.HIGH_RISK))

View File

@@ -36,7 +36,7 @@ public class PvPUtil
* @param point the point in the world to get the wilderness level for * @param point the point in the world to get the wilderness level for
* @return the int representing the wilderness level * @return the int representing the wilderness level
*/ */
public static int getWildernessLevelFrom(WorldPoint point) private static int getWildernessLevelFrom(WorldPoint point)
{ {
int y = point.getY(); int y = point.getY();

View File

@@ -30,12 +30,12 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
public class RefUtils implements Opcodes class RefUtils implements Opcodes
{ {
private static final String TYPE_PREFIX = "us/runelitepl/mixinprocessor/annotations/"; private static final String TYPE_PREFIX = "us/runelitepl/mixinprocessor/annotations/";
public static boolean isReturn(int opcode, boolean checkType) private static boolean isReturn(int opcode, boolean checkType)
{ {
return (opcode == RETURN && !checkType) || opcode == IRETURN || opcode == LRETURN || opcode == DRETURN || return (opcode == RETURN && !checkType) || opcode == IRETURN || opcode == LRETURN || opcode == DRETURN ||
opcode == ARETURN || opcode == FRETURN; opcode == ARETURN || opcode == FRETURN;
@@ -76,7 +76,7 @@ public class RefUtils implements Opcodes
return false; return false;
} }
public static String makeAnnotationDesc(String annot) private static String makeAnnotationDesc(String annot)
{ {
return "L" + TYPE_PREFIX + annot + ";"; return "L" + TYPE_PREFIX + annot + ";";
} }

View File

@@ -76,7 +76,7 @@ public class SwingUtil
* Sets some sensible defaults for swing. * Sets some sensible defaults for swing.
* IMPORTANT! Needs to be called before main frame creation * IMPORTANT! Needs to be called before main frame creation
*/ */
public static void setupDefaults() private static void setupDefaults()
{ {
// Force heavy-weight popups/tooltips. // Force heavy-weight popups/tooltips.
// Prevents them from being obscured by the game applet. // Prevents them from being obscured by the game applet.
@@ -117,7 +117,7 @@ public class SwingUtil
* *
* @param laf the swing look and feel * @param laf the swing look and feel
*/ */
public static void setTheme(@Nonnull final LookAndFeel laf) private static void setTheme(@Nonnull final LookAndFeel laf)
{ {
try try
{ {
@@ -135,7 +135,7 @@ public class SwingUtil
* *
* @param font the new font to use * @param font the new font to use
*/ */
public static void setFont(@Nonnull final Font font) private static void setFont(@Nonnull final Font font)
{ {
final FontUIResource f = new FontUIResource(font); final FontUIResource f = new FontUIResource(font);
final Enumeration keys = UIManager.getDefaults().keys(); final Enumeration keys = UIManager.getDefaults().keys();

View File

@@ -77,12 +77,12 @@ public enum WildernessLocation
this.worldArea = new WorldArea(location.x, location.y, location.width, location.height, plane); this.worldArea = new WorldArea(location.x, location.y, location.width, location.height, plane);
} }
public static class Location static class Location
{ {
public int x; final int x;
public int y; final int y;
public int width; final int width;
public int height; final int height;
Location(int x, int y, int x1, int y1) Location(int x, int y, int x1, int y1)
{ {

View File

@@ -30,7 +30,7 @@ import com.sun.jna.platform.win32.WinDef;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class IcmpEchoReply extends Structure class IcmpEchoReply extends Structure
{ {
private static final int IP_OPTION_INFO_SIZE = 1 + 1 + 1 + 1 + (Pointer.SIZE == 8 ? 12 : 4); // on 64bit vms add 4 byte padding private static final int IP_OPTION_INFO_SIZE = 1 + 1 + 1 + 1 + (Pointer.SIZE == 8 ? 12 : 4); // on 64bit vms add 4 byte padding
public static final int SIZE = 4 + 4 + 4 + 2 + 2 + Pointer.SIZE + IP_OPTION_INFO_SIZE; public static final int SIZE = 4 + 4 + 4 + 2 + 2 + Pointer.SIZE + IP_OPTION_INFO_SIZE;

View File

@@ -25,6 +25,7 @@
package net.runelite.mixins; package net.runelite.mixins;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import net.runelite.api.ClanMember; import net.runelite.api.ClanMember;
import net.runelite.api.EnumDefinition; import net.runelite.api.EnumDefinition;
@@ -207,7 +208,7 @@ public abstract class RSClientMixin implements RSClient
private static boolean hideFriendCastOptions = false; private static boolean hideFriendCastOptions = false;
@Inject @Inject
private static HashSet<String> unhiddenCasts = new HashSet<String>(); private static Set<String> unhiddenCasts = new HashSet<String>();
@Inject @Inject
@Override @Override
@@ -225,7 +226,7 @@ public abstract class RSClientMixin implements RSClient
@Inject @Inject
@Override @Override
public void setUnhiddenCasts(HashSet<String> casts) public void setUnhiddenCasts(Set<String> casts)
{ {
unhiddenCasts = casts; unhiddenCasts = casts;
} }