mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-27 05:28:25 +01:00
Fixed a crucial issue with saved classes data
This commit is contained in:
parent
04846d05bd
commit
968a3ec364
@ -29,10 +29,10 @@ public class SavedClassInformation {
|
||||
|
||||
attributes = new HashMap<>();
|
||||
if (config.contains("attribute"))
|
||||
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt(key)));
|
||||
config.getConfigurationSection("attribute").getKeys(false).forEach(key -> attributes.put(key, config.getInt("attribute." + key)));
|
||||
skills = new HashMap<>();
|
||||
if (config.contains("skill"))
|
||||
config.getConfigurationSection("skill").getKeys(false).forEach(key -> skills.put(key, config.getInt(key)));
|
||||
config.getConfigurationSection("skill").getKeys(false).forEach(key -> skills.put(key, config.getInt("skill." + key)));
|
||||
}
|
||||
|
||||
public SavedClassInformation(JsonObject json) {
|
||||
@ -150,9 +150,9 @@ public class SavedClassInformation {
|
||||
* resets information which much be reset after everything is saved.
|
||||
*/
|
||||
player.mapSkillLevels().forEach((skill, level) -> player.resetSkillLevel(skill));
|
||||
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
|
||||
while (player.hasSkillBound(0))
|
||||
player.unbindSkill(0);
|
||||
player.getAttributes().getInstances().forEach(ins -> ins.setBase(0));
|
||||
|
||||
/*
|
||||
* reads this class info, applies it to the player. set class after
|
||||
@ -164,6 +164,7 @@ public class SavedClassInformation {
|
||||
player.setSkillPoints(skillPoints);
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attributeReallocationPoints);
|
||||
|
||||
skills.forEach(player::setSkillLevel);
|
||||
attributes.forEach((id, pts) -> player.getAttributes().setBaseAttribute(id, pts));
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import net.Indyuce.mmocore.command.CommandVerbose;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
@ -12,6 +11,7 @@ import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
|
||||
import net.Indyuce.mmocore.command.CommandVerbose;
|
||||
import net.mmogroup.mmolib.command.api.CommandTreeNode;
|
||||
import net.mmogroup.mmolib.command.api.Parameter;
|
||||
|
||||
@ -20,8 +20,8 @@ public class ClassCommandTreeNode extends CommandTreeNode {
|
||||
super(parent, "class");
|
||||
|
||||
addParameter(Parameter.PLAYER);
|
||||
addParameter(new Parameter("<class>", (explorer, list) -> MMOCore.plugin.classManager.getAll()
|
||||
.forEach(profess -> list.add(profess.getId()))));
|
||||
addParameter(
|
||||
new Parameter("<class>", (explorer, list) -> MMOCore.plugin.classManager.getAll().forEach(profess -> list.add(profess.getId()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,26 +42,24 @@ public class ClassCommandTreeNode extends CommandTreeNode {
|
||||
}
|
||||
|
||||
PlayerClass profess = MMOCore.plugin.classManager.get(format);
|
||||
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if (data.getProfess().equals(profess))
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
PlayerChangeClassEvent called = new PlayerChangeClassEvent(data, profess);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
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);
|
||||
(data.hasSavedClass(profess) ? data.getClassInfo(profess)
|
||||
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, data);
|
||||
if (data.isOnline()) {
|
||||
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName())
|
||||
.send(data.getPlayer());
|
||||
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);
|
||||
}
|
||||
|
||||
CommandVerbose.verbose(sender, CommandVerbose.CommandType.CLASS, ChatColor.GOLD + player.getName()
|
||||
+ ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + ".");
|
||||
CommandVerbose.verbose(sender, CommandVerbose.CommandType.CLASS,
|
||||
ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + ".");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,7 @@ public class ClassConfirmation extends EditableInventory {
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -107,8 +105,7 @@ public class ClassConfirmation extends EditableInventory {
|
||||
private final PlayerClass profess;
|
||||
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);
|
||||
|
||||
this.profess = profess;
|
||||
@ -131,10 +128,8 @@ public class ClassConfirmation extends EditableInventory {
|
||||
return;
|
||||
|
||||
playerData.giveClassPoints(-1);
|
||||
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) : new SavedClassInformation(
|
||||
MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
|
||||
while (playerData.hasSkillBound(0))
|
||||
playerData.unbindSkill(0);
|
||||
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
|
||||
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
|
||||
MMOCore.plugin.soundManager.play(player, SoundManager.SoundEvent.SELECT_CLASS);
|
||||
player.closeInventory();
|
||||
|
@ -1,22 +1,23 @@
|
||||
package net.Indyuce.mmocore.manager.data;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
|
||||
public abstract class PlayerDataManager {
|
||||
private final static Map<UUID, PlayerData> data = new HashMap<>();
|
||||
private DefaultPlayerData defaultData = new DefaultPlayerData();
|
||||
private DefaultPlayerData defaultData = new DefaultPlayerData(1, 0, 0, 0, 0);
|
||||
|
||||
public PlayerData get(OfflinePlayer player) {
|
||||
return get(player.getUniqueId());
|
||||
@ -47,10 +48,11 @@ public abstract class PlayerDataManager {
|
||||
*/
|
||||
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
|
||||
PlayerData loaded = PlayerData.get(uuid);
|
||||
if(!loaded.isOnline()) return;
|
||||
if (!loaded.isOnline())
|
||||
return;
|
||||
loadData(loaded);
|
||||
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> {
|
||||
if(loaded.isOnline())
|
||||
if (loaded.isOnline())
|
||||
Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(loaded));
|
||||
});
|
||||
loaded.getStats().updateStats();
|
||||
@ -92,12 +94,12 @@ public abstract class PlayerDataManager {
|
||||
attrReallocPoints = config.getInt("attribute-realloc-points");
|
||||
}
|
||||
|
||||
public DefaultPlayerData() {
|
||||
level = 1;
|
||||
classPoints = 0;
|
||||
skillPoints = 0;
|
||||
attributePoints = 0;
|
||||
attrReallocPoints = 0;
|
||||
public DefaultPlayerData(int level, int classPoints, int skillPoints, int attributePoints, int attrReallocPoints) {
|
||||
this.level = level;
|
||||
this.classPoints = classPoints;
|
||||
this.skillPoints = skillPoints;
|
||||
this.attributePoints = attributePoints;
|
||||
this.attrReallocPoints = attrReallocPoints;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
@ -119,5 +121,13 @@ public abstract class PlayerDataManager {
|
||||
public int getAttributePoints() {
|
||||
return attributePoints;
|
||||
}
|
||||
|
||||
public void apply(PlayerData player) {
|
||||
player.setLevel(level);
|
||||
player.setClassPoints(classPoints);
|
||||
player.setSkillPoints(skillPoints);
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attrReallocPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user