screenshot: use playerdeath events (#1245)
* add PlayerDeath event * use LocalPlayerDeath and PlayerDeath events
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, HSJ <https://github.com/HSJ-OSRS>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
@@ -44,9 +44,6 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -67,11 +64,12 @@ import net.runelite.api.Point;
|
|||||||
import net.runelite.api.SpriteID;
|
import net.runelite.api.SpriteID;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.api.WorldType;
|
import net.runelite.api.WorldType;
|
||||||
import net.runelite.api.events.AnimationChanged;
|
|
||||||
import net.runelite.api.events.ChatMessage;
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
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.events.WidgetLoaded;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID;
|
import static net.runelite.api.widgets.WidgetID.BARROWS_REWARD_GROUP_ID;
|
||||||
@@ -199,8 +197,6 @@ public class ScreenshotPlugin extends Plugin
|
|||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private BufferedImage reportButton;
|
private BufferedImage reportButton;
|
||||||
|
|
||||||
private final Map<Player, Integer> dying = new HashMap<>();
|
|
||||||
|
|
||||||
private NavigationButton titleBarButton;
|
private NavigationButton titleBarButton;
|
||||||
|
|
||||||
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> this.hotkey)
|
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(ConfigChanged.class, this, this::onConfigChanged);
|
||||||
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
|
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
|
||||||
eventBus.subscribe(GameTick.class, this, this::onGameTick);
|
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(PlayerLootReceived.class, this, this::onPlayerLootReceived);
|
||||||
eventBus.subscribe(ChatMessage.class, this, this::onChatMessage);
|
eventBus.subscribe(ChatMessage.class, this, this::onChatMessage);
|
||||||
eventBus.subscribe(WidgetLoaded.class, this, this::onWidgetLoaded);
|
eventBus.subscribe(WidgetLoaded.class, this, this::onWidgetLoaded);
|
||||||
@@ -310,23 +307,6 @@ public class ScreenshotPlugin extends Plugin
|
|||||||
|
|
||||||
void onGameTick(GameTick event)
|
void onGameTick(GameTick event)
|
||||||
{
|
{
|
||||||
if (this.screenshotFriendDeath)
|
|
||||||
{
|
|
||||||
for (Iterator<Player> 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)
|
if (!shouldTakeScreenshot)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -356,51 +336,22 @@ public class ScreenshotPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAnimationChanged(AnimationChanged e)
|
private void onLocalPlayerDeath(LocalPlayerDeath event)
|
||||||
{
|
{
|
||||||
|
if (this.screenshotPlayerDeath && client.getLocalPlayer().getName() != null)
|
||||||
if (e.getActor().getAnimation() != 836)
|
|
||||||
{
|
{
|
||||||
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()));
|
takeScreenshot(event.getPlayer().getName() + " ded " + format(new Date()), "Deaths");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import net.runelite.api.coords.WorldPoint;
|
|||||||
import net.runelite.api.events.AnimationChanged;
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.HitsplatApplied;
|
import net.runelite.api.events.HitsplatApplied;
|
||||||
import net.runelite.api.events.LocalPlayerDeath;
|
import net.runelite.api.events.LocalPlayerDeath;
|
||||||
|
import net.runelite.api.events.PlayerDeath;
|
||||||
import net.runelite.api.events.SpotAnimationChanged;
|
import net.runelite.api.events.SpotAnimationChanged;
|
||||||
import net.runelite.api.events.InteractingChanged;
|
import net.runelite.api.events.InteractingChanged;
|
||||||
import net.runelite.api.events.OverheadTextChanged;
|
import net.runelite.api.events.OverheadTextChanged;
|
||||||
@@ -254,6 +255,11 @@ public abstract class RSActorMixin implements RSActor
|
|||||||
LocalPlayerDeath event = LocalPlayerDeath.INSTANCE;
|
LocalPlayerDeath event = LocalPlayerDeath.INSTANCE;
|
||||||
client.getCallbacks().post(LocalPlayerDeath.class, event);
|
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)
|
else if (this instanceof RSNPC)
|
||||||
{
|
{
|
||||||
((RSNPC) this).setDead(true);
|
((RSNPC) this).setDead(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user