mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-03 21:15:28 +02:00
More work on the new repair system
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
/**
|
||||
* Represents one item in a Repair Transaction
|
||||
*/
|
||||
public interface RepairCost {
|
||||
|
||||
public interface RepairCost<T extends ItemMatch<?>> {
|
||||
|
||||
/**
|
||||
* Searches a player inventory for a matching ItemStack that can be used to pay for the repair transaction
|
||||
* @param playerInventory inventory of player attempting to pay the cost
|
||||
* @return any compatible payment items if found, can be null
|
||||
*/
|
||||
ItemStack findPayment(PlayerInventory playerInventory);
|
||||
T findPayment(PlayerInventory playerInventory);
|
||||
|
||||
/**
|
||||
* Whether or not there is an item that can be used for this repair cost in the player's inventory
|
||||
|
@@ -1,13 +1,12 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
||||
import com.gmail.nossr50.bukkit.BukkitFactory;
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of RepairCost
|
||||
*
|
||||
@@ -17,7 +16,7 @@ import java.util.List;
|
||||
* This type is strictly for use with RepairTransaction, which represents the full cost of a Repair.
|
||||
* @see com.gmail.nossr50.skills.repair.RepairTransaction for more details
|
||||
*/
|
||||
public class SimpleRepairCost<T extends ItemMatch> implements RepairCost {
|
||||
public class SimpleRepairCost<T extends ItemMatch> implements RepairCost<ItemMatch<?>> {
|
||||
|
||||
private T itemMatch;
|
||||
|
||||
@@ -26,35 +25,24 @@ public class SimpleRepairCost<T extends ItemMatch> implements RepairCost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack findPayment(PlayerInventory playerInventory) {
|
||||
public T findPayment(PlayerInventory playerInventory) {
|
||||
for(ItemStack itemStack : playerInventory.getContents()) {
|
||||
if(itemStack == null || itemStack.getType() == Material.AIR)
|
||||
continue;
|
||||
|
||||
BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack);
|
||||
MMOItem<T> playerInventoryItem = (MMOItem<T>) BukkitFactory.createItem(itemStack);
|
||||
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO: Write the code that compares playerInventoryItem with the <T extends itemMatch>
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
//TODO:
|
||||
if(itemMatch.isMatch(playerInventoryItem)) {
|
||||
//Item is a match
|
||||
return (T) playerInventoryItem;
|
||||
}
|
||||
|
||||
//If the item matches return it
|
||||
if(itemMatch.isMatch(playerInventoryItem))
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemMatch getItemMatch() {
|
||||
public T getItemMatch() {
|
||||
return itemMatch;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,41 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatch;
|
||||
import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||
import com.gmail.nossr50.datatypes.items.MMOItem;
|
||||
import com.gmail.nossr50.skills.repair.RepairCost;
|
||||
import com.gmail.nossr50.skills.repair.SimpleRepairCost;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MultiRepairCost<T extends MMOItem<T>, U extends ItemMatch<T>> implements RepairCost<U> {
|
||||
|
||||
//Multiple potential item matches
|
||||
private Set<SimpleRepairCost<U>> repairCostWildcards;
|
||||
|
||||
public MultiRepairCost(ItemWildcards<T> itemWildcards) {
|
||||
repairCostWildcards = new HashSet<>();
|
||||
for(ItemMatch<T> wildcard : itemWildcards.getItemTargets()) {
|
||||
SimpleRepairCost<U> simpleRepairCost = new SimpleRepairCost<U>((U)wildcard);
|
||||
repairCostWildcards.add(simpleRepairCost);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public U findPayment(PlayerInventory playerInventory) {
|
||||
for(SimpleRepairCost simpleRepairCost : repairCostWildcards) {
|
||||
if(simpleRepairCost.findPayment(playerInventory) != null) {
|
||||
return (U) simpleRepairCost.findPayment(playerInventory);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayment(PlayerInventory playerInventory) {
|
||||
return findPayment(playerInventory) != null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user