From 789221490e78ea8bbbbc505c9c8c88e5a7e41550 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 09:47:07 -0500 Subject: [PATCH 1/5] runelite-api: add game object and wall object spawn/change/despawn events --- .../api/events/GameObjectChanged.java | 37 +++++++ .../api/events/GameObjectDespawned.java | 36 +++++++ ...ctsChanged.java => GameObjectSpawned.java} | 6 +- .../api/events/WallObjectChanged.java | 37 +++++++ .../api/events/WallObjectDespawned.java | 36 +++++++ .../api/events/WallObjectSpawned.java | 36 +++++++ .../java/net/runelite/mixins/RSTileMixin.java | 96 +++++++++++++++++-- 7 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java rename runelite-api/src/main/java/net/runelite/api/events/{GameObjectsChanged.java => GameObjectSpawned.java} (91%) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java new file mode 100644 index 0000000000..a3a2b73576 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectChanged.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Data; +import net.runelite.api.GameObject; +import net.runelite.api.Tile; + +@Data +public class GameObjectChanged +{ + private Tile tile; + private GameObject previous; + private GameObject gameObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java new file mode 100644 index 0000000000..ca576730ba --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectDespawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Data; +import net.runelite.api.GameObject; +import net.runelite.api.Tile; + +@Data +public class GameObjectDespawned +{ + private Tile tile; + private GameObject gameObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java b/runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java similarity index 91% rename from runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java rename to runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java index f5abaf6648..6e406d64d1 100644 --- a/runelite-api/src/main/java/net/runelite/api/events/GameObjectsChanged.java +++ b/runelite-api/src/main/java/net/runelite/api/events/GameObjectSpawned.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Robin Weymans + * Copyright (c) 2018, Adam * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +26,11 @@ package net.runelite.api.events; import lombok.Data; import net.runelite.api.GameObject; +import net.runelite.api.Tile; @Data -public class GameObjectsChanged +public class GameObjectSpawned { + private Tile tile; private GameObject gameObject; } diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java new file mode 100644 index 0000000000..c14fdbe999 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectChanged.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectChanged +{ + private Tile tile; + private WallObject previous; + private WallObject wallObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java new file mode 100644 index 0000000000..0188cf5e88 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectDespawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectDespawned +{ + private Tile tile; + private WallObject wallObject; +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java b/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java new file mode 100644 index 0000000000..d405227d53 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WallObjectSpawned.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.api.events; + +import lombok.Data; +import net.runelite.api.Tile; +import net.runelite.api.WallObject; + +@Data +public class WallObjectSpawned +{ + private Tile tile; + private WallObject wallObject; +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java index cd6b221e71..d212768f1d 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSTileMixin.java @@ -24,16 +24,24 @@ */ package net.runelite.mixins; +import net.runelite.api.Actor; import net.runelite.api.GameObject; import net.runelite.api.Perspective; import net.runelite.api.Point; +import net.runelite.api.WallObject; +import net.runelite.api.events.GameObjectChanged; +import net.runelite.api.events.GameObjectDespawned; +import net.runelite.api.events.GameObjectSpawned; +import net.runelite.api.events.WallObjectChanged; +import net.runelite.api.events.WallObjectDespawned; +import net.runelite.api.events.WallObjectSpawned; import net.runelite.api.mixins.FieldHook; import net.runelite.api.mixins.Inject; import net.runelite.api.mixins.Mixin; import net.runelite.api.mixins.Shadow; -import net.runelite.api.events.GameObjectsChanged; import static net.runelite.client.callback.Hooks.eventBus; import net.runelite.rs.api.RSClient; +import net.runelite.rs.api.RSGameObject; import net.runelite.rs.api.RSTile; @Mixin(RSTile.class) @@ -42,6 +50,12 @@ public abstract class RSTileMixin implements RSTile @Shadow("clientInstance") private static RSClient client; + @Inject + private WallObject previousWallObject; + + @Inject + private GameObject[] previousGameObjects; + @Inject @Override public Point getWorldLocation() @@ -65,18 +79,84 @@ public abstract class RSTileMixin implements RSTile return Perspective.regionToLocal(client, regionLocation); } + @FieldHook("wallObject") + @Inject + public void wallObjectChanged(int idx) + { + WallObject previous = previousWallObject; + WallObject current = getWallObject(); + + previousWallObject = current; + + if (current == null && previous != null) + { + WallObjectDespawned wallObjectDespawned = new WallObjectDespawned(); + wallObjectDespawned.setTile(this); + wallObjectDespawned.setWallObject(previous); + eventBus.post(wallObjectDespawned); + } + else if (current != null && previous == null) + { + WallObjectSpawned wallObjectSpawned = new WallObjectSpawned(); + wallObjectSpawned.setTile(this); + wallObjectSpawned.setWallObject(current); + eventBus.post(wallObjectSpawned); + } + else if (current != null && previous != null) + { + WallObjectChanged wallObjectChanged = new WallObjectChanged(); + wallObjectChanged.setTile(this); + wallObjectChanged.setPrevious(previous); + wallObjectChanged.setWallObject(current); + eventBus.post(wallObjectChanged); + } + } + @FieldHook("objects") @Inject - public void animationChanged(int idx) + public void gameObjectsChanged(int idx) { - if (idx != -1) // this happens from the field assignment + if (idx == -1) // this happens from the field assignment { - // GameObject that was changed. - GameObject go = getGameObjects()[idx]; - if (go != null) + return; + } + + if (previousGameObjects == null) + { + previousGameObjects = new GameObject[5]; + } + + // Previous game object + GameObject previous = previousGameObjects[idx]; + // GameObject that was changed. + RSGameObject current = (RSGameObject) getGameObjects()[idx]; + + // Update previous object to current + previousGameObjects[idx] = current; + + // Characters seem to generate a constant stream of new GameObjects + if (current == null || !(current.getRenderable() instanceof Actor)) + { + if (current == null && previous != null) { - GameObjectsChanged gameObjectsChanged = new GameObjectsChanged(); - gameObjectsChanged.setGameObject(go); + GameObjectDespawned gameObjectDespawned = new GameObjectDespawned(); + gameObjectDespawned.setTile(this); + gameObjectDespawned.setGameObject(previous); + eventBus.post(gameObjectDespawned); + } + else if (current != null && previous == null) + { + GameObjectSpawned gameObjectSpawned = new GameObjectSpawned(); + gameObjectSpawned.setTile(this); + gameObjectSpawned.setGameObject(current); + eventBus.post(gameObjectSpawned); + } + else if (current != null && previous != null) + { + GameObjectChanged gameObjectsChanged = new GameObjectChanged(); + gameObjectsChanged.setTile(this); + gameObjectsChanged.setPrevious(previous); + gameObjectsChanged.setGameObject(current); eventBus.post(gameObjectsChanged); } } From 94afeeda408b4f75736c82988077556d3aead59a Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 09:47:33 -0500 Subject: [PATCH 2/5] cannon plugin: update for event change --- .../java/net/runelite/client/plugins/cannon/CannonPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java index 41d1867876..3a6a3ee250 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java @@ -41,7 +41,7 @@ import net.runelite.api.Projectile; import static net.runelite.api.ProjectileID.CANNONBALL; import static net.runelite.api.ProjectileID.GRANITE_CANNONBALL; import net.runelite.api.events.ChatMessage; -import net.runelite.api.events.GameObjectsChanged; +import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.ProjectileMoved; import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; @@ -94,7 +94,7 @@ public class CannonPlugin extends Plugin } @Subscribe - public void onGameObjectsChanged(GameObjectsChanged event) + public void onGameObjectSpawned(GameObjectSpawned event) { GameObject gameObject = event.getGameObject(); From 90f7da166a1082b1cc677d2901b3c25180c06243 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 09:47:52 -0500 Subject: [PATCH 3/5] hunter plugin: update for event change --- .../net/runelite/client/plugins/hunter/HunterPlugin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hunter/HunterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/hunter/HunterPlugin.java index 2ce24ccdae..585baec567 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hunter/HunterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hunter/HunterPlugin.java @@ -49,7 +49,7 @@ import net.runelite.api.queries.GameObjectQuery; import net.runelite.api.queries.PlayerQuery; import net.runelite.client.config.ConfigManager; import net.runelite.api.events.ConfigChanged; -import net.runelite.api.events.GameObjectsChanged; +import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.GameStateChanged; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; @@ -107,7 +107,7 @@ public class HunterPlugin extends Plugin } @Subscribe - public void onGameObjectsChanged(GameObjectsChanged event) + public void onGameObjectSpawned(GameObjectSpawned event) { if (!config.enabled()) { @@ -285,6 +285,7 @@ public class HunterPlugin extends Plugin } //Check if all traps are still there, and remove the ones that are not. + //TODO: use despawn events Iterator it = traps.iterator(); while (it.hasNext()) { From 8a4fc564c2dbb4b501f6b609101d5318f21150d0 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 09:48:20 -0500 Subject: [PATCH 4/5] mlm plugin: rewrite to use events --- .../plugins/motherlode/MotherlodeConfig.java | 2 +- .../plugins/motherlode/MotherlodeOverlay.java | 34 +++-- .../plugins/motherlode/MotherlodePlugin.java | 124 ++++++++++++++++-- .../motherlode/MotherlodeRocksOverlay.java | 99 +++++--------- .../motherlode/MotherlodeSackOverlay.java | 16 +-- .../plugins/motherlode/MotherlodeSession.java | 2 +- 6 files changed, 171 insertions(+), 106 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java index 8e59bae775..8b1479ec08 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeOverlay.java index 3ad48f2cc1..a064da01f6 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeOverlay.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,21 +24,15 @@ */ package net.runelite.client.plugins.motherlode; -import net.runelite.api.Client; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.components.PanelComponent; - -import javax.inject.Inject; +import com.google.common.collect.Sets; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import java.time.Duration; import java.time.Instant; -import java.util.Arrays; -import java.util.List; - +import java.util.Set; +import javax.inject.Inject; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_ADAMANT; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BLACK; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_BRONZE; @@ -49,11 +43,14 @@ import static net.runelite.api.AnimationID.MINING_MOTHERLODE_IRON; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_MITHRIL; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_RUNE; import static net.runelite.api.AnimationID.MINING_MOTHERLODE_STEEL; +import net.runelite.api.Client; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.PanelComponent; class MotherlodeOverlay extends Overlay { - private static final List MINING_ANIMATION_IDS = Arrays.asList - ( + private static final Set MINING_ANIMATION_IDS = Sets.newHashSet( MINING_MOTHERLODE_BRONZE, MINING_MOTHERLODE_IRON, MINING_MOTHERLODE_STEEL, MINING_MOTHERLODE_BLACK, MINING_MOTHERLODE_MITHRIL, MINING_MOTHERLODE_ADAMANT, MINING_MOTHERLODE_RUNE, MINING_MOTHERLODE_DRAGON, MINING_MOTHERLODE_DRAGON_ORN, @@ -111,16 +108,15 @@ class MotherlodeOverlay extends Overlay } panelComponent.getLines().add(new PanelComponent.Line( - "Pay-dirt mined:", - Integer.toString(session.getTotalMined()) + "Pay-dirt mined:", + Integer.toString(session.getTotalMined()) )); - panelComponent.getLines().add(new PanelComponent.Line( - "Pay-dirt/hr:", - session.getRecentMined() > 2 - ? Integer.toString(session.getPerHour()) - : "" + "Pay-dirt/hr:", + session.getRecentMined() > 2 + ? Integer.toString(session.getPerHour()) + : "" )); return panelComponent.render(graphics, parent); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java index a60a4e492d..7997108ff2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodePlugin.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth +* Copyright (c) 2018, Adam * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,32 +25,54 @@ */ package net.runelite.client.plugins.motherlode; +import com.google.common.collect.Sets; import com.google.common.eventbus.Subscribe; import com.google.inject.Binder; import com.google.inject.Provides; -import lombok.Getter; -import net.runelite.api.ChatMessageType; -import net.runelite.api.events.ChatMessage; -import net.runelite.client.config.ConfigManager; -import net.runelite.client.plugins.Plugin; -import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.task.Schedule; -import net.runelite.client.ui.overlay.Overlay; - -import javax.imageio.ImageIO; -import javax.inject.Inject; import java.awt.image.BufferedImage; import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import javax.imageio.ImageIO; +import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; +import net.runelite.api.ChatMessageType; +import net.runelite.api.GameObject; +import net.runelite.api.GameState; +import static net.runelite.api.ObjectID.ORE_VEIN_26661; +import static net.runelite.api.ObjectID.ORE_VEIN_26662; +import static net.runelite.api.ObjectID.ORE_VEIN_26663; +import static net.runelite.api.ObjectID.ORE_VEIN_26664; +import static net.runelite.api.ObjectID.ROCKFALL; +import static net.runelite.api.ObjectID.ROCKFALL_26680; +import net.runelite.api.WallObject; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.GameObjectChanged; +import net.runelite.api.events.GameObjectDespawned; +import net.runelite.api.events.GameObjectSpawned; +import net.runelite.api.events.GameStateChanged; +import net.runelite.api.events.WallObjectChanged; +import net.runelite.api.events.WallObjectDespawned; +import net.runelite.api.events.WallObjectSpawned; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.task.Schedule; +import net.runelite.client.ui.overlay.Overlay; @PluginDescriptor( name = "Motherlode plugin" ) public class MotherlodePlugin extends Plugin { + private static final Set MINE_SPOTS = Sets.newHashSet(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664); + private static final Set ROCK_OBSTACLES = Sets.newHashSet(ROCKFALL, ROCKFALL_26680); + @Getter private BufferedImage mineIcon; @@ -67,6 +90,11 @@ public class MotherlodePlugin extends Plugin private final MotherlodeSession session = new MotherlodeSession(); + @Getter(AccessLevel.PACKAGE) + private final Set veins = new HashSet<>(); + @Getter(AccessLevel.PACKAGE) + private final Set rocks = new HashSet<>(); + @Override public void configure(Binder binder) { @@ -129,4 +157,76 @@ public class MotherlodePlugin extends Plugin session.resetRecent(); } } + + @Subscribe + public void onWallObjectSpanwed(WallObjectSpawned event) + { + WallObject wallObject = event.getWallObject(); + if (MINE_SPOTS.contains(wallObject.getId())) + { + veins.add(wallObject); + } + } + + @Subscribe + public void onWallObjectChanged(WallObjectChanged event) + { + WallObject previous = event.getPrevious(); + WallObject wallObject = event.getWallObject(); + + veins.remove(previous); + if (MINE_SPOTS.contains(wallObject.getId())) + { + veins.add(wallObject); + } + } + + @Subscribe + public void onWallObjectDespawned(WallObjectDespawned event) + { + WallObject wallObject = event.getWallObject(); + veins.remove(wallObject); + } + + @Subscribe + public void onGameObjectSpawned(GameObjectSpawned event) + { + GameObject gameObject = event.getGameObject(); + if (ROCK_OBSTACLES.contains(gameObject.getId())) + { + rocks.add(gameObject); + } + } + + @Subscribe + public void onGameObjectChanged(GameObjectChanged event) + { + GameObject previous = event.getPrevious(); + GameObject gameObject = event.getGameObject(); + + rocks.remove(previous); + if (ROCK_OBSTACLES.contains(gameObject.getId())) + { + rocks.add(gameObject); + } + + } + + @Subscribe + public void onGameObjectDespawned(GameObjectDespawned event) + { + GameObject gameObject = event.getGameObject(); + rocks.remove(gameObject); + } + + @Subscribe + public void onGameStateChanged(GameStateChanged event) + { + if (event.getGameState() == GameState.LOADING) + { + // on region changes the tiles get set to null + veins.clear(); + rocks.clear(); + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeRocksOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeRocksOverlay.java index 7ddf196cf1..8de088d31d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeRocksOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeRocksOverlay.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth +* Copyright (c) 2018, Adam * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,43 +25,26 @@ */ package net.runelite.client.plugins.motherlode; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Polygon; +import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.GameObject; import net.runelite.api.Perspective; import net.runelite.api.Player; -import net.runelite.api.Region; -import net.runelite.api.Tile; +import net.runelite.api.Point; import net.runelite.api.WallObject; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayUtil; -import javax.inject.Inject; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Polygon; -import java.util.Arrays; -import java.util.List; - -import static net.runelite.api.ObjectID.ORE_VEIN_26661; -import static net.runelite.api.ObjectID.ORE_VEIN_26662; -import static net.runelite.api.ObjectID.ORE_VEIN_26663; -import static net.runelite.api.ObjectID.ORE_VEIN_26664; -import static net.runelite.api.ObjectID.ROCKFALL; -import static net.runelite.api.ObjectID.ROCKFALL_26680; - class MotherlodeRocksOverlay extends Overlay { - private static final int REGION_SIZE = 104; private static final int MAX_DISTANCE = 2350; - private static final List MINE_SPOTS = Arrays.asList(ORE_VEIN_26661, ORE_VEIN_26662, ORE_VEIN_26663, ORE_VEIN_26664); - - private static final List ROCK_OBSTACLES = Arrays.asList(ROCKFALL, ROCKFALL_26680); - private final Client client; private final MotherlodePlugin plugin; private final MotherlodeConfig config; @@ -76,7 +60,7 @@ class MotherlodeRocksOverlay extends Overlay } @Override - public Dimension render(Graphics2D graphics, Point parent) + public Dimension render(Graphics2D graphics, java.awt.Point parent) { if (!config.enabled() || !config.showRocks()) { @@ -85,7 +69,6 @@ class MotherlodeRocksOverlay extends Overlay Player local = client.getLocalPlayer(); - //Render mining spot renderTiles(graphics, local); return null; @@ -93,57 +76,43 @@ class MotherlodeRocksOverlay extends Overlay private void renderTiles(Graphics2D graphics, Player local) { - Region region = client.getRegion(); - Tile[][][] tiles = region.getTiles(); - - int z = client.getPlane(); - - for (int x = 0; x < REGION_SIZE; ++x) + Point localLocation = local.getLocalLocation(); + for (WallObject vein : plugin.getVeins()) { - for (int y = 0; y < REGION_SIZE; ++y) + Point location = vein.getLocalLocation(); + if (localLocation.distanceTo(location) <= MAX_DISTANCE) { - Tile tile = tiles[z][x][y]; + renderVein(graphics, vein); + } + } - if (tile == null) - { - continue; - } - if (local.getLocalLocation().distanceTo(tile.getLocalLocation()) <= MAX_DISTANCE) - { - renderMine(graphics, tile); - } + for (GameObject rock : plugin.getRocks()) + { + Point location = rock.getLocalLocation(); + if (localLocation.distanceTo(location) <= MAX_DISTANCE) + { + renderRock(graphics, rock); } } } - private void renderMine(Graphics2D graphics, Tile tile) + private void renderVein(Graphics2D graphics, WallObject vein) { - //Draw the Pay-dirt spots - WallObject wallObject = tile.getWallObject(); - if (wallObject != null && MINE_SPOTS.contains(wallObject.getId())) - { - net.runelite.api.Point canvasLoc = Perspective.getCanvasImageLocation(client, graphics, wallObject.getLocalLocation(), plugin.getMineIcon(), 150); + Point canvasLoc = Perspective.getCanvasImageLocation(client, graphics, vein.getLocalLocation(), plugin.getMineIcon(), 150); - if (canvasLoc != null) - { - graphics.drawImage(plugin.getMineIcon(), canvasLoc.getX(), canvasLoc.getY(), null); - return; - } + if (canvasLoc != null) + { + graphics.drawImage(plugin.getMineIcon(), canvasLoc.getX(), canvasLoc.getY(), null); } + } - //Draw the rock obstacles - GameObject[] gameObjects = tile.getGameObjects(); - for (GameObject gameObject : gameObjects) + private void renderRock(Graphics2D graphics, GameObject rock) + { + Polygon poly = Perspective.getCanvasTilePoly(client, rock.getLocalLocation()); + + if (poly != null) { - if (gameObject != null && ROCK_OBSTACLES.contains(gameObject.getId())) - { - Polygon poly = Perspective.getCanvasTilePoly(client, gameObject.getLocalLocation()); - - if (poly != null) - { - OverlayUtil.renderPolygon(graphics, poly, Color.red); - } - } + OverlayUtil.renderPolygon(graphics, poly, Color.red); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java index e3f00b924b..f16fde8830 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSackOverlay.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth +* Copyright (c) 2018, Adam * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,6 +25,10 @@ */ package net.runelite.client.plugins.motherlode; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Point; +import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.Varbits; import net.runelite.api.widgets.Widget; @@ -32,11 +37,6 @@ import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.components.PanelComponent; -import javax.inject.Inject; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.Point; - class MotherlodeSackOverlay extends Overlay { private final Client client; @@ -70,8 +70,8 @@ class MotherlodeSackOverlay extends Overlay if (config.showSack()) { panelComponent.getLines().add(new PanelComponent.Line( - "Pay-dirt in sack:", - String.valueOf(client.getSetting(Varbits.SACK_NUMBER)) + "Pay-dirt in sack:", + String.valueOf(client.getSetting(Varbits.SACK_NUMBER)) )); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSession.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSession.java index 0413fb8589..11d31991e7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSession.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeSession.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018, Seth + * Copyright (c) 2018, Seth * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 9505da573d2208c7628c413f1506a923acde30d0 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jan 2018 10:42:01 -0500 Subject: [PATCH 5/5] mlm plugin: default to enabled once again --- .../runelite/client/plugins/motherlode/MotherlodeConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java index 8b1479ec08..988ca70d61 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/motherlode/MotherlodeConfig.java @@ -42,7 +42,7 @@ public interface MotherlodeConfig extends Config ) default boolean enabled() { - return false; + return true; } @ConfigItem(