9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-04 15:41:36 +00:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Auxilor
2021-09-26 13:51:53 +01:00
17 changed files with 211 additions and 61 deletions

View File

@@ -1,30 +1,27 @@
<h1 align="center">
<br>
<img src="https://i.imgur.com/nPWTJzV.png" alt="EcoSkills logo" width="256">
<img src="https://i.imgur.com/nOCGNDi.png" alt="EcoSkills logo" width="256">
<br>
</h1>
<h4 align="center">Source code for EcoSkills, a premium spigot plugin.</h4>
<p align="center">
<a href="https://www.spigotmc.org/resources/EcoSkills.94630/">
<img alt="spigot" src="https://img.shields.io/badge/spigot-EcoSkills-yellow?style=for-the-badge"/>
<a href="https://polymart.org/resource/1-16-1-17-ecoskills.1351">
<img alt="spigot" src="https://img.shields.io/badge/polymart-EcoSkills-ff00ae?style=for-the-badge"/>
</a>
<a href="https://bstats.org/plugin/bukkit/EcoSkills" alt="bstats servers">
<img src="https://img.shields.io/bstats/servers/12205?color=yellow&style=for-the-badge"/>
<img src="https://img.shields.io/bstats/servers/12205?color=ff00ae&style=for-the-badge"/>
</a>
<a href="https://bstats.org/plugin/bukkit/EcoSkills" alt="bstats players">
<img src="https://img.shields.io/bstats/players/12205?color=yellow&style=for-the-badge"/>
<img src="https://img.shields.io/bstats/players/12205?color=ff00ae&style=for-the-badge"/>
</a>
<a href="https://discord.gg/ZcwpSsE/" alt="Discord">
<img src="https://img.shields.io/discord/452518336627081236?label=discord&style=for-the-badge&color=yellow"/>
<img src="https://img.shields.io/discord/452518336627081236?label=discord&style=for-the-badge&color=ff00ae"/>
</a>
</p>
[![Title](https://i.imgur.com/XFSPL6M.png)]()
[![Features](https://i.imgur.com/dXKoMCL.png)]()
[![Docs](https://i.imgur.com/liqcxwv.png)](https://discord.gg/ZcwpSsE/)
[![Compatibility](https://i.imgur.com/6jm7fVS.png)]()
[![Docs](https://i.imgur.com/wssvbsS.png)](https://discord.gg/ZcwpSsE/)
## License
*Click here to read [the entire license](https://github.com/Auxilor/EcoSkills/blob/master/LICENSE.md).*

View File

@@ -41,7 +41,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:6.7.0'
compileOnly 'com.willfp:eco:6.8.1'
compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'

View File

@@ -7,6 +7,10 @@ dependencies {
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
compileOnly 'com.willfp:EcoEnchants:8.2.0'
compileOnly 'net.essentialsx:EssentialsX:2.19.0'
compileOnly 'org.jetbrains.exposed:exposed-core:0.34.1'
compileOnly 'org.jetbrains.exposed:exposed-dao:0.34.1'
compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.34.1'
compileOnly 'mysql:mysql-connector-java:5.1.48'
}
build.dependsOn publishToMavenLocal

View File

@@ -5,12 +5,14 @@ import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.ecoskills.commands.CommandEcoskills;
import com.willfp.ecoskills.commands.CommandSkills;
import com.willfp.ecoskills.config.EffectsYml;
import com.willfp.ecoskills.data.DataListener;
import com.willfp.ecoskills.data.LeaderboardHandler;
import com.willfp.ecoskills.data.PlayerBlockListener;
import com.willfp.ecoskills.data.SaveHandler;
import com.willfp.ecoskills.data.DataListener;
import com.willfp.ecoskills.config.DataYml;
import com.willfp.ecoskills.config.EffectsYml;
import com.willfp.ecoskills.data.LeaderboardHandler;
import com.willfp.ecoskills.data.storage.DataHandler;
import com.willfp.ecoskills.data.storage.MySQLDataHandler;
import com.willfp.ecoskills.data.storage.YamlDataHandler;
import com.willfp.ecoskills.effects.Effect;
import com.willfp.ecoskills.effects.Effects;
import com.willfp.ecoskills.integrations.EcoEnchantsEnchantingLeveller;
@@ -26,7 +28,6 @@ import com.willfp.ecoskills.stats.Stats;
import com.willfp.ecoskills.stats.modifier.StatModifierListener;
import org.bukkit.event.Listener;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -39,7 +40,7 @@ public class EcoSkillsPlugin extends EcoPlugin {
/**
* data.yml.
*/
private final DataYml dataYml;
private final DataHandler dataHandler;
/**
* effects.yml.
@@ -50,10 +51,11 @@ public class EcoSkillsPlugin extends EcoPlugin {
* Internal constructor called by bukkit on plugin load.
*/
public EcoSkillsPlugin() {
super(0, 12205, "&#ff00ae");
super(1351, 12205, "&#ff00ae");
instance = this;
dataYml = new DataYml(this);
effectsYml = new EffectsYml(this);
dataHandler = this.getConfigYml().getBool("mysql.enabled") ?
new MySQLDataHandler(this) : new YamlDataHandler(this);
}
@Override
@@ -78,20 +80,16 @@ public class EcoSkillsPlugin extends EcoPlugin {
@Override
protected void handleDisable() {
try {
dataYml.save();
} catch (IOException e) {
e.printStackTrace();
}
dataHandler.save();
}
/**
* Get data.yml.
* Get data handler.
*
* @return data.yml.
* @return data handler.
*/
public DataYml getDataYml() {
return dataYml;
public DataHandler getDataHandler() {
return dataHandler;
}
/**

View File

@@ -93,11 +93,11 @@ fun Player.giveSkillExperience(skill: Skill, experience: Double, isOvershoot: Bo
}
fun OfflinePlayer.getSkillLevel(skill: Skill): Int {
return plugin.dataYml.getInt("player.${this.uniqueId}.${skill.id}", 0)
return plugin.dataHandler.readInt(this.uniqueId, skill.id)
}
fun OfflinePlayer.setSkillLevel(skill: Skill, level: Int) {
plugin.dataYml.set("player.${this.uniqueId}.${skill.id}", level)
plugin.dataHandler.write(this.uniqueId, skill.id, level)
}
fun OfflinePlayer.getSkillProgressToNextLevel(skill: Skill): Double {
@@ -109,27 +109,27 @@ fun OfflinePlayer.getSkillProgressRequired(skill: Skill): Int {
}
fun OfflinePlayer.getSkillProgress(skill: Skill): Double {
return plugin.dataYml.getDoubleOrNull("player.${this.uniqueId}.${skill.xpKey.key}") ?: 0.0
return plugin.dataHandler.readDouble(this.uniqueId, skill.xpKey.key)
}
fun OfflinePlayer.setSkillProgress(skill: Skill, level: Double) {
plugin.dataYml.set("player.${this.uniqueId}.${skill.xpKey.key}", level)
plugin.dataHandler.write(this.uniqueId, skill.xpKey.key, level)
}
fun OfflinePlayer.getEffectLevel(effect: Effect): Int {
return plugin.dataYml.getInt("player.${this.uniqueId}.${effect.id}", 0)
return plugin.dataHandler.readInt(this.uniqueId, effect.id)
}
fun OfflinePlayer.setEffectLevel(effect: Effect, level: Int) {
plugin.dataYml.set("player.${this.uniqueId}.${effect.id}", level)
plugin.dataHandler.write(this.uniqueId, effect.id, level)
}
fun OfflinePlayer.getStatLevel(stat: Stat): Int {
return plugin.dataYml.getInt("player.${this.uniqueId}.${stat.id}", 0)
return plugin.dataHandler.readInt(this.uniqueId, stat.id)
}
fun Player.setStatLevel(stat: Stat, level: Int) {
plugin.dataYml.set("player.${this.uniqueId}.${stat.id}", level)
plugin.dataHandler.write(this.uniqueId, stat.id, level)
stat.updateStatLevel(this)
}

View File

@@ -43,7 +43,7 @@ class CommandRank(plugin: EcoPlugin) :
val messages = plugin.langYml.getStrings("top", false)
val lines = mutableListOf<String>()
val useDisplayName = plugin.configYml.getBool("commands.rank.use-display-name")
val useDisplayName = plugin.configYml.getBool("commands.top.use-display-name")
for ((rank, player) in top) {
var line = plugin.langYml.getString("top-line-format", false)

View File

@@ -17,7 +17,7 @@ class CommandReload(plugin: EcoPlugin) :
override fun getHandler(): CommandHandler {
return CommandHandler { sender: CommandSender, _: List<String> ->
try {
(plugin as EcoSkillsPlugin).dataYml.save()
(plugin as EcoSkillsPlugin).dataHandler.save()
} catch (e: IOException) {
e.printStackTrace()
}

View File

@@ -1,12 +0,0 @@
package com.willfp.ecoskills.config
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.yaml.YamlBaseConfig
class DataYml(
plugin: EcoPlugin
): YamlBaseConfig(
"data",
false,
plugin
)

View File

@@ -60,17 +60,18 @@ class DataListener : Listener {
private fun Player.convertFromLegacyData() {
for (effect in Effects.values()) {
plugin.dataYml.set("player.${this.uniqueId}.${effect.id}", this.getEffectLevel(effect))
plugin.dataHandler.write(this.uniqueId, effect.id, this.getEffectLevel(effect))
}
for (stat in Stats.values()) {
plugin.dataYml.set("player.${this.uniqueId}.${stat.id}", this.getStatLevel(stat))
plugin.dataHandler.write(this.uniqueId, stat.id, this.getStatLevel(stat))
}
for (skill in Skills.values()) {
plugin.dataYml.set("player.${this.uniqueId}.${skill.id}", this.getSkillLevel(skill))
plugin.dataHandler.write(this.uniqueId, skill.id, this.getSkillLevel(skill))
val prog = this.persistentDataContainer.get(skill.xpKey, PersistentDataType.DOUBLE)
if (prog != null) {
plugin.dataYml.set(
"player.${this.uniqueId}.${skill.xpKey.key}",
plugin.dataHandler.write(
this.uniqueId,
skill.xpKey.key,
prog
)
this.persistentDataContainer.remove(skill.xpKey)

View File

@@ -13,7 +13,7 @@ class SaveHandler {
if (plugin.configYml.getBool("log-autosaves")) {
plugin.logger.info("Auto-Saving player data!")
}
plugin.dataYml.save()
plugin.dataHandler.save()
expMultiplierCache.clear()
if (plugin.configYml.getBool("log-autosaves")) {
plugin.logger.info("Saved data!")

View File

@@ -26,11 +26,11 @@ class SavedPlayerNameListener(
var OfflinePlayer.savedDisplayName: String
get() {
if (this is Player) {
plugin.dataYml.set("player.${this.uniqueId}.name", this.displayName)
plugin.dataHandler.write(this.uniqueId, "name", this.displayName)
}
return plugin.dataYml.getStringOrNull("player.${this.uniqueId}.name") ?: this.name ?: "Unknown Player"
return plugin.dataHandler.readString(this.uniqueId, "name", this.name ?: "Unknown Player")
}
set(value) {
plugin.dataYml.set("player.${this.uniqueId}.name", value)
plugin.dataHandler.write(this.uniqueId, "name", value)
}

View File

@@ -0,0 +1,13 @@
package com.willfp.ecoskills.data.storage
import java.util.*
interface DataHandler {
fun save()
fun <T> write(uuid: UUID, key: String, value: T)
fun readInt(uuid: UUID, key: String): Int
fun readDouble(uuid: UUID, key: String): Double
fun readString(uuid: UUID, key: String, default: String = ""): String
}

View File

@@ -0,0 +1,97 @@
package com.willfp.ecoskills.data.storage
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.effects.Effects
import com.willfp.ecoskills.skills.Skills
import com.willfp.ecoskills.stats.Stats
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.UUIDTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*
@Suppress("UNCHECKED_CAST")
class MySQLDataHandler(
private val plugin: EcoSkillsPlugin
) : DataHandler {
init {
Database.connect(
"jdbc:mysql://" +
"${plugin.configYml.getString("mysql.host")}:" +
"${plugin.configYml.getString("mysql.port")}/" +
plugin.configYml.getString("mysql.database"),
driver = "com.mysql.cj.jdbc.Driver",
user = plugin.configYml.getString("mysql.user"),
password = plugin.configYml.getString("mysql.password")
)
transaction {
Players.apply {
for (skill in Skills.values()) {
registerColumn<Int>(skill.id, IntegerColumnType())
.default(0)
registerColumn<Double>(skill.xpKey.key, DoubleColumnType())
.default(0.0)
}
for (stat in Stats.values()) {
registerColumn<Int>(stat.id, IntegerColumnType())
.default(0)
}
for (effect in Effects.values()) {
registerColumn<Int>(effect.id, IntegerColumnType())
.default(0)
}
}
SchemaUtils.create(Players)
}
}
override fun save() {
// Do nothing
}
override fun <T> write(uuid: UUID, key: String, value: T) {
transaction {
Players.select { Players.id eq uuid }.firstOrNull() ?: run {
Players.insert {
it[this.id] = uuid
}
}
val column: Column<T> = Players.columns.stream().filter { it.name == key }.findFirst().get() as Column<T>
Players.update ({ Players.id eq uuid }) {
it[column] = value
}
}
}
private inline fun <reified T> read(uuid: UUID, key: String, default: T): T {
var value = default
transaction {
val player = Players.select { Players.id eq uuid }.firstOrNull() ?: return@transaction
value = player[Players.columns.stream().filter { it.name == key }.findFirst().get()] as T? ?: default
}
return value
}
override fun readInt(uuid: UUID, key: String): Int {
return read(uuid, key, 0)
}
override fun readDouble(uuid: UUID, key: String): Double {
return read(uuid, key, 0.0)
}
override fun readString(uuid: UUID, key: String, default: String): String {
return read(uuid, key, default)
}
object Players : UUIDTable("EcoSkills_Players") {
override val id: Column<EntityID<UUID>> = uuid("uuid")
.entityId()
val name = varchar("name", 50)
.default("Unknown Player")
}
}

View File

@@ -0,0 +1,40 @@
package com.willfp.ecoskills.data.storage
import com.willfp.eco.core.config.yaml.YamlBaseConfig
import com.willfp.ecoskills.EcoSkillsPlugin
import java.util.*
@Suppress("UNCHECKED_CAST")
class YamlDataHandler(
private val plugin: EcoSkillsPlugin
) : DataHandler {
private val dataYml = DataYml(plugin)
override fun save() {
dataYml.save()
}
override fun <T> write(uuid: UUID, key: String, value: T) {
dataYml.set("player.$uuid.$key", value)
}
override fun readInt(uuid: UUID, key: String): Int {
return dataYml.getInt("player.$uuid.$key", 0)
}
override fun readDouble(uuid: UUID, key: String): Double {
return dataYml.getDoubleOrNull("player.$uuid.$key") ?: 0.0
}
override fun readString(uuid: UUID, key: String, default: String): String {
return dataYml.getStringOrNull("player.$uuid.$key") ?: default
}
class DataYml(
plugin: EcoSkillsPlugin
) : YamlBaseConfig(
"data",
false,
plugin
)
}

View File

@@ -3,6 +3,14 @@
# by Auxilor
#
mysql:
enabled: false # Set to false, data.yml will be used instead.
host: localhost
port: 3306
database: database
user: username
password: passy
gui:
rows: 6

View File

@@ -12,7 +12,11 @@ softdepend:
- HolographicDisplays
- Essentials
libraries:
- org.jetbrains.kotlin:kotlin-stdlib:1.5.21
- 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
- 'org.jetbrains.exposed:exposed-core:0.34.1'
- 'org.jetbrains.exposed:exposed-dao:0.34.1'
- 'org.jetbrains.exposed:exposed-jdbc:0.34.1'
- 'mysql:mysql-connector-java:5.1.48'
commands:
ecoskills:

View File

@@ -1,2 +1,2 @@
version = 1.2.6
version = 1.3.1
plugin-name = EcoSkills