9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-25 09:59:20 +00:00
This commit is contained in:
Xiao-MoMi
2023-03-16 23:07:32 +08:00
parent 84ed09d35a
commit dc12da325b
18 changed files with 122 additions and 29 deletions

View File

@@ -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)));
}

View File

@@ -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<CCAntiGrief> internalAntiGriefs = new ArrayList<>();
public static List<CCAntiGrief> 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!");

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@@ -15,18 +15,19 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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) {

View File

@@ -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");

View File

@@ -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) {

View File

@@ -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");

View File

@@ -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) {

View File

@@ -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());

View File

@@ -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;
}
}

View File

@@ -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);
}
}