9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +00:00

1.5.0-SNAPSHOT-3

This commit is contained in:
Xiao-MoMi
2022-07-04 22:11:12 +08:00
parent 3d71bed588
commit e4b625a196
12 changed files with 157 additions and 66 deletions

View File

@@ -64,6 +64,7 @@ public class ConfigReader {
public static int yMin; public static int yMin;
public static int yMax; public static int yMax;
public static int sprinklerRefill; public static int sprinklerRefill;
public static int timeToGrow;
public static boolean logTime; public static boolean logTime;
public static boolean onlyLoadedGrow; public static boolean onlyLoadedGrow;
public static boolean quality; public static boolean quality;
@@ -86,10 +87,12 @@ public class ConfigReader {
} }
}); });
timeToGrow = config.getInt("config.time-to-grow",60)*20;
//异步读取时间 //异步读取时间
asyncCheck = config.getBoolean("config.async-time-check",false); asyncCheck = config.getBoolean("config.async-time-check",false);
logTime = config.getBoolean("config.log-time-consume",false); logTime = config.getBoolean("config.log-time-consume",false);
onlyLoadedGrow = config.getBoolean("config.only-grow-in-loaded-chunks",true); onlyLoadedGrow = !config.getBoolean("config.only-grow-in-loaded-chunks",true);
//骨粉设置(已废弃) //骨粉设置(已废弃)
// useBoneMeal = config.getBoolean("config.bone-meal.enable",false); // useBoneMeal = config.getBoolean("config.bone-meal.enable",false);
@@ -267,9 +270,9 @@ public class ConfigReader {
range = config.getInt("season.greenhouse.range",7); range = config.getInt("season.greenhouse.range",7);
} }
seasonChange = config.getBoolean("season.auto-season-change.enable",false); seasonChange = config.getBoolean("season.auto-season-change.enable",false);
duration = config.getInt("season.auto-season-change.duration",28);
if (seasonChange) { if (seasonChange) {
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>当前季节变换模式: <gold>自动"); AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>当前季节变换模式: <gold>自动");
duration = config.getInt("season.auto-season-change.duration",28);
}else { }else {
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>当前季节变换模式: <gold>指令"); AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>当前季节变换模式: <gold>指令");
} }
@@ -303,6 +306,7 @@ public class ConfigReader {
public static String forceSave; public static String forceSave;
public static boolean hasCropInfo; public static boolean hasCropInfo;
public static boolean hasSprinklerInfo; public static boolean hasSprinklerInfo;
public static boolean hasWaterInfo;
public static int cropTime; public static int cropTime;
public static int sprinklerTime; public static int sprinklerTime;
public static String cropText; public static String cropText;
@@ -311,6 +315,10 @@ public class ConfigReader {
public static String sprinklerEmpty; public static String sprinklerEmpty;
public static String sprinklerRight; public static String sprinklerRight;
public static String beforePlant; public static String beforePlant;
public static String waterLeft;
public static String waterFull;
public static String waterEmpty;
public static String waterRight;
public static double cropOffset; public static double cropOffset;
public static double sprinklerOffset; public static double sprinklerOffset;
@@ -340,6 +348,7 @@ public class ConfigReader {
forceSave = config.getString("messages.force-save"); forceSave = config.getString("messages.force-save");
beforePlant = config.getString("messages.before-plant"); beforePlant = config.getString("messages.before-plant");
hasCropInfo = config.getBoolean("hologram.grow-info.enable"); hasCropInfo = config.getBoolean("hologram.grow-info.enable");
if (hasCropInfo){ if (hasCropInfo){
cropTime = config.getInt("hologram.grow-info.duration"); cropTime = config.getInt("hologram.grow-info.duration");
@@ -355,6 +364,13 @@ public class ConfigReader {
sprinklerRight = config.getString("hologram.sprinkler-info.right"); sprinklerRight = config.getString("hologram.sprinkler-info.right");
sprinklerOffset = config.getDouble("hologram.sprinkler-info.y-offset"); sprinklerOffset = config.getDouble("hologram.sprinkler-info.y-offset");
} }
hasWaterInfo = config.getBoolean("actionbar.watering-can.enable");
if (hasWaterInfo){
waterLeft = config.getString("actionbar.watering-can.left");
waterFull = config.getString("actionbar.watering-can.full");
waterEmpty = config.getString("actionbar.watering-can.empty");
waterRight = config.getString("actionbar.watering-can.right");
}
} }
} }

View File

@@ -1,5 +1,6 @@
package net.momirealms.customcrops; package net.momirealms.customcrops;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.momirealms.customcrops.commands.Executor; import net.momirealms.customcrops.commands.Executor;
import net.momirealms.customcrops.commands.Completer; import net.momirealms.customcrops.commands.Completer;
@@ -15,6 +16,8 @@ import net.momirealms.customcrops.utils.BackUp;
import net.momirealms.customcrops.utils.HoloUtil; import net.momirealms.customcrops.utils.HoloUtil;
import net.momirealms.customcrops.utils.Placeholders; import net.momirealms.customcrops.utils.Placeholders;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects; import java.util.Objects;
@@ -76,6 +79,8 @@ public final class CustomCrops extends JavaPlugin {
this.potManager = new PotManager(this); this.potManager = new PotManager(this);
this.potManager.loadData(); this.potManager.loadData();
NBTItem nbtItem = new NBTItem(new ItemStack(Material.WHEAT));
//启动完成 //启动完成
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件已加载!作者:小默米 QQ:3266959688"); AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件已加载!作者:小默米 QQ:3266959688");
} }
@@ -91,6 +96,11 @@ public final class CustomCrops extends JavaPlugin {
this.seasonManager.saveData(); this.seasonManager.saveData();
} }
//备份数据
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件数据自动备份中...");
BackUp.backUpData();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>备份已完成!");
//清除悬浮展示实体 //清除悬浮展示实体
HoloUtil.cache.keySet().forEach(player -> { HoloUtil.cache.keySet().forEach(player -> {
HoloUtil.cache.get(player).remove(); HoloUtil.cache.get(player).remove();
@@ -104,11 +114,6 @@ public final class CustomCrops extends JavaPlugin {
this.cropTimerAsync.stopTimer(cropTimerAsync.getTaskID()); this.cropTimerAsync.stopTimer(cropTimerAsync.getTaskID());
} }
//备份数据
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件数据自动备份中...");
BackUp.backUpData();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>备份已完成!");
//卸载完成 //卸载完成
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件已卸载!作者:小默米 QQ:3266959688"); AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>插件已卸载!作者:小默米 QQ:3266959688");
} }

View File

@@ -4,6 +4,7 @@ import net.momirealms.customcrops.utils.AdventureManager;
import net.momirealms.customcrops.ConfigReader; import net.momirealms.customcrops.ConfigReader;
import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.utils.BackUp; import net.momirealms.customcrops.utils.BackUp;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -48,7 +49,9 @@ public class Executor implements CommandExecutor {
lackArgs(sender); lackArgs(sender);
return true; return true;
} }
plugin.getCropManager().cropGrow(args[1]); Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
plugin.getCropManager().cropGrow(args[1]);
});
if (sender instanceof Player player){ if (sender instanceof Player player){
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.forceGrow.replace("{world}",args[1])); AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.forceGrow.replace("{world}",args[1]));
}else { }else {
@@ -61,7 +64,9 @@ public class Executor implements CommandExecutor {
lackArgs(sender); lackArgs(sender);
return true; return true;
} }
plugin.getSprinklerManager().sprinklerWork(args[1]); Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
plugin.getSprinklerManager().sprinklerWork(args[1]);
});
if (sender instanceof Player player){ if (sender instanceof Player player){
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.forceWater.replace("{world}",args[1])); AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.forceWater.replace("{world}",args[1]));
}else { }else {
@@ -115,6 +120,9 @@ public class Executor implements CommandExecutor {
} }
return true; return true;
} }
case "test" -> {
plugin.getCropManager().testData();
}
case "setseason" -> { case "setseason" -> {
if (args.length < 3) { if (args.length < 3) {
lackArgs(sender); lackArgs(sender);

View File

@@ -14,10 +14,13 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.scheduler.BukkitScheduler;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class CropManager { public class CropManager {
@@ -25,9 +28,11 @@ public class CropManager {
private YamlConfiguration data; private YamlConfiguration data;
private final CustomCrops plugin; private final CustomCrops plugin;
public static ConcurrentHashMap<Location, String> Cache = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Location, String> Cache = new ConcurrentHashMap<>();
private BukkitScheduler bukkitScheduler;
public CropManager(CustomCrops plugin){ public CropManager(CustomCrops plugin){
this.plugin = plugin; this.plugin = plugin;
this.bukkitScheduler = Bukkit.getScheduler();
} }
//载入数据 //载入数据
@@ -45,6 +50,15 @@ public class CropManager {
this.data = YamlConfiguration.loadConfiguration(file); this.data = YamlConfiguration.loadConfiguration(file);
} }
public void testData(){
for (int i = -200; i <= 200; i++){
for (int j = -200; j <= 200; j++){
Location location = new Location(Bukkit.getWorld("world"), i, 91,j);
Cache.put(location, "tomato");
}
}
}
//保存数据 //保存数据
public void saveData() { public void saveData() {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "crop.yml"); File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "crop.yml");
@@ -84,7 +98,6 @@ public class CropManager {
Location seedLocation = new Location(world,Double.parseDouble(coordinate[0]),Double.parseDouble(coordinate[1]),Double.parseDouble(coordinate[2])); Location seedLocation = new Location(world,Double.parseDouble(coordinate[0]),Double.parseDouble(coordinate[1]),Double.parseDouble(coordinate[2]));
CustomBlock seedBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock()); CustomBlock seedBlock = CustomBlock.byAlreadyPlaced(seedLocation.getBlock());
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
//需要修改
stringBuilder.append(worldName).append(".").append(chunk).append(".").append(key); stringBuilder.append(worldName).append(".").append(chunk).append(".").append(key);
if(seedBlock == null) { if(seedBlock == null) {
data.set(stringBuilder.toString(), null); data.set(stringBuilder.toString(), null);
@@ -106,16 +119,16 @@ public class CropManager {
String potNamespacedID = pot.getNamespacedID(); String potNamespacedID = pot.getNamespacedID();
String[] cropNameList = StringUtils.split(id,"_"); String[] cropNameList = StringUtils.split(id,"_");
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]); CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
int random = new Random().nextInt(ConfigReader.Config.timeToGrow);
if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){ if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){
//如果启用季节限制且农作物有季节需求 //如果启用季节限制且农作物有季节需求
if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){ if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){
if (isWrongSeason(seedLocation, cropInstance.getSeasons(), worldName)){ if (isWrongSeason(seedLocation, cropInstance.getSeasons(), worldName)){
data.set(stringBuilder.toString(), null); data.set(stringBuilder.toString(), null);
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () -> { bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
CustomBlock.remove(seedLocation); CustomBlock.remove(seedLocation);
CustomBlock.place(ConfigReader.Basic.dead, seedLocation); CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
return null; }, random);
});
return; return;
} }
} }
@@ -128,18 +141,18 @@ public class CropManager {
fertilizer.setTimes(times - 1); fertilizer.setTimes(times - 1);
if (fertilizer instanceof SpeedGrow speedGrow){ if (fertilizer instanceof SpeedGrow speedGrow){
if (Math.random() < speedGrow.getChance() && CustomBlock.getInstance(StringUtils.chop(namespacedID) + (nextStage + 1)) != null){ if (Math.random() < speedGrow.getChance() && CustomBlock.getInstance(StringUtils.chop(namespacedID) + (nextStage + 1)) != null){
addStage(potLocation, seedLocation, namespacedID, nextStage + 1); addStage(potLocation, seedLocation, namespacedID, nextStage + 1, random);
}else { }else {
addStage(potLocation, seedLocation, namespacedID, nextStage); addStage(potLocation, seedLocation, namespacedID, nextStage, random);
} }
}else if(fertilizer instanceof RetainingSoil retainingSoil){ }else if(fertilizer instanceof RetainingSoil retainingSoil){
if (Math.random() < retainingSoil.getChance()){ if (Math.random() < retainingSoil.getChance()){
addStage(seedLocation, namespacedID, nextStage); addStage(seedLocation, namespacedID, nextStage, random);
}else { }else {
addStage(potLocation, seedLocation, namespacedID, nextStage); addStage(potLocation, seedLocation, namespacedID, nextStage, random);
} }
}else if(fertilizer instanceof QualityCrop){ }else if(fertilizer instanceof QualityCrop){
addStage(potLocation, seedLocation, namespacedID, nextStage); addStage(potLocation, seedLocation, namespacedID, nextStage, random);
}else { }else {
AdventureManager.consoleMessage("<red>[CustomCrops] 发现未知类型肥料,已自动清除错误数据!</red>"); AdventureManager.consoleMessage("<red>[CustomCrops] 发现未知类型肥料,已自动清除错误数据!</red>");
PotManager.Cache.remove(potLocation); PotManager.Cache.remove(potLocation);
@@ -149,11 +162,11 @@ public class CropManager {
} }
} }
else { else {
addStage(potLocation, seedLocation, namespacedID, nextStage); addStage(potLocation, seedLocation, namespacedID, nextStage, random);
} }
} }
else if(cropInstance.getGiant() != null){ else if(cropInstance.getGiant() != null){
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () ->{ bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
CustomBlock.remove(potLocation); CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation); CustomBlock.place(ConfigReader.Basic.pot, potLocation);
if(cropInstance.getGiantChance() > Math.random()){ if(cropInstance.getGiantChance() > Math.random()){
@@ -161,25 +174,22 @@ public class CropManager {
CustomBlock.remove(seedLocation); CustomBlock.remove(seedLocation);
CustomBlock.place(cropInstance.getGiant(), seedLocation); CustomBlock.place(cropInstance.getGiant(), seedLocation);
} }
return null; }, random);
});
}else { }else {
if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null); if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null);
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () -> { bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
CustomBlock.remove(potLocation); CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation); CustomBlock.place(ConfigReader.Basic.pot, potLocation);
return null; }, random);
});
} }
}else if(potNamespacedID.equals(ConfigReader.Basic.pot)){ }else if(potNamespacedID.equals(ConfigReader.Basic.pot)){
if(!ConfigReader.Season.enable || cropInstance.getSeasons() == null) return; if(!ConfigReader.Season.enable || cropInstance.getSeasons() == null) return;
if(isWrongSeason(seedLocation, cropInstance.getSeasons(), worldName)){ if(isWrongSeason(seedLocation, cropInstance.getSeasons(), worldName)){
data.set(stringBuilder.toString(), null); data.set(stringBuilder.toString(), null);
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () -> { bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
CustomBlock.remove(seedLocation); CustomBlock.remove(seedLocation);
CustomBlock.place(ConfigReader.Basic.dead, seedLocation); CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
return null; }, random);
});
} }
} }
}); });
@@ -216,21 +226,19 @@ public class CropManager {
return true; return true;
} }
private void addStage(Location potLocation, Location seedLocation, String namespacedID, int nextStage){ private void addStage(Location potLocation, Location seedLocation, String namespacedID, int nextStage, int random){
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () ->{ bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
CustomBlock.remove(potLocation); CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation); CustomBlock.place(ConfigReader.Basic.pot, potLocation);
CustomBlock.remove(seedLocation); CustomBlock.remove(seedLocation);
CustomBlock.place(StringUtils.chop(namespacedID) + nextStage, seedLocation); CustomBlock.place(StringUtils.chop(namespacedID) + nextStage, seedLocation);
return null; }, random);
});
} }
private void addStage(Location seedLocation, String namespacedID, int nextStage){ private void addStage(Location seedLocation, String namespacedID, int nextStage, int random){
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, () ->{ bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
CustomBlock.remove(seedLocation); CustomBlock.remove(seedLocation);
CustomBlock.place(StringUtils.chop(namespacedID) + nextStage, seedLocation); CustomBlock.place(StringUtils.chop(namespacedID) + nextStage, seedLocation);
return null; }, random);
});
} }
} }

View File

@@ -4,19 +4,26 @@ import com.plotsquared.core.location.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public record PlotSquared() implements Integration { public record PlotSquared() implements Integration {
@Override @Override
public boolean canBreak(org.bukkit.Location location, Player player) { public boolean canBreak(org.bukkit.Location location, Player player) {
// PlotAPI api = new PlotAPI(); return isAllowed(location, player);
// PlotPlayer<?> plotPlayer = com.plotsquared.core.PlotSquared.platform().playerManager().getPlayerIfExists(player.getUniqueId());
Location plotLoc = Location.at(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
if (plotLoc.isPlotRoad()) return false;
return plotLoc.getPlotArea().getPlot(plotLoc).isAdded(player.getUniqueId());
} }
@Override @Override
public boolean canPlace(org.bukkit.Location location, Player player) { public boolean canPlace(org.bukkit.Location location, Player player) {
return isAllowed(location, player);
}
private boolean isAllowed(org.bukkit.Location location, Player player) {
// PlotAPI api = new PlotAPI();
// PlotPlayer<?> plotPlayer = com.plotsquared.core.PlotSquared.platform().playerManager().getPlayerIfExists(player.getUniqueId());
Location plotLoc = Location.at(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); Location plotLoc = Location.at(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
if (plotLoc.isPlotRoad()) return false; if (plotLoc.isPlotRoad()) return false;
return plotLoc.getPlotArea().getPlot(plotLoc).isAdded(player.getUniqueId()); if (plotLoc.getPlotArea() != null){
return plotLoc.getPlotArea().getPlot(plotLoc).isAdded(player.getUniqueId());
}else {
return true;
}
} }
} }

View File

@@ -48,8 +48,8 @@ public class InteractEntity implements Listener {
int x = location.getBlockX(); int x = location.getBlockX();
int z = location.getBlockZ(); int z = location.getBlockZ();
int maxWater = config.getWater(); int maxWater = config.getWater();
int currentWater = 0; int currentWater;
Location loc = location.subtract(0,1,0).getBlock().getLocation().add(0,1,0); Location loc = location.clone().subtract(0,1,0).getBlock().getLocation().add(0,1,0);
Sprinkler sprinkler = SprinklerManager.Cache.get(loc); Sprinkler sprinkler = SprinklerManager.Cache.get(loc);
if (itemStack.getType() == Material.WATER_BUCKET){ if (itemStack.getType() == Material.WATER_BUCKET){
itemStack.setType(Material.BUCKET); itemStack.setType(Material.BUCKET);

View File

@@ -180,6 +180,11 @@ public class RightClick implements Listener {
nbtItem.setInteger("WaterAmount", water + 1); nbtItem.setInteger("WaterAmount", water + 1);
player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1); player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1);
itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
if (ConfigReader.Message.hasWaterInfo){
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water + 1) +
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Message.waterRight;
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water + 1)));
}
} }
return; return;
} }
@@ -197,11 +202,21 @@ public class RightClick implements Listener {
itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1);
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw()); waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
if (ConfigReader.Message.hasWaterInfo){
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) +
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight;
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
}
}else if (namespacedID.contains("_stage_")){ }else if (namespacedID.contains("_stage_")){
nbtItem.setInteger("WaterAmount", water - 1); nbtItem.setInteger("WaterAmount", water - 1);
itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1);
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0,1,0), player.getLocation().getYaw()); waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0,1,0), player.getLocation().getYaw());
if (ConfigReader.Message.hasWaterInfo){
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) +
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight;
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
}
} }
} }
return; return;

View File

@@ -25,8 +25,10 @@ public class TimeCheck extends BukkitRunnable {
if(time == cropGrowTime){ if(time == cropGrowTime){
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> { Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> {
plugin.getCropManager().cropGrow(world.getName()); plugin.getCropManager().cropGrow(world.getName());
plugin.getSprinklerManager().sprinklerWork(world.getName());
}); });
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.instance, ()->{
plugin.getSprinklerManager().sprinklerWork(world.getName());
}, ConfigReader.Config.timeToGrow);
} }
}); });
}); });

View File

@@ -33,4 +33,10 @@ public class AdventureManager {
Title title = Title.title(mm.deserialize(s1), mm.deserialize(s2), times); Title title = Title.title(mm.deserialize(s1), mm.deserialize(s2), times);
au.showTitle(title); au.showTitle(title);
} }
public static void playerActionbar(Player player, String s) {
Audience au = CustomCrops.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
au.sendActionBar(mm.deserialize(s));
}
} }

View File

@@ -18,6 +18,11 @@ config:
grow-time: grow-time:
- 1000 - 1000
#生长的时间(秒)
#农作物将在90秒内随机完成生长以避免在短时间内大量方块替换造成卡顿
#但也不建议设置过长时间,否则内存无法及时释放,区块会被持续加载
time-to-grow: 90
#产物品质 #产物品质
quality: quality:
#若不启用则植物成熟阶段会掉落IA配置里的loot #若不启用则植物成熟阶段会掉落IA配置里的loot

View File

@@ -20,8 +20,8 @@ crops:
#生长季节 #生长季节
season: season:
- spring
- summer - summer
- autumn
requirements: requirements:
#适宜的生长高度 #适宜的生长高度
@@ -44,21 +44,30 @@ crops:
2: customcrops:cabbage_silver_star 2: customcrops:cabbage_silver_star
3: customcrops:cabbage_golden_star 3: customcrops:cabbage_golden_star
gigantic: customcrops:gigantic_cabbage gigantic: customcrops:gigantic_cabbage
gigantic-chance: 0.02 gigantic-chance: 0.01
requirements: requirements:
season: season:
- spring - spring
- summer
grape: grape:
amount: 2~4 amount: 2~4
#空手收获后返回第几个生长状态
quality: quality:
1: customcrops:grape 1: customcrops:grape
2: customcrops:grape_silver_star 2: customcrops:grape_silver_star
3: customcrops:grape_golden_star 3: customcrops:grape_golden_star
#空手收获后返回第几个生长状态
return: customcrops:grape_stage_4 return: customcrops:grape_stage_4
requirements: requirements:
season: season:
- spring - autumn
corn:
amount: 1~2
quality:
1: customcrops:corn
2: customcrops:corn_silver_star
3: customcrops:corn_golden_star
requirements:
season:
- autumn
- summer - summer

View File

@@ -5,25 +5,25 @@ messages:
reload: '<white>重载成功! 耗时 <green>{time}ms' reload: '<white>重载成功! 耗时 <green>{time}ms'
no-perm: '<red>权限不足!' no-perm: '<red>权限不足!'
lack-args: '<white>参数不足!' lack-args: '<white>参数不足!'
wrong-args: '参数错误!' wrong-args: '<white>参数错误!'
spring: '春' spring: '春'
summer: '夏' summer: '夏'
autumn: '秋' autumn: '秋'
winter: '冬' winter: '冬'
sprinkler-limit: '此区块的洒水器已到达上限{max}' sprinkler-limit: '<white>此区块的洒水器已到达上限{max}'
crop-limit: '此区块的农作物数量已到达上限{max}' crop-limit: '<white>此区块的农作物数量已到达上限{max}'
not-configed: '此种子未在配置文件中配置!' not-configed: '<white>此种子未在配置文件中配置!'
bad-Y: '此高度不适合这种农作物生长!' bad-Y: '<white>此高度不适合这种农作物生长!'
bad-biome: '此生物群系不适合这种农作物生长!' bad-biome: '<white>此生物群系不适合这种农作物生长!'
bad-perm: '你还没有权限种植这种农作物呢!' bad-perm: '<white>你还没有权限种植这种农作物呢!'
bad-world: '这个农作物无法在这个世界生长!' bad-world: '<white>这个农作物无法在这个世界生长!'
bad-season: '当前季节不适合这种农作物生长!' bad-season: '<white>当前季节不适合这种农作物生长!'
force-grow: '成功强制 {world} 的农作物生长!' force-grow: '<white>成功强制 {world} 的农作物生长!'
force-water: '成功强制 {world} 的洒水器洒水!' force-water: '<white>成功强制 {world} 的洒水器洒水!'
force-save: '成功强制保存缓存信息!' force-save: '<white>成功强制保存缓存信息!'
back-up: '已完成数据备份!' back-up: '<white>已完成数据备份!'
set-season: '成功切换世界 {world} 的季节为 {season}!' set-season: '<white>成功切换世界 {world} 的季节为 {season}!'
before-plant: '这种肥料必须在种植前使用!' before-plant: '<white>这种肥料必须在种植前使用!'
#全息信息显示 #全息信息显示
hologram: hologram:
@@ -40,10 +40,20 @@ hologram:
#洒水器信息 #洒水器信息
sprinkler-info: sprinkler-info:
enable: true enable: true
y-offset: 0.8 y-offset: -0.2
duration: 1 duration: 1
#可用变量 {water}当前水量 {max_water}最大蓄水量 #可用变量 {water}当前水量 {max_water}最大蓄水量
left: '<font:customcrops:default>뀂' left: '<font:customcrops:default>뀂'
full: '뀁뀃' full: '뀁뀃'
empty: '뀁뀄' empty: '뀁뀄'
right: '뀁뀅</font>' right: '뀁뀅</font>'
actionbar:
#使用水壶的时候是否发送actionbar
watering-can:
enable: true
#可用变量 {water}当前水量 {max_water}最大蓄水量
left: '<font:customcrops:default>뀂'
full: '뀁뀃'
empty: '뀁뀄'
right: '뀁뀅</font>'