kourendlibrary: remove LibraryCustomer

This commit is contained in:
Hydrox6
2019-12-04 16:05:48 +00:00
committed by Adam
parent 7734b1199e
commit c0b193fd2e
4 changed files with 16 additions and 78 deletions

View File

@@ -210,12 +210,12 @@ class KourendLibraryOverlay extends Overlay
} }
// Render the customer's wanted book on their head and a poly under their feet // Render the customer's wanted book on their head and a poly under their feet
LibraryCustomer customer = library.getCustomer(); int customerId = library.getCustomerId();
if (customer != null) if (customerId != -1)
{ {
for (NPC n : plugin.getNpcsToMark()) for (NPC n : plugin.getNpcsToMark())
{ {
if (n.getId() != customer.getId()) if (n.getId() != customerId)
{ {
continue; continue;
} }

View File

@@ -44,6 +44,7 @@ import net.runelite.api.Item;
import net.runelite.api.ItemContainer; import net.runelite.api.ItemContainer;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.AnimationChanged;
@@ -270,8 +271,7 @@ public class KourendLibraryPlugin extends Plugin
Widget npcHead = client.getWidget(WidgetInfo.DIALOG_NPC_HEAD_MODEL); Widget npcHead = client.getWidget(WidgetInfo.DIALOG_NPC_HEAD_MODEL);
if (npcHead != null) if (npcHead != null)
{ {
LibraryCustomer cust = LibraryCustomer.getById(npcHead.getModelId()); if (isLibraryCustomer(npcHead.getModelId()))
if (cust != null)
{ {
Widget textw = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT); Widget textw = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
String text = textw.getText(); String text = textw.getText();
@@ -286,12 +286,12 @@ public class KourendLibraryPlugin extends Plugin
return; return;
} }
library.setCustomer(cust, book); library.setCustomer(npcHead.getModelId(), book);
panel.update(); panel.update();
} }
else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it.")) else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it."))
{ {
library.setCustomer(null, null); library.setCustomer(-1, null);
panel.update(); panel.update();
} }
} }
@@ -307,7 +307,7 @@ public class KourendLibraryPlugin extends Plugin
@Subscribe @Subscribe
public void onNpcSpawned(NpcSpawned event) public void onNpcSpawned(NpcSpawned event)
{ {
if (LibraryCustomer.getById(event.getNpc().getId()) != null) if (isLibraryCustomer(event.getNpc().getId()))
{ {
npcsToMark.add(event.getNpc()); npcsToMark.add(event.getNpc());
} }
@@ -345,4 +345,9 @@ public class KourendLibraryPlugin extends Plugin
playerBooks = books; playerBooks = books;
} }
} }
static boolean isLibraryCustomer(int npcId)
{
return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049;
}
} }

View File

@@ -74,7 +74,7 @@ class Library
private Book customerBook; private Book customerBook;
@Getter @Getter
private LibraryCustomer customer; private int customerId;
Library() Library()
{ {
@@ -93,9 +93,9 @@ class Library
return Collections.unmodifiableList(byIndex); return Collections.unmodifiableList(byIndex);
} }
void setCustomer(LibraryCustomer customer, Book book) void setCustomer(int customerId, Book book)
{ {
this.customer = customer; this.customerId = customerId;
this.customerBook = book; this.customerBook = book;
} }

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018 Abex
* 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.kourendlibrary;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import net.runelite.api.NpcID;
enum LibraryCustomer
{
VILLIA(NpcID.VILLIA, "Villia"),
PROFESSOR_GRACKLEBONE(NpcID.PROFESSOR_GRACKLEBONE, "Prof. Gracklebone"),
SAM(NpcID.SAM_7049, "Sam");
@Getter
private final int id;
@Getter
private final String name;
private static final Map<Integer, LibraryCustomer> byId = buildIdMap();
LibraryCustomer(int id, String name)
{
this.id = id;
this.name = name;
}
static LibraryCustomer getById(int id)
{
return byId.get(id);
}
private static Map<Integer, LibraryCustomer> buildIdMap()
{
Map<Integer, LibraryCustomer> byId = new HashMap<>();
for (LibraryCustomer c : values())
{
byId.put(c.id, c);
}
return byId;
}
}