Merge pull request #2385 from Adam-/puro-puro

impling plugin: use spawn events
This commit is contained in:
Adam
2018-05-06 16:46:55 -04:00
committed by GitHub
5 changed files with 259 additions and 128 deletions

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.implings;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.api.NpcID;
@AllArgsConstructor
@Getter
enum Impling
{
BABY(ImplingType.BABY, NpcID.BABY_IMPLING),
BABY_2(ImplingType.BABY, NpcID.BABY_IMPLING_1645),
YOUNG(ImplingType.YOUNG, NpcID.YOUNG_IMPLING),
YOUNG_2(ImplingType.YOUNG, NpcID.YOUNG_IMPLING_1646),
GOURMET(ImplingType.GOURMET, NpcID.GOURMET_IMPLING),
GOURMET_2(ImplingType.GOURMET, NpcID.GOURMET_IMPLING_1647),
EARTH(ImplingType.EARTH, NpcID.EARTH_IMPLING),
EARTH_2(ImplingType.EARTH, NpcID.EARTH_IMPLING_1648),
ESSENCE(ImplingType.ESSENCE, NpcID.ESSENCE_IMPLING),
ESSENCE_2(ImplingType.ESSENCE, NpcID.ESSENCE_IMPLING_1649),
ECLECTIC(ImplingType.ECLECTIC, NpcID.ECLECTIC_IMPLING),
ECLECTIC_2(ImplingType.ECLECTIC, NpcID.ECLECTIC_IMPLING_1650),
NATURE(ImplingType.NATURE, NpcID.NATURE_IMPLING),
NATURE_2(ImplingType.NATURE, NpcID.NATURE_IMPLING_1651),
MAGPIE(ImplingType.MAGPIE, NpcID.MAGPIE_IMPLING),
MAGPIE_2(ImplingType.MAGPIE, NpcID.MAGPIE_IMPLING_1652),
NINJA(ImplingType.NINJA, NpcID.NINJA_IMPLING),
NINJA_2(ImplingType.NINJA, NpcID.NINJA_IMPLING_1653),
DRAGON(ImplingType.DRAGON, NpcID.DRAGON_IMPLING),
DRAGON_2(ImplingType.DRAGON, NpcID.DRAGON_IMPLING_1654),
LUCKY(ImplingType.LUCKY, NpcID.LUCKY_IMPLING),
LUCKY_2(ImplingType.LUCKY, NpcID.LUCKY_IMPLING_7302);
private ImplingType implingType;
private final int npcId;
private static final Map<Integer, Impling> IMPLINGS = new HashMap<>();
static
{
for (Impling impling : values())
{
IMPLINGS.put(impling.npcId, impling);
}
}
static Impling findImpling(int npcId)
{
return IMPLINGS.get(npcId);
}
}

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.implings;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.NPC;
import net.runelite.api.Point;
@@ -52,8 +53,8 @@ public class ImplingMinimapOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
NPC[] imps = plugin.getImplings();
if (imps == null)
List<NPC> imps = plugin.getImplings();
if (imps.isEmpty())
{
return null;
}
@@ -61,16 +62,18 @@ public class ImplingMinimapOverlay extends Overlay
for (NPC imp : imps)
{
Point impLocation = imp.getMinimapLocation();
if (impLocation != null)
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || impLocation == null || color == null)
{
Color color = plugin.getIds().get(imp.getId());
OverlayUtil.renderMinimapLocation(graphics, impLocation, color);
continue;
}
if (config.showName())
{
Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
}
OverlayUtil.renderMinimapLocation(graphics, impLocation, color);
if (config.showName())
{
Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.implings;
enum ImplingType
{
BABY,
YOUNG,
GOURMET,
EARTH,
ESSENCE,
ECLECTIC,
NATURE,
MAGPIE,
NINJA,
DRAGON,
LUCKY
}

View File

@@ -28,6 +28,7 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.Actor;
import net.runelite.api.NPC;
@@ -38,7 +39,6 @@ import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
/**
*
* @author robin
*/
public class ImplingsOverlay extends Overlay
@@ -56,22 +56,22 @@ public class ImplingsOverlay extends Overlay
@Override
public Dimension render(Graphics2D graphics)
{
NPC[] imps = plugin.getImplings();
if (imps == null)
List<NPC> implings = plugin.getImplings();
if (implings.isEmpty())
{
return null;
}
for (NPC imp : imps)
for (NPC imp : implings)
{
if (imp == null || imp.getName() == null)
Color color = plugin.npcToColor(imp);
if (!plugin.showNpc(imp) || color == null)
{
continue;
}
//Spawns have the name "null", so they get changed to "Spawn"
String text = imp.getName().equals("null") ? "Spawn" : imp.getName();
drawImp(graphics, imp, text, plugin.getIds().get(imp.getId()));
drawImp(graphics, imp, imp.getName(), color);
}
return null;

View File

@@ -1,45 +1,42 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* 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.
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* 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.implings;
import com.google.common.eventbus.Subscribe;
import com.google.common.primitives.Ints;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.queries.NPCQuery;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -47,7 +44,6 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.util.QueryRunner;
/**
*
* @author robin
*/
@PluginDescriptor(
@@ -55,15 +51,8 @@ import net.runelite.client.util.QueryRunner;
)
public class ImplingsPlugin extends Plugin
{
// Impling spawns in PuroPuro. Not in NpcID.
private static final int STATIC_SPAWN = 1618;
private static final int DYNAMIC_SPAWN = 1633;
@Getter(AccessLevel.PACKAGE)
private NPC[] implings;
@Getter(AccessLevel.PACKAGE)
private final Map<Integer, Color> ids = new HashMap<>();
private final List<NPC> implings = new ArrayList<>();
@Inject
private ImplingsOverlay overlay;
@@ -83,13 +72,6 @@ public class ImplingsPlugin extends Plugin
return configManager.getConfig(ImplingsConfig.class);
}
@Override
protected void startUp() throws Exception
{
// Initialize overlay config
updateConfig();
}
@Override
public Collection<Overlay> getOverlays()
{
@@ -97,82 +79,101 @@ public class ImplingsPlugin extends Plugin
}
@Subscribe
public void updateConfig(ConfigChanged event)
public void onNpcSpawned(NpcSpawned npcSpawned)
{
updateConfig();
NPC npc = npcSpawned.getNpc();
Impling impling = Impling.findImpling(npc.getId());
if (impling != null)
{
implings.add(npc);
}
}
@Subscribe
public void onGameTick(GameTick event)
public void onNpcDespawned(NpcDespawned npcDespawned)
{
NPCQuery implingQuery = new NPCQuery()
.idEquals(Ints.toArray(ids.keySet()));
implings = queryRunner.runQuery(implingQuery);
if (implings.isEmpty())
{
return;
}
NPC npc = npcDespawned.getNpc();
implings.remove(npc);
}
public void updateConfig()
boolean showNpc(NPC npc)
{
ids.clear();
if (config.showBaby())
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
ids.put(NpcID.BABY_IMPLING, config.getBabyColor());
ids.put(NpcID.BABY_IMPLING_1645, config.getBabyColor());
return false;
}
if (config.showYoung())
switch (impling.getImplingType())
{
ids.put(NpcID.YOUNG_IMPLING, config.getYoungColor());
ids.put(NpcID.YOUNG_IMPLING_1646, config.getYoungColor());
}
if (config.showGourmet())
{
ids.put(NpcID.GOURMET_IMPLING, config.getGourmetColor());
ids.put(NpcID.GOURMET_IMPLING_1647, config.getGourmetColor());
}
if (config.showEarth())
{
ids.put(NpcID.EARTH_IMPLING, config.getEarthColor());
ids.put(NpcID.EARTH_IMPLING_1648, config.getEarthColor());
}
if (config.showEssence())
{
ids.put(NpcID.ESSENCE_IMPLING, config.getEssenceColor());
ids.put(NpcID.ESSENCE_IMPLING_1649, config.getEssenceColor());
}
if (config.showEclectic())
{
ids.put(NpcID.ECLECTIC_IMPLING, config.getEclecticColor());
ids.put(NpcID.ECLECTIC_IMPLING_1650, config.getEclecticColor());
}
if (config.showNature())
{
ids.put(NpcID.NATURE_IMPLING, config.getNatureColor());
ids.put(NpcID.NATURE_IMPLING_1651, config.getNatureColor());
}
if (config.showMagpie())
{
ids.put(NpcID.MAGPIE_IMPLING, config.getMagpieColor());
ids.put(NpcID.MAGPIE_IMPLING_1652, config.getMagpieColor());
}
if (config.showNinja())
{
ids.put(NpcID.NINJA_IMPLING, config.getNinjaColor());
ids.put(NpcID.NINJA_IMPLING_1653, config.getNinjaColor());
}
if (config.showDragon())
{
ids.put(NpcID.DRAGON_IMPLING, config.getDragonColor());
ids.put(NpcID.DRAGON_IMPLING_1654, config.getDragonColor());
}
if (config.showLucky())
{
ids.put(NpcID.LUCKY_IMPLING, config.getLuckyColor());
ids.put(NpcID.LUCKY_IMPLING_7302, config.getLuckyColor());
}
if (config.showSpawn())
{
ids.put(STATIC_SPAWN, config.getSpawnColor());
ids.put(DYNAMIC_SPAWN, config.getSpawnColor());
case BABY:
return config.showBaby();
case YOUNG:
return config.showYoung();
case GOURMET:
return config.showGourmet();
case EARTH:
return config.showEarth();
case ESSENCE:
return config.showEssence();
case ECLECTIC:
return config.showEclectic();
case NATURE:
return config.showNature();
case MAGPIE:
return config.showMagpie();
case NINJA:
return config.showNinja();
case DRAGON:
return config.showDragon();
case LUCKY:
return config.showLucky();
default:
return false;
}
}
Color npcToColor(NPC npc)
{
Impling impling = Impling.findImpling(npc.getId());
if (impling == null)
{
return null;
}
switch (impling.getImplingType())
{
case BABY:
return config.getBabyColor();
case YOUNG:
return config.getYoungColor();
case GOURMET:
return config.getGourmetColor();
case EARTH:
return config.getEarthColor();
case ESSENCE:
return config.getEssenceColor();
case ECLECTIC:
return config.getEclecticColor();
case NATURE:
return config.getNatureColor();
case MAGPIE:
return config.getMagpieColor();
case NINJA:
return config.getNinjaColor();
case DRAGON:
return config.getDragonColor();
case LUCKY:
return config.getLuckyColor();
default:
return null;
}
}
}