mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.5.1
This commit is contained in:
@@ -348,7 +348,6 @@ 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");
|
||||||
|
|||||||
@@ -120,8 +120,9 @@ public class Executor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "test" -> {
|
case "cleandata" -> {
|
||||||
plugin.getCropManager().testData();
|
plugin.getCropManager().cleanData();
|
||||||
|
plugin.getSprinklerManager().cleanData();
|
||||||
}
|
}
|
||||||
case "setseason" -> {
|
case "setseason" -> {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
|
|||||||
@@ -50,15 +50,6 @@ 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");
|
||||||
@@ -80,6 +71,17 @@ public class CropManager {
|
|||||||
Cache.clear();
|
Cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//隐藏指令,清除无用数据
|
||||||
|
public void cleanData(){
|
||||||
|
data.getKeys(false).forEach(world -> {
|
||||||
|
data.getConfigurationSection(world).getKeys(false).forEach(chunk ->{
|
||||||
|
if (data.getConfigurationSection(world + "." + chunk).getKeys(false).size() == 0){
|
||||||
|
data.set(world + "." + chunk, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//农作物生长
|
//农作物生长
|
||||||
public void cropGrow(String worldName){
|
public void cropGrow(String worldName){
|
||||||
Long time1 = System.currentTimeMillis();
|
Long time1 = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanData(){
|
||||||
|
data.getKeys(false).forEach(world -> {
|
||||||
|
data.getConfigurationSection(world).getKeys(false).forEach(chunk ->{
|
||||||
|
if (data.getConfigurationSection(world + "." + chunk).getKeys(false).size() == 0){
|
||||||
|
data.set(world + "." + chunk, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void updateData(){
|
public void updateData(){
|
||||||
Cache.forEach((location, sprinklerData) -> {
|
Cache.forEach((location, sprinklerData) -> {
|
||||||
String world = location.getWorld().getName();
|
String world = location.getWorld().getName();
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ public class RightClick implements Listener {
|
|||||||
Action action = event.getAction();
|
Action action = event.getAction();
|
||||||
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
|
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){
|
||||||
ItemStack itemStack = event.getItem();
|
ItemStack itemStack = event.getItem();
|
||||||
if (itemStack == null && action == Action.RIGHT_CLICK_BLOCK){
|
if (itemStack == null){
|
||||||
|
if (action != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||||
@@ -108,88 +109,121 @@ public class RightClick implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
}else {
|
||||||
}
|
NBTItem nbtItem = new NBTItem(itemStack);
|
||||||
NBTItem nbtItem = new NBTItem(itemStack);
|
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
||||||
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
if (nbtCompound != null){
|
||||||
if (nbtCompound != null){
|
String id = nbtCompound.getString("id");
|
||||||
String id = nbtCompound.getString("id");
|
if (id.endsWith("_seeds") && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
||||||
if (id.endsWith("_seeds") && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
String cropName = StringUtils.remove(id, "_seeds");
|
||||||
String cropName = StringUtils.remove(id, "_seeds");
|
Optional<CropInstance> crop = Optional.ofNullable(ConfigReader.CROPS.get(cropName));
|
||||||
Optional<CropInstance> crop = Optional.ofNullable(ConfigReader.CROPS.get(cropName));
|
if (crop.isPresent()){
|
||||||
if (crop.isPresent()){
|
Block block = event.getClickedBlock();
|
||||||
Block block = event.getClickedBlock();
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
if (customBlock == null) return;
|
||||||
if (customBlock == null) return;
|
String namespacedID = customBlock.getNamespacedID();
|
||||||
String namespacedID = customBlock.getNamespacedID();
|
if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
||||||
if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
Location location = block.getLocation().add(0,1,0); //已+1
|
||||||
Location location = block.getLocation().add(0,1,0); //已+1
|
for (Integration integration : ConfigReader.Config.integration){
|
||||||
for (Integration integration : ConfigReader.Config.integration){
|
if(!integration.canPlace(location, player)) return;
|
||||||
if(!integration.canPlace(location, player)) return;
|
|
||||||
}
|
|
||||||
CropInstance cropInstance = crop.get();
|
|
||||||
PlantingCondition plantingCondition = new PlantingCondition(player, location);
|
|
||||||
for (Requirement requirement : cropInstance.getRequirements()){
|
|
||||||
if (!requirement.canPlant(plantingCondition)) return;
|
|
||||||
}
|
|
||||||
Label_out:
|
|
||||||
if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){
|
|
||||||
for (String season : cropInstance.getSeasons()) {
|
|
||||||
if (season.equals(SeasonManager.SEASON.get(location.getWorld().getName()))){
|
|
||||||
break Label_out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(ConfigReader.Season.greenhouse){
|
CropInstance cropInstance = crop.get();
|
||||||
for(int i = 1; i <= ConfigReader.Season.range; i++){
|
PlantingCondition plantingCondition = new PlantingCondition(player, location);
|
||||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(location.clone().add(0,i,0).getBlock());
|
for (Requirement requirement : cropInstance.getRequirements()){
|
||||||
if (cb != null){
|
if (!requirement.canPlant(plantingCondition)) return;
|
||||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigReader.Basic.glass)){
|
}
|
||||||
break Label_out;
|
Label_out:
|
||||||
|
if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){
|
||||||
|
for (String season : cropInstance.getSeasons()) {
|
||||||
|
if (season.equals(SeasonManager.SEASON.get(location.getWorld().getName()))){
|
||||||
|
break Label_out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ConfigReader.Season.greenhouse){
|
||||||
|
for(int i = 1; i <= ConfigReader.Season.range; i++){
|
||||||
|
CustomBlock cb = CustomBlock.byAlreadyPlaced(location.clone().add(0,i,0).getBlock());
|
||||||
|
if (cb != null){
|
||||||
|
if(cb.getNamespacedID().equalsIgnoreCase(ConfigReader.Basic.glass)){
|
||||||
|
break Label_out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason);
|
if(location.getBlock().getType() != Material.AIR){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(CropsPerChunk.isLimited(location)){
|
||||||
|
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
CropManager.Cache.put(location, cropName);
|
||||||
|
CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(location.getBlock().getType() != Material.AIR){
|
}else {
|
||||||
return;
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.not_configed);
|
||||||
}
|
|
||||||
if(CropsPerChunk.isLimited(location)){
|
|
||||||
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
|
||||||
CropManager.Cache.put(location, cropName);
|
|
||||||
CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}else {
|
return;
|
||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.not_configed);
|
|
||||||
}
|
}
|
||||||
return;
|
Optional<WateringCan> can = Optional.ofNullable(ConfigReader.CANS.get(id));
|
||||||
}
|
if (can.isPresent()){
|
||||||
Optional<WateringCan> can = Optional.ofNullable(ConfigReader.CANS.get(id));
|
WateringCan wateringCan = can.get();
|
||||||
if (can.isPresent()){
|
int water = nbtItem.getInteger("WaterAmount");
|
||||||
WateringCan wateringCan = can.get();
|
List<Block> lineOfSight = player.getLineOfSight(null, 5);
|
||||||
int water = nbtItem.getInteger("WaterAmount");
|
for (Block block : lineOfSight) {
|
||||||
List<Block> lineOfSight = player.getLineOfSight(null, 5);
|
if (block.getType() == Material.WATER) {
|
||||||
for (Block block : lineOfSight) {
|
if (wateringCan.getMax() > water){
|
||||||
if (block.getType() == Material.WATER) {
|
nbtItem.setInteger("WaterAmount", water + 1);
|
||||||
if (wateringCan.getMax() > water){
|
player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1);
|
||||||
nbtItem.setInteger("WaterAmount", water + 1);
|
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(water != 0 && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
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.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
||||||
|
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);
|
||||||
|
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
|
||||||
if (ConfigReader.Message.hasWaterInfo){
|
if (ConfigReader.Message.hasWaterInfo){
|
||||||
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water + 1) +
|
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) +
|
||||||
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Message.waterRight;
|
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)));
|
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
|
||||||
|
}
|
||||||
|
}else if (namespacedID.contains("_stage_")){
|
||||||
|
nbtItem.setInteger("WaterAmount", water - 1);
|
||||||
|
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||||
|
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());
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
if(water != 0 && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
Optional<Fertilizer> fertilize = Optional.ofNullable(ConfigReader.FERTILIZERS.get(id));
|
||||||
|
if (fertilize.isPresent() && action == Action.RIGHT_CLICK_BLOCK){
|
||||||
|
Fertilizer fertilizerConfig = fertilize.get();
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||||
if (customBlock == null) return;
|
if (customBlock == null) return;
|
||||||
@@ -198,114 +232,81 @@ public class RightClick implements Listener {
|
|||||||
}
|
}
|
||||||
String namespacedID = customBlock.getNamespacedID();
|
String namespacedID = customBlock.getNamespacedID();
|
||||||
if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
||||||
nbtItem.setInteger("WaterAmount", water - 1);
|
CustomBlock customBlockUp = CustomBlock.byAlreadyPlaced(block.getLocation().clone().add(0,1,0).getBlock());
|
||||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
if (customBlockUp != null){
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1);
|
if (fertilizerConfig.isBefore() && customBlockUp.getNamespacedID().contains("_stage_")){
|
||||||
waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
||||||
if (ConfigReader.Message.hasWaterInfo){
|
return;
|
||||||
String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) +
|
}else {
|
||||||
ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight;
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1)));
|
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
||||||
}
|
addFertilizer(fertilizerConfig, block);
|
||||||
}else if (namespacedID.contains("_stage_")){
|
}
|
||||||
nbtItem.setInteger("WaterAmount", water - 1);
|
|
||||||
itemStack.setItemMeta(nbtItem.getItem().getItemMeta());
|
|
||||||
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());
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
Optional<Fertilizer> fertilize = Optional.ofNullable(ConfigReader.FERTILIZERS.get(id));
|
|
||||||
if (fertilize.isPresent() && action == Action.RIGHT_CLICK_BLOCK){
|
|
||||||
Fertilizer fertilizerConfig = fertilize.get();
|
|
||||||
Block block = event.getClickedBlock();
|
|
||||||
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.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
|
||||||
CustomBlock customBlockUp = CustomBlock.byAlreadyPlaced(block.getLocation().clone().add(0,1,0).getBlock());
|
|
||||||
if (customBlockUp != null){
|
|
||||||
if (fertilizerConfig.isBefore() && customBlockUp.getNamespacedID().contains("_stage_")){
|
|
||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
|
||||||
return;
|
|
||||||
}else {
|
}else {
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
||||||
addFertilizer(fertilizerConfig, block);
|
addFertilizer(fertilizerConfig, block);
|
||||||
}
|
}
|
||||||
}else {
|
}else if (namespacedID.contains("_stage_")){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
if (!fertilizerConfig.isBefore()){
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
addFertilizer(fertilizerConfig, block);
|
addFertilizer(fertilizerConfig, block);
|
||||||
}
|
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
||||||
}else if (namespacedID.contains("_stage_")){
|
}else {
|
||||||
if (!fertilizerConfig.isBefore()){
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
return;
|
||||||
addFertilizer(fertilizerConfig, block);
|
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1);
|
|
||||||
}else {
|
|
||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Optional<Sprinkler> sprinkler = Optional.ofNullable(ConfigReader.SPRINKLERS.get(id));
|
|
||||||
if (sprinkler.isPresent() && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
|
||||||
Location location = event.getClickedBlock().getLocation();
|
|
||||||
for (Integration integration : ConfigReader.Config.integration){
|
|
||||||
if (!integration.canPlace(location, player)) return;
|
|
||||||
}
|
|
||||||
if(IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld())){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(SprinklersPerChunk.isLimited(location)){
|
|
||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.sprinkler_limit.replace("{max}", String.valueOf(ConfigReader.Config.sprinklerLimit)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Sprinkler sprinklerData = new Sprinkler(sprinkler.get().getRange(), 0);
|
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
|
||||||
SprinklerManager.Cache.put(location.add(0,1,0), sprinklerData);
|
|
||||||
IAFurniture.placeFurniture(sprinkler.get().getNamespacedID_2(),location);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ConfigReader.Message.hasCropInfo && id.equals(ConfigReader.Basic.soilDetector) && action == Action.RIGHT_CLICK_BLOCK){
|
|
||||||
Block block = event.getClickedBlock();
|
|
||||||
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_")){
|
|
||||||
Location location = block.getLocation().subtract(0,1,0);
|
|
||||||
Fertilizer fertilizer = PotManager.Cache.get(location);
|
|
||||||
if (fertilizer != null){
|
|
||||||
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
|
||||||
String name = config.getName();
|
|
||||||
int max_times = config.getTimes();
|
|
||||||
if(HoloUtil.cache.get(player) == null) {
|
|
||||||
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5, ConfigReader.Message.cropOffset, 0.5), ConfigReader.Message.cropTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
return;
|
||||||
Location location = block.getLocation();
|
}
|
||||||
Fertilizer fertilizer = PotManager.Cache.get(block.getLocation());
|
Optional<Sprinkler> sprinkler = Optional.ofNullable(ConfigReader.SPRINKLERS.get(id));
|
||||||
if (fertilizer != null){
|
if (sprinkler.isPresent() && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){
|
||||||
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
Location location = event.getClickedBlock().getLocation();
|
||||||
String name = config.getName();
|
for (Integration integration : ConfigReader.Config.integration){
|
||||||
int max_times = config.getTimes();
|
if (!integration.canPlace(location, player)) return;
|
||||||
if(HoloUtil.cache.get(player) == null){
|
}
|
||||||
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5,ConfigReader.Message.cropOffset,0.5), ConfigReader.Message.cropTime);
|
if(IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(SprinklersPerChunk.isLimited(location)){
|
||||||
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.sprinkler_limit.replace("{max}", String.valueOf(ConfigReader.Config.sprinklerLimit)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Sprinkler sprinklerData = new Sprinkler(sprinkler.get().getRange(), 0);
|
||||||
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
SprinklerManager.Cache.put(location.add(0,1,0), sprinklerData);
|
||||||
|
IAFurniture.placeFurniture(sprinkler.get().getNamespacedID_2(),location);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ConfigReader.Message.hasCropInfo && id.equals(ConfigReader.Basic.soilDetector) && action == Action.RIGHT_CLICK_BLOCK){
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
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_")){
|
||||||
|
Location location = block.getLocation().subtract(0,1,0);
|
||||||
|
Fertilizer fertilizer = PotManager.Cache.get(location);
|
||||||
|
if (fertilizer != null){
|
||||||
|
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
||||||
|
String name = config.getName();
|
||||||
|
int max_times = config.getTimes();
|
||||||
|
if(HoloUtil.cache.get(player) == null) {
|
||||||
|
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5, ConfigReader.Message.cropOffset, 0.5), ConfigReader.Message.cropTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){
|
||||||
|
Location location = block.getLocation();
|
||||||
|
Fertilizer fertilizer = PotManager.Cache.get(block.getLocation());
|
||||||
|
if (fertilizer != null){
|
||||||
|
Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey());
|
||||||
|
String name = config.getName();
|
||||||
|
int max_times = config.getTimes();
|
||||||
|
if(HoloUtil.cache.get(player) == null){
|
||||||
|
HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5,ConfigReader.Message.cropOffset,0.5), ConfigReader.Message.cropTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ config:
|
|||||||
|
|
||||||
#生长时间点(tick)
|
#生长时间点(tick)
|
||||||
#洒水器将会在农作物全部完成生长后开始工作
|
#洒水器将会在农作物全部完成生长后开始工作
|
||||||
|
#1000代表上午7点,农作物陆续开始生长
|
||||||
grow-time:
|
grow-time:
|
||||||
- 1000
|
- 1000
|
||||||
|
|
||||||
#生长的时间(秒)
|
#生长的时间(秒)
|
||||||
#农作物将在90秒内随机完成生长以避免在短时间内大量方块替换造成卡顿
|
#农作物将在90秒内随机完成生长以避免在短时间内大量方块替换造成卡顿
|
||||||
#但也不建议设置过长时间,否则内存无法及时释放,区块会被持续加载
|
#但也不建议设置过长时间,否则内存无法及时释放,区块会被持续加载
|
||||||
|
#配合上方的默认时间点,意思为每天上午7点后,农作物将在90秒内完成生长过程
|
||||||
time-to-grow: 90
|
time-to-grow: 90
|
||||||
|
|
||||||
#产物品质
|
#产物品质
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: CustomCrops
|
name: CustomCrops
|
||||||
version: '1.5.0-SNAPSHOT'
|
version: '1.5.1'
|
||||||
main: net.momirealms.customcrops.CustomCrops
|
main: net.momirealms.customcrops.CustomCrops
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
depend:
|
depend:
|
||||||
|
|||||||
Reference in New Issue
Block a user