Merge pull request #26 from kireevm96/master

Fixed keepInventory soulbound dupe
This commit is contained in:
Auxilor 2021-01-16 14:48:20 +00:00 committed by GitHub
commit 5afeb01acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,11 +65,24 @@ public class Soulbound extends EcoEnchant {
player.setMetadata("soulbound-items", this.getPlugin().getMetadataValueFactory().create(soulboundItems)); player.setMetadata("soulbound-items", this.getPlugin().getMetadataValueFactory().create(soulboundItems));
} }
public boolean hasEmptyInventory(Player p) {
for(ItemStack it : p.getInventory().getContents())
{
if(it != null) return false;
}
return true;
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) { public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
this.getPlugin().getScheduler().runLater(() -> { this.getPlugin().getScheduler().runLater(() -> {
if (!hasEmptyInventory(player)) {
return;
}
if (!player.hasMetadata("soulbound-items")) { if (!player.hasMetadata("soulbound-items")) {
return; return;
} }
@ -88,10 +101,8 @@ public class Soulbound extends EcoEnchant {
assert meta != null; assert meta != null;
meta.getPersistentDataContainer().remove(this.getPlugin().getNamespacedKeyFactory().create("soulbound")); meta.getPersistentDataContainer().remove(this.getPlugin().getNamespacedKeyFactory().create("soulbound"));
soulboundItem.setItemMeta(meta); soulboundItem.setItemMeta(meta);
player.getInventory().addItem(soulboundItem);
if (!player.getInventory().contains(soulboundItem)) {
player.getInventory().addItem(soulboundItem);
}
} }
player.removeMetadata("soulbound-items", this.getPlugin()); player.removeMetadata("soulbound-items", this.getPlugin());