mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Added /mmocore admin attribute
This commit is contained in:
parent
ca7c90f7c1
commit
0f7f665632
@ -16,6 +16,7 @@ public class AdminCommandTreeNode extends CommandTreeNode {
|
||||
|
||||
addChild(new ExperienceCommandTreeNode(this));
|
||||
addChild(new LevelCommandTreeNode(this));
|
||||
addChild(new AttributeCommandTreeNode(this));
|
||||
|
||||
addChild(new PointsCommandTreeNode("skill", this, (data, points) -> data.setSkillPoints(points), (data, points) -> data.giveSkillPoints(points), (data) -> data.getSkillPoints()));
|
||||
addChild(new PointsCommandTreeNode("class", this, (data, points) -> data.setClassPoints(points), (data, points) -> data.giveClassPoints(points), (data) -> data.getClassPoints()));
|
||||
|
@ -0,0 +1,75 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes.AttributeInstance;
|
||||
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||
import net.mmogroup.mmolib.command.api.Parameter;
|
||||
|
||||
public class AttributeCommandTreeNode extends CommandTreeNode {
|
||||
public AttributeCommandTreeNode(CommandTreeNode parent) {
|
||||
super(parent, "attribute");
|
||||
|
||||
addChild(new ActionCommandTreeNode(this, "give", false));
|
||||
addChild(new ActionCommandTreeNode(this, "take", true));
|
||||
}
|
||||
|
||||
public class ActionCommandTreeNode extends CommandTreeNode {
|
||||
private final int c;
|
||||
|
||||
public ActionCommandTreeNode(CommandTreeNode parent, String type, boolean take) {
|
||||
super(parent, type);
|
||||
|
||||
this.c = take ? -1 : 1;
|
||||
|
||||
addParameter(Parameter.PLAYER);
|
||||
addParameter(new Parameter("<attribute>",
|
||||
(explorer, list) -> MMOCore.plugin.attributeManager.getAll().forEach(attribute -> list.add(attribute.getId()))));
|
||||
addParameter(Parameter.AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
if (args.length < 6)
|
||||
return CommandResult.THROW_USAGE;
|
||||
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
String format = args[4].toLowerCase().replace("_", "-");
|
||||
if (!MMOCore.plugin.attributeManager.has(format)) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the attribute called " + args[4] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(format);
|
||||
|
||||
int amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(args[5]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
AttributeInstance instance = PlayerData.get(player).getAttributes().getInstance(attribute);
|
||||
instance.setBase(Math.min(attribute.getMax(), instance.getBase() + c * amount));
|
||||
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + instance.getBase()
|
||||
+ ChatColor.YELLOW + " " + attribute.getName() + ".");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
return CommandResult.THROW_USAGE;
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ public class PointsCommandTreeNode extends CommandTreeNode {
|
||||
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + ".");
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -41,5 +41,4 @@ public class AttributeManager extends MMOManager {
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user