From ed9c86942bd71e11259dc3ce2b041ceae1d8a0b9 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Thu, 1 Oct 2020 16:30:40 +0200 Subject: [PATCH] Added default values for playerdata in config.yml This means you can now set the starting amount of most points, etc. without having to run commands on first player join! --- dependency-reduced-pom.xml | 10 +- pom.xml | 386 +++++++++--------- .../java/net/Indyuce/mmocore/MMOCore.java | 8 +- .../manager/data/PlayerDataManager.java | 33 +- .../manager/data/mysql/MySQLDataProvider.java | 5 +- .../data/mysql/MySQLPlayerDataManager.java | 33 +- .../data/yaml/YAMLPlayerDataManager.java | 12 +- src/main/resources/config.yml | 9 + 8 files changed, 276 insertions(+), 220 deletions(-) diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index a5c1f652..fb7756df 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -44,10 +44,6 @@ io.papermc.lib net.indyuce.mmocore.shaded.paperlib - - com.github.jasync.sql.db - eu.asangarin.sqltest - @@ -90,6 +86,12 @@ 7.0.2-SNAPSHOT provided + + org.projectlombok + lombok + 1.18.12 + provided + net.Indyuce mmoitems diff --git a/pom.xml b/pom.xml index e07986b4..a76f8192 100644 --- a/pom.xml +++ b/pom.xml @@ -1,199 +1,205 @@ - 4.0.0 - net.Indyuce - MMOCore - 1.4.7 - MMOCore - Offer your players a brand new RPG experience. + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + net.Indyuce + MMOCore + 1.4.7 + MMOCore + Offer your players a brand new RPG experience. - - SNAPSHOT - false - false - UTF-8 - UTF-8 - + + SNAPSHOT + false + false + UTF-8 + UTF-8 + - - - nexus - Lumine Releases - http://mvn.lumine.io/repository/maven-releases/ - - - nexus - Lumine Snapshots - http://mvn.lumine.io/repository/maven-snapshots/ - - + + + nexus + Lumine Releases + http://mvn.lumine.io/repository/maven-releases/ + + + nexus + Lumine Snapshots + http://mvn.lumine.io/repository/maven-snapshots/ + + - - ${project.name}-${project.version} - - - true - ${basedir}/src/main/resources/ - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - junit:junit - UTF-8 - UTF-8 - UTF-8 - -ea -Dfile.encoding=UTF-8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - - io.papermc.lib - net.indyuce.mmocore.shaded.paperlib - - - - - - package - - shade - - - - - - - - - jitpack.io - https://jitpack.io - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - sk89q-repo - https://maven.enginehub.org/repo/ - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - + + ${project.name}-${project.version} + + + true + ${basedir}/src/main/resources/ + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + junit:junit + UTF-8 + UTF-8 + UTF-8 + -ea -Dfile.encoding=UTF-8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + + io.papermc.lib + net.indyuce.mmocore.shaded.paperlib + + + + + + package + + shade + + + + + + + + + jitpack.io + https://jitpack.io + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sk89q-repo + https://maven.enginehub.org/repo/ + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + - - - net.Indyuce - mmoitems - 6.1.2 - system - ${basedir}/lib/MMOItems.jar - - - net.Indyuce - MMOLib - 1.3 - system - ${basedir}/lib/MMOLib.jar - + + + net.Indyuce + mmoitems + 6.1.2 + system + ${basedir}/lib/MMOItems.jar + + + net.Indyuce + MMOLib + 1.3 + system + ${basedir}/lib/MMOLib.jar + - - - org.spigotmc - spigot-api - 1.12-R1-1.16-R2 - system - ${basedir}/lib/spigot.jar - + + + org.spigotmc + spigot-api + 1.12-R1-1.16-R2 + system + ${basedir}/lib/spigot.jar + - - - org.jetbrains - annotations - 19.0.0 - provided - - - io.papermc - paperlib - 1.0.5 - compile - + + + org.jetbrains + annotations + 19.0.0 + provided + + + io.papermc + paperlib + 1.0.5 + compile + - - - com.bekvon.bukkit - Residence - 4.8.7.2 - system - ${basedir}/lib/Residence.jar - - - com.Zrips - CMI - 8.6.5.0 - system - ${basedir}/lib/CMI.jar - - - com.sainttx.holograms - holograms - 2.9.1 - system - ${basedir}/lib/Holograms.jar - - - com.gmail.filoghost - HolographicDisplays - 6.9.1 - system - ${basedir}/lib/HolographicDisplays.jar - - - io.lumine.xikage - MythicMobs - 4.8.0 - system - ${basedir}/lib/MythicMobs.jar - - - com.github.MilkBowl - VaultAPI - 1.7 - provided - - - com.sk89q.worldguard - worldguard-bukkit - 7.0.2-SNAPSHOT - provided - - - net.citizensnpcs - citizens - 2.0.25-SNAPSHOT - system - ${basedir}/lib/Citizens.jar - - - me.clip - placeholderapi - 2.10.7 - system - ${basedir}/lib/PlaceholderAPI.jar - - + + + com.bekvon.bukkit + Residence + 4.8.7.2 + system + ${basedir}/lib/Residence.jar + + + com.Zrips + CMI + 8.6.5.0 + system + ${basedir}/lib/CMI.jar + + + com.sainttx.holograms + holograms + 2.9.1 + system + ${basedir}/lib/Holograms.jar + + + com.gmail.filoghost + HolographicDisplays + 6.9.1 + system + ${basedir}/lib/HolographicDisplays.jar + + + io.lumine.xikage + MythicMobs + 4.8.0 + system + ${basedir}/lib/MythicMobs.jar + + + com.github.MilkBowl + VaultAPI + 1.7 + provided + + + com.sk89q.worldguard + worldguard-bukkit + 7.0.2-SNAPSHOT + provided + + + net.citizensnpcs + citizens + 2.0.25-SNAPSHOT + system + ${basedir}/lib/Citizens.jar + + + me.clip + placeholderapi + 2.10.7 + system + ${basedir}/lib/PlaceholderAPI.jar + + + org.projectlombok + lombok + 1.18.12 + provided + + \ No newline at end of file diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 91f54c40..acabcc5b 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -161,13 +161,16 @@ public class MMOCore extends JavaPlugin { } public void onEnable() { - new SpigotPlugin(70575, this).checkForUpdate(); new Metrics(this); - + saveDefaultConfig(); + if (getConfig().contains("mysql") && getConfig().getBoolean("mysql.enabled")) dataProvider = new MySQLDataProvider(); + if(getConfig().isConfigurationSection("default-playerdata")) + dataProvider.getDataManager().setDefaults(getConfig().getConfigurationSection("default-playerdata")); + if (Bukkit.getPluginManager().getPlugin("Vault") != null) economy = new VaultEconomy(); @@ -247,7 +250,6 @@ public class MMOCore extends JavaPlugin { return; } - saveDefaultConfig(); reloadPlugin(); if (getConfig().getBoolean("vanilla-exp-redirection.enabled")) diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java index 6bea17d5..126655ff 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/PlayerDataManager.java @@ -6,8 +6,10 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; +import lombok.Getter; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent; import net.Indyuce.mmocore.api.player.OfflinePlayerData; @@ -16,6 +18,7 @@ import net.mmogroup.mmolib.api.player.MMOPlayerData; public abstract class PlayerDataManager { // private final Map map = new HashMap<>(); + private DefaultPlayerData defaults = new DefaultPlayerData(); public PlayerData get(OfflinePlayer player) { return get(player.getUniqueId()); @@ -48,7 +51,7 @@ public abstract class PlayerDataManager { * calls the load event on the MAIN thread */ Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> { - loadData(generated); + loadData(generated, defaults); Bukkit.getScheduler().runTask(MMOCore.plugin, () -> Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(generated))); generated.getStats().updateStats(); }); @@ -63,9 +66,35 @@ public abstract class PlayerDataManager { return MMOPlayerData.getLoaded().stream().filter(data -> data.getMMOCore() != null).map(data -> data.getMMOCore()).collect(Collectors.toSet()); } - public abstract void loadData(PlayerData data); + public abstract void loadData(PlayerData data, DefaultPlayerData defaults); public abstract void saveData(PlayerData data); public abstract void remove(PlayerData data); + + public void setDefaults(ConfigurationSection config) { + defaults = new DefaultPlayerData(config); + } + + @Getter + public class DefaultPlayerData { + private final int level, classPoints, skillPoints, + attributePoints, attrReallocPoints; + + public DefaultPlayerData(ConfigurationSection config) { + level = config.getInt("level", 1); + classPoints = config.getInt("class-points"); + skillPoints = config.getInt("skill-points"); + attributePoints = config.getInt("attribute-points"); + attrReallocPoints = config.getInt("attribute-realloc-points"); + } + + public DefaultPlayerData() { + level = 1; + classPoints = 0; + skillPoints = 0; + attributePoints = 0; + attrReallocPoints = 0; + } + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java index ea7a328d..96cf93c4 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLDataProvider.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.manager.data.mysql; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.logging.Level; import org.bukkit.configuration.ConfigurationSection; @@ -27,7 +28,7 @@ public class MySQLDataProvider implements DataProvider { config = new MySQLConfig(MMOCore.plugin.getConfig().getConfigurationSection("mysql")); connection = MySQLConnectionBuilder.createConnectionPool(config.getConnectionString()); - executeUpdate("CREATE TABLE IF NOT EXISTS mmocore_playerdata (uuid VARCHAR(36),class_points INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 0,experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,attributes JSON,professions JSON,quests JSON,waypoints JSON,friends JSON,skills JSON,bound_skills JSON,class_info JSON,PRIMARY KEY (uuid));"); + executeUpdate("CREATE TABLE IF NOT EXISTS mmocore_playerdata (uuid VARCHAR(36),class_points INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 1,experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,attributes JSON,professions JSON,quests JSON,waypoints JSON,friends JSON,skills JSON,bound_skills JSON,class_info JSON,PRIMARY KEY (uuid));"); } public ResultSet getResult(String sql) { @@ -35,6 +36,7 @@ public class MySQLDataProvider implements DataProvider { CompletableFuture future = connection.sendPreparedStatement(sql); return future.get().getRows(); } catch (InterruptedException | ExecutionException e) { + MMOCore.log(Level.SEVERE, "MySQL Operation Failed!"); e.printStackTrace(); return null; } @@ -44,6 +46,7 @@ public class MySQLDataProvider implements DataProvider { try { connection.sendPreparedStatement(sql).get(); } catch (InterruptedException | ExecutionException e) { + MMOCore.log(Level.SEVERE, "MySQL Operation Failed!"); e.printStackTrace(); } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 24915b44..2c241d18 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -33,19 +33,26 @@ public class MySQLPlayerDataManager extends PlayerDataManager { } @Override - public void loadData(PlayerData data) { + public void loadData(PlayerData data, DefaultPlayerData defaults) { ResultSet result = provider .getResult("SELECT * FROM mmocore_playerdata WHERE uuid = '" + data.getUniqueId() + "';"); - if (result == null) { - MMOCore.log(Level.SEVERE, - "Failed to load playerdata of '" + data.getPlayer().getName() + "' from MySQL server"); + + // player data not initialized yet + if (result.size() < 1) { + data.setLevel(defaults.getLevel()); + data.setClassPoints(defaults.getClassPoints()); + data.setSkillPoints(defaults.getSkillPoints()); + data.setAttributePoints(defaults.getAttributePoints()); + data.setAttributeReallocationPoints(defaults.getAttrReallocPoints()); + data.setExperience(0); + data.setMana(data.getStats().getStat(StatType.MAX_MANA)); + data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); + data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + data.getQuestData().updateBossBar(); + return; } - // player data not initialized yet - if (result.size() < 1) - return; - RowData row = result.get(0); data.setClassPoints(row.getInt("class_points")); @@ -66,9 +73,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager { data.getAttributes().load(row.getString("attributes")); if (!isEmpty(row.getString("professions"))) data.getCollectionSkills().load(row.getString("professions")); - String quests = row.getString("quests"); - if (!isEmpty(quests)) - data.getQuestData().load(quests); + if (!isEmpty(row.getString("quests"))) + data.getQuestData().load(row.getString("quests")); data.getQuestData().updateBossBar(); if (!isEmpty(row.getString("waypoints"))) data.getWaypoints().addAll(getJSONArray(row.getString("waypoints"))); @@ -191,10 +197,9 @@ public class MySQLPlayerDataManager extends PlayerDataManager { level = row.getInt("level"); lastLogin = row.getLong("last_login"); - profess = row.getString("class").equalsIgnoreCase("null") - ? MMOCore.plugin.classManager.getDefaultClass() + profess = isEmpty(row.getString("class")) ? MMOCore.plugin.classManager.getDefaultClass() : MMOCore.plugin.classManager.get(row.getString("class")); - if (!row.getString("friends").equalsIgnoreCase("null")) + if (!isEmpty(row.getString("friends"))) getJSONArray(row.getString("friends")).forEach(str -> friends.add(UUID.fromString(str))); else friends = new ArrayList(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index 1abc3906..f25f4df1 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -21,14 +21,14 @@ import net.Indyuce.mmocore.manager.data.PlayerDataManager; public class YAMLPlayerDataManager extends PlayerDataManager { @Override - public void loadData(PlayerData data) { + public void loadData(PlayerData data, DefaultPlayerData defaults) { FileConfiguration config = new ConfigFile(data.getPlayer()).getConfig(); - data.setClassPoints(config.getInt("class-points")); - data.setSkillPoints(config.getInt("skill-points")); - data.setAttributePoints(config.getInt("attribute-points")); - data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points")); - data.setLevel(config.getInt("level")); + data.setClassPoints(config.getInt("class-points", defaults.getClassPoints())); + data.setSkillPoints(config.getInt("skill-points", defaults.getSkillPoints())); + data.setAttributePoints(config.getInt("attribute-points", defaults.getAttributePoints())); + data.setAttributeReallocationPoints(config.getInt("attribute-realloc-points", defaults.getAttrReallocPoints())); + data.setLevel(config.getInt("level", defaults.getLevel())); data.setExperience(config.getInt("experience")); if (config.contains("class")) data.setClass(MMOCore.plugin.classManager.get(config.getString("class"))); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bba5044d..75e1a39c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,6 +14,15 @@ mysql: user: mmolover pass: ILoveAria +# The default values for all playerdata +# All new players will start with these values +default-playerdata: + level: 1 + class-points: 0 + skill-points: 0 + attribute-points: 0 + attribute-realloc-points: 0 + # The list of all conditions which must be met for the # BLOCK REGEN and BLOCK RESTRICTIONS to apply. Set to # 'custom-mine-conditions: []' to disable custom mining entirely.