mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2166
This commit is contained in:
parent
2fc18aed0a
commit
76362b2acb
@ -71,6 +71,7 @@
|
|||||||
* Fixed #2156
|
* Fixed #2156
|
||||||
* Fixed #2165
|
* Fixed #2165
|
||||||
* Fixed #2162
|
* Fixed #2162
|
||||||
|
* Fixed #2166
|
||||||
|
|
||||||
## Release Candidate 14 (12 Jul 2020)
|
## Release Candidate 14 (12 Jul 2020)
|
||||||
|
|
||||||
|
@ -59,23 +59,22 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activate(Player p, PlayerDropItemEvent e, Item item) {
|
private void activate(Player p, PlayerDropItemEvent e, Item rune) {
|
||||||
// Being sure the entity is still valid and not picked up or whatsoever.
|
// Being sure the entity is still valid and not picked up or whatsoever.
|
||||||
if (!item.isValid()) {
|
if (!rune.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location l = item.getLocation();
|
Location l = rune.getLocation();
|
||||||
Collection<Entity> entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem);
|
Collection<Entity> entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem);
|
||||||
Optional<Entity> optional = entites.stream().findFirst();
|
Optional<Entity> optional = entites.stream().findFirst();
|
||||||
|
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
Item entity = (Item) optional.get();
|
Item item = (Item) optional.get();
|
||||||
ItemStack target = entity.getItemStack();
|
ItemStack itemStack = item.getItemStack();
|
||||||
|
|
||||||
SlimefunUtils.setSoulbound(target, true);
|
if (itemStack.getAmount() == 1) {
|
||||||
|
// Prevent other plugins from processing this Item as we will remove it soon
|
||||||
if (target.getAmount() == 1) {
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|
||||||
// This lightning is just an effect, it deals no damage.
|
// This lightning is just an effect, it deals no damage.
|
||||||
@ -83,17 +82,22 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
|
|
||||||
Slimefun.runSync(() -> {
|
Slimefun.runSync(() -> {
|
||||||
// Being sure entities are still valid and not picked up or whatsoever.
|
// Being sure entities are still valid and not picked up or whatsoever.
|
||||||
if (item.isValid() && entity.isValid() && target.getAmount() == 1) {
|
if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) {
|
||||||
|
|
||||||
l.getWorld().createExplosion(l, 0);
|
l.getWorld().createExplosion(l, 0);
|
||||||
l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1);
|
l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1);
|
||||||
|
|
||||||
entity.remove();
|
|
||||||
item.remove();
|
item.remove();
|
||||||
l.getWorld().dropItemNaturally(l, target);
|
rune.remove();
|
||||||
|
|
||||||
|
SlimefunUtils.setSoulbound(itemStack, true);
|
||||||
|
l.getWorld().dropItemNaturally(l, itemStack);
|
||||||
|
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.success", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.success", true);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.fail", true);
|
||||||
|
}
|
||||||
}, 10L);
|
}, 10L);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -102,9 +106,19 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean findCompatibleItem(Entity n) {
|
/**
|
||||||
if (n instanceof Item) {
|
* This method checks whether a given {@link Entity} is an {@link Item} which can
|
||||||
Item item = (Item) n;
|
* be bound to a soul. We exclude the {@link SoulboundRune} itself and any already
|
||||||
|
* {@link Soulbound} {@link Item}.
|
||||||
|
*
|
||||||
|
* @param entity
|
||||||
|
* The {@link Entity} to check
|
||||||
|
*
|
||||||
|
* @return Whether this {@link Entity} is compatible
|
||||||
|
*/
|
||||||
|
private boolean findCompatibleItem(Entity entity) {
|
||||||
|
if (entity instanceof Item) {
|
||||||
|
Item item = (Item) entity;
|
||||||
|
|
||||||
return !SlimefunUtils.isSoulbound(item.getItemStack()) && !isItem(item.getItemStack());
|
return !SlimefunUtils.isSoulbound(item.getItemStack()) && !isItem(item.getItemStack());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user