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