From f26154c4bc3ce00a851bdcb545f6f836a9c1222b Mon Sep 17 00:00:00 2001 From: Harry <37844423+HSJ-OSRS@users.noreply.github.com> Date: Sat, 3 Aug 2019 12:43:42 +0100 Subject: [PATCH] screenshot: use playerdeath events (#1245) * add PlayerDeath event * use LocalPlayerDeath and PlayerDeath events --- .../net/runelite/api/events/PlayerDeath.java | 37 +++++++++ .../plugins/screenshot/ScreenshotPlugin.java | 81 ++++--------------- .../net/runelite/mixins/RSActorMixin.java | 6 ++ 3 files changed, 59 insertions(+), 65 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/PlayerDeath.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/PlayerDeath.java b/runelite-api/src/main/java/net/runelite/api/events/PlayerDeath.java new file mode 100644 index 0000000000..96d7b6dd31 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/PlayerDeath.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019, HSJ + * 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.Value; +import net.runelite.api.Player; + +/** + * An event when a player dies. + */ +@Value +public class PlayerDeath implements Event +{ + private final Player player; +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java index d0d2c8de09..da50af8c41 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java @@ -44,9 +44,6 @@ import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Date; import java.util.EnumSet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -67,11 +64,12 @@ import net.runelite.api.Point; import net.runelite.api.SpriteID; import net.runelite.api.Varbits; import net.runelite.api.WorldType; -import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; +import net.runelite.api.events.LocalPlayerDeath; +import net.runelite.api.events.PlayerDeath; import net.runelite.api.events.WidgetLoaded; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID; @@ -199,8 +197,6 @@ public class ScreenshotPlugin extends Plugin @Getter(AccessLevel.PACKAGE) private BufferedImage reportButton; - private final Map dying = new HashMap<>(); - private NavigationButton titleBarButton; private final HotkeyListener hotkeyListener = new HotkeyListener(() -> this.hotkey) @@ -293,7 +289,8 @@ public class ScreenshotPlugin extends Plugin eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged); eventBus.subscribe(GameTick.class, this, this::onGameTick); - eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged); + eventBus.subscribe(LocalPlayerDeath.class, this, this::onLocalPlayerDeath); + eventBus.subscribe(PlayerDeath.class, this, this::onPlayerDeath); eventBus.subscribe(PlayerLootReceived.class, this, this::onPlayerLootReceived); eventBus.subscribe(ChatMessage.class, this, this::onChatMessage); eventBus.subscribe(WidgetLoaded.class, this, this::onWidgetLoaded); @@ -310,23 +307,6 @@ public class ScreenshotPlugin extends Plugin void onGameTick(GameTick event) { - if (this.screenshotFriendDeath) - { - for (Iterator it = dying.keySet().iterator(); it.hasNext();) - { - Player key = it.next(); - if (key.getAnimation() != 836) - { - it.remove(); - } - dying.replace(key, dying.get(key) - 1); - if (dying.get(key) == 0) - { - takeScreenshot(key.getName() + " ded " + format(new Date()), "Deaths"); - it.remove(); - } - } - } if (!shouldTakeScreenshot) { return; @@ -356,51 +336,22 @@ public class ScreenshotPlugin extends Plugin } } - private void onAnimationChanged(AnimationChanged e) + private void onLocalPlayerDeath(LocalPlayerDeath event) { - - if (e.getActor().getAnimation() != 836) + if (this.screenshotPlayerDeath && client.getLocalPlayer().getName() != null) { - return; + takeScreenshot(client.getLocalPlayer().getName() + " ded " + format(new Date()), "Deaths"); } + } - if (this.screenshotPlayerDeath && client.getLocalPlayer().equals(e.getActor())) + private void onPlayerDeath(PlayerDeath event) + { + int tob = client.getVar(Varbits.THEATRE_OF_BLOOD); + if (this.screenshotFriendDeath && event.getPlayer().getName() != null + && (event.getPlayer().isFriend() || event.getPlayer().isClanMember() + || (client.getVar(Varbits.IN_RAID) == 1 || tob == 2 || tob == 3))) { - takeScreenshot("Death - " + format(new Date())); - } - - - if (!(e.getActor() instanceof Player)) - return; - Player p = (Player) e.getActor(); - - - if (p.getAnimation() != 836) - { - return; - } - if (p.getName().equals(client.getLocalPlayer().getName())) - { - - if (this.screenshotPlayerDeath) - { - dying.put(p, 3); - return; - } - else - { - return; - } - } - if (this.screenshotFriendDeath) - { - int tob = client.getVar(Varbits.THEATRE_OF_BLOOD); - - if (client.getVar(Varbits.IN_RAID) == 1 || tob == 2 || tob == 3 || p.isFriend()) - { - //this is the same as the tick counter had, just want to make ss at right timing - dying.put(p, 3); - } + takeScreenshot(event.getPlayer().getName() + " ded " + format(new Date()), "Deaths"); } } @@ -940,4 +891,4 @@ public class ScreenshotPlugin extends Plugin this.screenshotUntradeableDrop = config.screenshotUntradeableDrop(); this.hotkey = config.hotkey(); } -} \ No newline at end of file +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java index 09aaf32a92..3c748ab51e 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSActorMixin.java @@ -38,6 +38,7 @@ import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.HitsplatApplied; import net.runelite.api.events.LocalPlayerDeath; +import net.runelite.api.events.PlayerDeath; import net.runelite.api.events.SpotAnimationChanged; import net.runelite.api.events.InteractingChanged; import net.runelite.api.events.OverheadTextChanged; @@ -254,6 +255,11 @@ public abstract class RSActorMixin implements RSActor LocalPlayerDeath event = LocalPlayerDeath.INSTANCE; client.getCallbacks().post(LocalPlayerDeath.class, event); } + else if (this != client.getLocalPlayer() && this instanceof Player) + { + final PlayerDeath event = new PlayerDeath((Player) this); + client.getCallbacks().post(PlayerDeath.class, event); + } else if (this instanceof RSNPC) { ((RSNPC) this).setDead(true);