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
2022-10-08 22:05:01 +08:00
parent 5cdb54954e
commit 3d481aadc9
15 changed files with 90 additions and 25 deletions

View File

@@ -21,6 +21,7 @@ import net.momirealms.customcrops.api.utils.SeasonUtils;
import net.momirealms.customcrops.commands.AbstractSubCommand;
import net.momirealms.customcrops.commands.SubCommand;
import net.momirealms.customcrops.config.MessageConfig;
import net.momirealms.customcrops.config.SeasonConfig;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bukkit.Bukkit;
@@ -40,6 +41,10 @@ public class SetSeasonCommand extends AbstractSubCommand {
@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (!SeasonConfig.enable) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.seasonDisabled);
return true;
}
if (args.size() < 2) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.lackArgs);
return true;
@@ -66,6 +71,7 @@ public class SetSeasonCommand extends AbstractSubCommand {
@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (!SeasonConfig.enable) return null;
if (args.size() == 1) {
return getWorlds(args);
}

View File

@@ -74,5 +74,9 @@ public class ConfigUtil {
CustomCrops.plugin.getPlaceholderManager().unload();
CustomCrops.plugin.getPlaceholderManager().load();
}
if (CustomCrops.plugin.getCropManager() != null) {
CustomCrops.plugin.getCropManager().loadMode();
CustomCrops.plugin.getCropManager().loadSeason();
}
}
}

View File

@@ -141,7 +141,7 @@ public class CropConfig {
config.getString(key + ".requirements." + requirement + ".message")
));
case "papi-condition" -> requirementList.add(new CustomPapi(
Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".papi-condition")).getValues(false),
Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false),
config.getString(key + ".requirements." + requirement + ".message")
));
}

View File

@@ -88,6 +88,8 @@ public class MainConfig {
public static boolean syncSeason;
public static World syncWorld;
public static boolean autoBackUp;
public static boolean needSkyLight;
public static int skyLightLevel;
public static void load() {
ConfigUtil.update("config.yml");
@@ -146,6 +148,9 @@ public class MainConfig {
enableCrow = config.getBoolean("mechanics.crow.enable", false);
crowChance = config.getDouble("mechanics.crow.chance", 0.001);
skyLightLevel = config.getInt("mechanics.dead-if-no-sky-light.level", 10);
needSkyLight = config.getBoolean("mechanics.dead-if-no-sky-light.enable", true);
String[] split = StringUtils.split(config.getString("mechanics.default-quality-ratio", "17/2/1"), "/");
double[] weight = new double[3];
assert split != null;

View File

@@ -148,7 +148,7 @@ public abstract class OraxenHandler extends HandlerP {
if (waterEvent.isCancelled()) {
return true;
}
nbtItem.setInteger("WaterAmount", water - 1);
nbtItem.setInteger("WaterAmount", --water);
if (SoundConfig.waterPot.isEnable()) {
AdventureUtil.playerSound(

View File

@@ -85,21 +85,41 @@ public class CropManager extends Function {
public void load() {
super.load();
this.customWorlds = new ConcurrentHashMap<>();
this.itemSpawnListener = new ItemSpawnListener(this);
this.worldListener = new WorldListener(this);
this.armorStandUtil = new ArmorStandUtil(this);
loadMode();
loadSeason();
//load Worlds
for (World world : Bukkit.getWorlds()) {
onWorldLoad(world);
}
//new Time Check task
this.timerTask = new TimerTask(this);
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
}
public void loadMode() {
if (this.handler != null) {
handler.unload();
handler = null;
}
//Custom Plugin
if (MainConfig.customPlugin.equals("itemsadder")) {
customInterface = new ItemsAdderHook();
if (MainConfig.cropMode) {
this.handler = new ItemsAdderWireHandler(this);
this.cropMode = new ItemsAdderWireCropImpl(this);
this.handler.load();
}
else {
this.handler = new ItemsAdderFrameHandler(this);
this.cropMode = new ItemsAdderFrameCropImpl(this);
this.handler.load();
}
}
else if (MainConfig.customPlugin.equals("oraxen")){
@@ -107,29 +127,25 @@ public class CropManager extends Function {
if (MainConfig.cropMode) {
this.handler = new OraxenWireHandler(this);
this.cropMode = new OraxenWireCropImpl(this);
this.handler.load();
}
else {
this.handler = new OraxenFrameHandler(this);
this.cropMode = new OraxenFrameCropImpl(this);
this.handler.load();
}
}
}
//new Time Check task
this.timerTask = new TimerTask(this);
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
handler.load();
public void loadSeason() {
if (SeasonConfig.enable) {
if (MainConfig.realisticSeasonHook) seasonInterface = new RealisticSeasonsHook();
else seasonInterface = new InternalSeason();
seasonInterface.load();
}
seasonInterface.load();
//load Worlds
for (World world : Bukkit.getWorlds()) {
onWorldLoad(world);
else if (this.seasonInterface != null) {
this.seasonInterface.unload();
this.seasonInterface = null;
}
}

View File

@@ -157,9 +157,7 @@ public class CustomWorld {
}
scarecrowCache.put(en.getKey(), simpleLocations);
}
}
SeasonUtils.setSeason(world, CCSeason.UNKNOWN);
}
catch (FileNotFoundException e) {
//bypass
@@ -183,7 +181,6 @@ public class CustomWorld {
} catch (IOException e) {
e.printStackTrace();
}
SeasonUtils.unloadSeason(world);
}
private void loadSeason() {

View File

@@ -62,6 +62,12 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface {
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
Crop crop = CropConfig.CROPS.get(cropKey);
if (crop == null) return true;
if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) {
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
return true;
}
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
return true;

View File

@@ -50,6 +50,15 @@ public class ItemsAdderWireCropImpl implements CropModeInterface{
String cropKey = StringUtils.split(cropNameList[0], ":")[1];
Crop crop = CropConfig.CROPS.get(cropKey);
if (crop == null) return true;
if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);
customInterface.placeWire(location, BasicItemConfig.deadCrop);
});
return true;
}
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);

View File

@@ -64,6 +64,13 @@ public class OraxenFrameCropImpl implements CropModeInterface {
String cropKey = cropNameList[0];
Crop crop = CropConfig.CROPS.get(cropKey);
if (crop == null) return true;
if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) {
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop);
return true;
}
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop);

View File

@@ -50,9 +50,16 @@ public class OraxenWireCropImpl implements CropModeInterface{
String cropKey = cropNameList[0];
Crop crop = CropConfig.CROPS.get(cropKey);
if (crop == null) return true;
if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.placeWire(location, BasicItemConfig.deadCrop);
});
return true;
}
if (cropManager.isWrongSeason(location, crop.getSeasons())) {
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);
customInterface.placeWire(location, BasicItemConfig.deadCrop);
});
return true;

View File

@@ -75,7 +75,7 @@ public class CustomPapi implements RequirementInterface {
@Override
public boolean isConditionMet(PlantingCondition plantingCondition) {
if (!papiRequirement.isMet(plantingCondition.getPapiMap())) {
AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg);
if (msg != null) AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg);
return false;
}
return true;