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

Added farming

This commit is contained in:
Auxilor
2021-08-20 18:08:31 +01:00
parent 1b892ab559
commit f37e74948b
3 changed files with 78 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.skills.skills.SkillCombat;
import com.willfp.ecoskills.skills.skills.SkillEnchanting;
import com.willfp.ecoskills.skills.skills.SkillFarming;
import com.willfp.ecoskills.skills.skills.SkillMining;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.ApiStatus;
@@ -23,8 +24,8 @@ public class Skills {
public static final Skill MINING = new SkillMining();
public static final Skill COMBAT = new SkillCombat();
public static final Skill ENCHANTING = new SkillEnchanting();
public static final Skill FARMING = new SkillFarming();
/*
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");

View File

@@ -0,0 +1,51 @@
package com.willfp.ecoskills.skills.skills
import com.willfp.ecoskills.api.PlayerSkillExpGainEvent
import com.willfp.ecoskills.skills.Skill
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.block.data.Ageable
import org.bukkit.enchantments.Enchantment
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.block.BlockBreakEvent
import java.util.*
class SkillFarming : Skill(
"farming"
) {
private val rewards: MutableMap<Material, Double>
init {
rewards = EnumMap(org.bukkit.Material::class.java)
}
override fun postUpdate() {
rewards.clear()
for (string in this.config.getStrings("xp-rewards", false)) {
val split = string.split(":")
val material = Material.getMaterial(split[0].uppercase()) ?: continue
rewards[material] = split[1].toDouble()
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
fun handleLevelling(event: BlockBreakEvent) {
val type = event.block.type
val player = event.player
if (event.block.blockData !is Ageable) {
return
}
val data = event.block.blockData as Ageable
if (data.age < data.maximumAge) {
return
}
val toGive = rewards[type] ?: return
val gainEvent = PlayerSkillExpGainEvent(player, this, toGive)
Bukkit.getPluginManager().callEvent(gainEvent)
}
}

View File

@@ -229,6 +229,31 @@ skills:
gui-item: golden_hoe
# The maximum obtainable level
max-level: 50
# The level/skill increases to give on levelup
level-up-rewards:
- "speed:1"
- "wisdom:1"
- "bountiful_harvest:1"
rewards-messages:
- " &f+1 %ecoskills_speed_name%"
- " &f+1 %ecoskills_wisdom_name%"
- " &6Bountiful Harvest %ecoskills_harvest_numeral%"
# The xp rewards for each crop type
# Specify with type:xp
xp-rewards:
- "wheat:4"
- "potato:4"
- "carrots:4"
- "melon:4"
- "pumpkin:4.5"
- "cactus:2"
- "sugar_cane:2"
- "brown_mushroom:6"
- "red_mushroom:6"
- "cocoa_beans:3"
woodcutting:
gui-position:
row: 3