mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-26 00:35:17 +01:00
Force class on profile selection
This commit is contained in:
parent
651e46697e
commit
7e134aac1d
@ -669,7 +669,11 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
||||
}
|
||||
|
||||
public void unloadClassInfo(PlayerClass profess) {
|
||||
classSlots.remove(profess.getId());
|
||||
unloadClassInfo(profess.getId());
|
||||
}
|
||||
|
||||
public void unloadClassInfo(String profess) {
|
||||
classSlots.remove(profess);
|
||||
}
|
||||
|
||||
public Set<String> getWaypoints() {
|
||||
|
@ -0,0 +1,79 @@
|
||||
package net.Indyuce.mmocore.comp.profile;
|
||||
|
||||
import fr.phoenixdevt.profile.ProfileDataModule;
|
||||
import fr.phoenixdevt.profile.ProfileProvider;
|
||||
import fr.phoenixdevt.profile.event.ProfileCreateEvent;
|
||||
import fr.phoenixdevt.profile.event.ProfileRemoveEvent;
|
||||
import fr.phoenixdevt.profile.event.ProfileSelectEvent;
|
||||
import fr.phoenixdevt.profile.event.ProfileUnloadEvent;
|
||||
import fr.phoenixdevt.profile.placeholder.PlaceholderRequest;
|
||||
import io.lumine.mythic.lib.api.event.SynchronizedDataLoadEvent;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ForceClassProfileDataModule implements ProfileDataModule, Listener {
|
||||
public ForceClassProfileDataModule() {
|
||||
final ProfileProvider<?> provider = Bukkit.getServicesManager().getRegistration(ProfileProvider.class).getProvider();
|
||||
provider.registerModule(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getOwningPlugin() {
|
||||
return MMOCore.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlaceholders() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "mmocore_force_class";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPlaceholderRequest(PlaceholderRequest placeholderRequest) {
|
||||
throw new RuntimeException("Not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Force class before profile creation
|
||||
*/
|
||||
@EventHandler
|
||||
public void onProfileCreate(ProfileCreateEvent event) {
|
||||
final PlayerData playerData = PlayerData.get(event.getPlayerData().getUniqueId());
|
||||
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force class before profile selection once MMOCore loaded its data
|
||||
*/
|
||||
@EventHandler
|
||||
public void onDataLoad(SynchronizedDataLoadEvent event) {
|
||||
if (event.getManager().getOwningPlugin().equals(MMOCore.plugin)) {
|
||||
final PlayerData playerData = (PlayerData) event.getHolder();
|
||||
final ProfileSelectEvent event1 = (ProfileSelectEvent) event.getProfileEvent();
|
||||
|
||||
// Validate if necessary
|
||||
if (playerData.getProfess().equals(MMOCore.plugin.classManager.getDefaultClass()))
|
||||
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event1.validate(this)).open();
|
||||
else event1.validate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProfileRemove(ProfileRemoveEvent event) {
|
||||
event.validate(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProfileUnload(ProfileUnloadEvent event) {
|
||||
event.validate(this);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package net.Indyuce.mmocore.comp.profile;
|
||||
|
||||
import fr.phoenixdevt.profile.ProfileDataModule;
|
||||
import fr.phoenixdevt.profile.event.ProfileCreateEvent;
|
||||
import fr.phoenixdevt.profile.event.ProfileDeleteEvent;
|
||||
import fr.phoenixdevt.profile.event.ProfileRemoveEvent;
|
||||
import fr.phoenixdevt.profile.placeholder.PlaceholderRequest;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
@ -10,8 +10,6 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.experience.Profession;
|
||||
import net.Indyuce.mmocore.manager.InventoryManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -55,19 +53,11 @@ public class MMOCoreProfileDataModule implements ProfileDataModule, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onProfileCreate(ProfileCreateEvent event) {
|
||||
|
||||
// Force to choose class first
|
||||
if (MMOCore.plugin.configManager.forceClassSelection) {
|
||||
final PlayerData playerData = PlayerData.get(event.getPlayerData().getUniqueId());
|
||||
InventoryManager.CLASS_SELECT.newInventory(playerData, () -> event.validate(this)).open();
|
||||
}
|
||||
|
||||
// Validate event directly
|
||||
else event.validate(this);
|
||||
event.validate(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProfileDelete(ProfileDeleteEvent event) {
|
||||
public void onProfileDelete(ProfileRemoveEvent event) {
|
||||
event.validate(this);
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ public class ClassConfirmation extends EditableInventory {
|
||||
return function.equalsIgnoreCase("yes") ? new YesItem(config) : new SimplePlaceholderItem(config);
|
||||
}
|
||||
|
||||
public GeneratedInventory newInventory(PlayerData data, PluginInventory last, boolean subclass) {
|
||||
return newInventory(data, last, subclass, null);
|
||||
public GeneratedInventory newInventory(PlayerData data, PluginInventory last, boolean setClass) {
|
||||
return newInventory(data, last, setClass, null);
|
||||
}
|
||||
|
||||
public GeneratedInventory newInventory(PlayerData data, PluginInventory last, boolean subclass, @Nullable Runnable profileRunnable) {
|
||||
return new ClassConfirmationInventory(data, this, playerClass, last, subclass, profileRunnable);
|
||||
public GeneratedInventory newInventory(PlayerData data, PluginInventory last, boolean setClass, @Nullable Runnable profileRunnable) {
|
||||
return new ClassConfirmationInventory(data, this, playerClass, last, setClass, profileRunnable);
|
||||
}
|
||||
|
||||
public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
|
||||
|
@ -143,7 +143,7 @@ public class ClassSelect extends EditableInventory {
|
||||
|
||||
canClose = true;
|
||||
final PlayerClass playerClass = findDeepestSubclass(playerData, profess);
|
||||
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(playerData, this, false, profileRunnable).open();
|
||||
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(playerData, this, profileRunnable != null, profileRunnable).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package net.Indyuce.mmocore.manager.data.sql;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.data.sql.SQLDataSynchronizer;
|
||||
@ -32,7 +35,8 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
|
||||
|
||||
@Override
|
||||
public void loadData(ResultSet result) throws SQLException {
|
||||
//Reset stats linked to triggers
|
||||
|
||||
// Reset stats linked to triggers
|
||||
getData().resetTriggerStats();
|
||||
|
||||
getData().setClassPoints(result.getInt("class_points"));
|
||||
@ -137,16 +141,7 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
|
||||
|
||||
@Override
|
||||
public void loadEmptyData() {
|
||||
final PlayerDataManager manager = MMOCore.plugin.playerDataManager;
|
||||
getData().setLevel(manager.getDefaultData().getLevel());
|
||||
getData().setClassPoints(manager.getDefaultData().getClassPoints());
|
||||
getData().setSkillPoints(manager.getDefaultData().getSkillPoints());
|
||||
getData().setSkillReallocationPoints(manager.getDefaultData().getSkillReallocationPoints());
|
||||
getData().setAttributePoints(manager.getDefaultData().getAttributePoints());
|
||||
getData().setAttributeReallocationPoints(manager.getDefaultData().getAttributeReallocationPoints());
|
||||
getData().setExperience(0);
|
||||
getData().getQuestData().updateBossBar();
|
||||
|
||||
MMOCore.plugin.playerDataManager.getDefaultData().apply(getData());
|
||||
UtilityMethods.debug(MMOCore.plugin, "SQL", "Loaded DEFAULT data for: '" + getData().getUniqueId() + "' as no saved data was found.");
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,12 @@ package net.Indyuce.mmocore.manager.data.yaml;
|
||||
|
||||
import io.lumine.mythic.lib.data.yaml.YAMLSynchronizedDataHandler;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||
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.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.guild.provided.Guild;
|
||||
import net.Indyuce.mmocore.player.DefaultPlayerData;
|
||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.skill.ClassSkill;
|
||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@ -17,7 +16,8 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -42,17 +42,21 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
||||
// Reset stats linked to triggers.
|
||||
data.resetTriggerStats();
|
||||
|
||||
final DefaultPlayerData defaultData = MMOCore.plugin.playerDataManager.getDefaultData();
|
||||
data.setClassPoints(config.getInt("class-points", defaultData.getClassPoints()));
|
||||
data.setSkillPoints(config.getInt("skill-points", defaultData.getSkillPoints()));
|
||||
data.setSkillReallocationPoints(config.getInt("skill-reallocation-points", defaultData.getSkillReallocationPoints()));
|
||||
data.setSkillTreeReallocationPoints(config.getInt("skill-tree-reallocation-points", defaultData.getSkillTreeReallocationPoints()));
|
||||
data.setAttributePoints(config.getInt("attribute-points", defaultData.getAttributePoints()));
|
||||
data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points", defaultData.getAttributeReallocationPoints()));
|
||||
data.setLevel(config.getInt("level", defaultData.getLevel()));
|
||||
// Load default data
|
||||
if (!config.contains("class-points")) {
|
||||
MMOCore.plugin.playerDataManager.getDefaultData().apply(data);
|
||||
return;
|
||||
}
|
||||
|
||||
data.setClassPoints(config.getInt("class-points"));
|
||||
data.setSkillPoints(config.getInt("skill-points"));
|
||||
data.setSkillReallocationPoints(config.getInt("skill-reallocation-points"));
|
||||
data.setSkillTreeReallocationPoints(config.getInt("skill-tree-reallocation-points"));
|
||||
data.setAttributePoints(config.getInt("attribute-points"));
|
||||
data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points"));
|
||||
data.setLevel(config.getInt("level"));
|
||||
data.setExperience(config.getInt("experience"));
|
||||
if (config.contains("class"))
|
||||
data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
|
||||
if (config.contains("class")) data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
|
||||
|
||||
if (config.contains("guild")) {
|
||||
Guild guild = MMOCore.plugin.nativeGuildManager.getGuild(config.getString("guild"));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.player;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -136,13 +137,15 @@ public class DefaultPlayerData implements ClassDataContainer {
|
||||
|
||||
public void apply(PlayerData player) {
|
||||
player.setLevel(level);
|
||||
player.setExperience(0);
|
||||
player.setClassPoints(classPoints);
|
||||
player.setSkillPoints(skillPoints);
|
||||
player.setAttributePoints(attributePoints);
|
||||
player.setAttributeReallocationPoints(attrReallocPoints);
|
||||
player.setSkillTreeReallocationPoints(skillTreeReallocPoints);
|
||||
player.setSkillReallocationPoints(skillReallocPoints);
|
||||
player.getPlayer().setHealth(Math.min(health, player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||
if (player.isOnline())
|
||||
player.getPlayer().setHealth(Math.min(health, player.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||
player.setMana(mana);
|
||||
player.setStamina(stamina);
|
||||
player.setStellium(stellium);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.Indyuce.mmocore;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.comp.profile.ForceClassProfileDataModule;
|
||||
import net.Indyuce.mmocore.listener.*;
|
||||
import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener;
|
||||
import net.Indyuce.mmocore.listener.option.*;
|
||||
@ -38,6 +40,9 @@ public class MMOCoreBukkit {
|
||||
if (plugin.getConfig().getBoolean("vanilla-exp-redirection.enabled"))
|
||||
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(plugin.getConfig().getDouble("vanilla-exp-redirection.ratio")), plugin);
|
||||
|
||||
if (plugin.getConfig().getBoolean("force-class-selection") && MythicLib.plugin.hasProfiles())
|
||||
new ForceClassProfileDataModule();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new WaypointsListener(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), plugin);
|
||||
|
@ -195,7 +195,8 @@ override-vanilla-exp: true
|
||||
|
||||
# When enabled and when using a profile plugin, MMOCore will
|
||||
# force the user to choose a class. The profile will not be
|
||||
# created until they choose a class.
|
||||
# created until they choose a class. Similarly, a player cannot
|
||||
# log into a profile with default class before choosing another class
|
||||
#
|
||||
# This option is useless unless you have installed a profile plugin.
|
||||
force-class-selection: true
|
||||
|
Loading…
Reference in New Issue
Block a user