diff --git a/src/main/java/dev/tricht/lunaris/listeners/ClipboardListenerStack.java b/src/main/java/dev/tricht/lunaris/listeners/ClipboardListenerStack.java index 8b17f53..57a02bb 100644 --- a/src/main/java/dev/tricht/lunaris/listeners/ClipboardListenerStack.java +++ b/src/main/java/dev/tricht/lunaris/listeners/ClipboardListenerStack.java @@ -1,6 +1,7 @@ package dev.tricht.lunaris.listeners; import dev.tricht.lunaris.item.ItemGrabber; +import dev.tricht.lunaris.util.Platform; import lombok.extern.slf4j.Slf4j; import java.awt.*; @@ -15,8 +16,6 @@ public class ClipboardListenerStack implements GameListener, ClipboardOwner { private final ItemGrabber itemGrabber; private final Robot robot; - private FlavorListener currentFlavorListener = null; - private static boolean isOwner = false; private static ClipboardCallback callback; @@ -36,15 +35,20 @@ public void addListener(GameListener listener) { public void onEvent(GameEvent event) { for (GameListener listenerEntry : keyListeners) { if (listenerEntry.supports(event)) { - if (currentFlavorListener != null) { - Toolkit.getDefaultToolkit().getSystemClipboard().removeFlavorListener(currentFlavorListener); - } if (!isOwner) { flushClipboard(); } - callback = (String clipboard) -> { - event.setItem(itemGrabber.grab(clipboard)); - listenerEntry.onEvent(event); + callback = new ClipboardCallback() { + private boolean fired = false; + @Override + public void onContentChange(String clipboard) { + if (clipboard.isEmpty() || fired) { + return; + } + event.setItem(itemGrabber.grab(clipboard)); + listenerEntry.onEvent(event); + fired = true; + } }; log.debug("Registered clipboard listener for " + listenerEntry.getClass().getName()); pressControlC(event); @@ -65,6 +69,9 @@ public boolean supports(GameEvent event) { private void registerClipboardListener() { Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(flavorEvent -> { + if (!Platform.isPoeActive()) { + return; + } String clipboardText = getClipboardText(); log.debug("Got clipboard text:" + clipboardText); if (clipboardText != null && callback != null) { @@ -99,6 +106,7 @@ private String getClipboardText() { } private void pressControlC(GameEvent event) { + HotKeyHandler.setPaused(true); boolean wasControlAlreadyPressed = (event.getOriginalEvent().getModifiers() & 34) != 0; if (!wasControlAlreadyPressed) { @@ -111,6 +119,7 @@ private void pressControlC(GameEvent event) { robot.keyRelease(KeyEvent.VK_CONTROL); } robot.keyRelease(KeyEvent.VK_C); + HotKeyHandler.setPaused(false); } @Override diff --git a/src/main/java/dev/tricht/lunaris/listeners/HotKeyHandler.java b/src/main/java/dev/tricht/lunaris/listeners/HotKeyHandler.java index e6ab576..20d40b7 100644 --- a/src/main/java/dev/tricht/lunaris/listeners/HotKeyHandler.java +++ b/src/main/java/dev/tricht/lunaris/listeners/HotKeyHandler.java @@ -2,6 +2,7 @@ import dev.tricht.lunaris.util.Platform; import dev.tricht.lunaris.tooltip.TooltipCreator; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; @@ -20,6 +21,9 @@ @Slf4j public class HotKeyHandler implements NativeKeyListener, NativeMouseInputListener, NativeMouseWheelListener { + @Setter + private static boolean isPaused = false; + private Point position; private ArrayList keyListeners = new ArrayList<>(); @@ -44,7 +48,10 @@ public void setRespondTo(ArrayList combos) { } public boolean shouldRespond(NativeKeyEvent event) { - for(KeyCombo combo : listenCombos) { + if (isPaused) { + return false; + } + for (KeyCombo combo : listenCombos) { if (combo.matches(event)) { return true; } diff --git a/src/main/java/dev/tricht/lunaris/listeners/ItemPriceListener.java b/src/main/java/dev/tricht/lunaris/listeners/ItemPriceListener.java index 92bb96c..4abebe8 100644 --- a/src/main/java/dev/tricht/lunaris/listeners/ItemPriceListener.java +++ b/src/main/java/dev/tricht/lunaris/listeners/ItemPriceListener.java @@ -103,7 +103,7 @@ public boolean supports(GameEvent event) { } private void displayItemTooltip(Item item) { - if (item == null || !item.hasPrice()) { + if (item == null || !item.exists()) { return; } @@ -130,6 +130,10 @@ private Map createBaseItemTooltip(Item item) { } private void addPoeNinjaPrice(Item item, Map elements) { + if (item.getMeanPrice() == null) { + elements.put(new Label("No poe.ninja price available"), new int[]{1, elements.size() - 1}); + return; + } elements.put(new Price(item), new int[]{1, elements.size() - 1}); if (item.getMeanPrice().getReason() != null) { elements.put(new Label("Reason: " + item.getMeanPrice().getReason()), new int[]{1, elements.size() - 1});