9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 08:29:35 +00:00
This commit is contained in:
Xiao-MoMi
2022-10-06 15:59:34 +08:00
parent 680c1119a8
commit ea707be872
10 changed files with 103 additions and 31 deletions

View File

@@ -26,21 +26,21 @@ import net.momirealms.customcrops.objects.requirements.RequirementInterface;
public interface Crop { public interface Crop {
public CCSeason[] getSeasons(); CCSeason[] getSeasons();
public RequirementInterface[] getRequirements(); RequirementInterface[] getRequirements();
public String getReturnStage(); String getReturnStage();
public QualityLoot getQualityLoot(); QualityLoot getQualityLoot();
public GiganticCrop getGiganticCrop(); GiganticCrop getGiganticCrop();
public double getSkillXP(); double getSkillXP();
public OtherLoot[] getOtherLoots(); OtherLoot[] getOtherLoots();
public ActionInterface[] getActions(); ActionInterface[] getActions();
public String getKey(); String getKey();
} }

View File

@@ -23,6 +23,11 @@ import org.jetbrains.annotations.Nullable;
public class CropUtils { public class CropUtils {
/**
* get a crop config
* @param crop crop
* @return crop config
*/
@Nullable @Nullable
public static Crop getCrop(String crop) { public static Crop getCrop(String crop) {
return CropConfig.CROPS.get(crop); return CropConfig.CROPS.get(crop);

View File

@@ -24,15 +24,29 @@ import org.jetbrains.annotations.NotNull;
public class SeasonUtils { public class SeasonUtils {
/**
* Set season for a specified world
* @param world world
* @param season season
*/
public static void setSeason(World world, CCSeason season) { public static void setSeason(World world, CCSeason season) {
CustomCrops.plugin.getCropManager().getSeasonAPI().setSeason(season, world); CustomCrops.plugin.getCropManager().getSeasonAPI().setSeason(season, world);
} }
/**
* return a world's season, if it has no season, it would return a new season
* @param world world
* @return season
*/
@NotNull @NotNull
public static CCSeason getSeason(World world) { public static CCSeason getSeason(World world) {
return CustomCrops.plugin.getCropManager().getSeasonAPI().getSeason(world); return CustomCrops.plugin.getCropManager().getSeasonAPI().getSeason(world);
} }
/**
* remove a world's season data from cache
* @param world world
*/
public static void unloadSeason(World world) { public static void unloadSeason(World world) {
CustomCrops.plugin.getCropManager().getSeasonAPI().unloadWorld(world); CustomCrops.plugin.getCropManager().getSeasonAPI().unloadWorld(world);
} }

View File

@@ -0,0 +1,24 @@
package net.momirealms.customcrops.api.utils;
import net.momirealms.customcrops.CustomCrops;
import org.bukkit.World;
public class WorldUtils {
/**
* load a world's crop data
* @param world world
*/
public static void loadCropWorld(World world) {
CustomCrops.plugin.getCropManager().onWorldLoad(world);
}
/**
* unload a world's crop data
* @param world world
* @param disable whether the server is stopping
*/
public static void unloadCropWorld(World world, boolean disable) {
CustomCrops.plugin.getCropManager().onWorldUnload(world, disable);
}
}

View File

@@ -21,6 +21,7 @@ import net.momirealms.customcrops.helper.Log;
import net.momirealms.customcrops.integrations.AntiGrief; import net.momirealms.customcrops.integrations.AntiGrief;
import net.momirealms.customcrops.integrations.SkillXP; import net.momirealms.customcrops.integrations.SkillXP;
import net.momirealms.customcrops.integrations.protection.*; import net.momirealms.customcrops.integrations.protection.*;
import net.momirealms.customcrops.integrations.skill.*;
import net.momirealms.customcrops.objects.QualityRatio; import net.momirealms.customcrops.objects.QualityRatio;
import net.momirealms.customcrops.utils.AdventureUtil; import net.momirealms.customcrops.utils.AdventureUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -135,6 +136,8 @@ public class MainConfig {
enableParticles = !config.getBoolean("optimization.disable-water-particles", false); enableParticles = !config.getBoolean("optimization.disable-water-particles", false);
enableAnimations = !config.getBoolean("optimization.disable-sprinkler-animation", false); enableAnimations = !config.getBoolean("optimization.disable-sprinkler-animation", false);
realisticSeasonHook = config.getBoolean("integration.RealisticSeasons");
try { try {
boneMealSuccess = Particle.valueOf(config.getString("mechanics.success-particle", "VILLAGER_HAPPY")); boneMealSuccess = Particle.valueOf(config.getString("mechanics.success-particle", "VILLAGER_HAPPY"));
} }
@@ -214,6 +217,27 @@ public class MainConfig {
if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!"); if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!");
else {antiGriefs.add(new BentoBoxHook());hookMessage("BentoBox");} else {antiGriefs.add(new BentoBoxHook());hookMessage("BentoBox");}
} }
if (config.getBoolean("integration.AureliumSkills")) {
if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!");
else {skillXP = new AureliumsHook();}
}
if (config.getBoolean("integration.mcMMO")) {
if (Bukkit.getPluginManager().getPlugin("mcMMO") == null) Log.warn("Failed to initialize mcMMO!");
else {skillXP = new mcMMOHook();}
}
if (config.getBoolean("integration.MMOCore")) {
if (Bukkit.getPluginManager().getPlugin("MMOCore") == null) Log.warn("Failed to initialize MMOCore!");
else {skillXP = new MMOCoreHook();}
}
if (config.getBoolean("integration.EcoSkills")) {
if (Bukkit.getPluginManager().getPlugin("EcoSkills") == null) Log.warn("Failed to initialize EcoSkills!");
else {skillXP = new EcoSkillsHook();}
}
if (config.getBoolean("integration.JobsReborn")) {
if (Bukkit.getPluginManager().getPlugin("JobsReborn") == null) Log.warn("Failed to initialize JobsReborn!");
else {skillXP = new JobsRebornHook();}
}
} }
public static World[] getWorldsArray() { public static World[] getWorldsArray() {

View File

@@ -56,7 +56,7 @@ public class SeasonPapi extends PlaceholderExpansion {
if (!SeasonConfig.enable) return MessageConfig.seasonDisabled; if (!SeasonConfig.enable) return MessageConfig.seasonDisabled;
switch (params) { switch (params) {
case "current" -> { case "current" -> {
if (!MainConfig.getWorldsList().contains(player.getWorld())) return MessageConfig.autoSeasonDisabled; if (!MainConfig.getWorldsList().contains(player.getWorld())) return MessageConfig.noSeason;
return getSeasonText(player.getWorld()); return getSeasonText(player.getWorld());
} }
case "days_left" -> { case "days_left" -> {
@@ -73,7 +73,7 @@ public class SeasonPapi extends PlaceholderExpansion {
if (params.startsWith("current_")) { if (params.startsWith("current_")) {
World world = Bukkit.getWorld(params.substring(8)); World world = Bukkit.getWorld(params.substring(8));
if (world == null) return MessageConfig.noSeason; if (world == null) return MessageConfig.noSeason;
if (!MainConfig.getWorldsList().contains(world)) return MessageConfig.autoSeasonDisabled; if (!MainConfig.getWorldsList().contains(world)) return MessageConfig.noSeason;
return getSeasonText(world); return getSeasonText(world);
} }
if (params.startsWith("days_left_")) { if (params.startsWith("days_left_")) {

View File

@@ -19,9 +19,11 @@ package net.momirealms.customcrops.integrations.season;
import me.casperge.realisticseasons.api.SeasonsAPI; import me.casperge.realisticseasons.api.SeasonsAPI;
import net.momirealms.customcrops.Function; import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.config.MainConfig;
import org.bukkit.World; import org.bukkit.World;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.mozilla.javascript.tools.jsc.Main;
public class RealisticSeasonsHook extends Function implements SeasonInterface { public class RealisticSeasonsHook extends Function implements SeasonInterface {
@@ -46,7 +48,7 @@ public class RealisticSeasonsHook extends Function implements SeasonInterface {
return false; return false;
} }
} }
return false; return true;
} }
@Override @Override
@@ -61,29 +63,26 @@ public class RealisticSeasonsHook extends Function implements SeasonInterface {
@Override @Override
@NotNull @NotNull
public CCSeason getSeason(World world){ public CCSeason getSeason(World world){
if (!MainConfig.syncSeason) {
switch (api.getSeason(world)){ switch (api.getSeason(world)){
case SPRING -> {return CCSeason.SPRING;} case SPRING -> {return CCSeason.SPRING;}
case SUMMER -> {return CCSeason.SUMMER;} case SUMMER -> {return CCSeason.SUMMER;}
case WINTER -> {return CCSeason.WINTER;} case WINTER -> {return CCSeason.WINTER;}
case FALL -> {return CCSeason.AUTUMN;} case FALL -> {return CCSeason.AUTUMN;}
} }
}
else {
switch (api.getSeason(MainConfig.syncWorld)){
case SPRING -> {return CCSeason.SPRING;}
case SUMMER -> {return CCSeason.SUMMER;}
case WINTER -> {return CCSeason.WINTER;}
case FALL -> {return CCSeason.AUTUMN;}
}
}
return CCSeason.UNKNOWN; return CCSeason.UNKNOWN;
} }
/**
* Set season for RealisticSeasons
* @param season season
* @param world world
*/
@Override @Override
public void setSeason(CCSeason season, World world) { public void setSeason(CCSeason season, World world) {
me.casperge.realisticseasons.season.Season rsSeason = switch (season) {
case SPRING -> me.casperge.realisticseasons.season.Season.SPRING;
case SUMMER -> me.casperge.realisticseasons.season.Season.SUMMER;
case AUTUMN -> me.casperge.realisticseasons.season.Season.FALL;
case WINTER -> me.casperge.realisticseasons.season.Season.WINTER;
default -> throw new IllegalStateException("Unexpected value: " + season);
};
api.setSeason(world, rsSeason);
} }
} }

View File

@@ -121,6 +121,8 @@ public class CropManager extends Function {
else seasonInterface = new InternalSeason(); else seasonInterface = new InternalSeason();
} }
seasonInterface.load();
//load Worlds //load Worlds
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
onWorldLoad(world); onWorldLoad(world);

View File

@@ -84,6 +84,10 @@ public class CustomWorld {
public void unload(boolean disable) { public void unload(boolean disable) {
if (disable) { if (disable) {
unloadData(); unloadData();
for (BukkitTask task : tasksCache) {
task.cancel();
}
tasksCache.clear();
} }
else { else {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {