From e769fe5447f31a999524bbf1a80f56bc5279aa3d Mon Sep 17 00:00:00 2001 From: Ganom Date: Sun, 25 Aug 2019 22:50:34 -0400 Subject: [PATCH] hideunder: add (#1452) * hideunder: add * hideunder: add license * hideunder: disable by default --- .../client/plugins/hidehunder/HideUnder.java | 186 ++++++++++++++++++ .../plugins/hidehunder/PlayerContainer.java | 45 +++++ 2 files changed, 231 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/HideUnder.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/PlayerContainer.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/HideUnder.java b/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/HideUnder.java new file mode 100644 index 0000000000..2cd76f376d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/HideUnder.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2019, ganom + * 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.hidehunder; + +import java.util.HashSet; +import java.util.Set; +import javax.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Actor; +import net.runelite.api.Client; +import net.runelite.api.Player; +import net.runelite.api.coords.WorldPoint; +import net.runelite.api.events.AnimationChanged; +import net.runelite.api.events.GameTick; +import net.runelite.api.events.InteractingChanged; +import net.runelite.api.events.PlayerDespawned; +import net.runelite.api.events.PlayerSpawned; +import net.runelite.client.eventbus.EventBus; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.PluginType; + +@PluginDescriptor( + name = "Hide Under", + description = "Hide local player when under targeted players", + tags = {"hide", "local", "player", "under"}, + type = PluginType.PVP, + enabledByDefault = false +) +@Slf4j +public class HideUnder extends Plugin +{ + @Inject + private Client client; + @Inject + private EventBus eventBus; + private Set playerContainer = new HashSet<>(); + + @Override + protected void startUp() + { + addSubscriptions(); + playerContainer.clear(); + } + + @Override + protected void shutDown() + { + eventBus.unregister(this); + } + + private void addSubscriptions() + { + eventBus.subscribe(PlayerSpawned.class, this, this::onPlayerSpawned); + eventBus.subscribe(PlayerDespawned.class, this, this::onPlayerDespawned); + eventBus.subscribe(GameTick.class, this, this::onGameTick); + eventBus.subscribe(InteractingChanged.class, this, this::onInteractingChanged); + eventBus.subscribe(AnimationChanged.class, this, this::onAnimationChanged); + } + + private void onInteractingChanged(InteractingChanged event) + { + if ((event.getSource() instanceof Player) && (event.getTarget() instanceof Player)) + { + final Player source = (Player) event.getSource(); + final Player target = (Player) event.getTarget(); + + if (source == client.getLocalPlayer()) + { + for (PlayerContainer player : playerContainer) + { + if (player.getPlayer() == target) + { + player.setTimer(16); + player.setTarget(true); + } + } + } + else if (target == client.getLocalPlayer()) + { + for (PlayerContainer player : playerContainer) + { + if (player.getPlayer() == source) + { + player.setTimer(16); + player.setTarget(true); + } + } + } + } + } + + private void onAnimationChanged(AnimationChanged event) + { + final Actor actor = event.getActor(); + + if (actor.getInteracting() != client.getLocalPlayer() || !(actor instanceof Player)) + { + return; + } + + if (actor.getAnimation() != -1 && actor.getInteracting() != null && actor.getInteracting() == client.getLocalPlayer()) + { + for (PlayerContainer player : playerContainer) + { + if (player.getPlayer() == actor) + { + player.setTimer(16); + player.setTarget(true); + } + } + } + } + + private void onPlayerSpawned(PlayerSpawned event) + { + final Player player = event.getPlayer(); + + if (player == client.getLocalPlayer()) + { + return; + } + + playerContainer.add(new PlayerContainer(player)); + } + + private void onPlayerDespawned(PlayerDespawned event) + { + final Player player = event.getPlayer(); + playerContainer.removeIf(playa -> playa.getPlayer() == player); + } + + private void onGameTick(GameTick event) + { + if (playerContainer.isEmpty()) + { + return; + } + + assert client.getLocalPlayer() != null; + final WorldPoint lp = client.getLocalPlayer().getWorldLocation(); + + client.setLocalPlayerHidden(false); + + for (PlayerContainer player : playerContainer) + { + if (player.getTimer() > 0) + { + player.setTimer(player.getTimer() - 1); + } + else + { + player.setTarget(false); + } + + if (player.isTarget()) + { + if (player.getPlayer().getWorldLocation().distanceTo(lp) == 0) + { + client.setLocalPlayerHidden(true); + } + } + } + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/PlayerContainer.java b/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/PlayerContainer.java new file mode 100644 index 0000000000..90d64b7606 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hidehunder/PlayerContainer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019, ganom + * 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.hidehunder; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import net.runelite.api.Player; + +@Getter(AccessLevel.PACKAGE) +@Setter(AccessLevel.PACKAGE) +class PlayerContainer +{ + private Player player; + private boolean target; + private int timer; + + PlayerContainer(Player player) + { + this.player = player; + this.target = false; + this.timer = 0; + } +} \ No newline at end of file