diff --git a/gradle.properties b/gradle.properties index ed023ea8..753c85d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -SBA_VERSION=1.5.11-dev4-pr28 +SBA_VERSION=1.5.11-dev5-pr28 PAPER_LEGACY_VERSION=1.16.5 BEDWARS_VERSION=0.2.30-SNAPSHOT CLOUD_COMMANDS_VERSION=1.6.2 diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/BedwarsBlockPlace.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/BedwarsBlockPlace.java index e2c4b7c9..891b3d9f 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/BedwarsBlockPlace.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/BedwarsBlockPlace.java @@ -120,16 +120,21 @@ public boolean isBreakableBlock(Block b) { } public boolean isBlockVisible(Block b) { - Player aiPlayer = (Player) getNPC().getEntity(); - if (aiPlayer == null) - return false; - World w = aiPlayer.getWorld(); - var rayTraceCheck = w.rayTraceBlocks(aiPlayer.getEyeLocation(), - aiPlayer.getEyeLocation().subtract(b.getLocation()).getDirection(), - 10); - if (rayTraceCheck == null) - return false; - return rayTraceCheck.getHitBlock().equals(b); + try { + Player aiPlayer = (Player) getNPC().getEntity(); + if (aiPlayer == null) + return false; + World w = aiPlayer.getWorld(); + var rayTraceCheck = w.rayTraceBlocks(aiPlayer.getEyeLocation(), + aiPlayer.getEyeLocation().subtract(b.getLocation()).getDirection(), + 10); + if (rayTraceCheck == null) + return false; + return rayTraceCheck.getHitBlock().equals(b); + } catch (Throwable t) { + // 1.8.8 + return true; + } } /* diff --git a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java index 9d2c5488..ccec5a38 100644 --- a/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java +++ b/plugin/src/main/java/io/github/pronze/sba/utils/citizens/FakeDeathTrait.java @@ -34,6 +34,48 @@ public class FakeDeathTrait extends Trait { // 3.Getting blocks from shops // 4.Collect ressource + class Pickup18 { + public void pick(Item itemEntity, ItemStack is, int space) { + PlayerPickupItemEvent pickupEvent = new PlayerPickupItemEvent( + (Player) npc.getEntity(), + itemEntity, + Math.max(0, is.getAmount() - space)); + + Bukkit.getPluginManager().callEvent(pickupEvent); + + if (!pickupEvent.isCancelled()) { + Logger.trace("NPC Pickup {}", itemEntity.getItemStack()); + getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack()); + blockPlace().getBlock(getNpcEntity().getInventory()); + if (pickupEvent.getRemaining() > 0) { + itemEntity.getItemStack().setAmount(pickupEvent.getRemaining()); + } else { + itemEntity.remove(); + } + } + } + } + + class Pickup112 { + public void pick(Item itemEntity, ItemStack is, int space) { + EntityPickupItemEvent pickupEvent = new EntityPickupItemEvent( + (LivingEntity) npc.getEntity(), + itemEntity, + Math.max(0, is.getAmount() - space)); + Bukkit.getPluginManager().callEvent(pickupEvent); + if (!pickupEvent.isCancelled()) { + Logger.trace("NPC Pickup {}", itemEntity.getItemStack()); + getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack()); + blockPlace().getBlock(getNpcEntity().getInventory()); + if (pickupEvent.getRemaining() > 0) { + itemEntity.getItemStack().setAmount(pickupEvent.getRemaining()); + } else { + itemEntity.remove(); + } + } + } + } + private List goals = new ArrayList<>(); @Getter @Setter @@ -157,39 +199,9 @@ && getPlayerObject().getGameMode() == GameMode.SURVIVAL) { int space = getAmountOfSpaceFor(is, getNpcEntity().getInventory()); if (space > 0) { if (Version.isVersion(1, 12)) { - EntityPickupItemEvent pickupEvent = new EntityPickupItemEvent( - (LivingEntity) npc.getEntity(), - itemEntity, - Math.max(0, is.getAmount() - space)); - Bukkit.getPluginManager().callEvent(pickupEvent); - if (!pickupEvent.isCancelled()) { - Logger.trace("NPC Pickup {}", itemEntity.getItemStack()); - getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack()); - blockPlace().getBlock(getNpcEntity().getInventory()); - if (pickupEvent.getRemaining() > 0) { - itemEntity.getItemStack().setAmount(pickupEvent.getRemaining()); - } else { - itemEntity.remove(); - } - } + new Pickup112().pick(itemEntity, is, space); } else { - PlayerPickupItemEvent pickupEvent = new PlayerPickupItemEvent( - (Player) npc.getEntity(), - itemEntity, - Math.max(0, is.getAmount() - space)); - - Bukkit.getPluginManager().callEvent(pickupEvent); - - if (!pickupEvent.isCancelled()) { - Logger.trace("NPC Pickup {}", itemEntity.getItemStack()); - getNpcEntity().getInventory().addItem(pickupEvent.getItem().getItemStack()); - blockPlace().getBlock(getNpcEntity().getInventory()); - if (pickupEvent.getRemaining() > 0) { - itemEntity.getItemStack().setAmount(pickupEvent.getRemaining()); - } else { - itemEntity.remove(); - } - } + new Pickup18().pick(itemEntity, is, space); } } } @@ -202,8 +214,12 @@ public static int getAmountOfSpaceFor(ItemStack m, Inventory inv) { m.setAmount(1); var oneStack = new ItemStack(m).getMaxStackSize(); int space = 0; - - var inventoryContent = inv.getStorageContents(); + ItemStack[] inventoryContent = null; + try { + inventoryContent = inv.getStorageContents(); + } catch (Throwable t) { + inventoryContent = inv.getContents(); + } for (int index = 0; index < inventoryContent.length; index++) { var itemStack = inventoryContent[index];