rl-api: add MagicConstant annotations

This commit is contained in:
Max Weber
2021-09-27 00:36:19 -06:00
parent 4f01dabed4
commit 22d1014bd3
8 changed files with 69 additions and 25 deletions

View File

@@ -50,6 +50,12 @@
<artifactId>jsr305</artifactId> <artifactId>jsr305</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@@ -34,15 +34,18 @@ import javax.annotation.Nullable;
import net.runelite.api.annotations.VisibleForDevtools; import net.runelite.api.annotations.VisibleForDevtools;
import net.runelite.api.annotations.VisibleForExternalPlugins; import net.runelite.api.annotations.VisibleForExternalPlugins;
import net.runelite.api.clan.ClanChannel; import net.runelite.api.clan.ClanChannel;
import net.runelite.api.clan.ClanID;
import net.runelite.api.clan.ClanSettings; import net.runelite.api.clan.ClanSettings;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.hooks.Callbacks; import net.runelite.api.hooks.Callbacks;
import net.runelite.api.hooks.DrawCallbacks; import net.runelite.api.hooks.DrawCallbacks;
import net.runelite.api.vars.AccountType; import net.runelite.api.vars.AccountType;
import net.runelite.api.widgets.ItemQuantityMode;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetConfig; import net.runelite.api.widgets.WidgetConfig;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import org.intellij.lang.annotations.MagicConstant;
/** /**
* Represents the RuneScape client. * Represents the RuneScape client.
@@ -392,7 +395,7 @@ public interface Client extends GameEngine
* @return the created sprite * @return the created sprite
*/ */
@Nullable @Nullable
SpritePixels createItemSprite(int itemId, int quantity, int border, int shadowColor, int stackable, boolean noted, int scale); SpritePixels createItemSprite(int itemId, int quantity, int border, int shadowColor, @MagicConstant(valuesFromClass = ItemQuantityMode.class) int stackable, boolean noted, int scale);
/** /**
* Loads and creates the sprite images of the passed archive and file IDs. * Loads and creates the sprite images of the passed archive and file IDs.
@@ -873,7 +876,7 @@ public interface Client extends GameEngine
* *
* @return the widget flags table * @return the widget flags table
*/ */
HashTable getWidgetFlags(); HashTable<IntegerNode> getWidgetFlags();
/** /**
* Gets the widget node component table. * Gets the widget node component table.
@@ -1937,7 +1940,7 @@ public interface Client extends GameEngine
* @return * @return
* @see KeyCode * @see KeyCode
*/ */
boolean isKeyPressed(int keycode); boolean isKeyPressed(@MagicConstant(valuesFromClass = KeyCode.class) int keycode);
/** /**
* Get the list of message ids for the recently received cross-world messages. The upper 32 bits of the * Get the list of message ids for the recently received cross-world messages. The upper 32 bits of the
@@ -1989,7 +1992,7 @@ public interface Client extends GameEngine
* @see net.runelite.api.clan.ClanID * @see net.runelite.api.clan.ClanID
*/ */
@Nullable @Nullable
ClanChannel getClanChannel(int clanId); ClanChannel getClanChannel(@MagicConstant(valuesFromClass = ClanID.class) int clanId);
/** /**
* Get clan settings by id * Get clan settings by id
@@ -1998,7 +2001,7 @@ public interface Client extends GameEngine
* @see net.runelite.api.clan.ClanID * @see net.runelite.api.clan.ClanID
*/ */
@Nullable @Nullable
ClanSettings getClanSettings(int clanId); ClanSettings getClanSettings(@MagicConstant(valuesFromClass = ClanID.class) int clanId);
void setUnlockedFps(boolean unlock); void setUnlockedFps(boolean unlock);
void setUnlockedFpsTarget(int fps); void setUnlockedFpsTarget(int fps);

View File

@@ -24,6 +24,8 @@
*/ */
package net.runelite.api; package net.runelite.api;
import org.intellij.lang.annotations.MagicConstant;
/** /**
* Represents tile collision data for the scene * Represents tile collision data for the scene
*/ */
@@ -42,5 +44,6 @@ public interface CollisionData
* @return all collision flags for the tiles in the scene * @return all collision flags for the tiles in the scene
* @see Constants#SCENE_SIZE * @see Constants#SCENE_SIZE
*/ */
@MagicConstant(flagsFromClass = CollisionDataFlag.class)
int[][] getFlags(); int[][] getFlags();
} }

View File

@@ -24,6 +24,9 @@
*/ */
package net.runelite.api; package net.runelite.api;
import net.runelite.api.widgets.WidgetModalMode;
import org.intellij.lang.annotations.MagicConstant;
/** /**
* Represents a widget as an iterable node. * Represents a widget as an iterable node.
*/ */
@@ -40,5 +43,6 @@ public interface WidgetNode extends Node
/** /**
* @see net.runelite.api.widgets.WidgetModalMode * @see net.runelite.api.widgets.WidgetModalMode
*/ */
@MagicConstant(valuesFromClass = WidgetModalMode.class)
int getModalMode(); int getModalMode();
} }

View File

@@ -27,6 +27,8 @@ package net.runelite.api.events;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import lombok.Value; import lombok.Value;
import net.runelite.api.clan.ClanChannel; import net.runelite.api.clan.ClanChannel;
import net.runelite.api.clan.ClanID;
import org.intellij.lang.annotations.MagicConstant;
/** /**
* An event fired when the local player joins or leaves a clan channel. * An event fired when the local player joins or leaves a clan channel.
@@ -43,6 +45,7 @@ public class ClanChannelChanged
* The clan id, or -1 for guest clan * The clan id, or -1 for guest clan
* @see net.runelite.api.clan.ClanID * @see net.runelite.api.clan.ClanID
*/ */
@MagicConstant(valuesFromClass = ClanID.class)
private int clanId; private int clanId;
/** /**
* Whether or not this was the guest clan channel * Whether or not this was the guest clan channel

View File

@@ -25,6 +25,8 @@
package net.runelite.api.events; package net.runelite.api.events;
import lombok.Value; import lombok.Value;
import net.runelite.api.widgets.WidgetModalMode;
import org.intellij.lang.annotations.MagicConstant;
/** /**
* Posted when an interface is about to be closed * Posted when an interface is about to be closed
@@ -40,6 +42,7 @@ public class WidgetClosed
/** /**
* @see net.runelite.api.widgets.WidgetModalMode * @see net.runelite.api.widgets.WidgetModalMode
*/ */
@MagicConstant(valuesFromClass = WidgetModalMode.class)
private final int modalMode; private final int modalMode;
/** /**

View File

@@ -29,6 +29,8 @@ import java.util.Collection;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.runelite.api.FontTypeFace; import net.runelite.api.FontTypeFace;
import net.runelite.api.Point; import net.runelite.api.Point;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.Range;
/** /**
* Represents an on-screen UI element that is drawn on the canvas. * Represents an on-screen UI element that is drawn on the canvas.
@@ -59,6 +61,7 @@ public interface Widget
* *
* @see WidgetType * @see WidgetType
*/ */
@MagicConstant(valuesFromClass = WidgetType.class)
int getType(); int getType();
/** /**
@@ -66,7 +69,7 @@ public interface Widget
* *
* @see WidgetType * @see WidgetType
*/ */
void setType(int type); void setType(@MagicConstant(valuesFromClass = WidgetType.class) int type);
/** /**
* Gets the type of content displayed by the widget. * Gets the type of content displayed by the widget.
@@ -81,9 +84,8 @@ public interface Widget
/** /**
* Gets the current click configuration of the widget. * Gets the current click configuration of the widget.
* @see WidgetConfig * @see WidgetConfig
*
* @see WidgetConfig
*/ */
@MagicConstant(flagsFromClass = WidgetConfig.class)
int getClickMask(); int getClickMask();
/** /**
@@ -91,7 +93,7 @@ public interface Widget
* *
* @see WidgetConfig * @see WidgetConfig
*/ */
Widget setClickMask(int mask); Widget setClickMask(@MagicConstant(flagsFromClass = WidgetConfig.class) int mask);
/** /**
* Gets the parent widget, if this widget is a child. * Gets the parent widget, if this widget is a child.
@@ -246,7 +248,7 @@ public interface Widget
/** /**
* Gets the Model/NPC/Item ID displayed in the widget. * Gets the Model/NPC/Item ID displayed in the widget.
* *
* @see WidgetModelType * @see #getModelType()
*/ */
int getModelId(); int getModelId();
@@ -262,6 +264,7 @@ public interface Widget
* *
* @see WidgetModelType * @see WidgetModelType
*/ */
@MagicConstant(valuesFromClass = WidgetModelType.class)
int getModelType(); int getModelType();
/** /**
@@ -270,7 +273,7 @@ public interface Widget
* @param type the new model type * @param type the new model type
* @see WidgetModelType * @see WidgetModelType
*/ */
Widget setModelType(int type); Widget setModelType(@MagicConstant(valuesFromClass = WidgetModelType.class) int type);
/** /**
* Gets the sequence ID used to animate the model in the widget * Gets the sequence ID used to animate the model in the widget
@@ -290,6 +293,7 @@ public interface Widget
* Gets the x rotation of the model displayed in the widget. * Gets the x rotation of the model displayed in the widget.
* 0 = no rotation, 2047 = full rotation * 0 = no rotation, 2047 = full rotation
*/ */
@Range(from = 0, to = 2047)
int getRotationX(); int getRotationX();
/** /**
@@ -300,12 +304,13 @@ public interface Widget
* *
* @param modelX the new model x rotation value * @param modelX the new model x rotation value
*/ */
Widget setRotationX(int modelX); Widget setRotationX(@Range(from = 0, to = 2047) int modelX);
/** /**
* Gets the y rotation of the model displayed in the widget. * Gets the y rotation of the model displayed in the widget.
* 0 = no rotation, 2047 = full rotation * 0 = no rotation, 2047 = full rotation
*/ */
@Range(from = 0, to = 2047)
int getRotationY(); int getRotationY();
/** /**
@@ -316,12 +321,13 @@ public interface Widget
* *
* @param modelY the new model y rotation value * @param modelY the new model y rotation value
*/ */
Widget setRotationY(int modelY); Widget setRotationY(@Range(from = 0, to = 2047) int modelY);
/** /**
* Gets the z rotation of the model displayed in the widget. * Gets the z rotation of the model displayed in the widget.
* 0 = no rotation, 2047 = full rotation * 0 = no rotation, 2047 = full rotation
*/ */
@Range(from = 0, to = 2047)
int getRotationZ(); int getRotationZ();
/** /**
@@ -332,7 +338,7 @@ public interface Widget
* *
* @param modelZ the new model z rotation value * @param modelZ the new model z rotation value
*/ */
Widget setRotationZ(int modelZ); Widget setRotationZ(@Range(from = 0, to = 2047) int modelZ);
/** /**
* Gets the amount zoomed in on the model displayed in the widget. * Gets the amount zoomed in on the model displayed in the widget.
@@ -577,8 +583,13 @@ public interface Widget
*/ */
Widget setOriginalY(int originalY); Widget setOriginalY(int originalY);
/**
* Sets the X/Y coordinates
*/
Widget setPos(int x, int y); Widget setPos(int x, int y);
Widget setPos(int x, int y, int xMode, int yMode); Widget setPos(int x, int y,
@MagicConstant(valuesFromClass = WidgetPositionMode.class) int xMode,
@MagicConstant(valuesFromClass = WidgetPositionMode.class) int yMode);
/** /**
* Gets the height coordinate of this widget before being adjusted by * Gets the height coordinate of this widget before being adjusted by
@@ -609,7 +620,9 @@ public interface Widget
Widget setOriginalWidth(int originalWidth); Widget setOriginalWidth(int originalWidth);
Widget setSize(int width, int height); Widget setSize(int width, int height);
Widget setSize(int width, int height, int widthMode, int heightMode); Widget setSize(int width, int height,
@MagicConstant(valuesFromClass = WidgetSizeMode.class) int widthMode,
@MagicConstant(valuesFromClass = WidgetSizeMode.class) int heightMode);
/** /**
* Gets the menu options available on the widget as a sparse array. * Gets the menu options available on the widget as a sparse array.
@@ -622,14 +635,14 @@ public interface Widget
* @param index the index of the new widget in the children list or -1 to append to the back * @param index the index of the new widget in the children list or -1 to append to the back
* @param type the {@link WidgetType} of the widget * @param type the {@link WidgetType} of the widget
*/ */
Widget createChild(int index, int type); Widget createChild(int index, @MagicConstant(valuesFromClass = WidgetType.class) int type);
/** /**
* Creates a dynamic widget child at the end of the children list * Creates a dynamic widget child at the end of the children list
* *
* @param type the {@link WidgetType} of the widget * @param type the {@link WidgetType} of the widget
*/ */
Widget createChild(int type); Widget createChild(@MagicConstant(valuesFromClass = WidgetType.class) int type);
/** /**
* Removes all of this widget's dynamic children * Removes all of this widget's dynamic children
@@ -821,11 +834,13 @@ public interface Widget
/** /**
* Returns widget {@link net.runelite.api.widgets.ItemQuantityMode}. * Returns widget {@link net.runelite.api.widgets.ItemQuantityMode}.
*/ */
@MagicConstant(valuesFromClass = ItemQuantityMode.class)
int getItemQuantityMode(); int getItemQuantityMode();
/** /**
* Sets the widget {@link net.runelite.api.widgets.ItemQuantityMode} * Sets the widget {@link net.runelite.api.widgets.ItemQuantityMode}
*/ */
@MagicConstant(valuesFromClass = ItemQuantityMode.class)
Widget setItemQuantityMode(int itemQuantityMode); Widget setItemQuantityMode(int itemQuantityMode);
/** /**
@@ -833,6 +848,7 @@ public interface Widget
* *
* @see WidgetPositionMode * @see WidgetPositionMode
*/ */
@MagicConstant(valuesFromClass = WidgetPositionMode.class)
int getXPositionMode(); int getXPositionMode();
/** /**
@@ -841,13 +857,14 @@ public interface Widget
* *
* @see WidgetPositionMode * @see WidgetPositionMode
*/ */
Widget setXPositionMode(int xpm); Widget setXPositionMode(@MagicConstant(valuesFromClass = WidgetPositionMode.class) int xpm);
/** /**
* Gets the mode that the Y position is calculated from the original Y position * Gets the mode that the Y position is calculated from the original Y position
* *
* @see WidgetPositionMode * @see WidgetPositionMode
*/ */
@MagicConstant(valuesFromClass = WidgetPositionMode.class)
int getYPositionMode(); int getYPositionMode();
/** /**
@@ -856,7 +873,7 @@ public interface Widget
* *
* @see WidgetPositionMode * @see WidgetPositionMode
*/ */
Widget setYPositionMode(int ypm); Widget setYPositionMode(@MagicConstant(valuesFromClass = WidgetPositionMode.class) int ypm);
/** /**
* Get the line height for this widget. * Get the line height for this widget.
@@ -877,6 +894,7 @@ public interface Widget
* *
* @see WidgetTextAlignment * @see WidgetTextAlignment
*/ */
@MagicConstant(valuesFromClass = WidgetTextAlignment.class)
int getXTextAlignment(); int getXTextAlignment();
/** /**
@@ -884,13 +902,14 @@ public interface Widget
* *
* @see WidgetTextAlignment * @see WidgetTextAlignment
*/ */
Widget setXTextAlignment(int xta); Widget setXTextAlignment(@MagicConstant(valuesFromClass = WidgetTextAlignment.class) int xta);
/** /**
* Gets the Y axis text position mode * Gets the Y axis text position mode
* *
* @see WidgetTextAlignment * @see WidgetTextAlignment
*/ */
@MagicConstant(valuesFromClass = WidgetTextAlignment.class)
int getYTextAlignment(); int getYTextAlignment();
/** /**
@@ -898,13 +917,14 @@ public interface Widget
* *
* @see WidgetTextAlignment * @see WidgetTextAlignment
*/ */
Widget setYTextAlignment(int yta); Widget setYTextAlignment(@MagicConstant(valuesFromClass = WidgetTextAlignment.class) int yta);
/** /**
* Gets the mode controlling widget width * Gets the mode controlling widget width
* *
* @see WidgetSizeMode * @see WidgetSizeMode
*/ */
@MagicConstant(valuesFromClass = WidgetSizeMode.class)
int getWidthMode(); int getWidthMode();
/** /**
@@ -913,13 +933,14 @@ public interface Widget
* *
* @see WidgetSizeMode * @see WidgetSizeMode
*/ */
Widget setWidthMode(int widthMode); Widget setWidthMode(@MagicConstant(valuesFromClass = WidgetSizeMode.class) int widthMode);
/** /**
* Gets the mode controlling widget width * Gets the mode controlling widget width
* *
* @see WidgetSizeMode * @see WidgetSizeMode
*/ */
@MagicConstant(valuesFromClass = WidgetSizeMode.class)
int getHeightMode(); int getHeightMode();
/** /**
@@ -928,7 +949,7 @@ public interface Widget
* *
* @see WidgetSizeMode * @see WidgetSizeMode
*/ */
Widget setHeightMode(int heightMode); Widget setHeightMode(@MagicConstant(valuesFromClass = WidgetSizeMode.class) int heightMode);
/** /**
* Gets the font that this widget uses * Gets the font that this widget uses

View File

@@ -52,6 +52,7 @@ import net.runelite.api.GameState;
import net.runelite.api.ItemComposition; import net.runelite.api.ItemComposition;
import static net.runelite.api.ItemID.*; import static net.runelite.api.ItemID.*;
import net.runelite.api.SpritePixels; import net.runelite.api.SpritePixels;
import net.runelite.api.widgets.ItemQuantityMode;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.util.AsyncBufferedImage; import net.runelite.client.util.AsyncBufferedImage;
@@ -389,7 +390,7 @@ public class ItemManager
return false; return false;
} }
SpritePixels sprite = client.createItemSprite(itemId, quantity, 1, SpritePixels.DEFAULT_SHADOW_COLOR, SpritePixels sprite = client.createItemSprite(itemId, quantity, 1, SpritePixels.DEFAULT_SHADOW_COLOR,
stackable ? 1 : 0, false, CLIENT_DEFAULT_ZOOM); stackable ? ItemQuantityMode.ALWAYS : ItemQuantityMode.NEVER, false, CLIENT_DEFAULT_ZOOM);
if (sprite == null) if (sprite == null)
{ {
return false; return false;