SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (c) 2016-2018, Adam <Adam@sigterm.info>
  3.  * Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright notice, this
  10.  *    list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright notice,
  12.  *    this list of conditions and the following disclaimer in the documentation
  13.  *    and/or other materials provided with the distribution.
  14.  *
  15.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18.  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26. package net.runelite.client.plugins.Learning3;
  27.  
  28. import com.google.inject.Provides;
  29. import lombok.AccessLevel;
  30. import lombok.Getter;
  31. import net.runelite.api.Actor;
  32. import net.runelite.api.Client;
  33. import net.runelite.api.GameState;
  34. import net.runelite.api.WorldType;
  35. import net.runelite.api.events.GameStateChanged;
  36. import net.runelite.api.events.GameTick;
  37. import net.runelite.api.events.InteractingChanged;
  38. import net.runelite.client.config.ConfigManager;
  39. import net.runelite.client.eventbus.Subscribe;
  40. import net.runelite.client.plugins.Plugin;
  41. import net.runelite.client.plugins.PluginDescriptor;
  42. import net.runelite.client.ui.overlay.OverlayManager;
  43. import net.runelite.http.api.hiscore.HiscoreEndpoint;
  44.  
  45. import javax.inject.Inject;
  46. import java.time.Duration;
  47. import java.time.Instant;
  48. import java.util.EnumSet;
  49.  
  50. @PluginDescriptor(
  51.     name = "Learning 3",
  52.     description = "Notify, when the NPC/Player is dead.",
  53.     tags = {"notify"}
  54. )
  55. public class OpponentInfoPlugin extends Plugin
  56. {
  57.     private static final Duration WAIT = Duration.ofSeconds(5);
  58.  
  59.     @Inject
  60.     private Client client;
  61.  
  62.     @Inject
  63.     private OpponentInfoConfig config;
  64.  
  65.     @Inject
  66.     private OverlayManager overlayManager;
  67.  
  68.     @Inject
  69.     private OpponentInfoOverlay opponentInfoOverlay;
  70.  
  71.  
  72.  
  73.     @Getter(AccessLevel.PACKAGE)
  74.     private HiscoreEndpoint hiscoreEndpoint = HiscoreEndpoint.NORMAL;
  75.  
  76.     @Getter(AccessLevel.PACKAGE)
  77.     private Actor lastOpponent;
  78.  
  79.     private Instant lastTime;
  80.  
  81.     @Provides
  82.     OpponentInfoConfig provideConfig(ConfigManager configManager)
  83.     {
  84.         return configManager.getConfig(OpponentInfoConfig.class);
  85.     }
  86.  
  87.     @Override
  88.     protected void startUp() throws Exception
  89.     {
  90.         overlayManager.add(opponentInfoOverlay);
  91.  
  92.     }
  93.  
  94.     @Override
  95.     protected void shutDown() throws Exception
  96.     {
  97.         lastOpponent = null;
  98.         lastTime = null;
  99.         overlayManager.remove(opponentInfoOverlay);
  100.  
  101.     }
  102.  
  103.     @Subscribe
  104.     public void onGameStateChanged(GameStateChanged gameStateChanged)
  105.     {
  106.         if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
  107.         {
  108.             return;
  109.         }
  110.  
  111.         final EnumSet<WorldType> worldType = client.getWorldType();
  112.         if (worldType.contains(WorldType.PVP))
  113.         {
  114.             hiscoreEndpoint = HiscoreEndpoint.NORMAL;
  115.         }
  116.         else if (worldType.contains(WorldType.PVP_HIGH_RISK))
  117.         {
  118.             hiscoreEndpoint = HiscoreEndpoint.NORMAL;
  119.         }
  120.         else if (worldType.contains(WorldType.DEADMAN))
  121.         {
  122.             hiscoreEndpoint = HiscoreEndpoint.DEADMAN;
  123.         }
  124.         else
  125.         {
  126.             hiscoreEndpoint = HiscoreEndpoint.NORMAL;
  127.         }
  128.     }
  129.  
  130.     @Subscribe
  131.     public void onInteractingChanged(InteractingChanged event)
  132.     {
  133.         final Actor source = event.getSource();
  134.         if (source != client.getLocalPlayer())
  135.         {
  136.             return;
  137.         }
  138.  
  139.         Actor opponent = event.getTarget();
  140.  
  141.         if (opponent == null)
  142.         {
  143.             lastTime = Instant.now();
  144.             return;
  145.         }
  146.  
  147.         lastOpponent = opponent;
  148.     }
  149.  
  150.     @Subscribe
  151.     public void onGameTick(GameTick gameTick)
  152.     {
  153.         if (lastOpponent != null
  154.             && lastTime != null
  155.             && client.getLocalPlayer().getInteracting() == null)
  156.         {
  157.             if (Duration.between(lastTime, Instant.now()).compareTo(WAIT) > 0)
  158.             {
  159.                 lastOpponent = null;
  160.             }
  161.         }
  162.     }
  163. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top