diff --git a/src/main/kotlin/main/VpcSpigotIntegration/SignHandler.kt b/src/main/kotlin/main/VpcSpigotIntegration/SignHandler.kt index 684b651..cc56e89 100644 --- a/src/main/kotlin/main/VpcSpigotIntegration/SignHandler.kt +++ b/src/main/kotlin/main/VpcSpigotIntegration/SignHandler.kt @@ -94,7 +94,12 @@ class SignHandler: Listener { LOGGER.info("Container block: $cordX $cordY $cordZ") val container: Chest = containerBlock.state as Chest - val firstItem = container.blockInventory.contents[0] + LOGGER.info("Content: ${container.blockInventory.contents}") + var firstItem = container.blockInventory.contents.filterNotNull().firstOrNull() + if (firstItem == null) { + Utils.send(event.player,"&cВ контейнере нет предметов для покупки.") + } + firstItem = firstItem as ItemStack LOGGER.info("firstItem: ${firstItem.type} | amount: ${firstItem.amount}") // Get info @@ -150,7 +155,7 @@ class SignHandler: Listener { var coloredLine: String // Check if some data is missing - if (vpcUsername.isEmpty() || cost == null || amount == null) { + if (vpcUsername.isEmpty() || cost == null || amount == null || amount < 0 || cost < 0) { coloredLine = ChatColor.translateAlternateColorCodes('&', "$PREFIX&cError") event.setLine(0, coloredLine) return diff --git a/src/main/kotlin/main/VpcSpigotIntegration/VpcServerIntegration.kt b/src/main/kotlin/main/VpcSpigotIntegration/VpcServerIntegration.kt index 67eec6f..2368b0c 100644 --- a/src/main/kotlin/main/VpcSpigotIntegration/VpcServerIntegration.kt +++ b/src/main/kotlin/main/VpcSpigotIntegration/VpcServerIntegration.kt @@ -712,10 +712,12 @@ pay_by_sign=${DEFAULT_PAY_BY_SIGN} val availableAmount = paymentInfo.container.inventory.all(type).values.sumOf { it.amount } if (availableAmount < paymentInfo.amount) { LOGGER.error("Not enough items after pay invoice, try to return VPC...") + Utils.send(paymentInfo.player, "&cВ контейнере недостаточно предметов, попытка вернуть VPC...") val vpcUsername = DataManager.getPlayerVPCUsername(paymentInfo.player.name).toString() val transferResult = VpcApi.transfer_coins(vpcUsername, paymentInfo.cost).toString() if (transferResult != "OK") { LOGGER.error("Can't return VPC, result: $transferResult") + Utils.send(paymentInfo.player, "&cНевозможно вернуть VPC, обратитесь к администратору: $transferResult") } } else { // If we have needed items