From d3ace7909f986e9b2d6860fc132c08610112d4da Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 10 Jul 2022 18:58:41 +0200 Subject: [PATCH 1/4] Three Dim GUI --- pom.xml | 16 +- .../java/net/Indyuce/mmocore/MMOCore.java | 25 +- .../mmocore/api/load/DefaultMMOLoader.java | 3 + .../mmocore/api/player/PlayerData.java | 4 + .../mmocore/api/util/MMOCoreUtils.java | 5 + .../Indyuce/mmocore/gui/AttributeView.java | 6 +- .../mmocore/gui/ClassConfirmation.java | 6 +- .../net/Indyuce/mmocore/gui/ClassSelect.java | 15 +- .../net/Indyuce/mmocore/gui/PlayerStats.java | 3 +- .../net/Indyuce/mmocore/gui/QuestViewer.java | 21 +- .../net/Indyuce/mmocore/gui/SkillList.java | 12 +- .../mmocore/gui/SubclassConfirmation.java | 5 +- .../Indyuce/mmocore/gui/SubclassSelect.java | 5 +- .../Indyuce/mmocore/gui/WaypointViewer.java | 5 +- .../Indyuce/mmocore/gui/api/ClickAction.java | 9 + .../mmocore/gui/api/EditableInventory.java | 155 +++++--- .../mmocore/gui/api/GeneratedInventory.java | 54 ++- .../gui/api/InventoryClickContext.java | 58 +++ .../mmocore/gui/api/PluginInventory.java | 6 +- .../mmocore/gui/api/adaptor/Adaptor.java | 22 ++ .../mmocore/gui/api/adaptor/AdaptorType.java | 21 ++ .../gui/api/adaptor/ClassicAdaptor.java | 63 ++++ .../gui/api/adaptor/ThreeDimAdaptor.java | 341 ++++++++++++++++++ .../Indyuce/mmocore/gui/eco/DepositMenu.java | 168 ++++----- .../Indyuce/mmocore/gui/eco/GoldPouch.java | 122 ++++--- .../gui/social/friend/EditableFriendList.java | 8 +- .../social/friend/EditableFriendRemoval.java | 3 +- .../gui/social/guild/EditableGuildAdmin.java | 8 +- .../social/guild/EditableGuildCreation.java | 7 +- .../gui/social/guild/EditableGuildView.java | 8 +- .../social/party/EditablePartyCreation.java | 5 +- .../gui/social/party/EditablePartyView.java | 8 +- .../mmocore/listener/PlayerListener.java | 16 +- .../bungee/GetMMOCorePlayerListener.java | 21 -- src/main/resources/plugin.yml | 2 +- 35 files changed, 918 insertions(+), 318 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/ClickAction.java create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/InventoryClickContext.java create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/adaptor/Adaptor.java create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/adaptor/AdaptorType.java create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ClassicAdaptor.java create mode 100644 src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java delete mode 100644 src/main/java/net/Indyuce/mmocore/listener/bungee/GetMMOCorePlayerListener.java diff --git a/pom.xml b/pom.xml index 88c9f1ee..454941c1 100644 --- a/pom.xml +++ b/pom.xml @@ -53,8 +53,8 @@ 3.8.1 - 9 - 9 + 16 + 16 UTF-8 -proc:none @@ -112,6 +112,11 @@ https://papermc.io/repo/repository/maven-public/ + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + + @@ -181,6 +186,13 @@ provided + + com.comphenix.protocol + ProtocolLib + 4.8.0 + provided + + net.citizensnpcs Citizens diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 99a62ed3..73bccb7b 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -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")) diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index da0ec28f..fdbde575 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -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; } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 5b770865..49d5d18d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -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 classSlots = new HashMap<>(); private final Map 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(); diff --git a/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java b/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java index bd3b4050..e49aacd3 100644 --- a/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java +++ b/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java @@ -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(); diff --git a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java index b63c7f22..f9c98ae9 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/AttributeView.java @@ -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()); diff --git a/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java b/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java index dad42be6..0e6ffd9b 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/ClassConfirmation.java @@ -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(); diff --git a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java index da5d505a..89259f20 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java +++ b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java index 54518f13..b115516e 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java +++ b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java @@ -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++; diff --git a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java index 8623599b..37fce99d 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index ee4393ea..a16a22e1 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java b/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java index bc64667d..4a24ac27 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SubclassConfirmation.java @@ -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(); diff --git a/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java b/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java index 1e85268b..25cff48a 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SubclassSelect.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java index 668c6b15..68e5176d 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/WaypointViewer.java @@ -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) : ""; diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/ClickAction.java b/src/main/java/net/Indyuce/mmocore/gui/api/ClickAction.java new file mode 100644 index 00000000..d6262bdb --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/ClickAction.java @@ -0,0 +1,9 @@ +package net.Indyuce.mmocore.gui.api; + +public enum ClickAction { + LEFT_CLICK, + RIGHT_CLICK, + SHIFT_LEFT_CLICK, + SHIFT_RIGHT_CLICK, + OTHER; +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java b/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java index 5660ded8..c35b9280 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java @@ -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 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 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 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 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); + } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java b/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java index 163ae7f5..589af602 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java @@ -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 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 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 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); } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/InventoryClickContext.java b/src/main/java/net/Indyuce/mmocore/gui/api/InventoryClickContext.java new file mode 100644 index 00000000..19781ebf --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/InventoryClickContext.java @@ -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; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java b/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java index f9dde71e..0ffffed5 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/PluginInventory.java @@ -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) { } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/Adaptor.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/Adaptor.java new file mode 100644 index 00000000..60f0f291 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/Adaptor.java @@ -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 update); +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/AdaptorType.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/AdaptorType.java new file mode 100644 index 00000000..431422f0 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/AdaptorType.java @@ -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 supplier; + + AdaptorType(Function supplier) { + this.supplier = supplier; + } + + public Adaptor supply(GeneratedInventory inv) { + return this.supplier.apply(inv); + } + +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ClassicAdaptor.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ClassicAdaptor.java new file mode 100644 index 00000000..da6ea82a --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ClassicAdaptor.java @@ -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 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 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)); + + } +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java new file mode 100644 index 00000000..24868132 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java @@ -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 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 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 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() { + + + } + + } +} diff --git a/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java b/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java index f443e970..9f7d6dc7 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java +++ b/src/main/java/net/Indyuce/mmocore/gui/eco/DepositMenu.java @@ -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()); + } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/eco/GoldPouch.java b/src/main/java/net/Indyuce/mmocore/gui/eco/GoldPouch.java index 0d553637..5826b3b1 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/eco/GoldPouch.java +++ b/src/main/java/net/Indyuce/mmocore/gui/eco/GoldPouch.java @@ -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; + } } diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendList.java b/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendList.java index c222a255..3b6eb86b 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendList.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendList.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendRemoval.java b/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendRemoval.java index e0ae0bea..0e6950b8 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendRemoval.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/friend/EditableFriendRemoval.java @@ -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()); diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java index f3a7218e..d7189f27 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildCreation.java b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildCreation.java index ae6e78e8..7cbd5bc0 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildCreation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildCreation.java @@ -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()) diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java index 3ae1ccd5..f04f3dda 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyCreation.java b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyCreation.java index 5cfdb14f..588ec384 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyCreation.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyCreation.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java index e15d038a..069bc611 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java @@ -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; diff --git a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index c3b074f3..60764e0c 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -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 diff --git a/src/main/java/net/Indyuce/mmocore/listener/bungee/GetMMOCorePlayerListener.java b/src/main/java/net/Indyuce/mmocore/listener/bungee/GetMMOCorePlayerListener.java deleted file mode 100644 index 81e40242..00000000 --- a/src/main/java/net/Indyuce/mmocore/listener/bungee/GetMMOCorePlayerListener.java +++ /dev/null @@ -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(); - } - - -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0516bd3a..1fe51576 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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: From 040489245566dae641d08c0075196a2ed7dab006 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 12 Jul 2022 20:29:39 +0200 Subject: [PATCH 2/4] 3D Gui enhancements --- .../mmocore/gui/api/EditableInventory.java | 8 +- .../gui/api/adaptor/ThreeDimAdaptor.java | 165 +++++++++++++++++- .../mmocore/loot/droptable/DropTable.java | 3 +- 3 files changed, 167 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java b/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java index c35b9280..84183989 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/EditableInventory.java @@ -22,7 +22,7 @@ public abstract class EditableInventory { private String name; private int slots; - protected double radius, angleGap, verticalGap, curvature, verticalOffset; + protected double radius, angleGap, verticalGap, curvature, verticalOffset, interactSensitivity; /* * this set is linked so it keeps the order/priority in which the items are * loaded from the config. @@ -47,7 +47,7 @@ public abstract class EditableInventory { this.verticalGap = config.getDouble("vertical-gap", 1); this.curvature = config.getDouble("curvature", 1); this.verticalOffset = config.getDouble("vertical-offset", 0); - + this.interactSensitivity = config.getDouble("interact-sensitivity", 0.97); this.name = config.getString("name"); Validate.notNull(name, "Name must not be null"); @@ -103,6 +103,10 @@ public abstract class EditableInventory { return verticalGap; } + public double getInteractSensitivity() { + return interactSensitivity; + } + public double getCurvature() { return curvature; } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java index 24868132..641c430d 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java @@ -12,10 +12,7 @@ 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.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -31,6 +28,7 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.function.Consumer; @@ -42,11 +40,19 @@ public class ThreeDimAdaptor extends Adaptor { private InteractListener interactListener; private final HashMap armorStands = new HashMap<>(); + private final HashSet loreArmorStand = new HashSet<>(); + + private final HashMap hiddenArmorStand =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)); + //Zoomed=-1 no armorstand are under zoom + private int zoomed = -1; + + public ThreeDimAdaptor(GeneratedInventory generated) { super(generated); } @@ -94,6 +100,8 @@ public class ThreeDimAdaptor extends Adaptor { //Closes the packet listener,the interact listener and destroys the armor stands. //MMOCore.plugin.protocolManager.removePacketListener(packetListener); interactListener.close(); + removeLore(); + new BukkitRunnable() { double total_percentage = 1; @@ -127,6 +135,10 @@ public class ThreeDimAdaptor extends Adaptor { setInventoryItem(item, 1); } } + if (zoomed != -1) { + displayLore(zoomed); + armorStands.get(zoomed).teleport(getLocation(zoomed, 0.75)); + } } @@ -140,6 +152,7 @@ public class ThreeDimAdaptor extends Adaptor { for (ArmorStand armorStand : armorStands.values()) armorStand.remove(); + removeLore(); } @@ -187,6 +200,113 @@ public class ThreeDimAdaptor extends Adaptor { } + public void displayLore(int n) { + ArmorStand armorStand = armorStands.get(n); + ItemStack itemStack = armorStand.getEquipment().getItem(EquipmentSlot.HEAD); + + Location initalLocation = getLocation(n, 1); + + for (ArmorStand armorStand1 : armorStands.values()) { + armorStand1.setCustomNameVisible(false); + } + + Vector xAxis=initalLocation.clone().toVector().subtract(generated.getPlayer().getLocation().toVector()).setY(0).normalize(); + Vector yAxis = new Vector(0, 1, 0); + Vector zAxis = xAxis.rotateAroundAxis(yAxis, -Math.PI / 2); + + + //Empiric height of a line: 0.25 + //Empiric size of a char: 0.13 + double lineHeight = 0.25; + double charSize = 0.09; + //We search the biggest line in the lore + int max=0; + for(String line:itemStack.getItemMeta().getLore()){ + if(line.length()>max) + max=line.length(); + } + + + + initalLocation.add(zAxis.clone().multiply(max*charSize/2+0.8)).add(yAxis.clone().multiply(2 + 0.125 * itemStack.getItemMeta().getLore().size())); + for (String line : itemStack.getItemMeta().getLore()) { + if (line.length() != 0) { + ArmorStand as = (ArmorStand) initalLocation.getWorld().spawnEntity(initalLocation, EntityType.ARMOR_STAND); + as.setSmall(false); + as.setMarker(true); + as.setVisible(false); + as.setCustomNameVisible(true); + as.setCustomName(line); + loreArmorStand.add(as); + } + + initalLocation.add(yAxis.clone().multiply(-lineHeight)); + + } + + double totalHeight=lineHeight*itemStack.getItemMeta().getLore().size(); + double totalLength=max*charSize; + Location topCorner=getLocation(n, 1).add(yAxis.clone().multiply(2 +totalHeight/2)); + + //We remove the items that can be in the field of vision + for(ArmorStand otherArmorStand:armorStands.values()) { + if(!otherArmorStand.equals(armorStand)) { + //Calculates the direction between the player and otherArmorStand + Vector direction=otherArmorStand.getLocation().add(new Vector(0,0.25*otherArmorStand.getHeight(),0)).subtract(generated.getPlayer().getLocation()).toVector(); + //The vector between the plan and the player. + Vector vector=initalLocation.clone().toVector().subtract(generated.getPlayer().getLocation().toVector()).setY(0); + //The intersection between 'direction' and the plane + Vector projection=generated.getPlayer().getLocation().toVector().add(xAxis.clone().multiply(vector.dot(direction))); + Vector relativeProjection=projection.subtract(topCorner.toVector()); + double z=zAxis.dot(relativeProjection); + double y=-yAxis.dot(relativeProjection); + Bukkit.broadcastMessage(otherArmorStand.getName()+" z:"+z+" y:"+y); + if(z>0&&z0&&y generated.getEditable().getInteractSensitivity()) { + as.teleport(getLocation(n, 0.75)); + zoomed = n; + displayLore(zoomed); + } + + + } + + } + } + + } + } @EventHandler diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java index ffc90a61..4e37479d 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java @@ -11,6 +11,7 @@ import net.Indyuce.mmocore.loot.chest.condition.Condition; import net.Indyuce.mmocore.loot.chest.condition.ConditionInstance; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.ArmorStand; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.loot.LootBuilder; @@ -30,7 +31,7 @@ public class DropTable extends PostLoadObject { public DropTable(String id) { super(null); - + ArmorStand armorStand; this.id = id; } From 9454302f4a86c4760227276c48f475e490d7ef54 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 12 Jul 2022 22:13:32 +0200 Subject: [PATCH 3/4] 3D Gui enhancements --- .../gui/api/adaptor/ThreeDimAdaptor.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java index 641c430d..fbc7cbf2 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/adaptor/ThreeDimAdaptor.java @@ -212,7 +212,7 @@ public class ThreeDimAdaptor extends Adaptor { Vector xAxis=initalLocation.clone().toVector().subtract(generated.getPlayer().getLocation().toVector()).setY(0).normalize(); Vector yAxis = new Vector(0, 1, 0); - Vector zAxis = xAxis.rotateAroundAxis(yAxis, -Math.PI / 2); + Vector zAxis = xAxis.clone().rotateAroundAxis(yAxis, -Math.PI / 2); //Empiric height of a line: 0.25 @@ -246,25 +246,29 @@ public class ThreeDimAdaptor extends Adaptor { double totalHeight=lineHeight*itemStack.getItemMeta().getLore().size(); double totalLength=max*charSize; - Location topCorner=getLocation(n, 1).add(yAxis.clone().multiply(2 +totalHeight/2)); + Location topCorner=getLocation(n, 1).add(yAxis.clone().multiply(armorStand.getHeight()*0.25 +totalHeight/2)); //We remove the items that can be in the field of vision - for(ArmorStand otherArmorStand:armorStands.values()) { + for(int slot:armorStands.keySet()) { + ArmorStand otherArmorStand = armorStands.get(slot); if(!otherArmorStand.equals(armorStand)) { //Calculates the direction between the player and otherArmorStand - Vector direction=otherArmorStand.getLocation().add(new Vector(0,0.25*otherArmorStand.getHeight(),0)).subtract(generated.getPlayer().getLocation()).toVector(); + Vector direction=otherArmorStand.getLocation().add(new Vector(0,0.25*otherArmorStand.getHeight(),0)).subtract(generated.getPlayer().getLocation()).toVector().normalize(); //The vector between the plan and the player. - Vector vector=initalLocation.clone().toVector().subtract(generated.getPlayer().getLocation().toVector()).setY(0); - //The intersection between 'direction' and the plane - Vector projection=generated.getPlayer().getLocation().toVector().add(xAxis.clone().multiply(vector.dot(direction))); - Vector relativeProjection=projection.subtract(topCorner.toVector()); - double z=zAxis.dot(relativeProjection); - double y=-yAxis.dot(relativeProjection); - Bukkit.broadcastMessage(otherArmorStand.getName()+" z:"+z+" y:"+y); - if(z>0&&z0&&y0&&z0&&y Date: Mon, 25 Jul 2022 09:33:54 +0200 Subject: [PATCH 4/4] Debug profession & chance stat --- .../mmocore/loot/droptable/dropitem/DropItem.java | 15 ++++++++++++++- .../data/mysql/MySQLPlayerDataManager.java | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java index b84e5cc3..ce1ec4c8 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java @@ -6,6 +6,7 @@ import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.loot.LootBuilder; import io.lumine.mythic.lib.api.MMOLineConfig; +import org.bukkit.Bukkit; public abstract class DropItem { protected static final Random random = new Random(); @@ -13,6 +14,8 @@ public abstract class DropItem { private final double chance, weight; private final RandomAmount amount; + private static final double CHANCE_COEFFICIENT = 7. / 100; + public DropItem(MMOLineConfig config) { chance = config.args().length > 0 ? Double.parseDouble(config.args()[0]) : 1; amount = config.args().length > 1 ? new RandomAmount(config.args()[1]) : new RandomAmount(1, 1); @@ -35,11 +38,21 @@ public abstract class DropItem { return amount.calculateInt(); } + + + /** + * CHANCE stat = 0 | tier chances are unchanged + * CHANCE stat = +inf | uniform law for any drop item + * CHANCE stat = 100 | all tier chances are taken their square root + * + * @return The real weight of an item considering the player's CHANCE stat. + */ /** * If the player chance is 0 the random value will remain the same. When he get lucks the chance gets closer to one. */ public boolean rollChance(PlayerData player) { - return Math.pow(random.nextDouble(), 1 / Math.log(1 + player.getStats().getStat("CHANCE"))) < chance; + double value=random.nextDouble(); + return value< Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * player.getStats().getStat("CHANCE"), 1.0 / 3.0)); } public abstract void collect(LootBuilder builder); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 34432b56..8527d082 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -138,6 +138,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { } } catch (SQLException e) { e.printStackTrace(); + cancel(); } }); }