From f470f242c6d3897d9ebc4bbc60e5331204efdfed Mon Sep 17 00:00:00 2001 From: sdburns1998 Date: Thu, 6 Jun 2019 15:04:42 +0200 Subject: [PATCH 1/5] Add license to parse menu entries --- .../plugins/menuentryswapper/Parse.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/Parse.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/Parse.java index 75a225589c..a44b56eb5e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/Parse.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/Parse.java @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2019, Owain van Brakel + * 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.plugins.menuentryswapper; import com.google.common.base.Splitter; From 0eae5e8452d6431a97609abf532267638a9edea9 Mon Sep 17 00:00:00 2001 From: sdburns1998 Date: Thu, 6 Jun 2019 15:05:05 +0200 Subject: [PATCH 2/5] Add parsing to raids scouter --- .../runelite/client/plugins/raids/Parse.java | 57 +++++++++++++++++++ .../client/plugins/raids/RaidsConfig.java | 10 +++- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/raids/Parse.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/raids/Parse.java b/runelite-client/src/main/java/net/runelite/client/plugins/raids/Parse.java new file mode 100644 index 0000000000..9e40aa3a3f --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/raids/Parse.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019, Owain van Brakel + * 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.plugins.raids; + +import com.google.common.base.Splitter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class Parse +{ + public static boolean parse(String value) + { + final ArrayList rooms = new ArrayList<>(); + Collections.addAll(rooms, "tekton", "muttadiles", "guardians", "vespula", "shamans", "vasa", "vanguards", "mystics", "crabs", "ice demon", "tightrope", "thieving", "unknown"); + + List enteredRooms = Splitter + .on(",") + .trimResults() + .omitEmptyStrings() + .splitToList(value); + + for (String room : enteredRooms) + { + if (!rooms.contains(room.toLowerCase())) + { + return false; + } + } + + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/raids/RaidsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/raids/RaidsConfig.java index b5200a5612..d69e974ad9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/raids/RaidsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/raids/RaidsConfig.java @@ -335,7 +335,10 @@ public interface RaidsConfig extends Config parent = "roomConfig", keyName = "whitelistedRooms", name = "Whitelisted rooms", - description = "Display whitelisted rooms in green on the overlay. Separate with comma (full name)" + description = "Display whitelisted rooms in green on the overlay. Separate with comma (full name)", + parse = true, + clazz = Parse.class, + method = "parse" ) default String whitelistedRooms() { @@ -347,7 +350,10 @@ public interface RaidsConfig extends Config parent = "roomConfig", keyName = "blacklistedRooms", name = "Blacklisted rooms", - description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)" + description = "Display blacklisted rooms in red on the overlay. Separate with comma (full name)", + parse = true, + clazz = Parse.class, + method = "parse" ) default String blacklistedRooms() { From 05ba61d44c316e9a1d9e6d7207cbbd5564a7329c Mon Sep 17 00:00:00 2001 From: sdburns1998 Date: Thu, 6 Jun 2019 15:30:36 +0200 Subject: [PATCH 3/5] Debounce textfield input so the parse function isn't run every keypress --- .../client/plugins/config/ConfigPanel.java | 20 +++---- .../DeferredDocumentChangedListener.java | 58 +++++++++++++++++++ 2 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/config/DeferredDocumentChangedListener.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java index 3e3f5aa0bf..1daaad5a29 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java @@ -36,8 +36,6 @@ import java.awt.Rectangle; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; @@ -468,9 +466,8 @@ public class ConfigPanel extends PluginPanel try { Method parse = item.clazz().getMethod(item.method(), String.class); - boolean result = (boolean) parse.invoke(null, value); - return result; + return (boolean) parse.invoke(null, value); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { @@ -506,7 +503,7 @@ public class ConfigPanel extends PluginPanel openGroupConfigPanel(listItem, config, cd, false); } - void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd, boolean refresh) + private void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd, boolean refresh) { showingPluginList = false; @@ -781,17 +778,14 @@ public class ConfigPanel extends PluginPanel parsingLabel.setHorizontalAlignment(SwingConstants.CENTER); parsingLabel.setPreferredSize(new Dimension(PANEL_WIDTH, 15)); - textField.addKeyListener(new KeyAdapter() - { - public void keyReleased(KeyEvent e) + DeferredDocumentChangedListener listener = new DeferredDocumentChangedListener(); + listener.addChangeListener(e -> { + if (cid.getItem().parse()) { - ConfigItem item = cid.getItem(); - if (item.parse()) - { - parseLabel(item, parsingLabel, textField.getText()); - } + parseLabel(cid.getItem(), parsingLabel, textField.getText()); } }); + textField.getDocument().addDocumentListener(listener); item.add(textField, BorderLayout.CENTER); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/DeferredDocumentChangedListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/DeferredDocumentChangedListener.java new file mode 100644 index 0000000000..c8ce0b37dc --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/DeferredDocumentChangedListener.java @@ -0,0 +1,58 @@ +package net.runelite.client.plugins.config; + +import java.util.ArrayList; +import java.util.List; +import javax.swing.Timer; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +class DeferredDocumentChangedListener implements DocumentListener +{ + private Timer timer; + private List listeners; + + DeferredDocumentChangedListener() + { + listeners = new ArrayList<>(25); + timer = new Timer(350, e -> fireStateChanged()); + timer.setRepeats(false); + } + + void addChangeListener(ChangeListener listener) + { + listeners.add(listener); + } + + private void fireStateChanged() + { + if (!listeners.isEmpty()) + { + ChangeEvent evt = new ChangeEvent(this); + for (ChangeListener listener : listeners) + { + listener.stateChanged(evt); + } + } + } + + @Override + public void insertUpdate(DocumentEvent e) + { + timer.restart(); + } + + @Override + public void removeUpdate(DocumentEvent e) + { + timer.restart(); + } + + @Override + public void changedUpdate(DocumentEvent e) + { + timer.restart(); + } + +} From a049ea4520d4555f29af45749e95515d0110635e Mon Sep 17 00:00:00 2001 From: sdburns1998 Date: Thu, 6 Jun 2019 15:46:37 +0200 Subject: [PATCH 4/5] Groups are meant for huge configs -> pile indicator uses titles now --- .../pileindicators/PileIndicatorsConfig.java | 155 ++++++++++++------ 1 file changed, 105 insertions(+), 50 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pileindicators/PileIndicatorsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/pileindicators/PileIndicatorsConfig.java index ed11f0cc5b..f761236a96 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pileindicators/PileIndicatorsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pileindicators/PileIndicatorsConfig.java @@ -24,22 +24,33 @@ package net.runelite.client.plugins.pileindicators; +import java.awt.Color; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; import net.runelite.client.config.Range; - -import java.awt.*; +import net.runelite.client.config.Stub; @ConfigGroup("pileindicators") public interface PileIndicatorsConfig extends Config { @ConfigItem( - position = 0, - keyName = "enablePlayers", - name = "Enable Player Piling", - description = "Enable the option to highlight players when they pile.", - group = "1. Player Piles" + keyName = "playerPilesStub", + name = "Player Piles", + description = "", + position = 0 + ) + default Stub playerPilesStub() + { + return new Stub(); + } + + @ConfigItem( + position = 1, + keyName = "enablePlayers", + name = "Enable Player Piling", + description = "Enable the option to highlight players when they pile.", + parent = "playerPilesStub" ) default boolean enablePlayers() { @@ -47,11 +58,11 @@ public interface PileIndicatorsConfig extends Config } @ConfigItem( - position = 1, - keyName = "wildyOnlyPlayer", - name = "Wilderness Only", - description = "Show player piling only when in the Wilderness.", - group = "1. Player Piles" + position = 2, + keyName = "wildyOnlyPlayer", + name = "Wilderness Only", + description = "Show player piling only when in the Wilderness.", + parent = "playerPilesStub" ) default boolean wildyOnlyPlayer() { @@ -59,11 +70,34 @@ public interface PileIndicatorsConfig extends Config } @ConfigItem( - position = 3, - keyName = "enableNPCS", - name = "Enable NPC Piling", - description = "Enable the option to highlight NPCs when they pile.", - group = "2. NPC Piles" + position = 3, + keyName = "playerPileColor", + name = "Player Pile Color", + description = "Color used for player piles.", + parent = "playerPilesStub" + ) + default Color playerPileColor() + { + return Color.RED; + } + + @ConfigItem( + keyName = "npcPilesStub", + name = "NPC Piles", + description = "", + position = 4 + ) + default Stub npcPilesStub() + { + return new Stub(); + } + + @ConfigItem( + position = 5, + keyName = "enableNPCS", + name = "Enable NPC Piling", + description = "Enable the option to highlight NPCs when they pile.", + parent = "npcPilesStub" ) default boolean enableNPCS() { @@ -71,23 +105,11 @@ public interface PileIndicatorsConfig extends Config } @ConfigItem( - position = 2, - keyName = "playerPileColor", - name = "Player Pile Color", - description = "Color used for player piles.", - group = "1. Player Piles" - ) - default Color playerPileColor() - { - return Color.RED; - } - - @ConfigItem( - position = 4, - keyName = "npcPileColor", - name = "NPC Pile Color", - description = "Color used for NPC piles.", - group = "2. NPC Piles" + position = 6, + keyName = "npcPileColor", + name = "NPC Pile Color", + description = "Color used for NPC piles.", + parent = "npcPilesStub" ) default Color npcPileColor() { @@ -95,26 +117,48 @@ public interface PileIndicatorsConfig extends Config } @ConfigItem( - position = 5, - keyName = "mixedPileColor", - name = "Mixed Pile Color", - description = "Color used for mixed piles.", - group = "3. Mixed Piles" + keyName = "mixedPilesStub", + name = "Mixed Piles", + description = "", + position = 7 + ) + default Stub mixedPilesStub() + { + return new Stub(); + } + + @ConfigItem( + position = 8, + keyName = "mixedPileColor", + name = "Mixed Pile Color", + description = "Color used for mixed piles.", + parent = "mixedPilesStub" ) default Color mixedPileColor() { return new Color(255, 0, 255); } + @ConfigItem( + keyName = "pilesSizeStub", + name = "Pile size", + description = "", + position = 9 + ) + default Stub pilesSizeStub() + { + return new Stub(); + } + @Range( - min = 2 + min = 2 ) @ConfigItem( - position = 6, - keyName = "minimumPileSize", - name = "Minimum Pile Size", - description = "Any pile under this size will not show up. (Minimum: 2)", - group = "4. Pile Size" + position = 10, + keyName = "minimumPileSize", + name = "Minimum Pile Size", + description = "Any pile under this size will not show up. (Minimum: 2)", + parent = "pilesSizeStub" ) default int minimumPileSize() { @@ -122,11 +166,22 @@ public interface PileIndicatorsConfig extends Config } @ConfigItem( - position = 7, - keyName = "numberOnly", - name = "Display Number Only", - description = "Shorten \"PILE SIZE: 1\" to \"1\"", - group = "5. Miscellaneous" + keyName = "miscellaneousStub", + name = "Miscellaneous", + description = "", + position = 11 + ) + default Stub miscellaneousStub() + { + return new Stub(); + } + + @ConfigItem( + position = 12, + keyName = "numberOnly", + name = "Display Number Only", + description = "Shorten \"PILE SIZE: 1\" to \"1\"", + parent = "miscellaneousStub" ) default boolean numberOnly() { From 6d834f8fd30d5f2d72ff6cebdee69ad070bc2b59 Mon Sep 17 00:00:00 2001 From: sdburns1998 Date: Thu, 6 Jun 2019 16:13:57 +0200 Subject: [PATCH 5/5] ConfigPanel checkstyle --- .../net/runelite/client/plugins/config/ConfigPanel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java index 1daaad5a29..e98cd09d47 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/ConfigPanel.java @@ -770,8 +770,7 @@ public class ConfigPanel extends PluginPanel } } }); - - + if (cid.getItem().parse()) { JLabel parsingLabel = new JLabel(); @@ -779,7 +778,8 @@ public class ConfigPanel extends PluginPanel parsingLabel.setPreferredSize(new Dimension(PANEL_WIDTH, 15)); DeferredDocumentChangedListener listener = new DeferredDocumentChangedListener(); - listener.addChangeListener(e -> { + listener.addChangeListener(e -> + { if (cid.getItem().parse()) { parseLabel(cid.getItem(), parsingLabel, textField.getText());