More 1.21 fixes

This commit is contained in:
Jules 2024-07-25 21:06:32 -07:00
parent d7ff655c86
commit dcd1b55099
4 changed files with 24 additions and 16 deletions

View File

@ -1,8 +1,10 @@
package net.Indyuce.mmocore.gui.api;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
public abstract class PluginInventory implements InventoryHolder {
@ -11,8 +13,8 @@ public abstract class PluginInventory implements InventoryHolder {
public PluginInventory(Player player) {
this.player = player;
this.playerData = player.getOpenInventory() != null && player.getOpenInventory().getTopInventory().getHolder() instanceof PluginInventory ?
((PluginInventory) player.getOpenInventory().getTopInventory().getHolder()).playerData : PlayerData.get(player);
final Inventory open = VersionUtils.getOpen(player).getTopInventory();
this.playerData = open.getHolder() instanceof PluginInventory ? ((PluginInventory) open.getHolder()).playerData : PlayerData.get(player);
}
public PluginInventory(PlayerData playerData) {

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmocore.guild.provided;
import io.lumine.mythic.lib.version.VInventoryView;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -63,7 +65,7 @@ public class Guild implements AbstractGuild {
// Disband boolean is to prevent co-modification exception when disbanding a guild
public void removeMember(UUID uuid, boolean disband) {
PlayerData data = PlayerData.get(uuid);
if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof EditableGuildView.GuildViewInventory)
if (data.isOnline() && VersionUtils.getOpen(data.getPlayer()).getTopInventory().getHolder() instanceof EditableGuildView.GuildViewInventory)
InventoryManager.GUILD_CREATION.newInventory(data).open();
if (!disband)
@ -102,9 +104,10 @@ public class Guild implements AbstractGuild {
public void reopenInventories() {
for (UUID uuid : members) {
PlayerData member = PlayerData.get(uuid);
if (member != null && member.isOnline() && member.getPlayer().getOpenInventory() != null && member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof EditableGuildView.GuildViewInventory)
((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open();
final PlayerData member = PlayerData.get(uuid);
final VInventoryView open = VersionUtils.getOpen(member.getPlayer());
if (member.isOnline() && open.getTopInventory().getHolder() instanceof EditableGuildView.GuildViewInventory)
((PluginInventory) open.getTopInventory().getHolder()).open();
}
}

View File

@ -1,5 +1,7 @@
package net.Indyuce.mmocore.party.provided;
import io.lumine.mythic.lib.version.VInventoryView;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -99,8 +101,7 @@ public class Party implements AbstractParty {
}
public void removeMember(PlayerData data, boolean notify) {
if (data.isOnline() && data.getPlayer().getOpenInventory() != null
&& data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof EditablePartyView.PartyViewInventory)
if (data.isOnline() && VersionUtils.getOpen(data.getPlayer()).getTopInventory().getHolder() instanceof EditablePartyView.PartyViewInventory)
InventoryManager.PARTY_CREATION.newInventory(data).open();
members.remove(data);
@ -137,10 +138,11 @@ public class Party implements AbstractParty {
}
private void updateOpenInventories() {
for (PlayerData member : members)
if (member.isOnline() && member.getPlayer().getOpenInventory() != null
&& member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof EditablePartyView.PartyViewInventory)
((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open();
for (PlayerData member : members) {
final VInventoryView open = VersionUtils.getOpen(member.getPlayer());
if (member.isOnline() && open.getTopInventory().getHolder() instanceof EditablePartyView.PartyViewInventory)
((PluginInventory) open.getTopInventory().getHolder()).open();
}
}
@Deprecated

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.listener;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmocore.gui.eco.GoldPouch;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -43,11 +44,11 @@ public class GoldPouchesListener implements Listener {
if (!(event.getEntity() instanceof Player))
return;
Player player = (Player) event.getEntity();
if (player.getOpenInventory() == null || !(player.getOpenInventory().getTopInventory().getHolder() instanceof GoldPouch))
return;
final Player player = (Player) event.getEntity();
if (!(VersionUtils.getOpen(player).getTopInventory().getHolder() instanceof GoldPouch))
return;
ItemStack item = event.getItem().getItemStack();
final ItemStack item = event.getItem().getItemStack();
if (NBTItem.get(item).hasTag("RpgPouchInventory"))
event.setCancelled(true);
}