From dc12da325b5173d009d19a0db6132fc9108626ca Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:07:32 +0800 Subject: [PATCH] 2.2.7.2 --- build.gradle | 3 +- .../customcrops/config/CropConfig.java | 1 + .../customcrops/config/MainConfig.java | 22 +++++++--- .../integrations/JobInterface.java | 8 ++++ .../{SkillXP.java => SkillInterface.java} | 2 +- .../customplugin/oraxen/OraxenHook.java | 2 +- .../integrations/job/EcoJobsHook.java | 43 +++++++++++++++++++ .../{skill => job}/JobsRebornHook.java | 7 +-- .../integrations/skill/AureliumsHook.java | 4 +- .../integrations/skill/EcoSkillsHook.java | 4 +- .../integrations/skill/MMOCoreHook.java | 4 +- .../integrations/skill/mcMMOHook.java | 4 +- .../customcrops/managers/CropManager.java | 9 ++-- .../objects/actions/ActionJobXP.java | 27 ++++++++++++ .../objects/actions/ActionSkillXP.java | 4 +- src/main/resources/config.yml | 5 ++- src/main/resources/crops_itemsadder.yml | 1 + src/main/resources/plugin.yml | 1 + 18 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/momirealms/customcrops/integrations/JobInterface.java rename src/main/java/net/momirealms/customcrops/integrations/{SkillXP.java => SkillInterface.java} (96%) create mode 100644 src/main/java/net/momirealms/customcrops/integrations/job/EcoJobsHook.java rename src/main/java/net/momirealms/customcrops/integrations/{skill => job}/JobsRebornHook.java (89%) create mode 100644 src/main/java/net/momirealms/customcrops/objects/actions/ActionJobXP.java diff --git a/build.gradle b/build.gradle index aaeb889..9ee427a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.2.7.1' +version = '2.2.7.2' repositories { mavenCentral() @@ -39,6 +39,7 @@ dependencies { compileOnly ('com.willfp:eco:6.38.3') compileOnly ('com.bgsoftware:SuperiorSkyblockAPI:2022.9') compileOnly ('com.github.Zrips:Jobs:4.17.2') + compileOnly ('com.willfp:EcoJobs:1.35.0') compileOnly fileTree(dir:'libs',includes:['*.jar']) implementation ('net.kyori:adventure-api:4.12.0') implementation ('net.kyori:adventure-platform-bukkit:4.2.0') diff --git a/src/main/java/net/momirealms/customcrops/config/CropConfig.java b/src/main/java/net/momirealms/customcrops/config/CropConfig.java index 2106748..bc24508 100644 --- a/src/main/java/net/momirealms/customcrops/config/CropConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/CropConfig.java @@ -111,6 +111,7 @@ public class CropConfig { switch (action) { case "xp" -> actions.add(new ActionXP(config.getInt(key + ".harvest-actions." + action), config.getDouble(key + ".harvest-actions." + action + "-chance", 1))); case "skill-xp" -> actions.add(new ActionSkillXP(config.getDouble(key + ".harvest-actions." + action), config.getDouble(key + ".harvest-actions." + action + "-chance", 1))); + case "job-xp" -> actions.add(new ActionJobXP(config.getDouble(key + ".harvest-actions." + action), config.getDouble(key + ".harvest-actions." + action + "-chance", 1))); case "commands" -> actions.add(new ActionCommand(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]), config.getDouble(key + ".harvest-actions." + action + "-chance", 1))); case "messages" -> actions.add(new ActionMessage(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]), config.getDouble(key + ".harvest-actions." + action + "-chance", 1))); } diff --git a/src/main/java/net/momirealms/customcrops/config/MainConfig.java b/src/main/java/net/momirealms/customcrops/config/MainConfig.java index cac9c47..d867a10 100644 --- a/src/main/java/net/momirealms/customcrops/config/MainConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/MainConfig.java @@ -19,7 +19,10 @@ package net.momirealms.customcrops.config; import net.momirealms.customcrops.helper.Log; import net.momirealms.customcrops.integrations.CCAntiGrief; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.JobInterface; +import net.momirealms.customcrops.integrations.SkillInterface; +import net.momirealms.customcrops.integrations.job.EcoJobsHook; +import net.momirealms.customcrops.integrations.job.JobsRebornHook; import net.momirealms.customcrops.integrations.protection.*; import net.momirealms.customcrops.integrations.skill.*; import net.momirealms.customcrops.objects.QualityRatio; @@ -47,7 +50,8 @@ public class MainConfig { public static boolean cropMode; public static List internalAntiGriefs = new ArrayList<>(); public static List externalAntiGriefs = new ArrayList<>(); - public static SkillXP skillXP; + public static SkillInterface skillInterface; + public static JobInterface jobInterface; public static double dryGrowChance; public static boolean limitation; public static int wireAmount; @@ -362,24 +366,28 @@ public class MainConfig { if (config.getBoolean("integration.AureliumSkills")) { if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!"); - else skillXP = new AureliumsHook(); + else skillInterface = new AureliumsHook(); } if (config.getBoolean("integration.mcMMO")) { if (Bukkit.getPluginManager().getPlugin("mcMMO") == null) Log.warn("Failed to initialize mcMMO!"); - else skillXP = new mcMMOHook(); + else skillInterface = new mcMMOHook(); } if (config.getBoolean("integration.MMOCore")) { if (Bukkit.getPluginManager().getPlugin("MMOCore") == null) Log.warn("Failed to initialize MMOCore!"); - else skillXP = new MMOCoreHook(); + else skillInterface = new MMOCoreHook(); } if (config.getBoolean("integration.EcoSkills")) { if (Bukkit.getPluginManager().getPlugin("EcoSkills") == null) Log.warn("Failed to initialize EcoSkills!"); - else skillXP = new EcoSkillsHook(); + else skillInterface = new EcoSkillsHook(); } if (config.getBoolean("integration.JobsReborn")) { if (Bukkit.getPluginManager().getPlugin("Jobs") == null) Log.warn("Failed to initialize JobsReborn!"); - else skillXP = new JobsRebornHook(); + else jobInterface = new JobsRebornHook(); + } else if (config.getBoolean("integration.EcoJobs")) { + if (Bukkit.getPluginManager().getPlugin("EcoJobs") == null) Log.warn("Failed to initialize EcoJobs!"); + else jobInterface = new EcoJobsHook(); } + realisticSeasonHook = false; if (config.getBoolean("integration.RealisticSeasons")) { if (Bukkit.getPluginManager().getPlugin("RealisticSeasons") == null) Log.warn("Failed to initialize RealisticSeasons!"); diff --git a/src/main/java/net/momirealms/customcrops/integrations/JobInterface.java b/src/main/java/net/momirealms/customcrops/integrations/JobInterface.java new file mode 100644 index 0000000..b1a5347 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/integrations/JobInterface.java @@ -0,0 +1,8 @@ +package net.momirealms.customcrops.integrations; + +import org.bukkit.entity.Player; + +public interface JobInterface { + void addXp(Player player, double amount); + int getLevel(Player player); +} diff --git a/src/main/java/net/momirealms/customcrops/integrations/SkillXP.java b/src/main/java/net/momirealms/customcrops/integrations/SkillInterface.java similarity index 96% rename from src/main/java/net/momirealms/customcrops/integrations/SkillXP.java rename to src/main/java/net/momirealms/customcrops/integrations/SkillInterface.java index a5e14a9..160c2f9 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/SkillXP.java +++ b/src/main/java/net/momirealms/customcrops/integrations/SkillInterface.java @@ -19,7 +19,7 @@ package net.momirealms.customcrops.integrations; import org.bukkit.entity.Player; -public interface SkillXP { +public interface SkillInterface { void addXp(Player player, double amount); diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java index 461e073..047db6f 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java @@ -47,7 +47,7 @@ public class OraxenHook implements CustomInterface { @Override public void removeBlock(Location location) { - location.getBlock().setType(Material.AIR); + OraxenBlocks.remove(location, null); } @Override diff --git a/src/main/java/net/momirealms/customcrops/integrations/job/EcoJobsHook.java b/src/main/java/net/momirealms/customcrops/integrations/job/EcoJobsHook.java new file mode 100644 index 0000000..20874cb --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/integrations/job/EcoJobsHook.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.integrations.job; + +import com.willfp.ecojobs.api.EcoJobsAPI; +import com.willfp.ecojobs.jobs.Job; +import com.willfp.ecojobs.jobs.Jobs; +import net.momirealms.customcrops.integrations.JobInterface; +import org.bukkit.entity.Player; + +public class EcoJobsHook implements JobInterface { + + @Override + public void addXp(Player player, double amount) { + Job job = EcoJobsAPI.getInstance().getActiveJob(player); + if (job == null) return; + if (job.getId().equals("farmer")) { + EcoJobsAPI.getInstance().giveJobExperience(player, job, amount); + } + } + + @Override + public int getLevel(Player player) { + Job job = Jobs.getByID("farmer"); + if (job == null) return 0; + return EcoJobsAPI.getInstance().getJobLevel(player, job); + } +} diff --git a/src/main/java/net/momirealms/customcrops/integrations/skill/JobsRebornHook.java b/src/main/java/net/momirealms/customcrops/integrations/job/JobsRebornHook.java similarity index 89% rename from src/main/java/net/momirealms/customcrops/integrations/skill/JobsRebornHook.java rename to src/main/java/net/momirealms/customcrops/integrations/job/JobsRebornHook.java index 6b62a6e..a7462c2 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/skill/JobsRebornHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/job/JobsRebornHook.java @@ -15,18 +15,19 @@ * along with this program. If not, see . */ -package net.momirealms.customcrops.integrations.skill; +package net.momirealms.customcrops.integrations.job; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.JobInterface; +import net.momirealms.customcrops.integrations.SkillInterface; import org.bukkit.entity.Player; import java.util.List; -public class JobsRebornHook implements SkillXP { +public class JobsRebornHook implements JobInterface { @Override public void addXp(Player player, double amount) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/skill/AureliumsHook.java b/src/main/java/net/momirealms/customcrops/integrations/skill/AureliumsHook.java index eb429b9..dc54d5b 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/skill/AureliumsHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/skill/AureliumsHook.java @@ -20,10 +20,10 @@ package net.momirealms.customcrops.integrations.skill; import com.archyx.aureliumskills.api.AureliumAPI; import com.archyx.aureliumskills.leveler.Leveler; import com.archyx.aureliumskills.skills.Skill; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.SkillInterface; import org.bukkit.entity.Player; -public class AureliumsHook implements SkillXP { +public class AureliumsHook implements SkillInterface { private static final Leveler leveler = AureliumAPI.getPlugin().getLeveler(); private static final Skill skill = AureliumAPI.getPlugin().getSkillRegistry().getSkill("farming"); diff --git a/src/main/java/net/momirealms/customcrops/integrations/skill/EcoSkillsHook.java b/src/main/java/net/momirealms/customcrops/integrations/skill/EcoSkillsHook.java index 0ef146e..f2532e6 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/skill/EcoSkillsHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/skill/EcoSkillsHook.java @@ -19,10 +19,10 @@ package net.momirealms.customcrops.integrations.skill; import com.willfp.ecoskills.api.EcoSkillsAPI; import com.willfp.ecoskills.skills.Skills; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.SkillInterface; import org.bukkit.entity.Player; -public class EcoSkillsHook implements SkillXP { +public class EcoSkillsHook implements SkillInterface { @Override public void addXp(Player player, double amount) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/skill/MMOCoreHook.java b/src/main/java/net/momirealms/customcrops/integrations/skill/MMOCoreHook.java index d48def2..4a0a338 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/skill/MMOCoreHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/skill/MMOCoreHook.java @@ -20,10 +20,10 @@ package net.momirealms.customcrops.integrations.skill; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.Profession; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.SkillInterface; import org.bukkit.entity.Player; -public class MMOCoreHook implements SkillXP { +public class MMOCoreHook implements SkillInterface { @Override public void addXp(Player player, double amount) { Profession profession = MMOCore.plugin.professionManager.get("farming"); diff --git a/src/main/java/net/momirealms/customcrops/integrations/skill/mcMMOHook.java b/src/main/java/net/momirealms/customcrops/integrations/skill/mcMMOHook.java index a29ca9e..2ae474c 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/skill/mcMMOHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/skill/mcMMOHook.java @@ -19,10 +19,10 @@ package net.momirealms.customcrops.integrations.skill; import com.gmail.nossr50.api.ExperienceAPI; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import net.momirealms.customcrops.integrations.SkillXP; +import net.momirealms.customcrops.integrations.SkillInterface; import org.bukkit.entity.Player; -public class mcMMOHook implements SkillXP { +public class mcMMOHook implements SkillInterface { @Override public void addXp(Player player, double amount) { diff --git a/src/main/java/net/momirealms/customcrops/managers/CropManager.java b/src/main/java/net/momirealms/customcrops/managers/CropManager.java index 71c4536..fc5a88d 100644 --- a/src/main/java/net/momirealms/customcrops/managers/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/managers/CropManager.java @@ -23,7 +23,6 @@ import net.momirealms.customcrops.api.event.CropHarvestEvent; import net.momirealms.customcrops.api.event.CrowAttackEvent; import net.momirealms.customcrops.api.utils.CCSeason; import net.momirealms.customcrops.config.*; -import net.momirealms.customcrops.helper.Log; import net.momirealms.customcrops.integrations.customplugin.CustomInterface; import net.momirealms.customcrops.integrations.customplugin.HandlerP; import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdderFrameHandler; @@ -346,8 +345,8 @@ public class CropManager extends Function { qualityRatio = qualityCrop.getQualityRatio(); } } - if (MainConfig.enableSkillBonus && MainConfig.skillXP != null) { - double bonus_chance = MainConfig.skillXP.getLevel(player) * MainConfig.bonusPerLevel; + if (MainConfig.enableSkillBonus && MainConfig.skillInterface != null) { + double bonus_chance = MainConfig.skillInterface.getLevel(player) * MainConfig.bonusPerLevel; amount *= (bonus_chance + 1); } dropQualityLoots(qualityLoot, amount, location.getBlock().getLocation(), qualityRatio); @@ -368,8 +367,8 @@ public class CropManager extends Function { for (OtherLoot otherLoot : otherLoots) { if (Math.random() < otherLoot.getChance()) { int random = ThreadLocalRandom.current().nextInt(otherLoot.getMin(), otherLoot.getMax() + 1); - if (MainConfig.enableSkillBonus && MainConfig.skillXP != null) { - double bonus_chance = MainConfig.skillXP.getLevel(player) * MainConfig.bonusPerLevel; + if (MainConfig.enableSkillBonus && MainConfig.skillInterface != null) { + double bonus_chance = MainConfig.skillInterface.getLevel(player) * MainConfig.bonusPerLevel; random *= (bonus_chance + 1); } ItemStack drop = getLoot(otherLoot.getItemID()); diff --git a/src/main/java/net/momirealms/customcrops/objects/actions/ActionJobXP.java b/src/main/java/net/momirealms/customcrops/objects/actions/ActionJobXP.java new file mode 100644 index 0000000..8daceaf --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/objects/actions/ActionJobXP.java @@ -0,0 +1,27 @@ +package net.momirealms.customcrops.objects.actions; + +import net.momirealms.customcrops.config.MainConfig; +import org.bukkit.entity.Player; + +public class ActionJobXP implements ActionInterface { + + private final double xp; + private final double chance; + + public ActionJobXP(double xp, double chance) { + this.xp = xp; + this.chance = chance; + } + + @Override + public void performOn(Player player) { + if (MainConfig.jobInterface != null) { + MainConfig.jobInterface.addXp(player, xp); + } + } + + @Override + public double getChance() { + return chance; + } +} diff --git a/src/main/java/net/momirealms/customcrops/objects/actions/ActionSkillXP.java b/src/main/java/net/momirealms/customcrops/objects/actions/ActionSkillXP.java index 8105ab4..d0a0f65 100644 --- a/src/main/java/net/momirealms/customcrops/objects/actions/ActionSkillXP.java +++ b/src/main/java/net/momirealms/customcrops/objects/actions/ActionSkillXP.java @@ -32,8 +32,8 @@ public class ActionSkillXP implements ActionInterface { @Override public void performOn(Player player) { - if (MainConfig.skillXP != null) { - MainConfig.skillXP.addXp(player, xp); + if (MainConfig.skillInterface != null) { + MainConfig.skillInterface.addXp(player, xp); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 43b0791..6fef651 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,6 @@ # Don't change # 请不要修改 -config-version: '23' +config-version: '24' metrics: true # lang: english / spanish / chinese lang: english @@ -25,7 +25,10 @@ integration: mcMMO: false MMOCore: false EcoSkills: false + # Job xp + # Don't forget to config job-xp for each crop if you enabled job xp integration JobsReborn: false + EcoJobs: false # Season # Synchronize season with other plugins RealisticSeasons: false diff --git a/src/main/resources/crops_itemsadder.yml b/src/main/resources/crops_itemsadder.yml index cc5fc6e..8ed6844 100644 --- a/src/main/resources/crops_itemsadder.yml +++ b/src/main/resources/crops_itemsadder.yml @@ -44,6 +44,7 @@ tomato: - 'say {player} harvested a tomato! lol' xp: 10 # skill-xp: 100 (You need to enable any skill plugin compatibility in config.yml) + # job-xp: 10 (You need to enable any job plugin compatibility in config.yml) # When you harvest with a single right click, the crop would return to a certain stage. If not set, crops would be removed when harvesting return: customcrops:tomato_stage_1 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b24409f..4209556 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -27,6 +27,7 @@ softdepend: - GriefPrevention - CrashClaim - BentoBox + - EcoJobs commands: customcrops: usage: /customcrops