chat message manager: avoid adding chat messages on threads
This commit is contained in:
@@ -40,6 +40,7 @@ import net.runelite.api.Point;
|
|||||||
import net.runelite.api.Projectile;
|
import net.runelite.api.Projectile;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
import net.runelite.client.events.*;
|
import net.runelite.client.events.*;
|
||||||
import net.runelite.client.game.DeathChecker;
|
import net.runelite.client.game.DeathChecker;
|
||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
@@ -56,6 +57,7 @@ public class Hooks
|
|||||||
private static final EventBus eventBus = injector.getInstance(EventBus.class);
|
private static final EventBus eventBus = injector.getInstance(EventBus.class);
|
||||||
private static final Scheduler scheduler = injector.getInstance(Scheduler.class);
|
private static final Scheduler scheduler = injector.getInstance(Scheduler.class);
|
||||||
private static final InfoBoxManager infoBoxManager = injector.getInstance(InfoBoxManager.class);
|
private static final InfoBoxManager infoBoxManager = injector.getInstance(InfoBoxManager.class);
|
||||||
|
private static final ChatMessageManager chatMessageManager = injector.getInstance(ChatMessageManager.class);
|
||||||
private static final DeathChecker death = new DeathChecker(client, eventBus);
|
private static final DeathChecker death = new DeathChecker(client, eventBus);
|
||||||
private static final GameTick tick = new GameTick();
|
private static final GameTick tick = new GameTick();
|
||||||
|
|
||||||
@@ -86,6 +88,8 @@ public class Hooks
|
|||||||
|
|
||||||
// cull infoboxes
|
// cull infoboxes
|
||||||
infoBoxManager.cull();
|
infoBoxManager.cull();
|
||||||
|
|
||||||
|
chatMessageManager.process();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y)
|
public static void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y)
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -56,6 +59,7 @@ public class ChatMessageManager
|
|||||||
private final ScheduledExecutorService executor;
|
private final ScheduledExecutorService executor;
|
||||||
private final RuneliteConfig config;
|
private final RuneliteConfig config;
|
||||||
private int transparancyVarbit = -1;
|
private int transparancyVarbit = -1;
|
||||||
|
private final Queue<QueuedMessage> queuedMessages = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ChatMessageManager(Provider<Client> clientProvider, ScheduledExecutorService executor, RuneliteConfig config)
|
public ChatMessageManager(Provider<Client> clientProvider, ScheduledExecutorService executor, RuneliteConfig config)
|
||||||
@@ -96,10 +100,25 @@ public class ChatMessageManager
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void queue(ChatMessageType type, String message)
|
||||||
|
{
|
||||||
|
queuedMessages.add(new QueuedMessage(type, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process()
|
||||||
|
{
|
||||||
|
for (Iterator<QueuedMessage> it = queuedMessages.iterator(); it.hasNext();)
|
||||||
|
{
|
||||||
|
QueuedMessage message = it.next();
|
||||||
|
add(message.getType(), message.getMessage());
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void add(final ChatMessageType type, final String mesage)
|
public void add(final ChatMessageType type, final String mesage)
|
||||||
{
|
{
|
||||||
final Client client = clientProvider.get();
|
final Client client = clientProvider.get();
|
||||||
client.sendGameMessage(type, mesage);
|
client.sendGameMessage(type, mesage); // this updates chat cycle
|
||||||
final ChatLineBuffer chatLineBuffer = client.getChatLineMap().get(type.getType());
|
final ChatLineBuffer chatLineBuffer = client.getChatLineMap().get(type.getType());
|
||||||
final MessageNode[] lines = chatLineBuffer.getLines();
|
final MessageNode[] lines = chatLineBuffer.getLines();
|
||||||
final MessageNode line = lines[0];
|
final MessageNode line = lines[0];
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2017, 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.chat;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.runelite.api.ChatMessageType;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
class QueuedMessage
|
||||||
|
{
|
||||||
|
private final ChatMessageType type;
|
||||||
|
private final String message;
|
||||||
|
}
|
||||||
@@ -235,8 +235,7 @@ public class ExaminePlugin extends Plugin
|
|||||||
.append(String.valueOf(alchPrice))
|
.append(String.valueOf(alchPrice))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
chatMessageManager.add(ChatMessageType.EXAMINE_ITEM, message);
|
chatMessageManager.queue(ChatMessageType.EXAMINE_ITEM, message);
|
||||||
client.refreshChat();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|||||||
Reference in New Issue
Block a user