mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-03 13:05:30 +02:00
Simplify the design of Repairable
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
@@ -18,21 +20,25 @@ import java.util.HashSet;
|
||||
* to pay that part of the RepairTransaction
|
||||
*/
|
||||
public class RepairTransaction {
|
||||
private HashSet<RepairCost> repairItems;
|
||||
private HashSet<RepairCost> repairCosts;
|
||||
|
||||
public RepairTransaction() {
|
||||
repairItems = new HashSet<>();
|
||||
repairCosts = new HashSet<>();
|
||||
}
|
||||
|
||||
public void addRepairCost(RepairCost repairCost) {
|
||||
repairItems.add(repairCost);
|
||||
repairCosts.add(repairCost);
|
||||
}
|
||||
|
||||
public HashSet<RepairCost> getRepairItems() {
|
||||
return repairItems;
|
||||
public HashSet<RepairCost> getRepairCosts() {
|
||||
return repairCosts;
|
||||
}
|
||||
|
||||
public void setRepairItems(HashSet<RepairCost> repairItems) {
|
||||
this.repairItems = repairItems;
|
||||
public void setRepairCosts(HashSet<RepairCost> repairItems) {
|
||||
this.repairCosts = repairItems;
|
||||
}
|
||||
|
||||
public boolean canPayRepairCosts(PlayerInventory playerInventory) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +1,32 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.CustomItemTarget;
|
||||
import com.gmail.nossr50.datatypes.permissions.PermissionWrapper;
|
||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Repairable {
|
||||
private final ItemStack item;
|
||||
private int minimumLevel = 0;
|
||||
private int minimumLevel;
|
||||
private short maximumDurability;
|
||||
private RepairTransaction repairTransaction;
|
||||
private boolean strictMatchingItem = false;
|
||||
// private boolean strictMatchingRepairTransaction = false;
|
||||
private int baseXP = 0;
|
||||
private RawNBT rawNBT;
|
||||
private int repairCount = 1;
|
||||
private int baseXP;
|
||||
private CustomItemTarget customItemTarget;
|
||||
private int repairCount;
|
||||
private PermissionWrapper permissionWrapper;
|
||||
private boolean hasPermission = false;
|
||||
private boolean hasNBT = false;
|
||||
|
||||
public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, int baseXP, int repairCount) {
|
||||
this.item = item;
|
||||
public Repairable(CustomItemTarget customItemTarget, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, int baseXP, int repairCount, PermissionWrapper permissionWrapper) {
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.repairTransaction = repairTransaction;
|
||||
this.strictMatchingItem = strictMatchingItem;
|
||||
// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
||||
this.baseXP = baseXP;
|
||||
this.customItemTarget = customItemTarget;
|
||||
this.repairCount = repairCount;
|
||||
}
|
||||
this.permissionWrapper = permissionWrapper;
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
if(permissionWrapper != null)
|
||||
hasPermission = true;
|
||||
}
|
||||
|
||||
public int getMinimumLevel() {
|
||||
@@ -58,22 +53,6 @@ public class Repairable {
|
||||
this.repairTransaction = repairTransaction;
|
||||
}
|
||||
|
||||
public boolean isStrictMatchingItem() {
|
||||
return strictMatchingItem;
|
||||
}
|
||||
|
||||
public void setStrictMatchingItem(boolean strictMatchingItem) {
|
||||
this.strictMatchingItem = strictMatchingItem;
|
||||
}
|
||||
|
||||
// public boolean isStrictMatchingRepairTransaction() {
|
||||
// return strictMatchingRepairTransaction;
|
||||
// }
|
||||
//
|
||||
// public void setStrictMatchingRepairTransaction(boolean strictMatchingRepairTransaction) {
|
||||
// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
||||
// }
|
||||
|
||||
public int getBaseXP() {
|
||||
return baseXP;
|
||||
}
|
||||
@@ -82,13 +61,12 @@ public class Repairable {
|
||||
this.baseXP = baseXP;
|
||||
}
|
||||
|
||||
public RawNBT getRawNBT() {
|
||||
return rawNBT;
|
||||
public CustomItemTarget getCustomItemTarget() {
|
||||
return customItemTarget;
|
||||
}
|
||||
|
||||
public void setRawNBT(RawNBT rawNBT) {
|
||||
this.rawNBT = rawNBT;
|
||||
hasNBT = true;
|
||||
public void setCustomItemTarget(CustomItemTarget customItemTarget) {
|
||||
this.customItemTarget = customItemTarget;
|
||||
}
|
||||
|
||||
public int getRepairCount() {
|
||||
@@ -105,10 +83,9 @@ public class Repairable {
|
||||
|
||||
public void setPermissionWrapper(PermissionWrapper permissionWrapper) {
|
||||
this.permissionWrapper = permissionWrapper;
|
||||
hasPermission = true;
|
||||
}
|
||||
|
||||
public boolean hasPermission() {
|
||||
public boolean hasPermissionNode() {
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
@@ -116,11 +93,4 @@ public class Repairable {
|
||||
this.hasPermission = hasPermission;
|
||||
}
|
||||
|
||||
public boolean hasNBT() {
|
||||
return hasNBT;
|
||||
}
|
||||
|
||||
public void setHasNBT(boolean hasNBT) {
|
||||
this.hasNBT = hasNBT;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.items.CustomItemTarget;
|
||||
import com.gmail.nossr50.datatypes.permissions.PermissionWrapper;
|
||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||
@@ -7,63 +8,46 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class RepairableBuilder {
|
||||
|
||||
private final ItemStack item;
|
||||
private int minimumLevel = 0;
|
||||
private int minimumLevel;
|
||||
private short maximumDurability;
|
||||
private RepairTransaction repairTransaction;
|
||||
private boolean strictMatchingItem = false;
|
||||
// private boolean strictMatchingRepairTransaction = false;
|
||||
private int baseXP = 0;
|
||||
private RawNBT rawNBT;
|
||||
private int repairCount = 1;
|
||||
private int baseXP;
|
||||
private CustomItemTarget customItemTarget;
|
||||
private int repairCount;
|
||||
private PermissionWrapper permissionWrapper;
|
||||
|
||||
public RepairableBuilder(ItemStack item) {
|
||||
this.item = item;
|
||||
this.maximumDurability = item.getType().getMaxDurability();
|
||||
public RepairableBuilder(CustomItemTarget customItemTarget, Short maximumDurability, RepairTransaction repairTransaction) {
|
||||
this.customItemTarget = customItemTarget;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.repairTransaction = repairTransaction;
|
||||
}
|
||||
|
||||
public RepairableBuilder minLevel(Integer minimumLevel) {
|
||||
public RepairableBuilder addMinLevel(Integer minimumLevel) {
|
||||
this.minimumLevel = minimumLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder maximumDurability(Short maximumDurability) {
|
||||
public RepairableBuilder setMaximumDurability(Short maximumDurability) {
|
||||
this.maximumDurability = maximumDurability;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder repairTransaction(RepairTransaction repairTransaction) {
|
||||
public RepairableBuilder setRepairTransaction(RepairTransaction repairTransaction) {
|
||||
this.repairTransaction = repairTransaction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder strictMatchingItem(Boolean strictMatchingItem) {
|
||||
this.strictMatchingItem = strictMatchingItem;
|
||||
return this;
|
||||
}
|
||||
|
||||
// public RepairableBuilder strictMatchingRepairTransaction(Boolean strictMatchingRepairTransaction) {
|
||||
// this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public RepairableBuilder baseXP(Integer baseXP) {
|
||||
public RepairableBuilder setBaseXP(Integer baseXP) {
|
||||
this.baseXP = baseXP;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder rawNBT(RawNBT rawNBT) {
|
||||
this.rawNBT = rawNBT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder repairCount(Integer repairCount) {
|
||||
public RepairableBuilder setRepairCount(Integer repairCount) {
|
||||
this.repairCount = repairCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder permissionWrapper(PermissionWrapper permissionWrapper) {
|
||||
public RepairableBuilder addPermissionWrapper(PermissionWrapper permissionWrapper) {
|
||||
this.permissionWrapper = permissionWrapper;
|
||||
return this;
|
||||
}
|
||||
@@ -73,16 +57,8 @@ public class RepairableBuilder {
|
||||
}
|
||||
|
||||
private Repairable makeRepairable() {
|
||||
Repairable repairable = new Repairable(item, minimumLevel, maximumDurability, repairTransaction,
|
||||
strictMatchingItem, baseXP, repairCount);
|
||||
|
||||
if(permissionWrapper != null) {
|
||||
repairable.setPermissionWrapper(permissionWrapper);
|
||||
}
|
||||
|
||||
if(rawNBT != null) {
|
||||
repairable.setRawNBT(rawNBT);
|
||||
}
|
||||
Repairable repairable = new Repairable(customItemTarget, minimumLevel, maximumDurability, repairTransaction,
|
||||
baseXP, repairCount, permissionWrapper);
|
||||
|
||||
return repairable;
|
||||
}
|
||||
|
Reference in New Issue
Block a user