9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-02 22:02:19 +00:00

Began backend

This commit is contained in:
Auxilor
2021-08-19 00:10:17 +01:00
parent a213de5444
commit 1156af9752
10 changed files with 305 additions and 9 deletions

View File

@@ -42,12 +42,6 @@ allprojects {
compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
}
tasks.withType(JavaCompile) {

View File

@@ -3,7 +3,8 @@ package com.willfp.ecoskills;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.ecoskills.commands.CommandEcoskills;
import lombok.Getter;
import com.willfp.ecoskills.effects.Effect;
import com.willfp.ecoskills.effects.Effects;
import org.bukkit.event.Listener;
import java.util.Arrays;
@@ -13,7 +14,6 @@ public class EcoSkillsPlugin extends EcoPlugin {
/**
* Instance of EcoItems.
*/
@Getter
private static EcoSkillsPlugin instance;
/**
@@ -24,6 +24,23 @@ public class EcoSkillsPlugin extends EcoPlugin {
instance = this;
}
@Override
protected void handleReload() {
for (Effect effect : Effects.values()) {
this.getEventManager().unregisterListener(effect);
this.getEventManager().registerListener(effect);
}
}
/**
* Get the instance of EcoSkills.
*
* @return Instance.
*/
public static EcoSkillsPlugin getInstance() {
return instance;
}
@Override
protected List<Listener> loadListeners() {
return Arrays.asList(

View File

@@ -0,0 +1,62 @@
package com.willfp.ecoskills.effects;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.EcoSkillsPlugin;
import com.willfp.ecoskills.skills.Skill;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Effects {
/**
* All registered Skills.
*/
private static final Map<String, Effect> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Skill MINING = new Skill(PLUGIN, "mining");
public static final Skill COMBAT = new Skill(PLUGIN, "combat");
public static final Skill ENCHANTING = new Skill(PLUGIN, "enchanting");
public static final Skill FARMING = new Skill(PLUGIN, "farming");
public static final Skill WOODCUTTING = new Skill(PLUGIN, "woodcutting");
public static final Skill FISHING = new Skill(PLUGIN, "fishing");
public static final Skill ALCHEMY = new Skill(PLUGIN, "alchemy");
public static final Skill ARMORY = new Skill(PLUGIN, "armory");
public static final Skill EXPLORATION = new Skill(PLUGIN, "exploration");
@ApiStatus.Internal
public static void registerNewEffect(@NotNull final Effect effect) {
REGISTRY.put(effect.getId(), effect);
}
@Nullable
public static Effect getByID(@NotNull final String id) {
return REGISTRY.get(id.toLowerCase());
}
@Nullable
public static Effect getByKey(@NotNull final NamespacedKey key) {
return REGISTRY.get(key.getKey());
}
public static Set<Effect> values() {
return ImmutableSet.copyOf(REGISTRY.values());
}
@ConfigUpdater
public static void update() {
for (Effect effect : Effects.values()) {
effect.update();
}
}
}

View File

@@ -0,0 +1,61 @@
package com.willfp.ecoskills.skills;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.EcoSkillsPlugin;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Skills {
/**
* All registered Skills.
*/
private static final Map<String, Skill> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Skill MINING = new Skill(PLUGIN, "mining");
public static final Skill COMBAT = new Skill(PLUGIN, "combat");
public static final Skill ENCHANTING = new Skill(PLUGIN, "enchanting");
public static final Skill FARMING = new Skill(PLUGIN, "farming");
public static final Skill WOODCUTTING = new Skill(PLUGIN, "woodcutting");
public static final Skill FISHING = new Skill(PLUGIN, "fishing");
public static final Skill ALCHEMY = new Skill(PLUGIN, "alchemy");
public static final Skill ARMORY = new Skill(PLUGIN, "armory");
public static final Skill EXPLORATION = new Skill(PLUGIN, "exploration");
@ApiStatus.Internal
public static void registerNewSkill(@NotNull final Skill skill) {
REGISTRY.put(skill.getId(), skill);
}
@Nullable
public static Skill getByID(@NotNull final String id) {
return REGISTRY.get(id.toLowerCase());
}
@Nullable
public static Skill getByKey(@NotNull final NamespacedKey key) {
return REGISTRY.get(key.getKey());
}
public static Set<Skill> values() {
return ImmutableSet.copyOf(REGISTRY.values());
}
@ConfigUpdater
public static void update() {
for (Skill skill : Skills.values()) {
skill.update();
}
}
}

View File

@@ -0,0 +1,58 @@
package com.willfp.ecoskills.stats;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.EcoSkillsPlugin;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Stats {
/**
* All registered stats.
*/
private static final Map<String, Stat> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Stat DEFENCE = new Stat(PLUGIN, "defence");
public static final Stat STRENGTH = new Stat(PLUGIN, "strength");
public static final Stat CRIT_CHANCE = new Stat(PLUGIN, "crit_chance");
public static final Stat CRIT_DAMAGE = new Stat(PLUGIN, "crit_damage");
public static final Stat SPEED = new Stat(PLUGIN, "speed");
public static final Stat WISDOM = new Stat(PLUGIN, "wisdom");
@ApiStatus.Internal
public static void registerNewStat(@NotNull final Stat skill) {
REGISTRY.put(skill.getId(), skill);
}
@Nullable
public static Stat getByID(@NotNull final String id) {
return REGISTRY.get(id.toLowerCase());
}
@Nullable
public static Stat getByKey(@NotNull final NamespacedKey key) {
return REGISTRY.get(key.getKey());
}
public static Set<Stat> values() {
return ImmutableSet.copyOf(REGISTRY.values());
}
@ConfigUpdater
public static void update() {
for (Stat skill : Stats.values()) {
skill.update();
}
}
}

View File

@@ -0,0 +1,22 @@
package com.willfp.ecoskills
import com.willfp.ecoskills.effects.Effect
import com.willfp.ecoskills.stats.Stat
import org.bukkit.entity.Player
import org.bukkit.persistence.PersistentDataType
fun Player.getSkillLevel(skill: Stat): Int {
return this.persistentDataContainer.getOrDefault(skill.key, PersistentDataType.INTEGER, 1)
}
fun Player.setSkillLevel(skill: Stat, level: Int) {
this.persistentDataContainer.set(skill.key, PersistentDataType.INTEGER, level)
}
fun Player.getEffectLevel(effect: Effect): Int {
return this.persistentDataContainer.getOrDefault(effect.key, PersistentDataType.INTEGER, 1)
}
fun Player.setEffectLevel(effect: Effect, level: Int) {
this.persistentDataContainer.set(effect.key, PersistentDataType.INTEGER, level)
}

View File

@@ -0,0 +1,31 @@
package com.willfp.ecoskills.effects
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoskills.EcoSkillsPlugin
import org.bukkit.NamespacedKey
import org.bukkit.event.Listener
import java.util.*
abstract class Effect(
val id: String
): Listener {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val key: NamespacedKey
val uuid: UUID
lateinit var name: String
lateinit var description: String
init {
update()
key = plugin.namespacedKeyFactory.create(id)
uuid = UUID.nameUUIDFromBytes(id.toByteArray())
Effects.registerNewEffect(this)
}
fun update() {
name = plugin.langYml.getString("effects.$id.name")
description = plugin.langYml.getString("effects.$id.description")
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.ecoskills.skills
import com.willfp.eco.core.EcoPlugin
import org.bukkit.NamespacedKey
class Skill(
protected val plugin: EcoPlugin,
val id: String
) {
val key: NamespacedKey
lateinit var name: String
init {
update()
key = plugin.namespacedKeyFactory.create(id)
Skills.registerNewSkill(this)
}
fun update() {
name = plugin.langYml.getString("skills.names.$id")
}
}

View File

@@ -0,0 +1,28 @@
package com.willfp.ecoskills.stats
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoskills.skills.Skills
import org.bukkit.NamespacedKey
class Stat(
protected val plugin: EcoPlugin,
val id: String
) {
val key: NamespacedKey
lateinit var icon: String
lateinit var color: String
lateinit var name: String
init {
update()
key = plugin.namespacedKeyFactory.create(id)
Stats.registerNewStat(this)
}
fun update() {
icon = plugin.langYml.getString("stats.icons.$id")
name = plugin.langYml.getString("stats.names.$id")
color = plugin.langYml.getString("stats.colors.$id")
}
}

View File

@@ -33,7 +33,7 @@ stats:
crit_damage: '&#000d9e'
speed: '&#40ffe6'
wisdom: '&#c8ffa6'
symbols:
icons:
defense: '&#e884b0❤'
strength: '&#db0000❁'
crit_chance: '&#f7ff85☣'