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