forked from Upstream/mmocore
Three Dim GUI
This commit is contained in:
parent
2a4d419398
commit
d3ace7909f
16
pom.xml
16
pom.xml
@ -53,8 +53,8 @@
|
||||
<version>3.8.1</version>
|
||||
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArgument>-proc:none</compilerArgument>
|
||||
</configuration>
|
||||
@ -112,6 +112,11 @@
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -181,6 +186,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.8.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.citizensnpcs</groupId>
|
||||
<artifactId>Citizens</artifactId>
|
||||
|
@ -1,14 +1,12 @@
|
||||
package net.Indyuce.mmocore;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.comp.Metrics;
|
||||
import io.lumine.mythic.lib.version.SpigotPlugin;
|
||||
import io.lumine.mythic.utils.plugin.LuminePlugin;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizensMMOLoader;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicHook;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicMobsMMOLoader;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.PlayerActionBar;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -16,6 +14,10 @@ import net.Indyuce.mmocore.api.player.attribute.AttributeModifier;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.util.debug.DebugMode;
|
||||
import net.Indyuce.mmocore.command.*;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizenInteractEventListener;
|
||||
import net.Indyuce.mmocore.comp.citizens.CitizensMMOLoader;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicHook;
|
||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicMobsMMOLoader;
|
||||
import net.Indyuce.mmocore.comp.placeholder.DefaultParser;
|
||||
import net.Indyuce.mmocore.comp.placeholder.PlaceholderAPIParser;
|
||||
import net.Indyuce.mmocore.comp.placeholder.PlaceholderParser;
|
||||
@ -30,7 +32,6 @@ import net.Indyuce.mmocore.guild.GuildModuleType;
|
||||
import net.Indyuce.mmocore.guild.provided.Guild;
|
||||
import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule;
|
||||
import net.Indyuce.mmocore.listener.*;
|
||||
import net.Indyuce.mmocore.listener.bungee.GetMMOCorePlayerListener;
|
||||
import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener;
|
||||
import net.Indyuce.mmocore.listener.option.*;
|
||||
import net.Indyuce.mmocore.listener.profession.FishingListener;
|
||||
@ -85,6 +86,8 @@ public class MMOCore extends LuminePlugin {
|
||||
@Deprecated
|
||||
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
|
||||
|
||||
public ProtocolManager protocolManager;
|
||||
|
||||
// Profession managers
|
||||
public final CustomBlockManager mineManager = new CustomBlockManager();
|
||||
public final FishingManager fishingManager = new FishingManager();
|
||||
@ -184,12 +187,9 @@ public class MMOCore extends LuminePlugin {
|
||||
// Checks if the server runs with Bungee
|
||||
hasBungee = SpigotConfig.bungee & !Bukkit.getServer().getOnlineMode();
|
||||
|
||||
//Setups the channel for Bungee
|
||||
if(hasBungee) {
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this,"namespace:give_mmocore_player");
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this,"namespace:get_mmocore_player");
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this,"namespace:get_mmocore_player",new GetMMOCorePlayerListener());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Resource regeneration. Must check if entity is dead otherwise regen will make
|
||||
@ -220,6 +220,9 @@ public class MMOCore extends LuminePlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
//load protocolManager
|
||||
protocolManager= ProtocolLibrary.getProtocolManager();
|
||||
|
||||
initializePlugin(false);
|
||||
|
||||
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
|
||||
|
@ -169,6 +169,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
if (config.getKey().equals("craftitem"))
|
||||
return new CraftItemExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("fishitem"))
|
||||
return new FishItemExperienceSource(dispenser, config);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import net.Indyuce.mmocore.experience.EXPSource;
|
||||
import net.Indyuce.mmocore.experience.ExperienceObject;
|
||||
import net.Indyuce.mmocore.experience.droptable.ExperienceItem;
|
||||
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.guild.provided.Guild;
|
||||
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor;
|
||||
import net.Indyuce.mmocore.party.AbstractParty;
|
||||
@ -88,6 +89,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
private final Map<String, SavedClassInformation> classSlots = new HashMap<>();
|
||||
private final Map<PlayerActivity, Long> lastActivity = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Saves all the items that have been unlocked so far by
|
||||
* the player. This is used for:
|
||||
@ -249,6 +251,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
return skillPoints;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getClaims(ExperienceObject object, ExperienceTable table, ExperienceItem item) {
|
||||
String key = object.getKey() + "." + table.getId() + "." + item.getId();
|
||||
|
@ -87,6 +87,11 @@ public class MMOCoreUtils {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static String toEnumName(String str) {
|
||||
return str.replace("-","_").replace(" ","_").toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
public static String toBase64(ItemStack[] items) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
@ -5,6 +5,7 @@ import net.Indyuce.mmocore.api.event.PlayerAttributeUseEvent;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
@ -99,7 +100,8 @@ public class AttributeView extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
|
||||
if (item.getFunction().equalsIgnoreCase("reallocation")) {
|
||||
int spent = playerData.getAttributes().countSkillPoints();
|
||||
@ -140,7 +142,7 @@ public class AttributeView extends EditableInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isShiftClick()) {
|
||||
if (context.getClickType().isShiftClick()) {
|
||||
if (playerData.getAttributePoints() < shiftCost) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("not-attribute-point-shift", "shift_points", "" + shiftCost).send(player);
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());
|
||||
|
@ -5,6 +5,7 @@ import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
@ -107,10 +108,7 @@ public class ClassConfirmation extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
if (event.getInventory() != event.getClickedInventory())
|
||||
return;
|
||||
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("back"))
|
||||
last.open();
|
||||
|
||||
|
@ -7,6 +7,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
@ -15,11 +16,14 @@ import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -82,9 +86,10 @@ public class ClassSelect extends EditableInventory {
|
||||
lore.add(index + j, profess.getAttributeDescription().get(j));
|
||||
}
|
||||
|
||||
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin,"class_id"), PersistentDataType.STRING,profess.getId());
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return NBTItem.get(item).addTag(new ItemTag("classId", profess.getId())).toItem();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,10 +107,10 @@ public class ClassSelect extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("class")) {
|
||||
String tag = NBTItem.get(event.getCurrentItem()).getString("classId");
|
||||
if (tag.equals(""))
|
||||
String classId = context.getItemStack().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(MMOCore.plugin,"class_id"),PersistentDataType.STRING);
|
||||
if (classId.equals(""))
|
||||
return;
|
||||
|
||||
if (playerData.getClassPoints() < 1) {
|
||||
@ -114,7 +119,7 @@ public class ClassSelect extends EditableInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerClass profess = MMOCore.plugin.classManager.get(tag);
|
||||
PlayerClass profess = MMOCore.plugin.classManager.get(classId);
|
||||
if (profess.equals(playerData.getProfess())) {
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.CANT_SELECT_CLASS).playTo(player);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("already-on-class", "class", profess.getName()).send(player);
|
||||
|
@ -8,6 +8,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
@ -171,7 +172,7 @@ public class PlayerStats extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.hasFunction())
|
||||
if (item.getFunction().equals("boost-next")) {
|
||||
boostOffset++;
|
||||
|
@ -6,6 +6,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.quest.Quest;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
@ -15,12 +16,16 @@ import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.math.format.DelayFormat;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -162,9 +167,12 @@ public class QuestViewer extends EditableInventory {
|
||||
meta.setDisplayName(holders.apply(inv.getPlayer(), getName()));
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
meta.setLore(lore);
|
||||
|
||||
|
||||
meta.getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin,"quest_id"), PersistentDataType.STRING,quest.getId());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return NBTItem.get(item).addTag(new ItemTag("questId", quest.getId())).toItem();
|
||||
return item;
|
||||
}
|
||||
|
||||
private Placeholders getPlaceholders(PlayerData data, Quest quest) {
|
||||
@ -207,7 +215,7 @@ public class QuestViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("previous")) {
|
||||
page--;
|
||||
open();
|
||||
@ -221,11 +229,12 @@ public class QuestViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("quest")) {
|
||||
String tag = NBTItem.get(event.getCurrentItem()).getString("questId");
|
||||
if (tag.equals(""))
|
||||
String questId = context.getItemStack().getItemMeta().getPersistentDataContainer()
|
||||
.get(new NamespacedKey(MMOCore.plugin,"quest_id"), PersistentDataType.STRING);
|
||||
if (questId.equals(""))
|
||||
return;
|
||||
|
||||
Quest quest = MMOCore.plugin.questManager.get(tag);
|
||||
Quest quest = MMOCore.plugin.questManager.get(questId);
|
||||
|
||||
if (playerData.getQuestData().hasCurrent()) {
|
||||
|
||||
@ -233,7 +242,7 @@ public class QuestViewer extends EditableInventory {
|
||||
* check if the player is cancelling his ongoing quest.
|
||||
*/
|
||||
if (playerData.getQuestData().hasCurrent(quest)) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (context.getClickType() == ClickType.RIGHT) {
|
||||
playerData.getQuestData().start(null);
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.CANCEL_QUEST).playTo(player);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("cancel-quest").send(player);
|
||||
|
@ -4,6 +4,7 @@ import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -17,6 +18,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@ -283,7 +285,7 @@ public class SkillList extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
/*
|
||||
if (skillSlots.contains(event.getRawSlot())
|
||||
@ -296,7 +298,7 @@ public class SkillList extends EditableInventory {
|
||||
*/
|
||||
|
||||
if (item.getFunction().equals("skill")) {
|
||||
int index = skillSlots.size() * page + skillSlots.indexOf(event.getRawSlot());
|
||||
int index = skillSlots.size() * page + skillSlots.indexOf(context.getSlot());
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
|
||||
selected = skills.get(index);
|
||||
open();
|
||||
@ -321,11 +323,11 @@ public class SkillList extends EditableInventory {
|
||||
* binding or unbinding skills.
|
||||
*/
|
||||
if (item.getFunction().equals("slot")) {
|
||||
int index = slotSlots.indexOf(event.getRawSlot());
|
||||
int index = slotSlots.indexOf(context.getSlot());
|
||||
|
||||
|
||||
// unbind if there is a current spell.
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (context.getClickType() == ClickType.RIGHT) {
|
||||
if (!playerData.hasSkillBound(index)) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
|
||||
@ -384,7 +386,7 @@ public class SkillList extends EditableInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isShiftClick()) {
|
||||
if (context.getClickType().isShiftClick()) {
|
||||
if (playerData.getSkillPoints() < shiftCost) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("not-enough-skill-points-shift", "shift_points", "" + shiftCost).send(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
|
||||
|
@ -5,6 +5,7 @@ import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.Placeholders;
|
||||
@ -50,9 +51,7 @@ public class SubclassConfirmation extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
if (event.getInventory() != event.getClickedInventory())
|
||||
return;
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
if (item.getFunction().equals("back"))
|
||||
last.open();
|
||||
|
@ -7,6 +7,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.gui.api.EditableInventory;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
@ -107,12 +108,12 @@ public class SubclassSelect extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("back"))
|
||||
InventoryManager.CLASS_SELECT.newInventory(playerData).open();
|
||||
|
||||
if (item.getFunction().equals("class")) {
|
||||
String tag = NBTItem.get(event.getCurrentItem()).getString("classId");
|
||||
String tag = NBTItem.get(context.getItemStack()).getString("classId");
|
||||
if (tag.equals(""))
|
||||
return;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.gui;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerActivity;
|
||||
@ -222,7 +223,7 @@ public class WaypointViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("next")) {
|
||||
page++;
|
||||
open();
|
||||
@ -236,7 +237,7 @@ public class WaypointViewer extends EditableInventory {
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("waypoint")) {
|
||||
PersistentDataContainer container = event.getCurrentItem().getItemMeta().getPersistentDataContainer();
|
||||
PersistentDataContainer container = context.getItemStack().getItemMeta().getPersistentDataContainer();
|
||||
String tag = container.has(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) ?
|
||||
container.get(new NamespacedKey(MMOCore.plugin, "waypointId"), PersistentDataType.STRING) : "";
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
public enum ClickAction {
|
||||
LEFT_CLICK,
|
||||
RIGHT_CLICK,
|
||||
SHIFT_LEFT_CLICK,
|
||||
SHIFT_RIGHT_CLICK,
|
||||
OTHER;
|
||||
}
|
@ -2,6 +2,8 @@ package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.gui.api.adaptor.AdaptorType;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@ -14,79 +16,116 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class EditableInventory {
|
||||
private final String id;
|
||||
private final String id;
|
||||
|
||||
private String name;
|
||||
private int slots;
|
||||
private AdaptorType adaptorType;
|
||||
private String name;
|
||||
private int slots;
|
||||
|
||||
/*
|
||||
* this set is linked so it keeps the order/priority in which the items are
|
||||
* loaded from the config.
|
||||
*/
|
||||
private final Set<InventoryItem> items = new LinkedHashSet<>();
|
||||
protected double radius, angleGap, verticalGap, curvature, verticalOffset;
|
||||
/*
|
||||
* this set is linked so it keeps the order/priority in which the items are
|
||||
* loaded from the config.
|
||||
*/
|
||||
private final Set<InventoryItem> items = new LinkedHashSet<>();
|
||||
|
||||
protected static final DecimalFormat decimal = MythicLib.plugin.getMMOConfig().decimal;
|
||||
protected static final DecimalFormat decimal = MythicLib.plugin.getMMOConfig().decimal;
|
||||
|
||||
public EditableInventory(String id) {
|
||||
this.id = id;
|
||||
Validate.notNull(id, "ID must not be null");
|
||||
}
|
||||
public EditableInventory(String id) {
|
||||
this.id = id;
|
||||
Validate.notNull(id, "ID must not be null");
|
||||
}
|
||||
|
||||
public void reload(FileConfiguration config) {
|
||||
public void reload(FileConfiguration config) {
|
||||
|
||||
this.name = config.getString("name");
|
||||
Validate.notNull(name, "Name must not be null");
|
||||
|
||||
this.slots = Math.min(Math.max(9, config.getInt("slots")), 54);
|
||||
Validate.isTrue((slots % 9) == 0, "Slots must be a multiple of 9");
|
||||
this.adaptorType = AdaptorType.valueOf(MMOCoreUtils.toEnumName(config.getString("adaptor-type", "classic-adaptor")));
|
||||
Validate.notNull(adaptorType, config.getString("adaptor-type") + " does not correspond to an adaptor-type.");//TODO
|
||||
|
||||
|
||||
items.clear();
|
||||
if (config.contains("items")) {
|
||||
Validate.notNull(config.getConfigurationSection("items"), "Could not load item list");
|
||||
for (String key : config.getConfigurationSection("items").getKeys(false))
|
||||
try {
|
||||
ConfigurationSection section = config.getConfigurationSection("items." + key);
|
||||
Validate.notNull(section, "Could not load config");
|
||||
InventoryItem loaded = loadInventoryItem(section);
|
||||
items.add(loaded);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load item '" + key + "' from inventory '" + getId() + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
this.radius = config.getDouble("radius", 2);
|
||||
this.angleGap = config.getDouble("angle-gap", 10);
|
||||
this.verticalGap = config.getDouble("vertical-gap", 1);
|
||||
this.curvature = config.getDouble("curvature", 1);
|
||||
this.verticalOffset = config.getDouble("vertical-offset", 0);
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Set<InventoryItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
this.name = config.getString("name");
|
||||
Validate.notNull(name, "Name must not be null");
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
this.slots = Math.min(Math.max(9, config.getInt("slots")), 54);
|
||||
Validate.isTrue((slots % 9) == 0, "Slots must be a multiple of 9");
|
||||
|
||||
public int getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public InventoryItem getByFunction(String function) {
|
||||
for (InventoryItem item : items)
|
||||
if (item.getFunction().equals(function))
|
||||
return item;
|
||||
return null;
|
||||
}
|
||||
items.clear();
|
||||
if (config.contains("items")) {
|
||||
Validate.notNull(config.getConfigurationSection("items"), "Could not load item list");
|
||||
for (String key : config.getConfigurationSection("items").getKeys(false))
|
||||
try {
|
||||
ConfigurationSection section = config.getConfigurationSection("items." + key);
|
||||
Validate.notNull(section, "Could not load config");
|
||||
InventoryItem loaded = loadInventoryItem(section);
|
||||
items.add(loaded);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load item '" + key + "' from inventory '" + getId() + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract InventoryItem load(String function, ConfigurationSection config);
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private InventoryItem loadInventoryItem(ConfigurationSection config) {
|
||||
String function = config.contains("function") ? config.getString("function").toLowerCase() : "";
|
||||
public Set<InventoryItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
if (function.startsWith("trigger:"))
|
||||
return new TriggerItem(config, function.substring(8));
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
return load(function, config);
|
||||
}
|
||||
public int getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public AdaptorType getAdaptorType() {
|
||||
return adaptorType;
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public double getAngleGap() {
|
||||
return angleGap;
|
||||
}
|
||||
|
||||
public double getVerticalGap() {
|
||||
return verticalGap;
|
||||
}
|
||||
|
||||
public double getCurvature() {
|
||||
return curvature;
|
||||
}
|
||||
|
||||
public double getVerticalOffset() {
|
||||
return verticalOffset;
|
||||
}
|
||||
|
||||
public InventoryItem getByFunction(String function) {
|
||||
for (InventoryItem item : items)
|
||||
if (item.getFunction().equals(function))
|
||||
return item;
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract InventoryItem load(String function, ConfigurationSection config);
|
||||
|
||||
private InventoryItem loadInventoryItem(ConfigurationSection config) {
|
||||
String function = config.contains("function") ? config.getString("function").toLowerCase() : "";
|
||||
|
||||
if (function.startsWith("trigger:"))
|
||||
return new TriggerItem(config, function.substring(8));
|
||||
|
||||
return load(function, config);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.adaptor.Adaptor;
|
||||
import net.Indyuce.mmocore.gui.api.adaptor.ClassicAdaptor;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -18,12 +17,15 @@ public abstract class GeneratedInventory extends PluginInventory {
|
||||
private final EditableInventory editable;
|
||||
private final List<InventoryItem> loaded = new ArrayList<>();
|
||||
|
||||
private final Adaptor adaptor;
|
||||
private Inventory open;
|
||||
|
||||
public GeneratedInventory(PlayerData playerData, EditableInventory editable) {
|
||||
super(playerData);
|
||||
|
||||
this.editable = editable;
|
||||
this.adaptor = editable.getAdaptorType().supply(this);
|
||||
|
||||
}
|
||||
|
||||
public List<InventoryItem> getLoaded() {
|
||||
@ -59,15 +61,13 @@ public abstract class GeneratedInventory extends PluginInventory {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, editable.getSlots(), MythicLib.plugin.getPlaceholderParser().parse(getPlayer(), calculateName()));
|
||||
|
||||
for (InventoryItem item : editable.getItems())
|
||||
if (item.canDisplay(this))
|
||||
item.setDisplayed(inv, this);
|
||||
|
||||
return inv;
|
||||
if (adaptor instanceof ClassicAdaptor) {
|
||||
return ((ClassicAdaptor) adaptor).getInventory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void open() {
|
||||
|
||||
/*
|
||||
@ -76,37 +76,33 @@ public abstract class GeneratedInventory extends PluginInventory {
|
||||
*/
|
||||
loaded.clear();
|
||||
|
||||
getPlayer().openInventory(open = getInventory());
|
||||
adaptor.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Not a fan of that implementation.
|
||||
* Better work with {@link InventoryItem#setDisplayed(Inventory, GeneratedInventory)}
|
||||
* Better work with {@link InventoryItem#setDisplayed(Inventory, GeneratedInventory)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
update.accept(placed);
|
||||
open.setItem(item.getSlots().get(n), placed);
|
||||
});
|
||||
adaptor.dynamicallyUpdateItem(item, n, placed, update);
|
||||
|
||||
}
|
||||
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
public void whenClicked(InventoryClickContext context) {
|
||||
context.setCancelled(true);
|
||||
InventoryItem item = getBySlot(context.getSlot());
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (event.getClickedInventory() != null && event.getClickedInventory().equals(event.getInventory())) {
|
||||
InventoryItem item = getBySlot(event.getSlot());
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
if (item instanceof TriggerItem)
|
||||
((TriggerItem) item).getTrigger().apply(getPlayerData());
|
||||
else
|
||||
whenClicked(event, item);
|
||||
}
|
||||
if (item instanceof TriggerItem)
|
||||
((TriggerItem) item).getTrigger().apply(getPlayerData());
|
||||
else
|
||||
whenClicked(context, item);
|
||||
}
|
||||
|
||||
|
||||
public abstract String calculateName();
|
||||
|
||||
public abstract void whenClicked(InventoryClickEvent event, InventoryItem item);
|
||||
public abstract void whenClicked(InventoryClickContext context, InventoryItem item);
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
|
||||
public class InventoryClickContext {
|
||||
private final int slot;
|
||||
private final ItemStack itemStack;
|
||||
private final ClickType clickType;
|
||||
|
||||
private final Cancellable event;
|
||||
|
||||
private Inventory inv;
|
||||
|
||||
public InventoryClickContext(int slot, ItemStack itemStack, ClickType clickType, Cancellable event) {
|
||||
this.slot = slot;
|
||||
this.itemStack = itemStack;
|
||||
this.clickType = clickType;
|
||||
this.event=event;
|
||||
}
|
||||
|
||||
|
||||
public void setCancelled(boolean val) {
|
||||
event.setCancelled(val);
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public Cancellable getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public boolean isClassic() {
|
||||
return inv!=null;
|
||||
}
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.gui.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -33,10 +34,9 @@ public abstract class PluginInventory implements InventoryHolder {
|
||||
public void open() {
|
||||
getPlayer().openInventory(getInventory());
|
||||
}
|
||||
|
||||
|
||||
public abstract Inventory getInventory();
|
||||
|
||||
public abstract void whenClicked(InventoryClickEvent event);
|
||||
public abstract void whenClicked(InventoryClickContext context);
|
||||
|
||||
public void whenClosed(InventoryCloseEvent event) {
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package net.Indyuce.mmocore.gui.api.adaptor;
|
||||
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class Adaptor {
|
||||
protected final GeneratedInventory generated;
|
||||
|
||||
public Adaptor(GeneratedInventory generated) {
|
||||
this.generated = generated;
|
||||
}
|
||||
|
||||
public abstract void open();
|
||||
|
||||
public abstract void close();
|
||||
|
||||
@Deprecated
|
||||
public abstract void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.Indyuce.mmocore.gui.api.adaptor;
|
||||
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum AdaptorType {
|
||||
CLASSIC_ADAPTOR(ClassicAdaptor::new),
|
||||
THREE_DIM_ADAPTOR(ThreeDimAdaptor::new);
|
||||
|
||||
private final Function<GeneratedInventory,Adaptor> supplier;
|
||||
|
||||
AdaptorType(Function<GeneratedInventory,Adaptor> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
public Adaptor supply(GeneratedInventory inv) {
|
||||
return this.supplier.apply(inv);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package net.Indyuce.mmocore.gui.api.adaptor;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ClassicAdaptor extends Adaptor {
|
||||
private Inventory open;
|
||||
|
||||
public ClassicAdaptor(GeneratedInventory generated) {
|
||||
super(generated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
generated.getPlayer().openInventory(open = getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
update.accept(placed);
|
||||
open.setItem(item.getSlots().get(n), placed);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(generated, generated.getEditable().getSlots(), MythicLib.plugin.getPlaceholderParser().parse(generated.getPlayer(), generated.calculateName()));
|
||||
|
||||
for (InventoryItem item : generated.getEditable().getItems())
|
||||
if (item.canDisplay(generated))
|
||||
setDisplayed(inv, item);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
private void setDisplayed(Inventory inv, InventoryItem item) {
|
||||
generated.addLoaded(item);
|
||||
List<Integer> slots = item.getSlots();
|
||||
|
||||
if (!item.hasDifferentDisplay()) {
|
||||
ItemStack display = item.display(generated);
|
||||
for (int slot : slots)
|
||||
inv.setItem(slot, display);
|
||||
} else
|
||||
for (int j = 0; j < slots.size(); j++)
|
||||
inv.setItem(slots.get(j), item.display(generated, j));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,341 @@
|
||||
package net.Indyuce.mmocore.gui.api.adaptor;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import io.lumine.mythic.lib.api.util.TemporaryListener;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ThreeDimAdaptor extends Adaptor {
|
||||
private final double INITIAL_PERCENTAGE = 0.20;
|
||||
private final double INCREMENT_PERCENTAGE = 0.20;
|
||||
|
||||
private SpawnPacketListener packetListener;
|
||||
private InteractListener interactListener;
|
||||
private final HashMap<Integer, ArmorStand> armorStands = new HashMap<>();
|
||||
|
||||
private boolean firstTime = true;
|
||||
|
||||
private final Vector direction = generated.getPlayer().getEyeLocation().getDirection().setY(0);
|
||||
private final Location location = generated.getPlayer().getLocation().add(new Vector(0, generated.getEditable().getVerticalOffset(), 0));
|
||||
|
||||
public ThreeDimAdaptor(GeneratedInventory generated) {
|
||||
super(generated);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
if (!firstTime) {
|
||||
fastClose();
|
||||
fastOpen();
|
||||
return;
|
||||
}
|
||||
firstTime = false;
|
||||
//MMOCore.plugin.protocolManager.addPacketListener(packetListener = new SpawnPacketListener());
|
||||
interactListener = new InteractListener();
|
||||
for (InventoryItem item : generated.getEditable().getItems()) {
|
||||
if (item.canDisplay(generated)) {
|
||||
setInventoryItem(item, INITIAL_PERCENTAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
new BukkitRunnable() {
|
||||
double total_percentage = INITIAL_PERCENTAGE;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (total_percentage < 1) {
|
||||
total_percentage += INCREMENT_PERCENTAGE;
|
||||
for (int slot : armorStands.keySet()) {
|
||||
armorStands.get(slot).teleport(getLocation(slot, total_percentage));
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
|
||||
}
|
||||
}.runTaskTimer(MMOCore.plugin, 0L, 1L);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
//Closes the packet listener,the interact listener and destroys the armor stands.
|
||||
//MMOCore.plugin.protocolManager.removePacketListener(packetListener);
|
||||
interactListener.close();
|
||||
new BukkitRunnable() {
|
||||
double total_percentage = 1;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (total_percentage > INITIAL_PERCENTAGE) {
|
||||
total_percentage -= INCREMENT_PERCENTAGE;
|
||||
for (int slot : armorStands.keySet()) {
|
||||
armorStands.get(slot).teleport(getLocation(slot, total_percentage));
|
||||
}
|
||||
} else {
|
||||
for (ArmorStand armorStand : armorStands.values())
|
||||
armorStand.remove();
|
||||
cancel();
|
||||
}
|
||||
|
||||
}
|
||||
}.runTaskTimer(MMOCore.plugin, 0L, 1L);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the inventory without the little animation
|
||||
*/
|
||||
public void fastOpen() {
|
||||
//MMOCore.plugin.protocolManager.addPacketListener(packetListener = new SpawnPacketListener());
|
||||
interactListener = new InteractListener();
|
||||
for (InventoryItem item : generated.getEditable().getItems()) {
|
||||
if (item.canDisplay(generated)) {
|
||||
setInventoryItem(item, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the inventory without the little animation
|
||||
*/
|
||||
public void fastClose() {
|
||||
//Closes the packet listener,the interact listener and destroys the armor stands.
|
||||
//MMOCore.plugin.protocolManager.removePacketListener(packetListener);
|
||||
interactListener.close();
|
||||
|
||||
for (ArmorStand armorStand : armorStands.values())
|
||||
armorStand.remove();
|
||||
|
||||
}
|
||||
|
||||
private void setInventoryItem(InventoryItem item, double percentage) {
|
||||
generated.addLoaded(item);
|
||||
|
||||
List<Integer> slots = item.getSlots();
|
||||
if (item.hasDifferentDisplay()) {
|
||||
for (int i : slots) {
|
||||
setItem(item.display(generated, i), i, percentage);
|
||||
}
|
||||
} else {
|
||||
ItemStack itemStack = item.display(generated);
|
||||
for (int i : slots) {
|
||||
setItem(itemStack, i, percentage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setItem(ItemStack item, int n, double percentage) {
|
||||
Location location = getLocation(n, percentage);
|
||||
//We create the armorStand corresponding to display the item
|
||||
ArmorStand armorStand = (ArmorStand) generated.getPlayer().getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||
armorStand.setVisible(false);
|
||||
armorStand.setSmall(false);
|
||||
armorStand.setArms(true);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.getEquipment().setItem(EquipmentSlot.HEAD, item);
|
||||
if (item.hasItemMeta() && item.getItemMeta().getDisplayName() != null) {
|
||||
armorStand.setCustomName(item.getItemMeta().getDisplayName());
|
||||
}
|
||||
armorStand.setCustomNameVisible(true);
|
||||
|
||||
//We add properties to the PersistentDataContainer of the armor stand
|
||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||
container.set(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER, n);
|
||||
|
||||
|
||||
//Makes the ArmorStand look at you
|
||||
//armorStand.setBodyPose(new EulerAngle(-direction.getX(),0,-direction.getZ()));
|
||||
|
||||
armorStands.put(n, armorStand);
|
||||
}
|
||||
|
||||
|
||||
public Location getLocation(int n, double percentage) {
|
||||
//Determines the location at which the ArmorStand will spawn
|
||||
|
||||
Location cloneLocation = location.clone();
|
||||
Vector cloneDirection = direction.clone().rotateAroundAxis(new Vector(0, 1, 0),
|
||||
-((n % 9) - 4) * generated.getEditable().getAngleGap() * Math.PI / 180);
|
||||
|
||||
//Curvature of 1: r=cst Curvature of 1: r=R/cos(angle) (a plane)
|
||||
double radius = percentage * generated.getEditable().getRadius() / Math.cos((1 - generated.getEditable().getCurvature())
|
||||
* -((n % 9) - 4) * generated.getEditable().getAngleGap() * Math.PI / 180);
|
||||
cloneDirection = cloneDirection.normalize().multiply(radius);
|
||||
cloneDirection.add(new Vector(0, percentage * generated.getEditable().getVerticalGap() * ((generated.getEditable().getSlots() - n - 1) / 9), 1));
|
||||
//We get the final direction
|
||||
cloneLocation.add(cloneDirection);
|
||||
|
||||
cloneLocation.setDirection(new Vector(-cloneDirection.getX(), 0, -cloneDirection.getZ()));
|
||||
return cloneLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update) {
|
||||
|
||||
}
|
||||
|
||||
private class SpawnPacketListener extends PacketAdapter {
|
||||
|
||||
|
||||
public SpawnPacketListener() {
|
||||
super(MMOCore.plugin, PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all the packet corresponding to an armorStand of the Gui to a player that should not see it.
|
||||
*/
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
|
||||
PacketContainer packet = event.getPacket();
|
||||
Entity entity = MMOCore.plugin.protocolManager
|
||||
.getEntityFromID(event.getPlayer().getWorld(), packet.getIntegers().read(0));
|
||||
if (entity instanceof ArmorStand armorStand) {
|
||||
if (true) {
|
||||
Bukkit.broadcastMessage("IN");
|
||||
|
||||
if (armorStands.values().contains(armorStand)) {
|
||||
Bukkit.broadcastMessage("CANCEL" + armorStand.getName());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class InteractListener extends TemporaryListener {
|
||||
|
||||
public InteractListener() {
|
||||
super(MMOCore.plugin, PlayerInteractAtEntityEvent.getHandlerList()
|
||||
, PlayerMoveEvent.getHandlerList(), PlayerInteractEvent.getHandlerList(), PlayerInteractAtEntityEvent.getHandlerList());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.getPlayer().equals(generated.getPlayer()) && !e.getFrom().getBlock().getLocation().equals(e.getTo().getBlock().getLocation()))
|
||||
ThreeDimAdaptor.this.close();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||
if (event.getPlayer().equals(generated.getPlayer()))
|
||||
if (event.getRightClicked() instanceof ArmorStand armorStand) {
|
||||
if (armorStands.values().contains(armorStand)) {
|
||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
||||
ClickType clickType;
|
||||
if (event.getPlayer().isSneaking())
|
||||
clickType = ClickType.SHIFT_RIGHT;
|
||||
else
|
||||
clickType = ClickType.RIGHT;
|
||||
generated.whenClicked(new InventoryClickContext(slot, armorStand.getEquipment().getItem(EquipmentSlot.HEAD), clickType, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getPlayer().equals(generated.getPlayer())) {
|
||||
Player player = event.getPlayer();
|
||||
for (ArmorStand armorStand : armorStands.values()) {
|
||||
//Little offset for the armorStand to have the location match the location of the itemstack
|
||||
if (player.getLocation().getDirection().normalize()
|
||||
.dot(armorStand.getLocation().add(new Vector(0, 0.25 * armorStand.getHeight(), 0)).subtract(player.getLocation()).toVector().normalize()) > 0.96) {
|
||||
|
||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
||||
ClickType clickType;
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (event.getPlayer().isSneaking())
|
||||
clickType = ClickType.SHIFT_LEFT;
|
||||
else
|
||||
clickType = ClickType.LEFT;
|
||||
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
|
||||
if (event.getPlayer().isSneaking())
|
||||
clickType = ClickType.SHIFT_RIGHT;
|
||||
else
|
||||
clickType = ClickType.RIGHT;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
generated.whenClicked(new InventoryClickContext(slot, armorStand.getEquipment().getItem(EquipmentSlot.HEAD), clickType, event));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
|
||||
if (event.getDamager() instanceof Player player) {
|
||||
if (player.equals(generated.getPlayer()))
|
||||
if (event.getEntity() instanceof ArmorStand armorStand) {
|
||||
if (armorStands.values().contains(armorStand)) {
|
||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
||||
ClickType clickType;
|
||||
if (player.isSneaking())
|
||||
clickType = ClickType.SHIFT_LEFT;
|
||||
else
|
||||
clickType = ClickType.LEFT;
|
||||
|
||||
ItemStack itemStack = armorStand.getEquipment().getItem(EquipmentSlot.HEAD);
|
||||
generated.whenClicked(new InventoryClickContext(slot, itemStack, clickType, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClosed() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.gui.eco;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.util.item.SimpleItemBuilder;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,102 +20,105 @@ import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.api.util.SmartGive;
|
||||
|
||||
public class DepositMenu extends PluginInventory {
|
||||
private ItemStack depositItem;
|
||||
private int deposit;
|
||||
private ItemStack depositItem;
|
||||
private int deposit;
|
||||
|
||||
public DepositMenu(Player player) {
|
||||
super(player);
|
||||
}
|
||||
public DepositMenu(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 27, "Deposit");
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 27, "Deposit");
|
||||
|
||||
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "0").build());
|
||||
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "0").build());
|
||||
|
||||
new BukkitRunnable() {
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (inv.getViewers().size() < 1) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
if (inv.getViewers().size() < 1) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
updateDeposit(inv);
|
||||
}
|
||||
}.runTaskTimer(MMOCore.plugin, 0, 20);
|
||||
return inv;
|
||||
}
|
||||
updateDeposit(inv);
|
||||
}
|
||||
}.runTaskTimer(MMOCore.plugin, 0, 20);
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
// event.setCancelled(true);
|
||||
if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)
|
||||
return;
|
||||
@Override
|
||||
public void whenClicked(InventoryClickContext context) {
|
||||
if (context.isClassic()) {
|
||||
|
||||
if (event.getCurrentItem().isSimilar(depositItem)) {
|
||||
event.setCancelled(true);
|
||||
// event.setCancelled(true);
|
||||
if (context.getItemStack() == null || context.getItemStack().getType() == Material.AIR)
|
||||
return;
|
||||
|
||||
updateDeposit(event.getInventory());
|
||||
if (deposit <= 0)
|
||||
return;
|
||||
if (context.getItemStack().isSimilar(depositItem)) {
|
||||
context.setCancelled(true);
|
||||
|
||||
EconomyResponse response = MMOCore.plugin.economy.getEconomy().depositPlayer(player, deposit);
|
||||
if (!response.transactionSuccess())
|
||||
return;
|
||||
updateDeposit(context.getInventory());
|
||||
if (deposit <= 0)
|
||||
return;
|
||||
|
||||
event.getInventory().clear();
|
||||
player.closeInventory();
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("deposit", "worth", "" + deposit).send(player);
|
||||
return;
|
||||
}
|
||||
EconomyResponse response = MMOCore.plugin.economy.getEconomy().depositPlayer(player, deposit);
|
||||
if (!response.transactionSuccess())
|
||||
return;
|
||||
|
||||
int worth = NBTItem.get(event.getCurrentItem()).getInteger("RpgWorth");
|
||||
if (worth < 1) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
;
|
||||
player.closeInventory();
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("deposit", "worth", "" + deposit).send(player);
|
||||
return;
|
||||
}
|
||||
|
||||
// in deposit menu
|
||||
// if (event.getRawSlot() < 27) {
|
||||
// int empty = player.getInventory().firstEmpty();
|
||||
// if (empty < 0)
|
||||
// return;
|
||||
//
|
||||
// player.playSound(player.getLocation(), Sound.ENTITY_SHULKER_TELEPORT,
|
||||
// 1, 2);
|
||||
// player.getInventory().addItem(event.getCurrentItem());
|
||||
// event.setCurrentItem(null);
|
||||
// updateDeposit(event.getInventory());
|
||||
// return;
|
||||
// }
|
||||
int worth = NBTItem.get(context.getItemStack()).getInteger("RpgWorth");
|
||||
if (worth < 1) {
|
||||
context.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// in player inventory
|
||||
// int empty = event.getInventory().firstEmpty();
|
||||
// if (empty < 0)
|
||||
// return;
|
||||
//
|
||||
// player.playSound(player.getLocation(),
|
||||
// Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||
// event.getInventory().addItem(event.getCurrentItem());
|
||||
// event.setCurrentItem(null);
|
||||
// updateDeposit(event.getInventory());
|
||||
// return;
|
||||
}
|
||||
// in deposit menu
|
||||
// if (event.getRawSlot() < 27) {
|
||||
// int empty = player.getInventory().firstEmpty();
|
||||
// if (empty < 0)
|
||||
// return;
|
||||
//
|
||||
// player.playSound(player.getLocation(), Sound.ENTITY_SHULKER_TELEPORT,
|
||||
// 1, 2);
|
||||
// player.getInventory().addItem(event.getCurrentItem());
|
||||
// event.setCurrentItem(null);
|
||||
// updateDeposit(event.getInventory());
|
||||
// return;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void whenClosed(InventoryCloseEvent event) {
|
||||
SmartGive smart = new SmartGive(player);
|
||||
for (int j = 0; j < 26; j++) {
|
||||
ItemStack item = event.getInventory().getItem(j);
|
||||
if (item != null)
|
||||
smart.give(item);
|
||||
}
|
||||
}
|
||||
// in player inventory
|
||||
// int empty = event.getInventory().firstEmpty();
|
||||
// if (empty < 0)
|
||||
// return;
|
||||
//
|
||||
// player.playSound(player.getLocation(),
|
||||
// Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||
// event.getInventory().addItem(event.getCurrentItem());
|
||||
// event.setCurrentItem(null);
|
||||
// updateDeposit(event.getInventory());
|
||||
// return;
|
||||
}
|
||||
|
||||
private void updateDeposit(Inventory inv) {
|
||||
deposit = MMOCoreUtils.getWorth(inv.getContents());
|
||||
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build());
|
||||
}
|
||||
@Override
|
||||
public void whenClosed(InventoryCloseEvent event) {
|
||||
SmartGive smart = new SmartGive(player);
|
||||
for (int j = 0; j < 26; j++) {
|
||||
ItemStack item = event.getInventory().getItem(j);
|
||||
if (item != null)
|
||||
smart.give(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDeposit(Inventory inv) {
|
||||
deposit = MMOCoreUtils.getWorth(inv.getContents());
|
||||
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.gui.eco;
|
||||
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -16,75 +17,78 @@ import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
|
||||
public class GoldPouch extends PluginInventory {
|
||||
private final boolean mob;
|
||||
private final NBTItem nbt;
|
||||
private final boolean mob;
|
||||
private final NBTItem nbt;
|
||||
|
||||
public GoldPouch(Player player, NBTItem nbt) {
|
||||
super(player);
|
||||
this.nbt = nbt;
|
||||
this.mob = nbt.getBoolean("RpgPouchMob");
|
||||
}
|
||||
public GoldPouch(Player player, NBTItem nbt) {
|
||||
super(player);
|
||||
this.nbt = nbt;
|
||||
this.mob = nbt.getBoolean("RpgPouchMob");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 18, ChatColor.UNDERLINE + "Gold Pouch");
|
||||
inv.setContents(MMOCoreUtils.itemStackArrayFromBase64(nbt.getString("RpgPouchInventory")));
|
||||
return inv;
|
||||
}
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 18, ChatColor.UNDERLINE + "Gold Pouch");
|
||||
inv.setContents(MMOCoreUtils.itemStackArrayFromBase64(nbt.getString("RpgPouchInventory")));
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
@Override
|
||||
public void whenClicked(InventoryClickContext context) {
|
||||
if (context.isClassic()) {
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if (!nbt.hasTag("RpgWorth")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
ItemStack item = context.getItemStack();
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if (!nbt.hasTag("RpgWorth")) {
|
||||
context.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mob) {
|
||||
event.setCancelled(true);
|
||||
if (mob) {
|
||||
context.setCancelled(true);
|
||||
|
||||
// in deposit menu
|
||||
if (event.getRawSlot() < 18) {
|
||||
int empty = player.getInventory().firstEmpty();
|
||||
if (empty < 0)
|
||||
return;
|
||||
// in deposit menu
|
||||
if (context.getSlot() < 18) {
|
||||
int empty = player.getInventory().firstEmpty();
|
||||
if (empty < 0)
|
||||
return;
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_SHULKER_TELEPORT, 1, 2);
|
||||
player.getInventory().addItem(event.getCurrentItem());
|
||||
event.setCurrentItem(null);
|
||||
}
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_SHULKER_TELEPORT, 1, 2);
|
||||
player.getInventory().addItem(context.getItemStack());
|
||||
context.getInventory().setItem(context.getSlot(), null);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Player cannot interact with a backpack item while
|
||||
* interacting with a backpack inventory. This fixes a
|
||||
* huge glitch where the player would lose the backpack
|
||||
* contents
|
||||
*/
|
||||
if (nbt.hasTag("RpgPouchInventory"))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
/*
|
||||
* Player cannot interact with a backpack item while
|
||||
* interacting with a backpack inventory. This fixes a
|
||||
* huge glitch where the player would lose the backpack
|
||||
* contents
|
||||
*/
|
||||
if (nbt.hasTag("RpgPouchInventory"))
|
||||
context.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClosed(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (mob && isEmpty(event.getInventory())) {
|
||||
player.getEquipment().setItemInMainHand(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack updated = NBTItem.get(player.getEquipment().getItemInMainHand()).addTag(new ItemTag("RpgPouchInventory", MMOCoreUtils.toBase64(event.getInventory().getContents()))).toItem();
|
||||
player.getEquipment().setItemInMainHand(updated);
|
||||
}
|
||||
@Override
|
||||
public void whenClosed(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (mob && isEmpty(event.getInventory())) {
|
||||
player.getEquipment().setItemInMainHand(null);
|
||||
return;
|
||||
}
|
||||
|
||||
private boolean isEmpty(Inventory inv) {
|
||||
for (ItemStack item : inv.getContents())
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
ItemStack updated = NBTItem.get(player.getEquipment().getItemInMainHand()).addTag(new ItemTag("RpgPouchInventory", MMOCoreUtils.toBase64(event.getInventory().getContents()))).toItem();
|
||||
player.getEquipment().setItemInMainHand(updated);
|
||||
}
|
||||
|
||||
private boolean isEmpty(Inventory inv) {
|
||||
for (ItemStack item : inv.getContents())
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.gui.social.friend;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerActivity;
|
||||
@ -18,6 +19,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -169,7 +171,7 @@ public class EditableFriendList extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("previous")) {
|
||||
page--;
|
||||
open();
|
||||
@ -221,8 +223,8 @@ public class EditableFriendList extends EditableInventory {
|
||||
});
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("friend") && event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
String tag = event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
if (item.getFunction().equals("friend") && context.getClickType() == ClickType.RIGHT) {
|
||||
String tag = context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
if (tag == null || tag.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.gui.social.friend;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -47,7 +48,7 @@ public class EditableFriendRemoval extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("yes")) {
|
||||
playerData.removeFriend(friend.getUniqueId());
|
||||
OfflinePlayerData.get(friend.getUniqueId()).removeFriend(playerData.getUniqueId());
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.social.guild;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -134,7 +136,7 @@ public class EditableGuildAdmin extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
if (item.getFunction().equals("leave")) {
|
||||
playerData.getGuild().removeMember(playerData.getUniqueId());
|
||||
@ -183,11 +185,11 @@ public class EditableGuildAdmin extends EditableInventory {
|
||||
});
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (item.getFunction().equals("member") && context.getClickType() == ClickType.RIGHT) {
|
||||
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
|
||||
return;
|
||||
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
if (target.equals(player))
|
||||
return;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.social.guild;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -34,10 +35,8 @@ public class EditableGuildCreation extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
if (event.getInventory() != event.getClickedInventory())
|
||||
return;
|
||||
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
if (item.getFunction().equals("create")) {
|
||||
MMOCore.plugin.configManager.newPlayerInput(player, PlayerInput.InputType.GUILD_CREATION_TAG, (input) -> {
|
||||
if(MMOCore.plugin.dataProvider.getGuildManager().getConfig().shouldUppercaseTags())
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.social.guild;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
@ -14,6 +15,7 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -160,7 +162,7 @@ public class EditableGuildView extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
if (item.getFunction().equals("leave")) {
|
||||
playerData.getGuild().removeMember(playerData.getUniqueId());
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
|
||||
@ -231,11 +233,11 @@ public class EditableGuildView extends EditableInventory {
|
||||
});
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (item.getFunction().equals("member") && context.getClickType() == ClickType.RIGHT) {
|
||||
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
|
||||
return;
|
||||
|
||||
String tag = event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
String tag = context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
|
||||
if (tag == null || tag.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.gui.social.party;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -32,9 +33,7 @@ public class EditablePartyCreation extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
if (event.getInventory() != event.getClickedInventory())
|
||||
return;
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
|
||||
if (item.getFunction().equals("create")) {
|
||||
((MMOCorePartyModule) MMOCore.plugin.partyModule).newRegisteredParty(playerData);
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.social.party;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.util.input.PlayerInput;
|
||||
import net.Indyuce.mmocore.gui.api.GeneratedInventory;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
|
||||
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -14,6 +15,7 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -130,7 +132,7 @@ public class EditablePartyView extends EditableInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
|
||||
public void whenClicked(InventoryClickContext context, InventoryItem item) {
|
||||
Party party = (Party) playerData.getParty();
|
||||
|
||||
if (item.getFunction().equals("leave")) {
|
||||
@ -186,11 +188,11 @@ public class EditablePartyView extends EditableInventory {
|
||||
});
|
||||
}
|
||||
|
||||
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (item.getFunction().equals("member") && context.getClickType() == ClickType.RIGHT) {
|
||||
if (!party.getOwner().equals(playerData))
|
||||
return;
|
||||
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(context.getItemStack().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
|
||||
if (target.equals(player))
|
||||
return;
|
||||
|
||||
|
@ -7,6 +7,8 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.gui.api.ClickAction;
|
||||
import net.Indyuce.mmocore.gui.api.InventoryClickContext;
|
||||
import net.Indyuce.mmocore.gui.api.PluginInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,10 +19,13 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@ -38,8 +43,15 @@ public class PlayerListener implements Listener {
|
||||
// Register custom inventory clicks
|
||||
@EventHandler
|
||||
public void b(InventoryClickEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof PluginInventory)
|
||||
((PluginInventory) event.getInventory().getHolder()).whenClicked(event);
|
||||
if (event.getInventory().getHolder() instanceof PluginInventory) {
|
||||
int slot = event.getRawSlot();
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null)
|
||||
|
||||
|
||||
((PluginInventory) event.getInventory().getHolder())
|
||||
.whenClicked(new InventoryClickContext(slot,event.getCurrentItem(),event.getClick(),event));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Register custom inventory close effect
|
||||
|
@ -1,21 +0,0 @@
|
||||
package net.Indyuce.mmocore.listener.bungee;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GetMMOCorePlayerListener implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived( String channel, Player player, byte[] bytes) {
|
||||
if(!channel.equals("give_mmocore_player"))
|
||||
return;
|
||||
ByteArrayDataInput input= ByteStreams.newDataInput(bytes);
|
||||
UUID uuid=UUID.fromString(input.readUTF());
|
||||
String Json=input.readUTF();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ author: Indyuce
|
||||
description: ${project.description}
|
||||
loadbefore: [MMOItems]
|
||||
depend: [MythicLib]
|
||||
softdepend: [Vault,MythicMobs,PlaceholderAPI,Residence,Citizens]
|
||||
softdepend: [Vault,MythicMobs,PlaceholderAPI,Residence,Citizens,ProtocolLib]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
mmocore:
|
||||
|
Loading…
Reference in New Issue
Block a user