Fixed kits sometimes giving no items.

This commit is contained in:
Lilac 2019-09-14 19:39:47 +01:00
parent 63e6b8e090
commit e8e2b26f10
2 changed files with 10 additions and 1 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "UltimateKits"
path: "/builds/$CI_PROJECT_PATH"
version: "2.3.23"
version: "2.3.24"
build:
stage: build

View File

@ -286,11 +286,18 @@ public class Kit {
if (amt != amtToGive || kitAnimation != KitAnimation.NONE)
Collections.shuffle(innerContents);
return generateRandomItem(innerContents, amtToGive, player);
}
private boolean generateRandomItem(List<KitItem> innerContents, int amtToGive, Player player) {
boolean chosenItem = false;
for (KitItem item : innerContents) {
if (amtToGive == 0) continue;
int ch = item.getChance() == 0 ? 100 : item.getChance();
double rand = Math.random() * 100;
if (rand - ch < 0 || ch == 100) {
chosenItem = true;
if (item.getContent() instanceof KitContentEconomy) {
try {
Methods.pay(player, ((KitContentEconomy) item.getContent()).getAmount());
@ -341,6 +348,8 @@ public class Kit {
}
}
if (!chosenItem) generateRandomItem(innerContents, amtToGive, player);
player.updateInventory();
return true;
}