forked from Upstream/mmocore
!small refactor
added force class command
This commit is contained in:
parent
0bf926eba3
commit
610045c319
@ -13,6 +13,7 @@ import com.google.gson.JsonObject;
|
|||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||||
import net.Indyuce.mmocore.api.skill.Skill;
|
import net.Indyuce.mmocore.api.skill.Skill;
|
||||||
|
import net.Indyuce.mmocore.manager.data.PlayerDataManager.DefaultPlayerData;
|
||||||
|
|
||||||
public class SavedClassInformation {
|
public class SavedClassInformation {
|
||||||
private final int level, experience, skillPoints, attributePoints, attributeReallocationPoints;
|
private final int level, experience, skillPoints, attributePoints, attributeReallocationPoints;
|
||||||
@ -53,23 +54,26 @@ public class SavedClassInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(PlayerData player) {
|
public SavedClassInformation(PlayerData player) {
|
||||||
level = player.getLevel();
|
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(),
|
||||||
skillPoints = player.getSkillPoints();
|
player.getAttributeReallocationPoints(), player.mapSkillLevels(), player.getAttributes().mapPoints());
|
||||||
experience = player.getExperience();
|
}
|
||||||
skills = player.mapSkillLevels();
|
|
||||||
attributes = player.getAttributes().mapPoints();
|
public SavedClassInformation(DefaultPlayerData data) {
|
||||||
attributePoints = player.getAttributePoints();
|
this(data.getLevel(), 0, data.getSkillPoints(), data.getAttributePoints(), data.getAttrReallocPoints());
|
||||||
attributeReallocationPoints = player.getAttributeReallocationPoints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedClassInformation(int level, int experience, int skillPoints, int attributePoints, int attributeReallocationPoints) {
|
public SavedClassInformation(int level, int experience, int skillPoints, int attributePoints, int attributeReallocationPoints) {
|
||||||
this.level = level;
|
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, new HashMap<>(), new HashMap<>());
|
||||||
this.experience = experience;
|
}
|
||||||
this.skillPoints = skillPoints;
|
|
||||||
this.attributePoints = attributePoints;
|
private SavedClassInformation(int l, int e, int sp, int ap, int arp, Map<String, Integer> a, Map<String, Integer> s) {
|
||||||
this.attributeReallocationPoints = attributeReallocationPoints;
|
this.level = l;
|
||||||
attributes = new HashMap<>();
|
this.experience = e;
|
||||||
skills = new HashMap<>();
|
this.skillPoints = sp;
|
||||||
|
this.attributePoints = ap;
|
||||||
|
this.attributeReallocationPoints = arp;
|
||||||
|
this.attributes = a;
|
||||||
|
this.skills = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel() {
|
public int getLevel() {
|
||||||
|
@ -7,12 +7,13 @@ import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
|||||||
public class AdminCommandTreeNode extends CommandTreeNode {
|
public class AdminCommandTreeNode extends CommandTreeNode {
|
||||||
public AdminCommandTreeNode(CommandTreeNode parent) {
|
public AdminCommandTreeNode(CommandTreeNode parent) {
|
||||||
super(parent, "admin");
|
super(parent, "admin");
|
||||||
|
|
||||||
addChild(new HideActionBarCommandTreeNode(this));
|
addChild(new HideActionBarCommandTreeNode(this));
|
||||||
addChild(new NoCooldownCommandTreeNode(this));
|
addChild(new NoCooldownCommandTreeNode(this));
|
||||||
addChild(new ResetCommandTreeNode(this));
|
addChild(new ResetCommandTreeNode(this));
|
||||||
addChild(new InfoCommandTreeNode(this));
|
addChild(new InfoCommandTreeNode(this));
|
||||||
addChild(new ClassCommandTreeNode(this));
|
addChild(new ClassCommandTreeNode(this));
|
||||||
|
addChild(new ForceClassCommandTreeNode(this));
|
||||||
|
|
||||||
addChild(new ExperienceCommandTreeNode(this));
|
addChild(new ExperienceCommandTreeNode(this));
|
||||||
addChild(new LevelCommandTreeNode(this));
|
addChild(new LevelCommandTreeNode(this));
|
||||||
|
@ -2,12 +2,15 @@ package net.Indyuce.mmocore.command.rpg.admin;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||||
|
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
|
||||||
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||||
import net.mmogroup.mmolib.command.api.Parameter;
|
import net.mmogroup.mmolib.command.api.Parameter;
|
||||||
|
|
||||||
@ -16,8 +19,8 @@ public class ClassCommandTreeNode extends CommandTreeNode {
|
|||||||
super(parent, "class");
|
super(parent, "class");
|
||||||
|
|
||||||
addParameter(Parameter.PLAYER);
|
addParameter(Parameter.PLAYER);
|
||||||
addParameter(
|
addParameter(new Parameter("<class>", (explorer, list) -> MMOCore.plugin.classManager.getAll()
|
||||||
new Parameter("<class>", (explorer, list) -> MMOCore.plugin.classManager.getAll().forEach(profess -> list.add(profess.getId()))));
|
.forEach(profess -> list.add(profess.getId()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -40,9 +43,24 @@ public class ClassCommandTreeNode extends CommandTreeNode {
|
|||||||
PlayerClass profess = MMOCore.plugin.classManager.get(format);
|
PlayerClass profess = MMOCore.plugin.classManager.get(format);
|
||||||
|
|
||||||
PlayerData data = PlayerData.get(player);
|
PlayerData data = PlayerData.get(player);
|
||||||
data.setClass(profess);
|
PlayerChangeClassEvent called = new PlayerChangeClassEvent(data, profess);
|
||||||
sender.sendMessage(
|
Bukkit.getPluginManager().callEvent(called);
|
||||||
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + ".");
|
if (called.isCancelled())
|
||||||
|
return CommandResult.SUCCESS;
|
||||||
|
|
||||||
|
data.giveClassPoints(-1);
|
||||||
|
(data.hasSavedClass(profess) ? data.getClassInfo(profess) : new SavedClassInformation(
|
||||||
|
MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, data);
|
||||||
|
while (data.hasSkillBound(0))
|
||||||
|
data.unbindSkill(0);
|
||||||
|
if (data.isOnline()) {
|
||||||
|
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName())
|
||||||
|
.send(data.getPlayer());
|
||||||
|
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD
|
||||||
|
+ profess.getName() + ChatColor.YELLOW + ".");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
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.profess.PlayerClass;
|
||||||
|
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||||
|
import net.mmogroup.mmolib.command.api.Parameter;
|
||||||
|
|
||||||
|
public class ForceClassCommandTreeNode extends CommandTreeNode {
|
||||||
|
public ForceClassCommandTreeNode(CommandTreeNode parent) {
|
||||||
|
super(parent, "force-class");
|
||||||
|
|
||||||
|
addParameter(Parameter.PLAYER);
|
||||||
|
addParameter(
|
||||||
|
new Parameter("<class>", (explorer, list) -> MMOCore.plugin.classManager.getAll().forEach(profess -> list.add(profess.getId()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(CommandSender sender, String[] args) {
|
||||||
|
if (args.length < 4)
|
||||||
|
return CommandResult.THROW_USAGE;
|
||||||
|
|
||||||
|
Player player = Bukkit.getPlayer(args[2]);
|
||||||
|
if (player == null) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + ".");
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
String format = args[3].toUpperCase().replace("-", "_");
|
||||||
|
if (!MMOCore.plugin.classManager.has(format)) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Could not find class " + format + ".");
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerClass profess = MMOCore.plugin.classManager.get(format);
|
||||||
|
|
||||||
|
PlayerData data = PlayerData.get(player);
|
||||||
|
data.setClass(profess);
|
||||||
|
sender.sendMessage(
|
||||||
|
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + ".");
|
||||||
|
return CommandResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
@ -92,7 +92,9 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack display(GeneratedInventory inv, int n) {
|
public ItemStack display(GeneratedInventory inv, int n) {
|
||||||
return inv.getPlayerData().hasSavedClass(((ClassConfirmationInventory) inv).profess) ? unlocked.display(inv, n) : locked.display(inv, n);
|
return inv.getPlayerData().hasSavedClass(((ClassConfirmationInventory) inv).profess)
|
||||||
|
? unlocked.display(inv, n)
|
||||||
|
: locked.display(inv, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,7 +107,8 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
private final PlayerClass profess;
|
private final PlayerClass profess;
|
||||||
private final PluginInventory last;
|
private final PluginInventory last;
|
||||||
|
|
||||||
public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) {
|
public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess,
|
||||||
|
PluginInventory last) {
|
||||||
super(playerData, editable);
|
super(playerData, editable);
|
||||||
|
|
||||||
this.profess = profess;
|
this.profess = profess;
|
||||||
@ -128,7 +131,8 @@ public class ClassConfirmation extends EditableInventory {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
playerData.giveClassPoints(-1);
|
playerData.giveClassPoints(-1);
|
||||||
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) : new SavedClassInformation(1, 0, 0, 0, 0)).load(profess, playerData);
|
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) : new SavedClassInformation(
|
||||||
|
MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
|
||||||
while (playerData.hasSkillBound(0))
|
while (playerData.hasSkillBound(0))
|
||||||
playerData.unbindSkill(0);
|
playerData.unbindSkill(0);
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
|
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
|
||||||
|
@ -99,25 +99,5 @@ public abstract class PlayerDataManager {
|
|||||||
attributePoints = 0;
|
attributePoints = 0;
|
||||||
attrReallocPoints = 0;
|
attrReallocPoints = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLevel() {
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSkillPoints() {
|
|
||||||
return skillPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getClassPoints() {
|
|
||||||
return classPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAttributeReallocationPoints() {
|
|
||||||
return attrReallocPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAttributePoints() {
|
|
||||||
return attributePoints;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setClassPoints(getDefaultData().getClassPoints());
|
data.setClassPoints(getDefaultData().getClassPoints());
|
||||||
data.setSkillPoints(getDefaultData().getSkillPoints());
|
data.setSkillPoints(getDefaultData().getSkillPoints());
|
||||||
data.setAttributePoints(getDefaultData().getAttributePoints());
|
data.setAttributePoints(getDefaultData().getAttributePoints());
|
||||||
data.setAttributeReallocationPoints(getDefaultData().getAttributeReallocationPoints());
|
data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints());
|
||||||
data.setExperience(0);
|
data.setExperience(0);
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
||||||
|
@ -27,7 +27,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints()));
|
data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints()));
|
||||||
data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints()));
|
data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints()));
|
||||||
data.setAttributePoints(config.getInt("attribute-points", getDefaultData().getAttributePoints()));
|
data.setAttributePoints(config.getInt("attribute-points", getDefaultData().getAttributePoints()));
|
||||||
data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points", getDefaultData().getAttributeReallocationPoints()));
|
data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points", getDefaultData().getAttrReallocPoints()));
|
||||||
data.setLevel(config.getInt("level", getDefaultData().getLevel()));
|
data.setLevel(config.getInt("level", getDefaultData().getLevel()));
|
||||||
data.setExperience(config.getInt("experience"));
|
data.setExperience(config.getInt("experience"));
|
||||||
if (config.contains("class"))
|
if (config.contains("class"))
|
||||||
|
Loading…
Reference in New Issue
Block a user