mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-09-18 10:47:53 +02:00
More work on the repair rewrite, fleshing out more serializers
This commit is contained in:
@@ -11,15 +11,15 @@ public interface RepairCost {
|
||||
/**
|
||||
* 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
|
||||
* @return any compatible payment items if found, can be null
|
||||
*/
|
||||
ItemStack findPayment(PlayerInventory playerInventory);
|
||||
|
||||
/**
|
||||
* Whether or not this repair cost is strictly matched
|
||||
* Strict matching compares Items by using metadata and material type
|
||||
* @return true if the RepairCost uses strict matching
|
||||
* Whether or not there is an item that can be used for this repair cost in the player's inventory
|
||||
* @param playerInventory target player
|
||||
* @return true if payment is found
|
||||
*/
|
||||
boolean hasStrictMatching();
|
||||
boolean hasPayment(PlayerInventory playerInventory);
|
||||
|
||||
}
|
||||
|
@@ -1,55 +0,0 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.ItemWildcards;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Represents a piece of a RepairTransaction
|
||||
* Multiple RepairCost pieces are used to pay for a RepairTransaction
|
||||
* This one represents a wildcard cost, which can be paid for with multiple items
|
||||
*
|
||||
*/
|
||||
public class RepairCostWildcard implements RepairCost {
|
||||
|
||||
private HashSet<SimpleRepairCost> simpleRepairCosts;
|
||||
private ItemWildcards itemWildcards;
|
||||
|
||||
|
||||
public RepairCostWildcard(ItemWildcards itemWildcards) {
|
||||
this.itemWildcards = itemWildcards;
|
||||
simpleRepairCosts = new HashSet<>();
|
||||
|
||||
for(ItemStack itemStack : )
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack findPayment(PlayerInventory playerInventory) {
|
||||
for(ItemStack itemStack : playerInventory.getContents()) {
|
||||
if(itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for(SimpleRepairCost simpleRepairCost : simpleRepairCosts) {
|
||||
//Attempt to match the item in the inventory to any of the compatible repair items
|
||||
if(simpleRepairCost.findPayment(playerInventory) != null) {
|
||||
return simpleRepairCost.findPayment(playerInventory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemWildcards getItemWildcards() {
|
||||
return itemWildcards;
|
||||
}
|
||||
|
||||
public void setItemWildcards(ItemWildcards itemWildcards) {
|
||||
this.itemWildcards = itemWildcards;
|
||||
}
|
||||
|
||||
}
|
@@ -39,6 +39,12 @@ public class RepairTransaction {
|
||||
}
|
||||
|
||||
public boolean canPayRepairCosts(PlayerInventory playerInventory) {
|
||||
for(RepairCost repairCost : repairCosts) {
|
||||
if(!repairCost.hasPayment(playerInventory)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.ItemMatchProperty;
|
||||
import com.gmail.nossr50.datatypes.items.BukkitMMOItem;
|
||||
import com.gmail.nossr50.datatypes.items.CustomItemTarget;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Implementation of RepairCost
|
||||
* <p>
|
||||
*
|
||||
* A SimpleRepairCost can be one or more items, any one of which can be used to pay for a RepairTransaction
|
||||
* If a SimpleRepairCost is more than one item, then only one of the items are required to represent its cost.
|
||||
*
|
||||
@@ -18,49 +17,30 @@ import java.util.Objects;
|
||||
*/
|
||||
public class SimpleRepairCost implements RepairCost {
|
||||
|
||||
private ItemMatchProperty itemMatchProperty;
|
||||
private CustomItemTarget desiredItemTarget;
|
||||
|
||||
public SimpleRepairCost(ItemMatchProperty itemMatchProperty) {
|
||||
this.itemMatchProperty = itemMatchProperty;
|
||||
public SimpleRepairCost(CustomItemTarget customItemTarget) {
|
||||
this.desiredItemTarget = customItemTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack findPayment(PlayerInventory playerInventory) {
|
||||
for(ItemStack itemStack : playerInventory.getContents()) {
|
||||
if(itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
if(itemStack == null || itemStack.getType() == Material.AIR)
|
||||
continue;
|
||||
}
|
||||
|
||||
//Attempt to match the item in the inventory to any of the compatible repair items
|
||||
if(hasStrictMatching()) {
|
||||
//TODO: Replace with strict matching code
|
||||
if(item)
|
||||
return itemStack;
|
||||
} else {
|
||||
if(itemStack.getType() == itemMatchProperty.getType()) {
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
BukkitMMOItem playerInventoryItem = new BukkitMMOItem(itemStack);
|
||||
|
||||
//If the item matches return it
|
||||
if(desiredItemTarget.isMatch(playerInventoryItem))
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(itemMatchProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SimpleRepairCost)) return false;
|
||||
SimpleRepairCost that = (SimpleRepairCost) o;
|
||||
return itemMatchProperty.equals(that.itemMatchProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStrictMatching() {
|
||||
return strictMatching;
|
||||
public boolean hasPayment(PlayerInventory playerInventory) {
|
||||
return findPayment(playerInventory) != null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user