9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-26 02:19:28 +00:00
This commit is contained in:
Xiao-MoMi
2022-07-30 15:33:58 +08:00
parent 9f11da2b60
commit 9caf4804cd
18 changed files with 190 additions and 105 deletions

View File

@@ -34,6 +34,7 @@ import net.momirealms.customcrops.requirements.YPos;
import net.momirealms.customcrops.utils.*;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -91,7 +92,12 @@ public class ConfigReader {
public static boolean quality;
public static boolean canAddWater;
public static boolean allWorld;
public static boolean pwSeason;
public static boolean nwSeason;
public static boolean needEmptyHand;
public static boolean boneMeal;
public static Particle boneMealSuccess;
public static double boneMealChance;
public static double quality_1;
public static double quality_2;
public static SkillXP skillXP;
@@ -123,6 +129,14 @@ public class ConfigReader {
hasParticle = config.getBoolean("config.water-particles", true);
rightClickHarvest = config.getBoolean("config.right-click-harvest", true);
needEmptyHand = config.getBoolean("config.harvest-with-empty-hand", true);
pwSeason = config.getBoolean("config.prevent-plant-if-wrong-season", true);
nwSeason = config.getBoolean("config.should-notify-if-wrong-season", true);
boneMeal = config.getBoolean("config.bone-meal.enable", true);
if (boneMeal){
boneMealChance = config.getDouble("config.bone-meal.chance",0.5);
boneMealSuccess = Particle.valueOf(config.getString("config.bone-meal.success-particle", "VILLAGER_HAPPY").toUpperCase());
}
//数量与高度限制
enableLimit = config.getBoolean("config.limit.enable",true);
@@ -532,78 +546,37 @@ public class ConfigReader {
YamlConfiguration config = getConfig("fertilizer.yml");
if (config.contains("speed")){
config.getConfigurationSection("speed").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("speed." + key + ".item"), ":")[1].equals(key)){
SpeedGrow speedGrow = new SpeedGrow(key, config.getInt("speed." + key + ".times"), config.getDouble("speed." + key + ".chance"), config.getBoolean("加速肥料." + key + ".before-plant"));
speedGrow.setName(config.getString("speed." + key + ".name"));
FERTILIZERS.put(key, speedGrow);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] fertilizer " + key + "'s key should be the same with ItemsAdder item's key </red>");
SpeedGrow speedGrow = new SpeedGrow(key, config.getInt("speed." + key + ".times"), config.getDouble("speed." + key + ".chance"), config.getBoolean("speed." + key + ".before-plant"));
speedGrow.setName(config.getString("speed." + key + ".name"));
if (config.contains("speed." + key + ".particle")){
speedGrow.setParticle(Particle.valueOf(config.getString("speed." + key + ".particle").toUpperCase()));
}
FERTILIZERS.put(StringUtils.split(config.getString("speed." + key + ".item"), ":")[1], speedGrow);
});
}
if (config.contains("retaining")){
config.getConfigurationSection("retaining").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("retaining." + key + ".item"), ":")[1].equals(key)){
RetainingSoil retainingSoil = new RetainingSoil(key, config.getInt("retaining." + key + ".times"), config.getDouble("retaining." + key + ".chance"), config.getBoolean("保湿肥料." + key + ".before-plant"));
retainingSoil.setName(config.getString("retaining." + key + ".name"));
FERTILIZERS.put(key, retainingSoil);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] fertilizer " + key + "'s key should be the same with ItemsAdder item's key </red>");
RetainingSoil retainingSoil = new RetainingSoil(key, config.getInt("retaining." + key + ".times"), config.getDouble("retaining." + key + ".chance"), config.getBoolean("retaining." + key + ".before-plant"));
retainingSoil.setName(config.getString("retaining." + key + ".name"));
if (config.contains("retaining." + key + ".particle")){
retainingSoil.setParticle(Particle.valueOf(config.getString("retaining." + key + ".particle").toUpperCase()));
}
FERTILIZERS.put(StringUtils.split(config.getString("retaining." + key + ".item"), ":")[1], retainingSoil);
});
}
if (config.contains("quality")){
config.getConfigurationSection("quality").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("quality." + key + ".item"), ":")[1].equals(key)){
String[] split = StringUtils.split(config.getString("quality." + key + ".chance"), "/");
int[] weight = new int[3];
weight[0] = Integer.parseInt(split[0]);
weight[1] = Integer.parseInt(split[1]);
weight[2] = Integer.parseInt(split[2]);
QualityCrop qualityCrop = new QualityCrop(key, config.getInt("quality." + key + ".times"), weight, config.getBoolean("quality." + key + ".before-plant"));
qualityCrop.setName(config.getString("quality." + key + ".name"));
FERTILIZERS.put(key, qualityCrop);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] fertilizer " + key + "'s key should be the same with ItemsAdder item's key </red>");
}
});
}
if (config.contains("加速肥料")){
config.getConfigurationSection("加速肥料").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("加速肥料." + key + ".item"), ":")[1].equals(key)){
SpeedGrow speedGrow = new SpeedGrow(key, config.getInt("加速肥料." + key + ".times"), config.getDouble("加速肥料." + key + ".chance"), config.getBoolean("加速肥料." + key + ".before-plant"));
speedGrow.setName(config.getString("加速肥料." + key + ".name"));
FERTILIZERS.put(key, speedGrow);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] 肥料 " + key + " 与ItemsAdder物品ID不一致</red>");
}
});
}
if (config.contains("保湿肥料")){
config.getConfigurationSection("保湿肥料").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("保湿肥料." + key + ".item"), ":")[1].equals(key)){
RetainingSoil retainingSoil = new RetainingSoil(key, config.getInt("保湿肥料." + key + ".times"), config.getDouble("保湿肥料." + key + ".chance"), config.getBoolean("保湿肥料." + key + ".before-plant"));
retainingSoil.setName(config.getString("保湿肥料." + key + ".name"));
FERTILIZERS.put(key, retainingSoil);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] 肥料 " + key + " 与ItemsAdder物品ID不一致</red>");
}
});
}
if (config.contains("品质肥料")){
config.getConfigurationSection("品质肥料").getKeys(false).forEach(key -> {
if (StringUtils.split(config.getString("品质肥料." + key + ".item"), ":")[1].equals(key)){
String[] split = StringUtils.split(config.getString("品质肥料." + key + ".chance"), "/");
int[] weight = new int[3];
weight[0] = Integer.parseInt(split[0]);
weight[1] = Integer.parseInt(split[1]);
weight[2] = Integer.parseInt(split[2]);
QualityCrop qualityCrop = new QualityCrop(key, config.getInt("品质肥料." + key + ".times"), weight, config.getBoolean("品质肥料." + key + ".before-plant"));
qualityCrop.setName(config.getString("品质肥料." + key + ".name"));
FERTILIZERS.put(key, qualityCrop);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] 肥料 " + key + " 与ItemsAdder物品ID不一致</red>");
String[] split = StringUtils.split(config.getString("quality." + key + ".chance"), "/");
int[] weight = new int[3];
weight[0] = Integer.parseInt(split[0]);
weight[1] = Integer.parseInt(split[1]);
weight[2] = Integer.parseInt(split[2]);
QualityCrop qualityCrop = new QualityCrop(key, config.getInt("quality." + key + ".times"), weight, config.getBoolean("quality." + key + ".before-plant"));
qualityCrop.setName(config.getString("quality." + key + ".name"));
if (config.contains("quality." + key + ".particle")){
qualityCrop.setParticle(Particle.valueOf(config.getString("quality." + key + ".particle").toUpperCase()));
}
FERTILIZERS.put(StringUtils.split(config.getString("quality." + key + ".item"), ":")[1], qualityCrop);
});
}
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><white>" + FERTILIZERS.size() + " <color:#FFEBCD>fertilizers loaded!");
@@ -632,6 +605,9 @@ public class ConfigReader {
public static Key harvestKey;
public static net.kyori.adventure.sound.Sound.Source harvestSource;
public static Key boneMealKey;
public static net.kyori.adventure.sound.Sound.Source boneMealSource;
public static void loadSound(){
YamlConfiguration config = getConfig("sounds.yml");
@@ -655,6 +631,9 @@ public class ConfigReader {
harvestKey = Key.key(config.getString("harvest.sound", "minecraft:block.crop.break"));
harvestSource = net.kyori.adventure.sound.Sound.Source.valueOf(config.getString("harvest.type", "player").toUpperCase());
boneMealKey = Key.key(config.getString("bonemeal.sound", "minecraft:item.hoe.till"));
boneMealSource = net.kyori.adventure.sound.Sound.Source.valueOf(config.getString("bonemeal.type","player").toUpperCase());
}
}
}

View File

@@ -17,10 +17,13 @@
package net.momirealms.customcrops.fertilizer;
import org.bukkit.Particle;
public interface Fertilizer {
String getKey();
int getTimes();
void setTimes(int times);
boolean isBefore();
String getName();
Particle getParticle();
}

View File

@@ -17,6 +17,8 @@
package net.momirealms.customcrops.fertilizer;
import org.bukkit.Particle;
public class QualityCrop implements Fertilizer{
private int[] chance;
@@ -24,6 +26,7 @@ public class QualityCrop implements Fertilizer{
private int times;
private final boolean before;
private String name;
private Particle particle;
public QualityCrop(String key, int times, int[] chance, boolean before) {
this.chance = chance;
@@ -42,9 +45,12 @@ public class QualityCrop implements Fertilizer{
public boolean isBefore() {return this.before;}
@Override
public String getName() {return this.name;}
@Override
public Particle getParticle() {return this.particle;}
public int[] getChance() {return chance;}
public void setName(String name) {this.name = name;}
public void setChance(int[] chance) {this.chance = chance;}
public void setKey(String key) {this.key = key;}
public int[] getChance() {return chance;}
public void setParticle(Particle particle) {this.particle = particle;}
}

View File

@@ -17,13 +17,16 @@
package net.momirealms.customcrops.fertilizer;
import org.bukkit.Particle;
public class RetainingSoil implements Fertilizer{
private double chance;
private String key;
private int times;
private final boolean before;
public String name;
private String name;
private Particle particle;
public RetainingSoil(String key, int times, double chance, boolean before){
this.times = times;
@@ -42,9 +45,12 @@ public class RetainingSoil implements Fertilizer{
public boolean isBefore() {return this.before;}
@Override
public String getName() {return this.name;}
@Override
public Particle getParticle() {return this.particle;}
public double getChance() {return chance;}
public void setName(String name) {this.name = name;}
public void setChance(double chance) {this.chance = chance;}
public void setKey(String key) {this.key = key;}
public double getChance() {return chance;}
public void setParticle(Particle particle) {this.particle = particle;}
}

View File

@@ -17,6 +17,8 @@
package net.momirealms.customcrops.fertilizer;
import org.bukkit.Particle;
public class SpeedGrow implements Fertilizer{
private double chance;
@@ -24,6 +26,7 @@ public class SpeedGrow implements Fertilizer{
private int times;
private final boolean before;
private String name;
private Particle particle;
public SpeedGrow(String key, int times, double chance, boolean before){
this.chance = chance;
@@ -42,9 +45,12 @@ public class SpeedGrow implements Fertilizer{
public boolean isBefore() {return this.before;}
@Override
public String getName() {return this.name;}
@Override
public Particle getParticle() {return this.particle;}
public double getChance() {return chance;}
public void setName(String name) {this.name = name;}
public double getChance() {return chance;}
public void setParticle(Particle particle) {this.particle = particle;}
public void setChance(double chance) {this.chance = chance;}
public void setKey(String key) {this.key = key;}
}

View File

@@ -136,8 +136,9 @@ public class BreakBlock implements Listener {
if(CustomBlock.byAlreadyPlaced(blockUp) != null){
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(blockUp);
String cropNamespacedId = customBlock.getNamespacedID();
if(cropNamespacedId.contains("_stage_") && !cropNamespacedId.equals(ConfigReader.Basic.dead)){
if(cropNamespacedId.contains("_stage_")){
CustomBlock.remove(location);
if (cropNamespacedId.equals(ConfigReader.Basic.dead)) return;
if (ConfigReader.Config.quality){
String[] cropNameList = StringUtils.split(StringUtils.split(cropNamespacedId, ":")[1], "_");
int nextStage = Integer.parseInt(cropNameList[2]) + 1;

View File

@@ -123,8 +123,12 @@ public class RightClick implements Listener {
}
}
}
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason);
return;
if (ConfigReader.Config.nwSeason){
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason);
}
if (ConfigReader.Config.pwSeason){
return;
}
}
if(location.getBlock().getType() != Material.AIR){
return;
@@ -314,18 +318,35 @@ public class RightClick implements Listener {
}
}
}
else if(ConfigReader.Config.rightClickHarvest && !ConfigReader.Config.needEmptyHand){
else if (ConfigReader.Config.boneMeal && itemStack.getType() == Material.BONE_MEAL && action == Action.RIGHT_CLICK_BLOCK){
Block block = event.getClickedBlock();
if (block != null){
rightClickHarvest(block, player);
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
if (customBlock == null) return;
for (Integration integration : ConfigReader.Config.integration){
if(!integration.canPlace(block.getLocation(), player)) return;
}
String namespacedID = customBlock.getNamespacedID();
if (namespacedID.contains("_stage_") && !namespacedID.equals(ConfigReader.Basic.dead)){
int nextStage = Integer.parseInt(namespacedID.substring(namespacedID.length()-1)) + 1;
String next = StringUtils.chop(namespacedID) + nextStage;
if (CustomBlock.getInstance(next) != null){
Location location = block.getLocation();
itemStack.setAmount(itemStack.getAmount() - 1);
AdventureManager.playerSound(player, ConfigReader.Sounds.boneMealSource, ConfigReader.Sounds.boneMealKey);
if (Math.random() < ConfigReader.Config.boneMealChance){
CustomBlock.remove(location);
CustomBlock.place(next, location);
block.getWorld().spawnParticle(ConfigReader.Config.boneMealSuccess, location.add(0.5,0.3,0.5),5,0.2,0.2,0.2);
}
}
}
}
else if(ConfigReader.Config.rightClickHarvest && !ConfigReader.Config.needEmptyHand && action == Action.RIGHT_CLICK_BLOCK){
rightClickHarvest(event.getClickedBlock(), player);
}
}
else if (ConfigReader.Config.rightClickHarvest && action == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
if (block != null){
rightClickHarvest(block, player);
}
rightClickHarvest(event.getClickedBlock(), player);
}
}
}
@@ -426,6 +447,9 @@ public class RightClick implements Listener {
RetainingSoil retainingSoil = new RetainingSoil(config.getKey(), config.getTimes(),config.getChance(), config.isBefore());
PotManager.Cache.put(SimpleLocation.fromLocation(location), retainingSoil);
}
if (fertilizerConfig.getParticle() != null){
location.getWorld().spawnParticle(fertilizerConfig.getParticle(), location.add(0.5,1.3,0.5), 5,0.2,0.2,0.2);
}
}
/**

View File

@@ -2,7 +2,6 @@ config:
#english spanish chinese
lang: english
integration:
#integration to prevent other players' grief
Residence: false
@@ -67,10 +66,10 @@ config:
log-time-consume: false
#Defaultly crops will only grow in loaded chunks.
#If you want a mechanic similar to OriginRealms just DISABLE SEASON, GIGANTIC(OverWeight) and REPEATED HARVESTING.
#In this way crops data will be removed from file after it comes to its final stage.
#If you want a mechanic similar to OriginRealms just DISABLE SEASON and REPEATED HARVESTING.
#In this way crops data will be removed from file when it comes to its final stage.
#In other words, plugin will only record the crops still on growing.
#NEVER SET "only-grow-in-loaded-chunks" FALSE IF YOU DON'T DISABLE THE THREE FEATURES MENTIONED ABOVE.
#NEVER SET "only-grow-in-loaded-chunks" FALSE IF YOU ARE USING THE FEATURES MENTIONED ABOVE.
#Otherwise it would be laggy because too many data in cache.
only-grow-in-loaded-chunks: true
@@ -85,4 +84,15 @@ config:
#If "right-click-harvest" is true
#Should player be allowed to harvest with items in hand
harvest-with-empty-hand: true
harvest-with-empty-hand: true
#Should player be prevented from planting if wrong season
prevent-plant-if-wrong-season: true
#Should notify player of the wrong season?
should-notify-if-wrong-season: true
#Will bone meal accelerate the growth of crop
bone-meal:
enable: true
chance: 0.5
success-particle: VILLAGER_HAPPY

View File

@@ -4,21 +4,23 @@
crops:
tomato:
#the total amount of crops to be dropped
amount: 1~4
#Quality Items
quality:
1: customcrops:tomato
2: customcrops:tomato_silver_star
3: customcrops:tomato_golden_star
#When harvesting, should the crop drop the loots from ItemsAdder too
#This is useful for dropping seeds and other items
drop-ia-loots: false
#optional
#The chance that a crop grow a stage at grow time
grow-chance: 0.9
#When harvesting, should the crop drop the loots from ItemsAdder too
#This is useful for droping seeds and other items
drop-ia-loots: false
#optional
#Overweight
gigantic:
@@ -61,7 +63,6 @@ crops:
season:
- spring
grape:
amount: 2~4
quality:

View File

@@ -10,6 +10,10 @@ speed:
item: customcrops:speed_1
#Should this fertilizer be used before planting
before-plant: true
#Optional
#The particle to display
#https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html
#particle: VILLAGER_HAPPY
speed_2:
name: '뀍'

View File

@@ -24,4 +24,8 @@ use-fertilizer:
harvest:
sound: minecraft:block.crop.break
type: player
bonemeal:
sound: minecraft:item.hoe.till
type: player

View File

@@ -8,6 +8,9 @@ config:
PlotSquared: false
Towny: false
Lands: false
AureliumSkills: false
mcMMO: false
MMOCore: false
#生长时间点(tick)
#1000代表上午7点农作物陆续开始生长
@@ -59,11 +62,11 @@ config:
log-time-consume: false
#是否只有加载中的区块农作物才会生长
#如果你不使用季节、可重复收获、巨大化农作物特性
#如果你不使用季节、可重复收获特性
#插件data只会记录正在生长中某个阶段的农作物数据
#生长到最后一阶段农作物生长数据就会清除
#那么可以尝试设置此值为false来让数据内全部农作物生长
#如果你使用上述三个特性中的任意一个请不要设置为false
#如果你使用上述特性中的任意一个请不要设置为false
#否则农作物生长到最后一阶段不会从数据中清除,过大的数据量
#可能会导致服务器严重卡顿
only-grow-in-loaded-chunks: true
@@ -79,4 +82,15 @@ config:
right-click-harvest: true
#玩家是否需要空手右键收获
harvest-with-empty-hand: true
harvest-with-empty-hand: true
#是否阻止玩家在错误的季节种植
prevent-plant-if-wrong-season: true
#是否告知玩家这是错误的季节
should-notify-if-wrong-season: true
#骨粉设置
bone-meal:
enable: true
chance: 0.5
success-particle: VILLAGER_HAPPY

View File

@@ -12,21 +12,24 @@ crops:
1: customcrops:tomato
2: customcrops:tomato_silver_star
3: customcrops:tomato_golden_star
#农作物每个时间点生长一个阶段的概率
#不设置默认为1
grow-chance: 0.9
#收获的时候是否额外掉落IA配置里的战利品
#可用于最后一阶段掉落种子等操作
drop-ia-loots: false
#巨大化植物,以极低的概率生长为另一种形态
gigantic:
block: customcrops:gigantic_tomato
chance: 0.01
#收获时候执行指令
commands:
- 'say {player} harvested a tomato! lol'
#生长季节
season:
- summer
- autumn
#种植所需的条件
requirements:
#适宜的生长高度
yPos:
@@ -53,7 +56,6 @@ crops:
season:
- spring
grape:
amount: 2~4
quality:
@@ -73,4 +75,22 @@ crops:
3: customcrops:corn_golden_star
season:
- autumn
- summer
- summer
pepper:
amount: 3~6
quality:
1: customcrops:pepper
2: customcrops:pepper_silver_star
3: customcrops:pepper_golden_star
season:
- spring
- summer
return: customcrops:pepper_stage_3
garlic:
amount: 3~4
quality:
1: customcrops:garlic
2: customcrops:garlic_silver_star
3: customcrops:garlic_golden_star

View File

@@ -13,6 +13,9 @@ speed:
item: customcrops:speed_1
#肥料是否只有在种植前才能使用
before-plant: true
#施肥的粒子效果(可选)
#https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html
#particle: VILLAGER_HAPPY
speed_2:
name: '뀍'

View File

@@ -25,4 +25,8 @@ use-fertilizer:
#空手收获的音效
harvest:
sound: minecraft:block.crop.break
type: player
#使用骨粉的音效
bonemeal:
sound: minecraft:item.hoe.till
type: player