mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-01 03:55:28 +02:00
RepairableBuilder, ItemStackSerializer WIP
This commit is contained in:
@@ -4,36 +4,100 @@ import com.gmail.nossr50.datatypes.permissions.PermissionWrapper;
|
||||
import com.gmail.nossr50.skills.repair.RepairTransaction;
|
||||
import com.gmail.nossr50.util.nbt.RawNBT;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Repairable {
|
||||
private final Material itemMaterial;
|
||||
private final int minimumLevel;
|
||||
private final short maximumDurability;
|
||||
private final ItemStack item;
|
||||
private int minimumLevel = 0;
|
||||
private short maximumDurability;
|
||||
private RepairTransaction repairTransaction;
|
||||
private boolean strictMatching;
|
||||
private int baseXP;
|
||||
private boolean strictMatchingItem = false;
|
||||
private boolean strictMatchingRepairTransaction = false;
|
||||
private int baseXP = 0;
|
||||
private RawNBT rawNBT;
|
||||
private int repairCount;
|
||||
private int repairCount = 1;
|
||||
private PermissionWrapper permissionWrapper;
|
||||
private boolean hasPermission = false;
|
||||
private boolean hasNBT = false;
|
||||
|
||||
public Repairable(Material itemMaterial, RepairTransaction repairTransaction, int minimumLevel, int repairCount, int baseXP, RawNBT rawNBT) {
|
||||
this(itemMaterial.getKey().getKey(), repairTransaction, minimumLevel, repairCount, baseXP, false, rawNBT);
|
||||
}
|
||||
|
||||
public Repairable(Material itemMaterial, RepairTransaction repairTransaction, int minimumLevel, int repairCount, int baseXP) {
|
||||
this(itemMaterial.getKey().getKey(), repairTransaction, minimumLevel, repairCount, baseXP, false, null);
|
||||
}
|
||||
|
||||
public Repairable(String itemMaterial, RepairTransaction repairTransaction, int minimumLevel, int repairCount, int baseXP, boolean strictMatching, RawNBT rawNBT) {
|
||||
this.itemMaterial = Material.matchMaterial(itemMaterial);
|
||||
this.minimumLevel = Math.max(0, minimumLevel);
|
||||
|
||||
this.maximumDurability = this.itemMaterial.getMaxDurability();
|
||||
this.repairCount = repairCount;
|
||||
public Repairable(ItemStack item, int minimumLevel, short maximumDurability, RepairTransaction repairTransaction, boolean strictMatchingItem, boolean strictMatchingRepairTransaction, int baseXP, int repairCount) {
|
||||
this.item = item;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.repairTransaction = repairTransaction;
|
||||
this.strictMatching = strictMatching;
|
||||
this.strictMatchingItem = strictMatchingItem;
|
||||
this.strictMatchingRepairTransaction = strictMatchingRepairTransaction;
|
||||
this.baseXP = baseXP;
|
||||
this.repairCount = repairCount;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getMinimumLevel() {
|
||||
return minimumLevel;
|
||||
}
|
||||
|
||||
public void setMinimumLevel(int minimumLevel) {
|
||||
this.minimumLevel = minimumLevel;
|
||||
}
|
||||
|
||||
public short getMaximumDurability() {
|
||||
return maximumDurability;
|
||||
}
|
||||
|
||||
public void setMaximumDurability(short maximumDurability) {
|
||||
this.maximumDurability = maximumDurability;
|
||||
}
|
||||
|
||||
public RepairTransaction getRepairTransaction() {
|
||||
return repairTransaction;
|
||||
}
|
||||
|
||||
public void setRepairTransaction(RepairTransaction repairTransaction) {
|
||||
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;
|
||||
}
|
||||
|
||||
public void setBaseXP(int baseXP) {
|
||||
this.baseXP = baseXP;
|
||||
}
|
||||
|
||||
public RawNBT getRawNBT() {
|
||||
return rawNBT;
|
||||
}
|
||||
|
||||
public void setRawNBT(RawNBT rawNBT) {
|
||||
this.rawNBT = rawNBT;
|
||||
hasNBT = true;
|
||||
}
|
||||
|
||||
public int getRepairCount() {
|
||||
return repairCount;
|
||||
}
|
||||
|
||||
public void setRepairCount(int repairCount) {
|
||||
this.repairCount = repairCount;
|
||||
}
|
||||
|
||||
public PermissionWrapper getPermissionWrapper() {
|
||||
@@ -42,41 +106,22 @@ public class Repairable {
|
||||
|
||||
public void setPermissionWrapper(PermissionWrapper permissionWrapper) {
|
||||
this.permissionWrapper = permissionWrapper;
|
||||
hasPermission = true;
|
||||
}
|
||||
|
||||
public RawNBT getRawNBT() {
|
||||
return rawNBT;
|
||||
public boolean hasPermission() {
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
public int getRepairCount() {
|
||||
return repairCount;
|
||||
public void setHasPermission(boolean hasPermission) {
|
||||
this.hasPermission = hasPermission;
|
||||
}
|
||||
|
||||
public Material getItemMaterial() {
|
||||
return itemMaterial;
|
||||
public boolean hasNBT() {
|
||||
return hasNBT;
|
||||
}
|
||||
|
||||
public RepairTransaction getRepairTransaction() {
|
||||
return repairTransaction;
|
||||
}
|
||||
|
||||
public boolean useStrictMatching() {
|
||||
return strictMatching;
|
||||
}
|
||||
|
||||
public int getBaseXP() {
|
||||
return baseXP;
|
||||
}
|
||||
|
||||
public short getMaximumDurability() {
|
||||
return maximumDurability;
|
||||
}
|
||||
|
||||
public short getBaseRepairDurability() {
|
||||
return (short) (maximumDurability / repairCount);
|
||||
}
|
||||
|
||||
public int getMinimumLevel() {
|
||||
return minimumLevel;
|
||||
public void setHasNBT(boolean hasNBT) {
|
||||
this.hasNBT = hasNBT;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,90 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
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 RepairableBuilder {
|
||||
|
||||
private final ItemStack item;
|
||||
private int minimumLevel = 0;
|
||||
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 PermissionWrapper permissionWrapper;
|
||||
|
||||
public RepairableBuilder(ItemStack item) {
|
||||
this.item = item;
|
||||
this.maximumDurability = item.getType().getMaxDurability();
|
||||
}
|
||||
|
||||
public RepairableBuilder minLevel(Integer minimumLevel) {
|
||||
this.minimumLevel = minimumLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder maximumDurability(Short maximumDurability) {
|
||||
this.maximumDurability = maximumDurability;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder repairTransaction(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) {
|
||||
this.baseXP = baseXP;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder rawNBT(RawNBT rawNBT) {
|
||||
this.rawNBT = rawNBT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder repairCount(Integer repairCount) {
|
||||
this.repairCount = repairCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepairableBuilder permissionWrapper(PermissionWrapper permissionWrapper) {
|
||||
this.permissionWrapper = permissionWrapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Repairable build() {
|
||||
return makeRepairable();
|
||||
}
|
||||
|
||||
private Repairable makeRepairable() {
|
||||
Repairable repairable = new Repairable(item, minimumLevel, maximumDurability, repairTransaction,
|
||||
strictMatchingItem, strictMatchingRepairTransaction, baseXP, repairCount);
|
||||
|
||||
if(permissionWrapper != null) {
|
||||
repairable.setPermissionWrapper(permissionWrapper);
|
||||
}
|
||||
|
||||
if(rawNBT != null) {
|
||||
repairable.setRawNBT(rawNBT);
|
||||
}
|
||||
|
||||
return repairable;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user