forked from Upstream/mmocore
PluginInv#whenClicked is systematically called
This commit is contained in:
parent
fa953f890f
commit
2c9a9bec4b
@ -105,7 +105,7 @@ public class ClassSelect extends EditableInventory {
|
||||
@Override
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("class")) {
|
||||
String classId = context.getItemStack().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING);
|
||||
String classId = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin, "class_id"), PersistentDataType.STRING);
|
||||
if (classId.equals(""))
|
||||
return;
|
||||
|
||||
|
@ -224,7 +224,7 @@ public class QuestViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("quest")) {
|
||||
String questId = context.getItemStack().getItemMeta().getPersistentDataContainer()
|
||||
String questId = context.getClickedItem().getItemMeta().getPersistentDataContainer()
|
||||
.get(new NamespacedKey(MMOCore.plugin,"quest_id"), PersistentDataType.STRING);
|
||||
if (questId==null||questId.equals(""))
|
||||
return;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.Indyuce.mmocore.gui;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.tree.NodeState;
|
||||
@ -399,7 +398,7 @@ public class SkillTreeViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("skill-tree")) {
|
||||
String id = event.getItemStack().getItemMeta().getPersistentDataContainer().get(
|
||||
String id = event.getClickedItem().getItemMeta().getPersistentDataContainer().get(
|
||||
new NamespacedKey(MMOCore.plugin, "skill-tree-id"), PersistentDataType.STRING);
|
||||
playerData.setCachedSkillTree(MMOCore.plugin.skillTreeManager.get(id));
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.CHANGE_SKILL_TREE).playTo(player);
|
||||
@ -411,7 +410,7 @@ public class SkillTreeViewer extends EditableInventory {
|
||||
|
||||
if (item.getFunction().equals("skill-tree-node")) {
|
||||
if (event.getClickType() == ClickType.LEFT) {
|
||||
PersistentDataContainer container = event.getItemStack().getItemMeta().getPersistentDataContainer();
|
||||
PersistentDataContainer container = event.getClickedItem().getItemMeta().getPersistentDataContainer();
|
||||
int x = container.get(new NamespacedKey(MMOCore.plugin, "coordinates.x"), PersistentDataType.INTEGER);
|
||||
int y = container.get(new NamespacedKey(MMOCore.plugin, "coordinates.y"), PersistentDataType.INTEGER);
|
||||
if (!skillTree.isNode(new IntegerCoordinates(x, y))) {
|
||||
|
@ -112,7 +112,7 @@ public class SubclassSelect extends EditableInventory {
|
||||
InventoryManager.CLASS_SELECT.newInventory(playerData).open();
|
||||
|
||||
if (item.getFunction().equals("class")) {
|
||||
String tag = NBTItem.get(context.getItemStack()).getString("classId");
|
||||
String tag = NBTItem.get(context.getClickedItem()).getString("classId");
|
||||
if (tag.equals(""))
|
||||
return;
|
||||
|
||||
|
@ -236,7 +236,7 @@ public class WaypointViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("waypoint")) {
|
||||
PersistentDataContainer container = context.getItemStack().getItemMeta().getPersistentDataContainer();
|
||||
PersistentDataContainer container = context.getClickedItem().getItemMeta().getPersistentDataContainer();
|
||||
String tag = container.has(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) ?
|
||||
container.get(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) : "";
|
||||
|
||||
|
@ -8,6 +8,7 @@ import net.Indyuce.mmocore.gui.api.item.TriggerItem;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -80,7 +81,6 @@ public abstract class GeneratedInventory extends PluginInventory {
|
||||
@Deprecated
|
||||
public void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update) {
|
||||
adaptor.dynamicallyUpdateItem(item, n, placed, update);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -96,8 +96,7 @@ public abstract class GeneratedInventory extends PluginInventory {
|
||||
whenClicked(context, item);
|
||||
}
|
||||
|
||||
|
||||
public abstract String calculateName();
|
||||
|
||||
public abstract void whenClicked(InventoryClickContext context, InventoryItem item);
|
||||
public abstract void whenClicked(@NotNull InventoryClickContext context, @NotNull InventoryItem item);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class InventoryClickContext {
|
||||
private final int slot;
|
||||
@ -41,7 +41,13 @@ public class InventoryClickContext {
|
||||
return slot;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
/**
|
||||
* @return The Bukkit InventoryClickEvent's current item. This is the item
|
||||
* which the player just clicked on. The item on the player's
|
||||
* cursor is NOT provided by click contexts
|
||||
*/
|
||||
@Nullable
|
||||
public ItemStack getClickedItem() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
@ -8,28 +8,15 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
public abstract class PluginInventory implements InventoryHolder {
|
||||
protected final Player player;
|
||||
protected final PlayerData playerData;
|
||||
/**
|
||||
* If all the clicks sould be cancelled for the inventory
|
||||
*/
|
||||
private boolean shouldCancel = true;
|
||||
|
||||
public PluginInventory(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
player = playerData.getPlayer();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public PluginInventory(Player player, boolean shouldCancel) {
|
||||
this(player);
|
||||
this.shouldCancel=shouldCancel;
|
||||
}
|
||||
public PluginInventory(PlayerData playerData, boolean shouldCancel) {
|
||||
this(playerData);
|
||||
this.shouldCancel=shouldCancel;
|
||||
public PluginInventory(PlayerData playerData) {
|
||||
this.player = playerData.getPlayer();
|
||||
this.playerData = playerData;
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData() {
|
||||
@ -40,13 +27,6 @@ public abstract class PluginInventory implements InventoryHolder {
|
||||
return player;
|
||||
}
|
||||
|
||||
public boolean shouldCancel() {
|
||||
return shouldCancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens classic inventory, throws
|
||||
*/
|
||||
public void open() {
|
||||
getPlayer().openInventory(getInventory());
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class DepositMenu extends PluginInventory {
|
||||
private BukkitRunnable updateRunnable;
|
||||
|
||||
public DepositMenu(Player player) {
|
||||
super(player,false);
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,10 +42,10 @@ public class DepositMenu extends PluginInventory {
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickContext event) {
|
||||
if (event.getItemStack() == null || event.getItemStack().getType() == Material.AIR)
|
||||
if (event.getClickedItem() == null || event.getClickedItem().getType() == Material.AIR)
|
||||
return;
|
||||
|
||||
if (event.getItemStack().isSimilar(depositItem)) {
|
||||
if (event.getClickedItem().isSimilar(depositItem)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
updateDeposit(event.getInventory());
|
||||
@ -63,7 +63,7 @@ public class DepositMenu extends PluginInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
int worth = NBTItem.get(event.getItemStack()).getInteger("RpgWorth");
|
||||
int worth = NBTItem.get(event.getClickedItem()).getInteger("RpgWorth");
|
||||
if (worth < 1)
|
||||
event.setCancelled(true);
|
||||
else
|
||||
|
@ -35,7 +35,12 @@ public class GoldPouch extends PluginInventory {
|
||||
@Override
|
||||
public void whenClicked(InventoryClickContext context) {
|
||||
|
||||
ItemStack item = context.getItemStack();
|
||||
ItemStack item = context.getClickedItem();
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
context.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if (!nbt.hasTag("RpgWorth")) {
|
||||
context.setCancelled(true);
|
||||
@ -52,7 +57,7 @@ public class GoldPouch extends PluginInventory {
|
||||
return;
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_SHULKER_TELEPORT, 1, 2);
|
||||
player.getInventory().addItem(context.getItemStack());
|
||||
player.getInventory().addItem(context.getClickedItem());
|
||||
context.getInventory().setItem(context.getSlot(), null);
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ public class EditableFriendList extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("friend") && context.getClickType() == ClickType.RIGHT) {
|
||||
String tag = context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
String tag = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
if (tag == null || tag.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class EditableGuildAdmin extends EditableInventory {
|
||||
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
|
||||
return;
|
||||
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getClickedItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
if (target.equals(player))
|
||||
return;
|
||||
|
||||
|
@ -236,7 +236,7 @@ public class EditableGuildView extends EditableInventory {
|
||||
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
|
||||
return;
|
||||
|
||||
String tag = context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
String tag = context.getClickedItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
if (tag == null || tag.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -192,7 +192,7 @@ public class EditablePartyView extends EditableInventory {
|
||||
if (!party.getOwner().equals(playerData))
|
||||
return;
|
||||
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getClickedItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
if (target.equals(player))
|
||||
return;
|
||||
|
||||
|
@ -24,7 +24,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
/*
|
||||
/**
|
||||
* Load player data. Event priority is set to LOW as most plugins
|
||||
* do not change their priority which is NORMAL by default. Making
|
||||
* it low is important because MMOCore is a core plugin so other plugins
|
||||
@ -35,16 +35,19 @@ public class PlayerListener implements Listener {
|
||||
MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
// Register custom inventory clicks
|
||||
/**
|
||||
* Register custom inventory clicks
|
||||
*/
|
||||
@EventHandler
|
||||
public void b(InventoryClickEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof PluginInventory)
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null)
|
||||
((PluginInventory) event.getInventory().getHolder())
|
||||
.whenClicked(new InventoryClickContext(event.getRawSlot(), event.getCurrentItem(), event.getClick(), event, event.getInventory()));
|
||||
((PluginInventory) event.getInventory().getHolder())
|
||||
.whenClicked(new InventoryClickContext(event.getRawSlot(), event.getCurrentItem(), event.getClick(), event, event.getInventory()));
|
||||
}
|
||||
|
||||
// Register custom inventory close effect
|
||||
/**
|
||||
* Register custom inventory close effect
|
||||
*/
|
||||
@EventHandler
|
||||
public void c(InventoryCloseEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof PluginInventory)
|
||||
@ -76,12 +79,12 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Using the Bukkit health update event is not a good way of interacting
|
||||
* with MMOCore health regeneration. The PlayerResourceUpdateEvent
|
||||
* should be heavily prioritized if possible.
|
||||
* Using the Bukkit health update event is not a good way of
|
||||
* interacting with MMOCore health regeneration. The
|
||||
* PlayerResourceUpdateEvent should be heavily prioritized if possible.
|
||||
* <p>
|
||||
* This method makes sure that all the plugins which utilize this event
|
||||
* can also communicate with MMOCore
|
||||
* This method makes sure that all the plugins which
|
||||
* utilize this event can also communicate with MMOCore
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void g(PlayerResourceUpdateEvent event) {
|
||||
|
Loading…
Reference in New Issue
Block a user