Skip to content

Commit 76362b2

Browse files
Fixes #2166
1 parent 2fc18ae commit 76362b2

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
* Fixed #2156
7272
* Fixed #2165
7373
* Fixed #2162
74+
* Fixed #2166
7475

7576
## Release Candidate 14 (12 Jul 2020)
7677

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,45 @@ public ItemDropHandler getItemHandler() {
5959
};
6060
}
6161

62-
private void activate(Player p, PlayerDropItemEvent e, Item item) {
62+
private void activate(Player p, PlayerDropItemEvent e, Item rune) {
6363
// Being sure the entity is still valid and not picked up or whatsoever.
64-
if (!item.isValid()) {
64+
if (!rune.isValid()) {
6565
return;
6666
}
6767

68-
Location l = item.getLocation();
68+
Location l = rune.getLocation();
6969
Collection<Entity> entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem);
7070
Optional<Entity> optional = entites.stream().findFirst();
7171

7272
if (optional.isPresent()) {
73-
Item entity = (Item) optional.get();
74-
ItemStack target = entity.getItemStack();
73+
Item item = (Item) optional.get();
74+
ItemStack itemStack = item.getItemStack();
7575

76-
SlimefunUtils.setSoulbound(target, true);
77-
78-
if (target.getAmount() == 1) {
76+
if (itemStack.getAmount() == 1) {
77+
// Prevent other plugins from processing this Item as we will remove it soon
7978
e.setCancelled(true);
8079

8180
// This lightning is just an effect, it deals no damage.
8281
l.getWorld().strikeLightningEffect(l);
8382

8483
Slimefun.runSync(() -> {
8584
// Being sure entities are still valid and not picked up or whatsoever.
86-
if (item.isValid() && entity.isValid() && target.getAmount() == 1) {
85+
if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) {
8786

8887
l.getWorld().createExplosion(l, 0);
8988
l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1);
9089

91-
entity.remove();
9290
item.remove();
93-
l.getWorld().dropItemNaturally(l, target);
91+
rune.remove();
92+
93+
SlimefunUtils.setSoulbound(itemStack, true);
94+
l.getWorld().dropItemNaturally(l, itemStack);
9495

9596
SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.success", true);
9697
}
98+
else {
99+
SlimefunPlugin.getLocalization().sendMessage(p, "messages.soulbound-rune.fail", true);
100+
}
97101
}, 10L);
98102
}
99103
else {
@@ -102,9 +106,19 @@ private void activate(Player p, PlayerDropItemEvent e, Item item) {
102106
}
103107
}
104108

105-
private boolean findCompatibleItem(Entity n) {
106-
if (n instanceof Item) {
107-
Item item = (Item) n;
109+
/**
110+
* This method checks whether a given {@link Entity} is an {@link Item} which can
111+
* be bound to a soul. We exclude the {@link SoulboundRune} itself and any already
112+
* {@link Soulbound} {@link Item}.
113+
*
114+
* @param entity
115+
* The {@link Entity} to check
116+
*
117+
* @return Whether this {@link Entity} is compatible
118+
*/
119+
private boolean findCompatibleItem(Entity entity) {
120+
if (entity instanceof Item) {
121+
Item item = (Item) entity;
108122

109123
return !SlimefunUtils.isSoulbound(item.getItemStack()) && !isItem(item.getItemStack());
110124
}

0 commit comments

Comments
 (0)