mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-26 15:45:12 +01:00
Merge pull request #26 from kireevm96/master
Fixed keepInventory soulbound dupe
This commit is contained in:
commit
5afeb01acb
@ -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());
|
||||||
|
Loading…
Reference in New Issue
Block a user