Merge branch 'master' into Skills-update

# Conflicts:
#	MMOCore-API/src/main/java/net/Indyuce/mmocore/command/SkillsCommand.java
This commit is contained in:
Ka0rX 2023-04-04 21:11:49 +01:00
commit 333ffe08d5
16 changed files with 116 additions and 44 deletions

19
LICENSE
View File

@ -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.

View File

@ -208,7 +208,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();
}
/**
@ -271,7 +271,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());
}
/**
@ -286,10 +286,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);
@ -998,7 +1002,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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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);

View File

@ -11,32 +11,28 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import java.util.stream.Collectors;
public class SkillsCommand extends RegisteredCommand {
public SkillsCommand(ConfigurationSection config) {
super(config, ToggleableCommand.SKILLS);
}
public SkillsCommand(ConfigurationSection config) {
super(config, ToggleableCommand.SKILLS);
}
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if (sender instanceof Player) {
PlayerData data = PlayerData.get((Player) sender);
MMOCommandEvent event = new MMOCommandEvent(data, "skills");
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
@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");
Bukkit.getServer().getPluginManager().callEvent(event);
if(event.isCancelled()) return true;
if (data.getProfess().getSkills()
.stream()
.filter((classSkill) -> data.hasUnlocked(classSkill.getSkill()))
.collect(Collectors.toList())
.size() < 1) {
MMOCore.plugin.configManager.getSimpleMessage("no-class-skill").send((Player) sender);
return true;
}
if (data.getProfess().getSkills().size() < 1) {
MMOCore.plugin.configManager.getSimpleMessage("no-class-skill").send((Player) sender);
return true;
}
InventoryManager.SKILL_LIST.newInventory(data).open();
}
return true;
}
InventoryManager.SKILL_LIST.newInventory(data).open();
}
return true;
}
}

View File

@ -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");

View File

@ -113,16 +113,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("stellium"));
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();
}

View File

@ -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 ? 20 : health;
health = Math.min(health, data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
data.getPlayer().setHealth(health);
data.setFullyLoaded();
}

View File

@ -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;
}

View File

@ -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

View File

@ -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%