From 8b5a94bf3a8de79ae6e161d54566af0e2210e551 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 26 Mar 2023 10:50:25 +0200 Subject: [PATCH 01/10] Fixed data sync health issue --- .../manager/data/mysql/MMOCoreDataSynchronizer.java | 10 ++++++---- .../manager/data/yaml/YAMLPlayerDataManager.java | 12 ++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java index 1364026b..b37a6bb8 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MMOCoreDataSynchronizer.java @@ -118,16 +118,18 @@ public class MMOCoreDataSynchronizer extends DataSynchronizer { } } - //These should be loaded after to make sure that the MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded. + /* + * These should be loaded after to make sure that the + * MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded. + */ data.setMana(result.getDouble("mana")); data.setStamina(result.getDouble("stamina")); data.setStellium(result.getDouble("stamina")); double health = result.getDouble("health"); - health = health == 0 ? 20 : health; - health = Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + health = health == 0 ? data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() : health; + health = Math.max(Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()), 0); data.getPlayer().setHealth(health); - UtilityMethods.debug(MMOCore.plugin, "SQL", String.format("{ class: %s, level: %d }", data.getProfess().getId(), data.getLevel())); data.setFullyLoaded(); } diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index 40926977..b7d7529a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -116,14 +116,18 @@ public class YAMLPlayerDataManager extends PlayerDataManager { MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage()); } - - //These should be loaded after to make sure that the MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded. + /* + * These should be loaded after to make sure that the + * MAX_MANA, MAX_STAMINA & MAX_STELLIUM stats are already loaded. + */ data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA")); data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA")); data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM")); - double health=config.contains("health") ? config.getDouble("health") : data.getStats().getStat("MAX_HEALTH"); - health=Math.min(health,data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + double health = config.contains("health") ? config.getDouble("health") : data.getStats().getStat("MAX_HEALTH"); + health = health == 0 ? data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() : health; + health = Math.max(Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()), 0); data.getPlayer().setHealth(health); + data.setFullyLoaded(); } From fda62fca84cfb8cdd642d0ab7f58f780274f751d Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 27 Mar 2023 01:10:13 +0200 Subject: [PATCH 02/10] Update ver nb --- MMOCore-API/pom.xml | 2 +- MMOCore-Dist/pom.xml | 4 ++-- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MMOCore-API/pom.xml b/MMOCore-API/pom.xml index 1ac1239c..8add30f8 100644 --- a/MMOCore-API/pom.xml +++ b/MMOCore-API/pom.xml @@ -5,7 +5,7 @@ MMOCore net.Indyuce - 1.11.2-SNAPSHOT + 1.11.3-SNAPSHOT 4.0.0 diff --git a/MMOCore-Dist/pom.xml b/MMOCore-Dist/pom.xml index cf6bc6f3..447a720b 100644 --- a/MMOCore-Dist/pom.xml +++ b/MMOCore-Dist/pom.xml @@ -5,7 +5,7 @@ MMOCore net.Indyuce - 1.11.2-SNAPSHOT + 1.11.3-SNAPSHOT 4.0.0 @@ -67,7 +67,7 @@ net.Indyuce MMOCore-API - 1.11.2-SNAPSHOT + 1.11.3-SNAPSHOT true diff --git a/pom.xml b/pom.xml index ec4f22e3..a998f2e7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.Indyuce MMOCore pom - 1.11.2-SNAPSHOT + 1.11.3-SNAPSHOT MMOCore-API From 8a2a7c638113bd617cf89faed004767e1fb164f0 Mon Sep 17 00:00:00 2001 From: Jules Date: Fri, 31 Mar 2023 15:31:34 +0200 Subject: [PATCH 03/10] Update license --- LICENSE | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 911389d0..5102ff96 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,18 @@ -This project is owned and maintained by PhoenixDvpt and is distributed with "All Right's Reserved". +This project is owned and maintained by "Phoenix Development" and is distributed with "All Rights Reserved". +PhoenixDevt reserves the right to change these terms at any time, you have to comply with the most recent version. +We do NOT provide support to servers involved with piracy in any form, or owners who have downloaded ANY of our plugins from an unofficial/illegal source. -You can fork and modify the source code of this project as you wish to meet your server's needs, and merge requests are accepted under the terms that you grant full rights to us using any pushed code. However, you may not distribute the plugin for any purpose other than providing cross-compatibility with other Minecraft plugins, and may not bypass any anti-piracy protection. +Things can you CANNOT do: +- Issue a refund on PayPal without our explicit permission, as this is a digital good. +- Redistribute, sell or give an official/modified version of the plugin (with or without any type of counterpart) to anyone else. +- Modify and compile the project source code to bypass an anti-piracy protection. +- Download, compile, decompile or use the plugin on a production server without purchasing a license. + +Things can you CAN do when purchasing the plugin: +- Download and decompile the plugin file. +- Fork and modify the project source code to meet your production server's needs. +- Use it on ONE production server or network (= proxy-connected servers) at a time. + +You may propose a merge request, under the terms that you grant full rights to us using any pushed code. + +If you are a developer and have not purchased a license, you have the permission to download, fork, edit and compile the project source code, and sell code modifications to your client ONLY IF they have already purchased a license. This only applies to one-time comission works and does NOT apply to public sales. From c31a3fcec144790a33a9ca8312b004fdeff2ab70 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 2 Apr 2023 23:09:37 +0100 Subject: [PATCH 04/10] Fixed the bug where player die when joining server. --- .../mmocore/manager/data/yaml/YAMLPlayerDataManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index 40926977..cf0eb84a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -121,8 +121,9 @@ public class YAMLPlayerDataManager extends PlayerDataManager { data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA")); data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA")); data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM")); - double health=config.contains("health") ? config.getDouble("health") : data.getStats().getStat("MAX_HEALTH"); - health=Math.min(health,data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + double health = config.contains("health") ? config.getDouble("health") : data.getStats().getStat("MAX_HEALTH"); + health = health == 0 ? 20 : health; + health = Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); data.getPlayer().setHealth(health); data.setFullyLoaded(); } @@ -148,7 +149,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { data.mapSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value)); config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints()); config.set("skill", null); - config.set("health",data.getHealth()); + config.set("health", data.getHealth()); config.set("mana", data.getMana()); config.set("stellium", data.getStellium()); config.set("stamina", data.getStamina()); From d7db3f6d681712ff3428bd4ad84f1100a3a0d52d Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 2 Apr 2023 23:23:11 +0100 Subject: [PATCH 05/10] Fixed bug related to fetching player health when he is offline. --- .../main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index abb701a0..0479bd9a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -950,7 +950,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc @Override public double getHealth() { - return getPlayer() == null ? health : getPlayer().getHealth(); + return isOnline() ? getPlayer().getHealth():health ; } @Override From 8192d6caa8f35794aa137a64250bc3040924ec60 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sun, 2 Apr 2023 23:41:22 +0100 Subject: [PATCH 06/10] Test --- .../src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 1 + 1 file changed, 1 insertion(+) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 94c06980..8a85f229 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -851,6 +851,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc new ConfigMessage("level-up").addPlaceholders("level", String.valueOf(level)).send(getPlayer()); MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_UP).playTo(getPlayer()); new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT); + //TEST } getStats().updateStats(); } From 8f2da7a865b9a0f9760cce069ea16468d20b5630 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Mon, 3 Apr 2023 07:28:36 +0100 Subject: [PATCH 07/10] . --- .../src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 1 - 1 file changed, 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 54c41735..0479bd9a 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -851,7 +851,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc new ConfigMessage("level-up").addPlaceholders("level", String.valueOf(level)).send(getPlayer()); MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_UP).playTo(getPlayer()); new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT); - //TEST } getStats().updateStats(); } From e6cfde3ce79c17bf985ae845f2060fb38771bac9 Mon Sep 17 00:00:00 2001 From: Taner <11832079-Tanerx@users.noreply.gitlab.com> Date: Mon, 3 Apr 2023 15:11:40 +0000 Subject: [PATCH 08/10] Update Crowdin configuration file --- crowdin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crowdin.yml b/crowdin.yml index 05dfa962..fee22a6d 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -3,3 +3,5 @@ files: translation: /**/MMOCore-Dist/src/main/resources/default/translation/%language%/gui/%file_name%.%file_extension% - source: MMOCore-Dist/src/main/resources/default/messages.yml translation: /**/MMOCore-Dist/src/main/resources/default/translation/%language%/%file_name%.%file_extension% + - source: MMOCore-Dist/src/main/resources/default/gui/class-confirm/*.yml + translation: /**/MMOCore-Dist/src/main/resources/default/translation/%language%/gui/class-confirm/%file_name%.%file_extension% From a54bfc03a08807e69cfa9f381b1c16dbee884670 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 4 Apr 2023 07:11:16 +0100 Subject: [PATCH 09/10] Added permission associated with every MMOCore command. --- .../mmocore/command/AttributesCommand.java | 3 +++ .../mmocore/command/FriendsCommand.java | 2 ++ .../Indyuce/mmocore/command/GuildCommand.java | 2 ++ .../Indyuce/mmocore/command/PartyCommand.java | 2 ++ .../mmocore/command/PlayerStatsCommand.java | 2 ++ .../mmocore/command/QuestsCommand.java | 2 ++ .../mmocore/command/SkillTreesCommand.java | 2 ++ .../mmocore/command/SkillsCommand.java | 2 ++ .../command/api/ToggleableCommand.java | 2 +- MMOCore-Dist/src/main/resources/plugin.yml | 24 +++++++++++++++++++ 10 files changed, 42 insertions(+), 1 deletion(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/AttributesCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/AttributesCommand.java index a418202d..c3b756d3 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/AttributesCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/AttributesCommand.java @@ -18,6 +18,9 @@ public class AttributesCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.attributes")) + return false; + if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is for players only."); return true; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/FriendsCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/FriendsCommand.java index d230ea74..b0b457f2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/FriendsCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/FriendsCommand.java @@ -25,6 +25,8 @@ public class FriendsCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.friends")) + return false; if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is for players only."); return true; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/GuildCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/GuildCommand.java index f1fd656b..7f0437ff 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/GuildCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/GuildCommand.java @@ -26,6 +26,8 @@ public class GuildCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.guild")) + return false; if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is for players only."); return true; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java index d9f02a10..e398ece2 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java @@ -27,6 +27,8 @@ public class PartyCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.party")) + return false; if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is for players only."); return true; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PlayerStatsCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PlayerStatsCommand.java index af2b8cef..6fd8c2e1 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PlayerStatsCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/PlayerStatsCommand.java @@ -18,6 +18,8 @@ public class PlayerStatsCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.profile")) + return false; if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is for players only."); return true; diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/QuestsCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/QuestsCommand.java index 7946c3e9..56b81eae 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/QuestsCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/QuestsCommand.java @@ -17,6 +17,8 @@ public class QuestsCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.quests")) + return false; if (sender instanceof Player) { PlayerData data = PlayerData.get((Player) sender); MMOCommandEvent event = new MMOCommandEvent(data, "quests"); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillTreesCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillTreesCommand.java index ae53e0d9..bf1513a0 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillTreesCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillTreesCommand.java @@ -19,6 +19,8 @@ public class SkillTreesCommand extends RegisteredCommand { @Override public boolean execute(@NotNull CommandSender sender, String s, String[] args) { + if (!sender.hasPermission("mmocore.skilltrees")) + return false; if (!(sender instanceof Player player)) return false; PlayerData data = PlayerData.get(player); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillsCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillsCommand.java index 25429f56..2e3bf259 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillsCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillsCommand.java @@ -18,6 +18,8 @@ public class SkillsCommand extends RegisteredCommand { @Override public boolean execute(CommandSender sender, String label, String[] args) { + if (!sender.hasPermission("mmocore.skills")) + return false; if (sender instanceof Player) { PlayerData data = PlayerData.get((Player) sender); MMOCommandEvent event = new MMOCommandEvent(data, "skills"); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/api/ToggleableCommand.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/api/ToggleableCommand.java index 8e43385a..bfad893b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/api/ToggleableCommand.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/command/api/ToggleableCommand.java @@ -32,7 +32,7 @@ public enum ToggleableCommand { PARTY("party", "Invite players in a party to split exp", config -> new PartyCommand(config)), GUILD("guild", "Show players in current guild", config -> new GuildCommand(config)), WITHDRAW("withdraw", "Withdraw money into coins and notes", config -> new WithdrawCommand(config), v -> MMOCore.plugin.hasEconomy() && MMOCore.plugin.economy.isValid(), "w"), - SKILL_TREES("skiltrees", "Open up the skill tree menu", config -> new SkillTreesCommand(config), "st", "trees", "tree"), + SKILL_TREES("skilltrees", "Open up the skill tree menu", config -> new SkillTreesCommand(config), "st", "trees", "tree"), DEPOSIT("deposit", "Open the currency deposit menu", config -> new DepositCommand(config), "d"), PVP_MODE("pvpmode", "Toggle on/off PVP mode.", config -> new PvpModeCommand(config), "pvp"); diff --git a/MMOCore-Dist/src/main/resources/plugin.yml b/MMOCore-Dist/src/main/resources/plugin.yml index dbf24e51..152a94ca 100644 --- a/MMOCore-Dist/src/main/resources/plugin.yml +++ b/MMOCore-Dist/src/main/resources/plugin.yml @@ -27,3 +27,27 @@ permissions: mmocore.class-select: description: Access to /class default: op + mmocore.attributes: + description: Access to /attributes + default: true + mmocore.skills: + description: Access to /skills + default: true + mmocore.profile: + description: Access to /profile + default: true + mmocore.friends: + description: Access to /friends + default: true + mmocore.guild: + description: Access to /guild + default: true + mmocore.party: + description: Access to /party + default: true + mmocore.skilltrees: + description: Access to /skilltrees + default: true + mmocore.quests: + description: Access to /quests + default: true \ No newline at end of file From 08b82392911c53cd5d237e6f8f362fc4da438e46 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Tue, 4 Apr 2023 13:05:27 +0100 Subject: [PATCH 10/10] Added option to have more than 1 skill tree point required for a certain some skill tree. --- .../Indyuce/mmocore/api/player/PlayerData.java | 18 +++++++++++------- .../mmocore/skilltree/SkillTreeNode.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 0479bd9a..43ab6769 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -207,7 +207,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } public int countSkillTreePoints(SkillTree skillTree) { - return nodeLevels.keySet().stream().filter(node -> node.getTree().equals(skillTree)).mapToInt(nodeLevels::get).sum(); + return nodeLevels.keySet().stream().filter(node -> node.getTree().equals(skillTree)).mapToInt(node -> nodeLevels.get(node) * node.getSkillTreePointsConsumed()).sum(); } /** @@ -262,7 +262,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc //Check the State of the node if (nodeStatus != NodeStatus.UNLOCKED && nodeStatus != NodeStatus.UNLOCKABLE) return false; - return getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) > 0 || skillTreePoints.getOrDefault("global", 0) > 0); + return getNodeLevel(node) < node.getMaxLevel() && (skillTreePoints.getOrDefault(node.getTree().getId(), 0) + skillTreePoints.getOrDefault("global", 0) >= node.getSkillTreePointsConsumed()); } /** @@ -277,10 +277,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc if (nodeStates.get(node) == NodeStatus.UNLOCKABLE) setNodeState(node, NodeStatus.UNLOCKED); - if (skillTreePoints.get(node.getTree().getId()) > 0) - withdrawSkillTreePoints(node.getTree().getId(), 1); - else - withdrawSkillTreePoints("global", 1); + int pointToWithdraw = node.getSkillTreePointsConsumed(); + if (skillTreePoints.get(node.getTree().getId()) > 0) { + int pointWithdrawn = Math.min(pointToWithdraw, skillTreePoints.get(node.getTree().getId())); + withdrawSkillTreePoints(node.getTree().getId(), pointWithdrawn); + pointToWithdraw -= pointWithdrawn; + } + if (pointToWithdraw > 0) + withdrawSkillTreePoints("global", pointToWithdraw); //We unload the nodeStates map (for the skill tree) and reload it completely for (SkillTreeNode node1 : node.getTree().getNodes()) nodeStates.remove(node1); @@ -950,7 +954,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc @Override public double getHealth() { - return isOnline() ? getPlayer().getHealth():health ; + return isOnline() ? getPlayer().getHealth() : health; } @Override diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java index 5dbf9cb8..6fcb73b7 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/skilltree/SkillTreeNode.java @@ -22,6 +22,10 @@ public class SkillTreeNode implements ExperienceObject { private final SkillTree tree; private final String name, id; private IntegerCoordinates coordinates; + /** + * The number of skill tree points this node requires. + */ + private final int skillTreePointsConsumed; private boolean isRoot; /** @@ -56,7 +60,8 @@ public class SkillTreeNode implements ExperienceObject { name = Objects.requireNonNull(config.getString("name"), "Could not find node name"); size = Objects.requireNonNull(config.getInt("size")); isRoot = config.getBoolean("is-root", false); - + skillTreePointsConsumed=config.getInt("skill-tree-points",1); + Validate.isTrue(skillTreePointsConsumed>0,"The skill tree points consumed by a node must be greater than 0."); if (config.contains("lores")) for (String key : config.getConfigurationSection("lores").getKeys(false)) try { @@ -100,6 +105,10 @@ public class SkillTreeNode implements ExperienceObject { children.add(child); } + public int getSkillTreePointsConsumed() { + return skillTreePointsConsumed; + } + public void setCoordinates(IntegerCoordinates coordinates) { this.coordinates = coordinates; } @@ -112,6 +121,7 @@ public class SkillTreeNode implements ExperienceObject { return softParents.containsKey(parent) || strongParents.containsKey(parent); } + public int getMaxLevel() { return maxLevel; }