mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2184
This commit is contained in:
parent
d8f5992282
commit
cafa66b1a8
@ -33,6 +33,7 @@
|
|||||||
* Fixed Programmable Androids rotating in the wrong direction
|
* Fixed Programmable Androids rotating in the wrong direction
|
||||||
* Fixed #2176
|
* Fixed #2176
|
||||||
* Fixed #2103
|
* Fixed #2103
|
||||||
|
* Fixed #2184
|
||||||
|
|
||||||
## Release Candidate 15 (01 Aug 2020)
|
## Release Candidate 15 (01 Aug 2020)
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler;
|
||||||
@ -70,7 +69,7 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
if (Slimefun.hasUnlocked(p, this, true)) {
|
if (Slimefun.hasUnlocked(p, this, true)) {
|
||||||
Slimefun.runSync(() -> {
|
Slimefun.runSync(() -> {
|
||||||
try {
|
try {
|
||||||
addRandomEnchantment(p, e, item);
|
addRandomEnchantment(p, item);
|
||||||
}
|
}
|
||||||
catch (Exception x) {
|
catch (Exception x) {
|
||||||
error("An Exception occured while trying to apply an Enchantment Rune", x);
|
error("An Exception occured while trying to apply an Enchantment Rune", x);
|
||||||
@ -85,21 +84,21 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRandomEnchantment(Player p, PlayerDropItemEvent e, Item item) {
|
private void addRandomEnchantment(Player p, 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();
|
||||||
|
|
||||||
List<Enchantment> potentialEnchantments = applicableEnchantments.get(target.getType());
|
List<Enchantment> potentialEnchantments = applicableEnchantments.get(itemStack.getType());
|
||||||
|
|
||||||
if (potentialEnchantments == null) {
|
if (potentialEnchantments == null) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.fail", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.fail", true);
|
||||||
@ -111,7 +110,7 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
|
|
||||||
// Removing the enchantments that the item already has from enchantmentSet
|
// Removing the enchantments that the item already has from enchantmentSet
|
||||||
// This also removes any conflicting enchantments
|
// This also removes any conflicting enchantments
|
||||||
removeIllegalEnchantments(target, potentialEnchantments);
|
removeIllegalEnchantments(itemStack, potentialEnchantments);
|
||||||
|
|
||||||
if (potentialEnchantments.isEmpty()) {
|
if (potentialEnchantments.isEmpty()) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.no-enchantment", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.no-enchantment", true);
|
||||||
@ -119,30 +118,24 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Enchantment enchantment = potentialEnchantments.get(ThreadLocalRandom.current().nextInt(potentialEnchantments.size()));
|
Enchantment enchantment = potentialEnchantments.get(ThreadLocalRandom.current().nextInt(potentialEnchantments.size()));
|
||||||
int level = 1;
|
int level = getRandomlevel(enchantment);
|
||||||
|
|
||||||
if (enchantment.getMaxLevel() != 1) {
|
|
||||||
level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.addEnchantment(enchantment, level);
|
|
||||||
|
|
||||||
if (target.getAmount() == 1) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
|
if (itemStack.getAmount() == 1) {
|
||||||
// This lightning is just an effect, it deals no damage.
|
// This lightning is just an effect, it deals no damage.
|
||||||
l.getWorld().strikeLightningEffect(l);
|
l.getWorld().strikeLightningEffect(l);
|
||||||
|
|
||||||
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().spawnParticle(Particle.CRIT_MAGIC, l, 1);
|
l.getWorld().spawnParticle(Particle.CRIT_MAGIC, l, 1);
|
||||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
||||||
|
|
||||||
entity.remove();
|
|
||||||
item.remove();
|
item.remove();
|
||||||
l.getWorld().dropItemNaturally(l, target);
|
rune.remove();
|
||||||
|
|
||||||
|
itemStack.addEnchantment(enchantment, level);
|
||||||
|
l.getWorld().dropItemNaturally(l, itemStack);
|
||||||
|
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.success", true);
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.success", true);
|
||||||
}
|
}
|
||||||
@ -154,6 +147,16 @@ public class EnchantmentRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getRandomlevel(Enchantment enchantment) {
|
||||||
|
int level = 1;
|
||||||
|
|
||||||
|
if (enchantment.getMaxLevel() != 1) {
|
||||||
|
level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
private void removeIllegalEnchantments(ItemStack target, List<Enchantment> potentialEnchantments) {
|
private void removeIllegalEnchantments(ItemStack target, List<Enchantment> potentialEnchantments) {
|
||||||
for (Enchantment enchantment : target.getEnchantments().keySet()) {
|
for (Enchantment enchantment : target.getEnchantments().keySet()) {
|
||||||
Iterator<Enchantment> iterator = potentialEnchantments.iterator();
|
Iterator<Enchantment> iterator = potentialEnchantments.iterator();
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound;
|
||||||
@ -51,7 +50,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Slimefun.runSync(() -> activate(p, e, item), 20L);
|
Slimefun.runSync(() -> activate(p, item), 20L);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -59,7 +58,7 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activate(Player p, PlayerDropItemEvent e, Item rune) {
|
private void activate(Player p, 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 (!rune.isValid()) {
|
if (!rune.isValid()) {
|
||||||
return;
|
return;
|
||||||
@ -74,9 +73,6 @@ public class SoulboundRune extends SimpleSlimefunItem<ItemDropHandler> {
|
|||||||
ItemStack itemStack = item.getItemStack();
|
ItemStack itemStack = item.getItemStack();
|
||||||
|
|
||||||
if (itemStack.getAmount() == 1) {
|
if (itemStack.getAmount() == 1) {
|
||||||
// Prevent other plugins from processing this Item as we will remove it soon
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
// This lightning is just an effect, it deals no damage.
|
// This lightning is just an effect, it deals no damage.
|
||||||
l.getWorld().strikeLightningEffect(l);
|
l.getWorld().strikeLightningEffect(l);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user