Merge pull request #4547 from Abextm/fairy-ring-defer
Prevent crash when updating the fairy ring filter
This commit is contained in:
@@ -41,9 +41,9 @@ public class ClientThread
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
public void invokeLater(Runnable r)
|
||||
public void invoke(Runnable r)
|
||||
{
|
||||
invokeLater(() ->
|
||||
invoke(() ->
|
||||
{
|
||||
r.run();
|
||||
return true;
|
||||
@@ -54,7 +54,7 @@ public class ClientThread
|
||||
* Will run r on the game thread, at a unspecified point in the future.
|
||||
* If r returns false, r will be ran again, at a later point
|
||||
*/
|
||||
public void invokeLater(BooleanSupplier r)
|
||||
public void invoke(BooleanSupplier r)
|
||||
{
|
||||
if (client.isClientThread())
|
||||
{
|
||||
@@ -64,6 +64,25 @@ public class ClientThread
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
invokeLater(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will run r on the game thread after this method returns
|
||||
* If r returns false, r will be ran again, at a later point
|
||||
*/
|
||||
public void invokeLater(Runnable r)
|
||||
{
|
||||
invokeLater(() ->
|
||||
{
|
||||
r.run();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void invokeLater(BooleanSupplier r)
|
||||
{
|
||||
invokes.add(r);
|
||||
}
|
||||
|
||||
@@ -85,7 +104,7 @@ public class ClientThread
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
log.warn("Exception in invokeLater", e);
|
||||
log.warn("Exception in invoke", e);
|
||||
}
|
||||
if (remove)
|
||||
{
|
||||
|
||||
@@ -141,7 +141,7 @@ public class CommandManager
|
||||
}
|
||||
resumed = true;
|
||||
|
||||
clientThread.invokeLater(() -> sendChatboxInput(chatType, typedText));
|
||||
clientThread.invoke(() -> sendChatboxInput(chatType, typedText));
|
||||
}
|
||||
};
|
||||
boolean stop = false;
|
||||
@@ -180,7 +180,7 @@ public class CommandManager
|
||||
}
|
||||
resumed = true;
|
||||
|
||||
clientThread.invokeLater(() -> sendPrivmsg(target, message));
|
||||
clientThread.invoke(() -> sendPrivmsg(target, message));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ChatboxInputManager
|
||||
this.changed = changed;
|
||||
this.characterLimit = characterLimit;
|
||||
this.open = true;
|
||||
clientThread.invokeLater(() -> client.runScript(
|
||||
clientThread.invoke(() -> client.runScript(
|
||||
ScriptID.RUNELITE_CHATBOX_INPUT_INIT,
|
||||
text,
|
||||
defaul
|
||||
@@ -99,7 +99,7 @@ public class ChatboxInputManager
|
||||
return;
|
||||
}
|
||||
this.open = false;
|
||||
clientThread.invokeLater(() -> client.runScript(
|
||||
clientThread.invoke(() -> client.runScript(
|
||||
ScriptID.CLOSE_CHATBOX_INPUT,
|
||||
1,
|
||||
1
|
||||
@@ -116,30 +116,23 @@ public class ChatboxInputManager
|
||||
int stringStackSize = client.getStringStackSize();
|
||||
int typedKey = client.getIntStack()[--intStackSize];
|
||||
String str = client.getStringStack()[--stringStackSize];
|
||||
int retval = 0;
|
||||
boolean isDone = false;
|
||||
|
||||
switch (typedKey)
|
||||
{
|
||||
case 27: // Escape
|
||||
str = "";
|
||||
if (changed != null)
|
||||
{
|
||||
changed.accept(str);
|
||||
}
|
||||
// fallthrough
|
||||
case '\n':
|
||||
if (done != null)
|
||||
{
|
||||
done.accept(str);
|
||||
}
|
||||
this.open = false;
|
||||
retval = 1;
|
||||
isDone = true;
|
||||
break;
|
||||
case '\b':
|
||||
if (str.length() > 0)
|
||||
{
|
||||
str = str.substring(0, str.length() - 1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// If we wanted to do numbers only, we could add a limit here
|
||||
if (typedKey >= 32 && (str.length() < characterLimit))
|
||||
@@ -153,8 +146,13 @@ public class ChatboxInputManager
|
||||
changed.accept(str);
|
||||
}
|
||||
|
||||
if (isDone && done != null)
|
||||
{
|
||||
done.accept(str);
|
||||
}
|
||||
|
||||
client.getStringStack()[stringStackSize++] = str;
|
||||
client.getIntStack()[intStackSize++] = retval;
|
||||
client.getIntStack()[intStackSize++] = isDone ? 1 : 0;
|
||||
client.setIntStackSize(intStackSize);
|
||||
client.setStringStackSize(stringStackSize);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class ItemManager
|
||||
private AsyncBufferedImage loadImage(int itemId, int quantity, boolean stackable)
|
||||
{
|
||||
AsyncBufferedImage img = new AsyncBufferedImage(36, 32, BufferedImage.TYPE_INT_ARGB);
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
if (client.getGameState().ordinal() < GameState.LOGIN_SCREEN.ordinal())
|
||||
{
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SpriteManager
|
||||
return;
|
||||
}
|
||||
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
BufferedImage img = getSprite(archive, file);
|
||||
if (img == null)
|
||||
|
||||
@@ -99,7 +99,7 @@ public class AttackStylesPlugin extends Plugin
|
||||
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
clientThread.invokeLater(this::start);
|
||||
clientThread.invoke(this::start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ public class CannonPlugin extends Plugin
|
||||
{
|
||||
if (cannonPlaced)
|
||||
{
|
||||
clientThread.invokeLater(this::addCounter);
|
||||
clientThread.invoke(this::addCounter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,11 +82,11 @@ public class ChatKeyboardListener implements KeyListener
|
||||
replacement = "";
|
||||
}
|
||||
|
||||
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement));
|
||||
clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement));
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""));
|
||||
clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class DemonicGorillaPlugin extends Plugin
|
||||
recentBoulders = new ArrayList<>();
|
||||
pendingAttacks = new ArrayList<>();
|
||||
memorizedPlayers = new HashMap<>();
|
||||
clientThread.invokeLater(this::reset); // Updates the list of gorillas and players
|
||||
clientThread.invoke(this::reset); // Updates the list of gorillas and players
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,6 +51,7 @@ import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ChatboxInputManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -83,9 +84,11 @@ public class FairyRingPlugin extends Plugin
|
||||
@Inject
|
||||
private ChatboxInputManager chatboxInputManager;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
private Widget searchBtn;
|
||||
private boolean chatboxOpenLastTick = false;
|
||||
private boolean clearFilter = false;
|
||||
private Collection<CodeWidgets> codes = null;
|
||||
|
||||
@Data
|
||||
@@ -198,23 +201,18 @@ public class FairyRingPlugin extends Plugin
|
||||
{
|
||||
updateFilter("");
|
||||
searchBtn.setAction(1, MENU_CLOSE);
|
||||
chatboxInputManager.openInputWindow("Filter fairy rings", "", ChatboxInputManager.NO_LIMIT, this::updateFilter, s ->
|
||||
{
|
||||
// We can't run it right now because scripts can't run other scripts in their callbacks
|
||||
clearFilter = true;
|
||||
searchBtn.setAction(1, MENU_OPEN);
|
||||
});
|
||||
chatboxInputManager.openInputWindow("Filter fairy rings", "", ChatboxInputManager.NO_LIMIT,
|
||||
s -> clientThread.invokeLater(() -> updateFilter(s)),
|
||||
s ->
|
||||
{
|
||||
clientThread.invokeLater(() -> updateFilter(""));
|
||||
searchBtn.setAction(1, MENU_OPEN);
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick t)
|
||||
{
|
||||
if (clearFilter)
|
||||
{
|
||||
updateFilter("");
|
||||
clearFilter = false;
|
||||
}
|
||||
|
||||
// This has to happen because the only widget that gets hidden is the tli one
|
||||
Widget fairyRingTeleportButton = client.getWidget(WidgetInfo.FAIRY_RING_TELEPORT_BUTTON);
|
||||
boolean fairyRingWidgetOpen = fairyRingTeleportButton != null && !fairyRingTeleportButton.isHidden();
|
||||
|
||||
@@ -80,7 +80,7 @@ public class InterfaceStylesPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
overrideSprites();
|
||||
overrideWidgetSprites();
|
||||
@@ -92,7 +92,7 @@ public class InterfaceStylesPlugin extends Plugin
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
restoreWidgetDimensions();
|
||||
removeGameframe();
|
||||
@@ -104,7 +104,7 @@ public class InterfaceStylesPlugin extends Plugin
|
||||
{
|
||||
if (config.getGroup().equals("interfaceStyles"))
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
removeGameframe();
|
||||
overrideSprites();
|
||||
|
||||
@@ -188,7 +188,7 @@ public class NpcIndicatorsPlugin extends Plugin
|
||||
overlayManager.add(npcMinimapOverlay);
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
highlights = getHighlights();
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
skipNextSpawnCheck = true;
|
||||
rebuildAllNpcs();
|
||||
|
||||
@@ -80,13 +80,13 @@ public class ReportButtonPlugin extends Plugin
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
clientThread.invokeLater(this::updateReportButtonTime);
|
||||
clientThread.invoke(this::updateReportButtonTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown()
|
||||
{
|
||||
clientThread.invokeLater(() ->
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
Widget reportButton = client.getWidget(WidgetInfo.CHATBOX_REPORT_TEXT);
|
||||
if (reportButton != null)
|
||||
|
||||
@@ -179,7 +179,7 @@ public class SlayerPlugin extends Plugin
|
||||
streak = config.streak();
|
||||
setExpeditiousChargeCount(config.expeditious());
|
||||
setSlaughterChargeCount(config.slaughter());
|
||||
clientThread.invokeLater(() -> setTask(config.taskName(), config.amount()));
|
||||
clientThread.invoke(() -> setTask(config.taskName(), config.amount()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ public class SlayerPlugin extends Plugin
|
||||
|
||||
if (config.showInfobox())
|
||||
{
|
||||
clientThread.invokeLater(this::addCounter);
|
||||
clientThread.invoke(this::addCounter);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user