Better support for profiles (revID issue)

This commit is contained in:
Jules 2023-07-08 22:59:16 +02:00
parent a284fb1a49
commit 40b6e97e65
4 changed files with 39 additions and 6 deletions

View File

@ -19,6 +19,7 @@
<!-- Dependencies --> <!-- Dependencies -->
<dependencies> <dependencies>
<!-- Spigot API --> <!-- Spigot API -->
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
@ -26,6 +27,7 @@
<version>1.18-R0.1-SNAPSHOT</version> <version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- MMOItems API --> <!-- MMOItems API -->
<dependency> <dependency>
<groupId>net.Indyuce</groupId> <groupId>net.Indyuce</groupId>
@ -33,6 +35,15 @@
<version>6.9.4-SNAPSHOT</version> <version>6.9.4-SNAPSHOT</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Profile API -->
<dependency>
<groupId>fr.phoenixdevt</groupId>
<artifactId>Profile-API</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<!-- Build --> <!-- Build -->

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems; package net.Indyuce.mmoitems;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.api.player.PlayerData; 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;
@ -32,6 +33,10 @@ public class MMOItemsBukkit {
if (plugin.getLanguage().disableRemovedItems) if (plugin.getLanguage().disableRemovedItems)
Bukkit.getPluginManager().registerEvents(new DisabledItemsListener(plugin), plugin); 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); Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20);
} }
} }

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.listener; 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.item.NBTItem;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
@ -24,7 +25,6 @@ import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -131,7 +131,8 @@ public class ItemListener implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
private void inventoryMove(InventoryClickEvent event) { 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); ItemStack newItem = modifyItem(event.getCurrentItem(), (Player) event.getWhoClicked(), ReforgeReason.CLICK);
if (newItem != null) event.setCurrentItem(newItem); if (newItem != null) event.setCurrentItem(newItem);
} }
@ -143,10 +144,12 @@ public class ItemListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void playerJoin(PlayerJoinEvent event) { 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); ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, ReforgeReason.JOIN);
if (newItem != null) player.getEquipment().setHelmet(newItem); if (newItem != null) player.getEquipment().setHelmet(newItem);
newItem = modifyItem(player.getEquipment().getChestplate(), player, ReforgeReason.JOIN); newItem = modifyItem(player.getEquipment().getChestplate(), player, ReforgeReason.JOIN);
@ -166,7 +169,7 @@ public class ItemListener implements Listener {
} }
@Nullable @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 // Sleep on metaless stacks
if (stack == null || !stack.hasItemMeta()) if (stack == null || !stack.hasItemMeta())
@ -186,7 +189,7 @@ public class ItemListener implements Listener {
return null; return null;
// Greater RevID in template? Go ahead, update! // 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); int mmoitemRevision = (mod.getNBTItem().hasTag(ItemStats.REVISION_ID.getNBTPath()) ? mod.getNBTItem().getInteger(ItemStats.REVISION_ID.getNBTPath()) : 1);
if (templateRevision <= mmoitemRevision) if (templateRevision <= mmoitemRevision)
return null; return null;

View File

@ -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());
}
}