1
mirror of https://github.com/CarmJos/UltraDepository.git synced 2024-09-19 19:55:45 +00:00

[v1.1.8] [U] 支持无限背包容量

This commit is contained in:
Carm Jos 2022-01-05 23:50:41 +08:00
parent b6a6502713
commit 27ad14c7ab
3 changed files with 22 additions and 9 deletions

View File

@ -42,10 +42,21 @@ public class DepositoryCapacity {
} }
public int getPlayerCapacity(Player player) { public int getPlayerCapacity(Player player) {
return getPermissions().entrySet().stream() if (defaultCapacity == -1) return -1;
.filter(entry -> player.hasPermission(entry.getKey()))
.mapToInt(Map.Entry::getValue) int capacity = defaultCapacity;
.max().orElse(defaultCapacity); for (Map.Entry<String, Integer> entry : getPermissions().entrySet()) {
if (player.hasPermission(entry.getKey())) {
int value = entry.getValue();
if (value == -1) {
return -1;
} else if (value > capacity) {
capacity = value;
}
}
}
return capacity;
} }
} }

View File

@ -19,7 +19,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
"%UltraDepository_amount_<BackpackID>_<ItemTypeID>%", "%UltraDepository_amount_<BackpackID>_<ItemTypeID>%",
"%UltraDepository_sold_<BackpackID>_<ItemTypeID>%", "%UltraDepository_sold_<BackpackID>_<ItemTypeID>%",
"%UltraDepository_price_<BackpackID>_<ItemTypeID>%", "%UltraDepository_price_<BackpackID>_<ItemTypeID>%",
"%UltraDepository_reUltraDepository_<BackpackID>_<ItemTypeID>%", "%UltraDepository_remain_<BackpackID>_<ItemTypeID>%",
"%UltraDepository_capacity_<BackpackID>%", "%UltraDepository_capacity_<BackpackID>%",
"%UltraDepository_used_<BackpackID>%", "%UltraDepository_used_<BackpackID>%",
"%UltraDepository_usable_<BackpackID>%" "%UltraDepository_usable_<BackpackID>%"
@ -80,7 +80,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
if (sold == null) return "Depository or Item not exists"; if (sold == null) return "Depository or Item not exists";
else return sold.toString(); else return sold.toString();
} }
case "reUltraDepository": { case "remain": {
if (args.length < 2) return "Error Params"; if (args.length < 2) return "Error Params";
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]); Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
if (depository == null) return "Depository not exists"; if (depository == null) return "Depository not exists";
@ -106,7 +106,8 @@ public class PAPIExpansion extends PlaceholderExpansion {
if (args.length < 2) return "Error Params"; if (args.length < 2) return "Error Params";
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]); Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
if (depository == null) return "Depository not exists"; if (depository == null) return "Depository not exists";
return Integer.toString(depository.getCapacity().getPlayerCapacity(player)); int capacity = depository.getCapacity().getPlayerCapacity(player);
return capacity < 0 ? "" : Integer.toString(capacity);
} }
case "used": { case "used": {
if (args.length < 2) return "Error Params"; if (args.length < 2) return "Error Params";
@ -118,8 +119,9 @@ public class PAPIExpansion extends PlaceholderExpansion {
if (args.length < 2) return "Error Params"; if (args.length < 2) return "Error Params";
Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]); Depository depository = UltraDepository.getDepositoryManager().getDepository(args[1]);
if (depository == null) return "Depository not exists"; if (depository == null) return "Depository not exists";
int max = depository.getCapacity().getPlayerCapacity(player);
int used = data.getDepositoryData(depository).getUsedCapacity(); int used = data.getDepositoryData(depository).getUsedCapacity();
return Integer.toString(depository.getCapacity().getPlayerCapacity(player) - used); return max < 0 ? "" : Integer.toString(max - used);
} }
case "version": { case "version": {
return getVersion(); return getVersion();

View File

@ -115,7 +115,7 @@ public class DepositoryManager {
return getItemDepositories(itemStack).stream().filter(configuration -> { return getItemDepositories(itemStack).stream().filter(configuration -> {
int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity(); int used = UltraDepository.getUserManager().getData(player).getDepositoryData(configuration).getUsedCapacity();
int max = configuration.getCapacity().getPlayerCapacity(player); int max = configuration.getCapacity().getPlayerCapacity(player);
return used + itemStack.getAmount() <= max; return max < 0 || used + itemStack.getAmount() <= max;
}).collect(Collectors.toSet()); }).collect(Collectors.toSet());
} }