9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +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);
}
}
/**