Merge branch 'pr/11' into upstream3

This commit is contained in:
Kyleeld
2020-01-28 15:53:22 +00:00
10 changed files with 69 additions and 78 deletions

View File

@@ -63,6 +63,10 @@ public class WidgetItem
* The widget which contains this item.
*/
private final Widget widget;
/**
* Whether or not this widget item is being dragged.
*/
private final boolean dragging;
/**
* Gets the upper-left coordinate of where the widget is being drawn

View File

@@ -40,6 +40,11 @@ import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import java.io.IOException;
import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -78,6 +83,7 @@ import net.runelite.client.task.ScheduledMethod;
import net.runelite.client.task.Scheduler;
import net.runelite.client.ui.RuneLiteSplashScreen;
import net.runelite.client.util.GameEventManager;
import net.runelite.client.util.ReflectUtil;
@Singleton
@Slf4j
@@ -552,7 +558,30 @@ public class PluginManager
continue;
}
ScheduledMethod scheduledMethod = new ScheduledMethod(schedule, method, plugin);
Runnable runnable = null;
try
{
final Class<?> clazz = method.getDeclaringClass();
final MethodHandles.Lookup caller = ReflectUtil.privateLookupIn(clazz);
final MethodType subscription = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
final MethodHandle target = caller.findVirtual(clazz, method.getName(), subscription);
final CallSite site = LambdaMetafactory.metafactory(
caller,
"run",
MethodType.methodType(Runnable.class, clazz),
subscription,
target,
subscription);
final MethodHandle factory = site.getTarget();
runnable = (Runnable) factory.bindTo(plugin).invokeExact();
}
catch (Throwable e)
{
log.warn("Unable to create lambda for method {}", method, e);
}
ScheduledMethod scheduledMethod = new ScheduledMethod(schedule, method, plugin, runnable);
log.debug("Scheduled task {}", scheduledMethod);
scheduler.addScheduledMethod(scheduledMethod);

View File

@@ -94,7 +94,7 @@ public class ChatCommandsPlugin extends Plugin
{
private static final Pattern KILLCOUNT_PATTERN = Pattern.compile("Your (.+) (?:kill|harvest|lap|completion) count is: <col=ff0000>(\\d+)</col>");
private static final Pattern RAIDS_PATTERN = Pattern.compile("Your completed (.+) count is: <col=ff0000>(\\d+)</col>");
private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("Congratulations - your raid is complete! Duration <col=ff0000>([0-9:]+)</col>");
private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete! Duration:</col> <col=ff0000>([0-9:]+)</col>");
private static final Pattern WINTERTODT_PATTERN = Pattern.compile("Your subdued Wintertodt count is: <col=ff0000>(\\d+)</col>");
private static final Pattern BARROWS_PATTERN = Pattern.compile("Your Barrows chest count is: <col=ff0000>(\\d+)</col>");
private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)^(?:Fight |Lap |Challenge |Corrupted challenge )?duration: <col=ff0000>[0-9:]+</col>\\. Personal best: ([0-9:]+)");
@@ -411,7 +411,8 @@ public class ChatCommandsPlugin extends Plugin
{
if (chatMessage.getType() != ChatMessageType.TRADE
&& chatMessage.getType() != ChatMessageType.GAMEMESSAGE
&& chatMessage.getType() != ChatMessageType.SPAM)
&& chatMessage.getType() != ChatMessageType.SPAM
&& chatMessage.getType() != ChatMessageType.FRIENDSCHATNOTIFICATION)
{
return;
}

View File

@@ -536,7 +536,9 @@ public class ClanChatPlugin extends Plugin
{
final int[] intStack = client.getIntStack();
final int size = client.getIntStackSize();
intStack[size - 1] = config.clanTabChat() ? 1 : 0;
// If the user accidentally adds a / when the config and the clan chat tab is active, handle it like a normal message
boolean alterClanChatDispatch = config.clanTabChat() && !client.getVar(VarClientStr.CHATBOX_TYPED_TEXT).startsWith("/");
intStack[size - 1] = alterClanChatDispatch ? 1 : 0;
break;
}
case "confirmClanKick":

View File

@@ -87,7 +87,7 @@ public class CoordinateClue extends ClueScroll implements TextClueScroll, Locati
.put(new WorldPoint(3770, 3898, 0), "On the small island north-east of Fossil Island's mushroom forest.")
// Hard
.put(new WorldPoint(2209, 3161, 0), "North-east of Tyras Camp (BJS).")
.put(new WorldPoint(2181, 3206, 0), "South of Elf Camp.")
.put(new WorldPoint(2181, 3206, 0), "South of Iorwerth Camp.")
.put(new WorldPoint(3081, 3209, 0), "Small Island (CLP).")
.put(new WorldPoint(3399, 3246, 0), "Behind the Duel Arena.")
.put(new WorldPoint(2699, 3251, 0), "Little island (AIR).")
@@ -142,7 +142,7 @@ public class CoordinateClue extends ClueScroll implements TextClueScroll, Locati
.put(new WorldPoint(3587, 3180, 0), "Meiyerditch.")
.put(new WorldPoint(2820, 3078, 0), "Tai Bwo Wannai. Hardwood Grove.")
.put(new WorldPoint(3811, 3060, 0), "Small island north-east of Mos Le'Harmless.")
.put(new WorldPoint(2180, 3282, 0), "North of Elf Camp.")
.put(new WorldPoint(2180, 3282, 0), "North of Iorwerth Camp.")
.put(new WorldPoint(2870, 2997, 0), "North-east of Shilo Village.")
.put(new WorldPoint(3302, 2988, 0), "On top of a cliff to the west of Pollnivneach.")
.put(new WorldPoint(2511, 2980, 0), "Just south of Gu'Tanoth, west of gnome glider.")
@@ -171,7 +171,7 @@ public class CoordinateClue extends ClueScroll implements TextClueScroll, Locati
.put(new WorldPoint(2872, 3937, 0), "Weiss.")
.put(new WorldPoint(2484, 4016, 0), "Northeast corner of the Island of Stone.")
// Master
.put(new WorldPoint(2178, 3209, 0), "South of Elf Camp.")
.put(new WorldPoint(2178, 3209, 0), "South of Iorwerth Camp.")
.put(new WorldPoint(2155, 3100, 0), "South of Port Tyras (BJS).")
.put(new WorldPoint(2217, 3092, 0), "Poison Waste island (DLR).")
.put(new WorldPoint(3830, 3060, 0), "Small island located north-east of Mos Le'Harmless.")

View File

@@ -131,8 +131,8 @@ public enum HotColdLocation
WESTERN_PROVINCE_PISCATORIS(new WorldPoint(2337, 3689, 0), WESTERN_PROVINCE, "Piscatoris Fishing Colony"),
WESTERN_PROVINCE_PISCATORIS_HUNTER_AREA(new WorldPoint(2359, 3564, 0), WESTERN_PROVINCE, "Eastern part of Piscatoris Hunter area, south-west of the Falconry."),
WESTERN_PROVINCE_ARANDAR(new WorldPoint(2366, 3318, 0), WESTERN_PROVINCE, "South-west of the crystal gate to Arandar."),
WESTERN_PROVINCE_ELF_CAMP_EAST(new WorldPoint(2270, 3244, 0), WESTERN_PROVINCE, "East of Elf Camp."),
WESTERN_PROVINCE_ELF_CAMP_NW(new WorldPoint(2174, 3280, 0), WESTERN_PROVINCE, "North-west of Elf Camp."),
WESTERN_PROVINCE_ELF_CAMP_EAST(new WorldPoint(2270, 3244, 0), WESTERN_PROVINCE, "East of Iorwerth Camp."),
WESTERN_PROVINCE_ELF_CAMP_NW(new WorldPoint(2174, 3280, 0), WESTERN_PROVINCE, "North-west of Iorwerth Camp."),
WESTERN_PROVINCE_LLETYA(new WorldPoint(2335, 3166, 0), WESTERN_PROVINCE, "In Lletya."),
WESTERN_PROVINCE_TYRAS(new WorldPoint(2204, 3157, 0), WESTERN_PROVINCE, "Near Tyras Camp."),
WESTERN_PROVINCE_ZULANDRA(new WorldPoint(2196, 3057, 0), WESTERN_PROVINCE, "The northern house at Zul-Andra."),

View File

@@ -26,49 +26,22 @@ package net.runelite.client.task;
import java.lang.reflect.Method;
import java.time.Instant;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@RequiredArgsConstructor
@ToString
@Getter
public class ScheduledMethod
{
private final Schedule schedule;
private final Method method;
private final Object object;
@EqualsAndHashCode.Exclude
private final Runnable lambda;
@Setter
private Instant last = Instant.now();
public ScheduledMethod(Schedule schedule, Method method, Object object)
{
this.schedule = schedule;
this.method = method;
this.object = object;
}
@Override
public String toString()
{
return "ScheduledMethod{" + "schedule=" + schedule + ", method=" + method + ", object=" + object + '}';
}
public Schedule getSchedule()
{
return schedule;
}
public Method getMethod()
{
return method;
}
public Object getObject()
{
return object;
}
public Instant getLast()
{
return last;
}
public void setLast(Instant last)
{
this.last = last;
}
}

View File

@@ -120,11 +120,18 @@ public class Scheduler
private void run(ScheduledMethod scheduledMethod)
{
Method method = scheduledMethod.getMethod();
try
{
method.invoke(scheduledMethod.getObject());
Runnable lambda = scheduledMethod.getLambda();
if (lambda != null)
{
lambda.run();
}
else
{
Method method = scheduledMethod.getMethod();
method.invoke(scheduledMethod.getObject());
}
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
{

View File

@@ -612,32 +612,6 @@ public class ClientUI
{
OSXUtil.requestFocus();
}
// See https://stackoverflow.com/questions/309023/how-to-bring-a-window-to-the-front/7435722#7435722
else if (OSType.getOSType() == OSType.Windows && !frame.isFocused())
{
SwingUtilities.invokeLater(() ->
{
if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH)
{
frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
else
{
// If the client is snapped to the top and bottom edges of the screen, setExtendedState will
// will reset it so setSize and setLocation ensure that the client doesn't move or resize.
// It is done this way because Windows does not support JFrame.MAXIMIZED_VERT
int x = frame.getLocation().x;
int y = frame.getLocation().y;
int width = frame.getWidth();
int height = frame.getHeight();
frame.setExtendedState(JFrame.ICONIFIED);
frame.setExtendedState(JFrame.NORMAL);
frame.setLocation(x, y);
frame.setSize(width, height);
}
});
}
frame.requestFocus();
giveClientFocus();

View File

@@ -29,6 +29,7 @@ import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import static net.runelite.api.ChatMessageType.TRADE;
import net.runelite.api.Client;
@@ -371,7 +372,7 @@ public class ChatCommandsPluginTest
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Congratulations - your raid is complete! Duration <col=ff0000>37:04</col>", null, 0);
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete! Duration:</col> <col=ff0000>37:04</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>51</col>.", null, 0);
@@ -387,7 +388,7 @@ public class ChatCommandsPluginTest
when(client.getUsername()).thenReturn("Adam");
when(configManager.getConfiguration(anyString(), anyString(), any())).thenReturn(2224);
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Congratulations - your raid is complete! Duration <col=ff0000>1:45:04</col>", null, 0);
ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "<col=ef20ff>Congratulations - your raid is complete! Duration:</col> <col=ff0000>1:45:04</col>", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: <col=ff0000>52</col>.", null, 0);