diff --git a/MMOItems-Dist/pom.xml b/MMOItems-Dist/pom.xml index 7e18b291..d02937c1 100644 --- a/MMOItems-Dist/pom.xml +++ b/MMOItems-Dist/pom.xml @@ -19,6 +19,7 @@ + org.spigotmc @@ -26,6 +27,7 @@ 1.18-R0.1-SNAPSHOT provided + net.Indyuce @@ -33,6 +35,15 @@ 6.9.4-SNAPSHOT true + + + + fr.phoenixdevt + Profile-API + 1.0 + provided + true + diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java index b83856c3..77cc334d 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java @@ -1,5 +1,6 @@ package net.Indyuce.mmoitems; +import io.lumine.mythic.lib.MythicLib; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.comp.PhatLootsHook; import net.Indyuce.mmoitems.gui.listener.GuiListener; @@ -32,6 +33,10 @@ public class MMOItemsBukkit { if (plugin.getLanguage().disableRemovedItems) Bukkit.getPluginManager().registerEvents(new DisabledItemsListener(plugin), plugin); + // Profile support + if (MythicLib.plugin.hasProfiles()) + Bukkit.getPluginManager().registerEvents(new ProfileSupportListener(), plugin); + Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20); } } diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java index 05b258e3..12a959a3 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java @@ -1,5 +1,6 @@ package net.Indyuce.mmoitems.listener; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import net.Indyuce.mmoitems.ItemStats; @@ -24,7 +25,6 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -131,7 +131,8 @@ public class ItemListener implements Listener { @EventHandler(ignoreCancelled = true) private void inventoryMove(InventoryClickEvent event) { - if (event.getInventory().getType() != InventoryType.CRAFTING || !(event.getWhoClicked() instanceof Player)) return; + if (event.getInventory().getType() != InventoryType.CRAFTING || !(event.getWhoClicked() instanceof Player)) + return; ItemStack newItem = modifyItem(event.getCurrentItem(), (Player) event.getWhoClicked(), ReforgeReason.CLICK); if (newItem != null) event.setCurrentItem(newItem); } @@ -143,10 +144,12 @@ public class ItemListener implements Listener { event.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void playerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); + if (!MythicLib.plugin.hasProfiles()) updateInventory(event.getPlayer()); + } + public static void updateInventory(Player player) { ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, ReforgeReason.JOIN); if (newItem != null) player.getEquipment().setHelmet(newItem); newItem = modifyItem(player.getEquipment().getChestplate(), player, ReforgeReason.JOIN); @@ -166,7 +169,7 @@ public class ItemListener implements Listener { } @Nullable - private ItemStack modifyItem(@Nullable ItemStack stack, @NotNull Player player, @NotNull ReforgeReason reason) { + private static ItemStack modifyItem(@Nullable ItemStack stack, @NotNull Player player, @NotNull ReforgeReason reason) { // Sleep on metaless stacks if (stack == null || !stack.hasItemMeta()) @@ -186,7 +189,7 @@ public class ItemListener implements Listener { return null; // Greater RevID in template? Go ahead, update! - int templateRevision =mod. getTemplate().getRevisionId(); + int templateRevision = mod.getTemplate().getRevisionId(); int mmoitemRevision = (mod.getNBTItem().hasTag(ItemStats.REVISION_ID.getNBTPath()) ? mod.getNBTItem().getInteger(ItemStats.REVISION_ID.getNBTPath()) : 1); if (templateRevision <= mmoitemRevision) return null; diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ProfileSupportListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ProfileSupportListener.java new file mode 100644 index 00000000..5d6d18f9 --- /dev/null +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ProfileSupportListener.java @@ -0,0 +1,14 @@ +package net.Indyuce.mmoitems.listener; + +import fr.phoenixdevt.profile.event.ProfileSelectEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +public class ProfileSupportListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void a(ProfileSelectEvent event) { + ItemListener.updateInventory(event.getPlayer()); + } +}