Search in sources :

Example 1 with DurabilityData

use of org.spongepowered.api.data.manipulator.mutable.item.DurabilityData in project Nucleus by NucleusPowered.

the class RepairCommand method repairStack.

private RepairResult repairStack(ItemStack stack, boolean checkRestrictions) {
    if (checkRestrictions && (whitelist && !restrictions.contains(stack.getType()) || restrictions.contains(stack.getType()))) {
        return new RepairResult(stack, ResultType.RESTRICTED);
    }
    if (stack.get(DurabilityData.class).isPresent()) {
        DurabilityData durabilityData = stack.get(DurabilityData.class).get();
        DataTransactionResult transactionResult = stack.offer(Keys.ITEM_DURABILITY, durabilityData.durability().getMaxValue());
        if (transactionResult.isSuccessful()) {
            return new RepairResult(stack, ResultType.SUCCESS);
        } else {
            return new RepairResult(stack, ResultType.ERROR);
        }
    } else {
        return new RepairResult(stack, ResultType.NO_DURABILITY);
    }
}
Also used : DurabilityData(org.spongepowered.api.data.manipulator.mutable.item.DurabilityData) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult)

Aggregations

DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)1 DurabilityData (org.spongepowered.api.data.manipulator.mutable.item.DurabilityData)1