Now relies on ML item glow

This commit is contained in:
Indyuce 2022-08-19 13:52:23 +02:00
parent 28dd0cb67c
commit a3e22eda66
12 changed files with 96 additions and 212 deletions

View File

@ -325,13 +325,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.inventivetalent</groupId>
<artifactId>glowapi</artifactId>
<version>1.4.8</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.denizenscript</groupId> <groupId>com.denizenscript</groupId>
<artifactId>denizen</artifactId> <artifactId>denizen</artifactId>

View File

@ -25,8 +25,6 @@ import net.Indyuce.mmoitems.comp.enchants.EnchantPlugin;
import net.Indyuce.mmoitems.comp.enchants.MythicEnchantsSupport; import net.Indyuce.mmoitems.comp.enchants.MythicEnchantsSupport;
import net.Indyuce.mmoitems.comp.enchants.advanced_enchants.AdvancedEnchantmentsHook; import net.Indyuce.mmoitems.comp.enchants.advanced_enchants.AdvancedEnchantmentsHook;
import net.Indyuce.mmoitems.comp.inventory.*; import net.Indyuce.mmoitems.comp.inventory.*;
import net.Indyuce.mmoitems.comp.itemglow.ItemGlowListener;
import net.Indyuce.mmoitems.comp.itemglow.NoGlowListener;
import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader; import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader;
import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport; import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport;
import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener; import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener;
@ -248,13 +246,6 @@ public class MMOItems extends JavaPlugin {
placeholderParser = new PlaceholderAPIParser(); placeholderParser = new PlaceholderAPIParser();
} }
if (getConfig().getBoolean("item-glow")) {
if (Bukkit.getPluginManager().getPlugin("GlowAPI") != null && Bukkit.getPluginManager().getPlugin("PacketListenerApi") != null) {
Bukkit.getPluginManager().registerEvents(new ItemGlowListener(), this);
getLogger().log(Level.INFO, "Hooked onto GlowAPI (Item Glow)");
} else Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
}
if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) { if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
getLogger().log(Level.INFO, "Hooked onto BossShopPro"); getLogger().log(Level.INFO, "Hooked onto BossShopPro");
(new BukkitRunnable() { (new BukkitRunnable() {

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems; package net.Indyuce.mmoitems;
import com.google.common.collect.ImmutableMap;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
@ -9,6 +10,8 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.skill.trigger.TriggerType; import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -46,6 +49,33 @@ public class MMOUtils {
} }
} }
/**
* Source: https://gist.github.com/Mystiflow/c42f45bac9916c84e381155f72a96d84
*/
private static final Map<ChatColor, Color> COLOR_MAPPINGS = ImmutableMap.<ChatColor, Color>builder()
.put(ChatColor.BLACK, Color.fromRGB(0, 0, 0))
.put(ChatColor.DARK_BLUE, Color.fromRGB(0, 0, 170))
.put(ChatColor.DARK_GREEN, Color.fromRGB(0, 170, 0))
.put(ChatColor.DARK_AQUA, Color.fromRGB(0, 170, 170))
.put(ChatColor.DARK_RED, Color.fromRGB(170, 0, 0))
.put(ChatColor.DARK_PURPLE, Color.fromRGB(170, 0, 170))
.put(ChatColor.GOLD, Color.fromRGB(255, 170, 0))
.put(ChatColor.GRAY, Color.fromRGB(170, 170, 170))
.put(ChatColor.DARK_GRAY, Color.fromRGB(85, 85, 85))
.put(ChatColor.BLUE, Color.fromRGB(85, 85, 255))
.put(ChatColor.GREEN, Color.fromRGB(85, 255, 85))
.put(ChatColor.AQUA, Color.fromRGB(85, 255, 255))
.put(ChatColor.RED, Color.fromRGB(255, 85, 85))
.put(ChatColor.LIGHT_PURPLE, Color.fromRGB(255, 85, 255))
.put(ChatColor.YELLOW, Color.fromRGB(255, 255, 85))
.put(ChatColor.WHITE, Color.fromRGB(255, 255, 255))
.build();
@NotNull
public static Color toRGB(ChatColor color) {
return Objects.requireNonNull(COLOR_MAPPINGS.get(color), "Not a color");
}
public static int getPickaxePower(Player player) { public static int getPickaxePower(Player player) {
ItemStack item = player.getInventory().getItemInMainHand(); ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.getType() != Material.AIR) { if (item != null && item.getType() != Material.AIR) {

View File

@ -1,12 +1,12 @@
package net.Indyuce.mmoitems.api; package net.Indyuce.mmoitems.api;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.MMOItems; import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmoitems.api.droptable.DropTable; import net.Indyuce.mmoitems.api.droptable.DropTable;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.NumericStatFormula; import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.comp.itemglow.TierColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -26,7 +26,7 @@ public class ItemTier {
@Nullable private final DropTable deconstruct; @Nullable private final DropTable deconstruct;
// item glow options // item glow options
@Nullable private TierColor color = null; @Nullable private ChatColor color = null;
private boolean hint = false; private boolean hint = false;
// item generation // item generation
@ -54,30 +54,12 @@ public class ItemTier {
if (unidentificationSection == null) { unidentificationInfo = getDefaultUnident(); } if (unidentificationSection == null) { unidentificationInfo = getDefaultUnident(); }
else { unidentificationInfo = new UnidentificationInfo(unidentificationSection); } else { unidentificationInfo = new UnidentificationInfo(unidentificationSection); }
//noinspection ErrorNotRethrown if (config.contains("item-glow")) {
try { hint = config.getBoolean("item-glow.hint");
color = ChatColor.valueOf(UtilityMethods.enumName(config.getString("item-glow.color", "WHITE")));
// Is it defined? } else {
ConfigurationSection glowSection = config.getConfigurationSection("item-glow");
// Alr then lets read it
if (glowSection != null) {
// Does it hint?
hint = glowSection.getBoolean("hint");
// Does it color?
color = new TierColor(config.getString("color", "WHITE"), GLOW);
}
} catch (NoClassDefFoundError | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
// No hints
hint = false; hint = false;
color = null; color = null;
// Grrr but GlowAPI crashing shall not crash MMOItems tiers wtf
MMOItems.print(null, "Could not load glow color for tier $r{0}$b;$f {1}", "Tier Hints", id, exception.getMessage());
} }
// What are the chances? // What are the chances?
@ -95,7 +77,7 @@ public class ItemTier {
public boolean hasColor() { return color != null; } public boolean hasColor() { return color != null; }
@Nullable public TierColor getColor() { return color; } @Nullable public ChatColor getColor() { return color; }
public boolean isHintEnabled() { return hint; } public boolean isHintEnabled() { return hint; }

View File

@ -1,43 +0,0 @@
package net.Indyuce.mmoitems.comp.itemglow;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Color;
import org.inventivetalent.glow.GlowAPI;
public class GlowColor {
private final GlowAPI.Color glow;
private static final Map<Color, GlowAPI.Color> map = new HashMap<>();
static {
map.put(Color.AQUA, GlowAPI.Color.AQUA);
map.put(Color.BLACK, GlowAPI.Color.BLACK);
map.put(Color.BLUE, GlowAPI.Color.BLUE);
map.put(Color.FUCHSIA, GlowAPI.Color.DARK_PURPLE);
map.put(Color.GRAY, GlowAPI.Color.DARK_GRAY);
map.put(Color.GREEN, GlowAPI.Color.DARK_GREEN);
map.put(Color.LIME, GlowAPI.Color.GREEN);
map.put(Color.NAVY, GlowAPI.Color.DARK_BLUE);
map.put(Color.OLIVE, GlowAPI.Color.AQUA);
map.put(Color.ORANGE, GlowAPI.Color.GOLD);
map.put(Color.PURPLE, GlowAPI.Color.PURPLE);
map.put(Color.RED, GlowAPI.Color.RED);
map.put(Color.SILVER, GlowAPI.Color.GRAY);
map.put(Color.WHITE, GlowAPI.Color.WHITE);
map.put(Color.YELLOW, GlowAPI.Color.YELLOW);
// no equivalent
map.put(Color.TEAL, GlowAPI.Color.BLUE);
map.put(Color.MAROON, GlowAPI.Color.DARK_RED);
}
public GlowColor(Color color) {
glow = map.get(color);
}
public GlowAPI.Color get() {
return glow;
}
}

View File

@ -1,70 +0,0 @@
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.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.inventivetalent.glow.GlowAPI;
public class ItemGlowListener implements Listener {
/*
* Applies both item hints & item glow depending
* on the tier of the item dropped.
*/
@EventHandler
public void a(ItemSpawnEvent event) {
ItemStack item = event.getEntity().getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.isHintEnabled()) {
event.getEntity().setCustomNameVisible(true);
event.getEntity().setCustomName(item.getItemMeta().getDisplayName());
}
// Delayed task otherwise packet is sent too soon
if (tier.hasColor())
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> GlowAPI.setGlowing(event.getEntity(), GlowAPI.Color.GOLD, Bukkit.getPlayer("Indyuce")));
}
}
@EventHandler
public void b(PlayerLoginEvent event) {
Player player = event.getPlayer();
for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) {
ItemStack item = entity.getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.hasColor())
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player));
}
}
}
@EventHandler
public void c(PlayerTeleportEvent event) {
if (event.getFrom().getWorld().equals(event.getTo().getWorld()))
return;
Player player = event.getPlayer();
for (Item entity : player.getWorld().getEntitiesByClass(Item.class)) {
ItemStack item = entity.getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id)) {
ItemTier tier = MMOItems.plugin.getTiers().get(id);
if (tier.hasColor())
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> GlowAPI.setGlowing(entity, tier.getColor().toGlow().get(), player));
}
}
}
}

View File

@ -1,25 +0,0 @@
package net.Indyuce.mmoitems.comp.itemglow;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import io.lumine.mythic.lib.api.item.NBTItem;
public class NoGlowListener implements Listener {
/*
* only applies item hints.
*/
@EventHandler
public void a(ItemSpawnEvent event) {
ItemStack item = event.getEntity().getItemStack();
String id = NBTItem.get(item).getString("MMOITEMS_TIER");
if (MMOItems.plugin.getTiers().has(id) && MMOItems.plugin.getTiers().get(id).isHintEnabled()) {
event.getEntity().setCustomNameVisible(true);
event.getEntity().setCustomName(item.getItemMeta().getDisplayName());
}
}
}

View File

@ -1,24 +0,0 @@
package net.Indyuce.mmoitems.comp.itemglow;
import org.apache.commons.lang.Validate;
import org.bukkit.Color;
public class TierColor {
private final GlowColor glow;
private final Color bukkit;
public TierColor(String format, boolean glow) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
Validate.notNull(format, "String must not be null");
bukkit = (Color) Color.class.getField(format.toUpperCase().replace("-", "_").replace(" ", "_")).get(Color.class);
this.glow = glow ? new GlowColor(bukkit) : null;
}
public GlowColor toGlow() {
return glow;
}
public org.bukkit.Color toBukkit() {
return bukkit;
}
}

View File

@ -4,8 +4,10 @@ import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.ItemTier;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@ -74,7 +76,7 @@ public class LootsplosionListener implements Listener {
if (nbt.hasTag("MMOITEMS_TIER")) { if (nbt.hasTag("MMOITEMS_TIER")) {
ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER")); ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER"));
if (tier.hasColor()) if (tier.hasColor())
new LootColor(item, tier.getColor().toBukkit()); new LootColor(item, tier.getColor());
} }
}); });
} }
@ -92,9 +94,9 @@ public class LootsplosionListener implements Listener {
private int j = 0; private int j = 0;
public LootColor(Item item, Color color) { public LootColor(Item item, ChatColor color) {
this.item = item; this.item = item;
this.color = color; this.color = MMOUtils.toRGB(color);
runTaskTimer(MMOItems.plugin, 0, 1); runTaskTimer(MMOItems.plugin, 0, 1);
} }

View File

@ -4,6 +4,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.comp.PhatLootsHook; import net.Indyuce.mmoitems.comp.PhatLootsHook;
import net.Indyuce.mmoitems.gui.listener.GuiListener; import net.Indyuce.mmoitems.gui.listener.GuiListener;
import net.Indyuce.mmoitems.listener.*; import net.Indyuce.mmoitems.listener.*;
import net.Indyuce.mmoitems.listener.option.DroppedItems;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
public class MMOItemsBukkit { public class MMOItemsBukkit {
@ -25,6 +26,9 @@ public class MMOItemsBukkit {
if (Bukkit.getPluginManager().getPlugin("PhatLoots") != null) if (Bukkit.getPluginManager().getPlugin("PhatLoots") != null)
Bukkit.getPluginManager().registerEvents(new PhatLootsHook(), plugin); Bukkit.getPluginManager().registerEvents(new PhatLootsHook(), plugin);
if (plugin.getConfig().getBoolean("dropped-items.tier-glow") || plugin.getConfig().getBoolean("dropped-items.hints"))
Bukkit.getPluginManager().registerEvents(new DroppedItems(plugin.getConfig().getConfigurationSection("dropped-items")), plugin);
Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20); Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20);
} }
} }

View File

@ -0,0 +1,41 @@
package net.Indyuce.mmoitems.listener.option;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public class DroppedItems implements Listener {
private final boolean tierGlow, hints;
public DroppedItems(ConfigurationSection config) {
tierGlow = config.getBoolean("tier-glow");
hints = config.getBoolean("hints");
}
/**
* Applies both item hints & item glow
* depending on the tier of the item dropped.
*/
@EventHandler
public void applyOnSpawn(ItemSpawnEvent event) {
final ItemStack item = event.getEntity().getItemStack();
final @Nullable ItemTier tier = MMOItems.plugin.getTiers().get(NBTItem.get(item).getString("MMOITEMS_TIER"));
if (tier == null)
return;
if (hints && tier.isHintEnabled()) {
event.getEntity().setCustomNameVisible(true);
event.getEntity().setCustomName(item.getItemMeta().getDisplayName());
}
if (tierGlow && tier.hasColor())
MythicLib.plugin.getGlowing().setGlowing(event.getEntity(), tier.getColor());
}
}

View File

@ -44,11 +44,14 @@ default:
blunt-rating: 33 blunt-rating: 33
recoil: 0.1 recoil: 0.1
# Enable/disable the item glow feature. Make sure you # Restart server when changing this option
# reload your server when changing this option. This dropped-items:
# option might take extra performance so consider toggling
# it off if you have players or mobs dropping many items. # Items glow based on their tier
item-glow: true tier-glow: true
# Display item name over the dropped item
hints: true
item-upgrading: item-upgrading: