Skip to content

Commit

Permalink
Add better detection of non-overriden copy method for ItemRequirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoinkwiz committed Sep 24, 2023
1 parent c3fb2f3 commit 44f8f7b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,35 @@
package com.questhelper.requirements.item;

import com.questhelper.ItemCollections;
import com.questhelper.requirements.item.ItemRequirement;
import java.util.List;
import net.runelite.api.Client;
import net.runelite.api.Item;

public class FollowerItemRequirement extends ItemRequirement
{
private final List<Integer> followerIDs;
private final List<Integer> itemIDs;

public FollowerItemRequirement(String name, List<Integer> itemIDs, List<Integer> followerIDs)
{
super(name, itemIDs);
this.itemIDs = itemIDs;
this.followerIDs = followerIDs;
}

public FollowerItemRequirement(String name, ItemCollections itemIDs, List<Integer> followerIDs)
{
super(name, itemIDs);
this.itemIDs = itemIDs.getItems();
this.followerIDs = followerIDs;
}

@Override
protected FollowerItemRequirement copyOfClass()
{
return new FollowerItemRequirement(getName(), itemIDs, followerIDs);
}

@Override
public boolean check(Client client, boolean checkConsideringSlotRestrictions, List<Item> items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,22 @@ public ItemRequirement showConditioned(Requirement condition)
return newItem;
}

protected ItemRequirement copyOfClass()
{
if (this.getClass() != ItemRequirement.class)
{
throw new UnsupportedOperationException("Subclasses must override copy()");
}
return new ItemRequirement(name, id, quantity, equip);
}

public ItemRequirement copy()
{
ItemRequirement newItem = new ItemRequirement(name, id, quantity, equip);
ItemRequirement newItem = copyOfClass();
newItem.setName(name);
newItem.setId(id);
newItem.setEquip(equip);
newItem.setQuantity(quantity);
newItem.addAlternates(alternateItems);
newItem.setDisplayItemId(displayItemId);
newItem.setExclusiveToOneItemType(exclusiveToOneItemType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ else if (super.check(client, checkConsideringSlotRestrictions, new ArrayList<>()
}
return color;
}

@Override
protected KeyringRequirement copyOfClass()
{
return new KeyringRequirement(getName(), configManager, keyringCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
public class NoItemRequirement extends ItemRequirement
{
private final ItemSlots slot;
private final int matchingItemID;

/**
* Checks if a player has no items in a given {@link ItemSlots}
Expand All @@ -51,7 +50,6 @@ public NoItemRequirement(String text, @Nonnull ItemSlots slot)
{
super(text, -1, -1);
this.slot = slot;
matchingItemID = -1;
}

@Override
Expand All @@ -71,4 +69,10 @@ public String getDisplayText()
{
return "Nothing in your " + slot.getName();
}

@Override
protected NoItemRequirement copyOfClass()
{
return new NoItemRequirement(getName(), slot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public TeleportItemRequirement(String name, ItemCollections itemCollection, int
super(name, itemCollection, quantity);
setChargedItem(true);
}

@Override
protected TeleportItemRequirement copyOfClass()
{
return new TeleportItemRequirement(getName(), getId());
}
}

0 comments on commit 44f8f7b

Please sign in to comment.