Skip to content

Commit

Permalink
fix: Fixed potential null pointer issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Jun 9, 2024
1 parent 51583f3 commit 7de0112
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ private void performSellCommand(Player player, String[] args) {
player.sendMessage(I18n.getStrAndHeader("price-null"));
return;
}
ItemStack itemStack = player.getInventory().getItemInMainHand().clone();
ItemStack itemStack = player.getInventory().getItemInMainHand();
if (itemStack == null || itemStack.getType() == Material.AIR) {
player.sendMessage(I18n.getStrAndHeader("hand-air"));
return;
}
if (this.marketData.getDeniedFilter().check(itemStack)) {
ItemStack cloneItem = itemStack.clone();
if (this.marketData.getDeniedFilter().check(cloneItem)) {
player.sendMessage(I18n.getStrAndHeader("deny-item"));
return;
}
Expand All @@ -82,7 +83,7 @@ private void performSellCommand(Player player, String[] args) {
return;
}
String extraPrice = this.marketData.getExtraMap().entrySet().stream()
.filter((s) -> new FilterHandler().addKeyFilter(new KeyFilterImpl(s.getKey())).check(itemStack))
.filter((s) -> new FilterHandler().addKeyFilter(new KeyFilterImpl(s.getKey())).check(cloneItem))
.findFirst()
.map(Map.Entry::getValue)
.orElse(null);
Expand Down Expand Up @@ -120,7 +121,7 @@ private void performSellCommand(Player player, String[] args) {
player.getInventory().setItemInMainHand(null);
// 上架物品
SaleCache saleItem = new SaleCache(UUID.randomUUID().toString(), this.marketData.getMarketKey(), player.getUniqueId().toString(),
player.getName(), itemStack, PayType.VAULT, this.marketData.getEconomyType(), price, System.currentTimeMillis());
player.getName(), cloneItem, PayType.VAULT, this.marketData.getEconomyType(), price, System.currentTimeMillis());
// add sale to storage handler
ServerMarket.getStorageHandler().addSale(this.marketData.getMarketKey(), saleItem);
// call PlayerSaleEvent.Sell
Expand All @@ -130,12 +131,12 @@ private void performSellCommand(Player player, String[] args) {
player.sendMessage(I18n.getStrAndHeader("sell"));
// 判断是否公告
if (this.marketData.isSaleBroadcast()) {
String displayName = itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() ?
itemStack.getItemMeta().getDisplayName() : itemStack.getType().name();
String displayName = cloneItem.hasItemMeta() && cloneItem.getItemMeta().hasDisplayName() ?
cloneItem.getItemMeta().getDisplayName() : cloneItem.getType().name();
Bukkit.getServer().broadcastMessage(I18n.getStrAndHeader("broadcast")
.replace("%item%", displayName)
.replace("%market_name%", this.marketData.getDisplayName())
.replace("%amount%", String.valueOf(itemStack.getAmount()))
.replace("%amount%", String.valueOf(cloneItem.getAmount()))
.replace("%player%", player.getName()));
}
}
Expand Down

0 comments on commit 7de0112

Please sign in to comment.