Fixed item tier glowing finally

This commit is contained in:
Indyuce 2022-05-27 18:31:46 +02:00
parent b8ac21fff6
commit d4ea058bca

View File

@ -1,5 +1,8 @@
package net.Indyuce.mmoitems.comp.itemglow; package net.Indyuce.mmoitems.comp.itemglow;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,60 +14,57 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.inventivetalent.glow.GlowAPI; import org.inventivetalent.glow.GlowAPI;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import io.lumine.mythic.lib.api.item.NBTItem;
public class ItemGlowListener implements Listener { public class ItemGlowListener implements Listener {
/* /*
* applies both item hints & item glow depending on the tier of the item * Applies both item hints & item glow depending
* dropped. * on the tier of the item dropped.
*/ */
@EventHandler @EventHandler
public void a(ItemSpawnEvent event) { public void a(ItemSpawnEvent event) {
ItemStack item = event.getEntity().getItemStack(); ItemStack item = event.getEntity().getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER"); String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) { if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id); ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.isHintEnabled()) { if (tier.isHintEnabled()) {
event.getEntity().setCustomNameVisible(true); event.getEntity().setCustomNameVisible(true);
event.getEntity().setCustomName(item.getItemMeta().getDisplayName()); event.getEntity().setCustomName(item.getItemMeta().getDisplayName());
} }
if (tier.hasColor()) // Delayed task otherwise packet is sent too soon
GlowAPI.setGlowing(event.getEntity(), tier.getColor().toGlow().get(), event.getEntity().getWorld().getPlayers()); if (tier.hasColor())
} Bukkit.getScheduler().runTask(MMOItems.plugin, () -> GlowAPI.setGlowing(event.getEntity(), GlowAPI.Color.GOLD, Bukkit.getPlayer("Indyuce")));
} }
}
@EventHandler @EventHandler
public void b(PlayerLoginEvent event) { public void b(PlayerLoginEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) { for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) {
ItemStack item = entity.getItemStack(); ItemStack item = entity.getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER"); String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) { if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id); ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.hasColor()) if (tier.hasColor())
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player)); Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player));
} }
} }
} }
@EventHandler @EventHandler
public void c(PlayerTeleportEvent event) { public void c(PlayerTeleportEvent event) {
if (event.getFrom().getWorld().equals(event.getTo().getWorld())) if (event.getFrom().getWorld().equals(event.getTo().getWorld()))
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) { for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) {
ItemStack item = entity.getItemStack(); ItemStack item = entity.getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER"); String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) { if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id); ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.hasColor()) if (tier.hasColor())
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player)); Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player));
} }
} }
} }
} }