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-06-14 14:51:37 +08:00
parent a1f53c4ad7
commit bea7e823b6
9 changed files with 142 additions and 145 deletions

View File

@@ -25,11 +25,13 @@ public class BackUp {
BackUp.backUp(crop_data,cropBackUp);
} catch (IOException e) {
e.printStackTrace();
CustomCrops.instance.getLogger().warning("crop-data.yml备份出错!");
}
try {
BackUp.backUp(sprinkler_data,sprinklerBackUp);
} catch (IOException e) {
e.printStackTrace();
CustomCrops.instance.getLogger().warning("sprinkler-data.yml备份出错!");
}
}

View File

@@ -163,35 +163,39 @@ public class ConfigManager {
YamlConfiguration cropConfig = getConfig("crops.yml");
Set<String> keys = cropConfig.getConfigurationSection("crops").getKeys(false);
keys.forEach(key -> {
double chance = cropConfig.getDouble("crops."+key+".grow-chance");
Crop crop = new Crop(key, chance);
if(cropConfig.getConfigurationSection("crops."+key).contains("return")){
crop.setWillReturn(true);
crop.setReturnStage(cropConfig.getString("crops."+key+".return"));
}else {
crop.setWillReturn(false);
}
if(Config.season){
if(cropConfig.getConfigurationSection("crops."+key).contains("season")){
crop.setSeasons(StringUtils.split( cropConfig.getString("crops."+key+".season"), ","));
if(cropConfig.getConfigurationSection("crops."+key).contains("grow-chance")){
double chance = cropConfig.getDouble("crops."+key+".grow-chance");
Crop crop = new Crop(key, chance);
if(cropConfig.getConfigurationSection("crops."+key).contains("return")){
crop.setWillReturn(true);
crop.setReturnStage(cropConfig.getString("crops."+key+".return"));
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误!在启用季节模式的情况下未设置农作物 &f"+ key +" &c的生长季节!", Bukkit.getConsoleSender());
return;
crop.setWillReturn(false);
}
}
if(cropConfig.getConfigurationSection("crops."+key).contains("gigantic")){
crop.setWillGiant(true);
crop.setGiant(cropConfig.getString("crops."+key+".gigantic"));
if(cropConfig.getConfigurationSection("crops."+key).contains("gigantic-chance")){
crop.setGiantChance(cropConfig.getDouble("crops."+key+".gigantic-chance"));
if(Config.season){
if(cropConfig.getConfigurationSection("crops."+key).contains("season")){
crop.setSeasons(StringUtils.split( cropConfig.getString("crops."+key+".season"), ","));
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误!在启用季节模式的情况下未设置农作物 &f"+ key +" &c的生长季节!", Bukkit.getConsoleSender());
return;
}
}
if(cropConfig.getConfigurationSection("crops."+key).contains("gigantic")){
crop.setWillGiant(true);
crop.setGiant(cropConfig.getString("crops."+key+".gigantic"));
if(cropConfig.getConfigurationSection("crops."+key).contains("gigantic-chance")){
crop.setGiantChance(cropConfig.getDouble("crops."+key+".gigantic-chance"));
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误!未设置农作物 &f"+ key +" &c的巨大化概率!", Bukkit.getConsoleSender());
return;
}
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误!未设置农作物 &f"+ key +" &c的巨大化概率!", Bukkit.getConsoleSender());
return;
crop.setWillGiant(false);
}
CONFIG.put(key, crop);
}else {
crop.setWillGiant(false);
MessageManager.consoleMessage("&c[CustomCrops] 错误!未设置农作物 &f"+ key +" &c的生长概率!", Bukkit.getConsoleSender());
}
CONFIG.put(key, crop);
});
if(keys.size() == CONFIG.size()){
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &f成功载入 &a" + CONFIG.size() + " &f种农作物", Bukkit.getConsoleSender());

View File

@@ -51,7 +51,6 @@ public class CropManager {
FileConfiguration data;
data = YamlConfiguration.loadConfiguration(file);
//性能更高
Set<Map.Entry<Location, String>> en = CROPS.entrySet();
for(Map.Entry<Location, String> entry : en){
Location loc = entry.getKey();
@@ -65,8 +64,6 @@ public class CropManager {
CustomCrops.instance.getLogger().warning("农作物数据保存出错");
}
}
/*
生长部分
*/
@@ -78,7 +75,6 @@ public class CropManager {
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
Set<Map.Entry<Location, String>> en = CROPS.entrySet();
for(Map.Entry<Location, String> entry : en){
Location key = entry.getKey();
@@ -86,7 +82,6 @@ public class CropManager {
}
long finish1 = System.currentTimeMillis();
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7农作物数据更新耗时&a" + (finish1 - start1) + "&fms",Bukkit.getConsoleSender());
/*
阶段2清理数据内无效的农作物并让有效农作物生长
*/
@@ -97,10 +92,8 @@ public class CropManager {
String[] coordinate = StringUtils.split(key,",");
//先判断区块是否加载,未加载则不进行下一步计算
if (world.isChunkLoaded(Integer.parseInt(coordinate[0])/16, Integer.parseInt(coordinate[2])/16)){
Location sLoc = new Location(world,Double.parseDouble(coordinate[0]),Double.parseDouble(coordinate[1]),Double.parseDouble(coordinate[2]));
CustomBlock seedBlock = CustomBlock.byAlreadyPlaced(sLoc.getBlock());
if(seedBlock == null){
CROPS.remove(sLoc);
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
@@ -116,22 +109,18 @@ public class CropManager {
return;
}
if(namespacedID.contains("_stage_")){
Location potLoc = sLoc.clone().subtract(0,1,0);
Block potBlock = potLoc.getBlock();
CustomBlock pot = CustomBlock.byAlreadyPlaced(potBlock);
if (pot != null){
String potName = pot.getNamespacedID();
/*
是湿润的种植盆吗
*/
if (potName.equalsIgnoreCase(ConfigManager.Config.watered_pot)){
String[] split = StringUtils.split(namespacedID,":");
String[] cropNameList = StringUtils.split(split[1],"_");
Crop crop = ConfigManager.CONFIG.get(cropNameList[0]);
//季节判断
Label_out:
if(ConfigManager.Config.season){
@@ -246,7 +235,7 @@ public class CropManager {
data.save(file);
}catch (IOException e){
e.printStackTrace();
CustomCrops.instance.getLogger().warning("农作物缓存清理保存出错!");
CustomCrops.instance.getLogger().warning("crop-data.yml保存出错!");
}
long finish3 = System.currentTimeMillis();
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7农作物数据保存耗时&a" + (finish3 - start3) + "&fms",Bukkit.getConsoleSender());

View File

@@ -22,7 +22,7 @@ public class NextSeason {
ConfigManager.Config.current = nextSeason;
CustomCrops.instance.saveConfig();
}else {
CustomCrops.instance.getLogger().warning("季节配置文件出错!");
CustomCrops.instance.getLogger().warning("季节出错!");
}
}
}

View File

@@ -129,7 +129,7 @@ public class SprinklerManager {
data.save(file);
}catch (IOException e){
e.printStackTrace();
CustomCrops.instance.getLogger().warning("洒水器数据保存出错!");
CustomCrops.instance.getLogger().warning("sprinkler-data.yml保存出错!");
}
long finish3 = System.currentTimeMillis();
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据保存耗时&a" + (finish3-start3) + "&fms",Bukkit.getConsoleSender());

View File

@@ -8,7 +8,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
public class ResidenceIntegrations {
public static boolean checkResBuild(Location location, Player player){
FlagPermissions.addFlag("build");
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);

View File

@@ -70,115 +70,115 @@ public class RightClickCustomBlock implements Listener {
右键的是特殊作物吗
*/
if (namespacedId.contains("stage")) {
//下方方块不是自定义方块则返回
Player player = event.getPlayer();
Block blockUnder = clickedBlockLocation.clone().subtract(0,1,0).getBlock();
CustomBlock cb = CustomBlock.byAlreadyPlaced(blockUnder);
if (cb == null) return;
//检测右键的方块下方是否为干燥的种植盆方块
if (cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)) {
//获取手中的物品
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
Location locUnder = clickedBlockLocation.clone().subtract(0,1,0);
//如果手中的是水桶,那么转干为湿
if (mainHandItem.getType() == Material.WATER_BUCKET) {
//扣除水桶
if (player.getGameMode() != GameMode.CREATIVE) {
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
player.getInventory().addItem(new ItemStack(Material.BUCKET));
}
CustomBlock.remove(locUnder);
CustomBlock.place(ConfigManager.Config.watered_pot, locUnder);
} else if (mainHandItem.getType() == Material.WOODEN_SWORD) {
waterPot(mainHandItem, player, locUnder);
//下方方块不是自定义方块则返回
Player player = event.getPlayer();
Block blockUnder = clickedBlockLocation.clone().subtract(0,1,0).getBlock();
CustomBlock cb = CustomBlock.byAlreadyPlaced(blockUnder);
if (cb == null) return;
//检测右键的方块下方是否为干燥的种植盆方块
if (cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)) {
//获取手中的物品
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
Location locUnder = clickedBlockLocation.clone().subtract(0,1,0);
//如果手中的是水桶,那么转干为湿
if (mainHandItem.getType() == Material.WATER_BUCKET) {
//扣除水桶
if (player.getGameMode() != GameMode.CREATIVE) {
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
player.getInventory().addItem(new ItemStack(Material.BUCKET));
}
CustomBlock.remove(locUnder);
CustomBlock.place(ConfigManager.Config.watered_pot, locUnder);
} else if (mainHandItem.getType() == Material.WOODEN_SWORD) {
waterPot(mainHandItem, player, locUnder);
}
//检测右键的方块下方是否为湿润的种植盆方块
else if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.watered_pot)){
//获取手中的物品
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
//如果是骨粉
if (mainHandItem.getType() == Material.BONE_MEAL){
//植物是否具有stage属性
if (namespacedId.contains("_stage_")){
String[] split = StringUtils.split(namespacedId,":");
String[] cropNameList = StringUtils.split(split[1],"_");
//下一生长阶段
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
//植物是否存在下一个stage
if (CustomBlock.getInstance(split[0]+ ":" + cropNameList[0] + "_stage_" + nextStage) != null){
if(player.getGameMode() != GameMode.CREATIVE){
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
}
World world = player.getWorld();
//骨粉的成功率
if (Math.random() < ConfigManager.Config.bone_chance){
CustomBlock.remove(clickedBlockLocation);
CustomBlock.place(split[0] + ":" + cropNameList[0] + "_stage_" + nextStage,clickedBlockLocation);
Particle particleSuccess = Particle.valueOf(ConfigManager.Config.success);
world.spawnParticle(particleSuccess, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
//使用骨粉是否消耗水分
if(ConfigManager.Config.need_water){
CustomBlock.remove(clickedBlockLocation.clone().subtract(0,1,0));
CustomBlock.place(ConfigManager.Config.pot, clickedBlockLocation.clone().subtract(0,1,0));
}
}else {
Particle particleFailure = Particle.valueOf(ConfigManager.Config.failure);
world.spawnParticle(particleFailure, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
}
//检测右键的方块下方是否为湿润的种植盆方块
else if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.watered_pot)){
//获取手中的物品
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
//如果是骨粉
if (mainHandItem.getType() == Material.BONE_MEAL){
//植物是否具有stage属性
if (namespacedId.contains("_stage_")){
String[] split = StringUtils.split(namespacedId,":");
String[] cropNameList = StringUtils.split(split[1],"_");
//下一生长阶段
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
//植物是否存在下一个stage
if (CustomBlock.getInstance(split[0]+ ":" + cropNameList[0] + "_stage_" + nextStage) != null){
if(player.getGameMode() != GameMode.CREATIVE){
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
}
World world = player.getWorld();
//骨粉的成功率
if (Math.random() < ConfigManager.Config.bone_chance){
CustomBlock.remove(clickedBlockLocation);
CustomBlock.place(split[0] + ":" + cropNameList[0] + "_stage_" + nextStage,clickedBlockLocation);
Particle particleSuccess = Particle.valueOf(ConfigManager.Config.success);
world.spawnParticle(particleSuccess, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
//使用骨粉是否消耗水分
if(ConfigManager.Config.need_water){
CustomBlock.remove(clickedBlockLocation.clone().subtract(0,1,0));
CustomBlock.place(ConfigManager.Config.pot, clickedBlockLocation.clone().subtract(0,1,0));
}
}else {
Particle particleFailure = Particle.valueOf(ConfigManager.Config.failure);
world.spawnParticle(particleFailure, clickedBlockLocation.clone().add(0.5, 0.1,0.5), 1 ,0,0,0,0);
}
}
}
}
}
}
/*
右键的是种植盆吗
*/
else if (event.getBlockFace() == BlockFace.UP){
//获取手中的物品
ItemStack item = event.getItem();
Player player = event.getPlayer();
//检测右键的方块是否为干燥的种植盆方块
if (namespacedId.equalsIgnoreCase(ConfigManager.Config.pot)){
//如果手中的是水桶,那么转干为湿
if (item.getType() == Material.WATER_BUCKET){
//扣除水桶
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() - 1);
player.getInventory().addItem(new ItemStack(Material.BUCKET));
}
CustomBlock.remove(clickedBlockLocation);
CustomBlock.place(ConfigManager.Config.watered_pot,clickedBlockLocation);
return;
//获取手中的物品
ItemStack item = event.getItem();
Player player = event.getPlayer();
//检测右键的方块是否为干燥的种植盆方块
if (namespacedId.equalsIgnoreCase(ConfigManager.Config.pot)){
//如果手中的是水桶,那么转干为湿
if (item.getType() == Material.WATER_BUCKET){
//扣除水桶
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() - 1);
player.getInventory().addItem(new ItemStack(Material.BUCKET));
}
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null){
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")){
if(tryPlantSeed(clickedBlockLocation, namespacedID, player)){
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() -1);
}
CustomBlock.remove(clickedBlockLocation);
CustomBlock.place(ConfigManager.Config.watered_pot,clickedBlockLocation);
return;
}
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null){
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")){
if(tryPlantSeed(clickedBlockLocation, namespacedID, player)){
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() -1);
}
}else {
waterPot(item, player, clickedBlockLocation);
}
}else {
waterPot(item, player, clickedBlockLocation);
}
}
//检测右键的方块是否为湿润的种植盆方块
else if(namespacedId.equalsIgnoreCase(ConfigManager.Config.watered_pot)){
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null){
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")){
if(tryPlantSeed(clickedBlockLocation, namespacedID, player)){
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() -1);
}
}
//检测右键的方块是否为湿润的种植盆方块
else if(namespacedId.equalsIgnoreCase(ConfigManager.Config.watered_pot)){
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null){
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")){
if(tryPlantSeed(clickedBlockLocation, namespacedID, player)){
if(player.getGameMode() != GameMode.CREATIVE){
item.setAmount(item.getAmount() -1);
}
}
}
}
}
}
}
}
@@ -280,7 +280,6 @@ public class RightClickCustomBlock implements Listener {
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
if(cb != null){
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
//同步替换方块
CustomBlock.remove(tempLoc);
CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc);
}
@@ -299,7 +298,6 @@ public class RightClickCustomBlock implements Listener {
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
if(cb != null){
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
//同步替换方块
CustomBlock.remove(tempLoc);
CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc);
}

View File

@@ -3,6 +3,7 @@ package net.momirealms.customcrops.timer;
import net.momirealms.customcrops.datamanager.ConfigManager;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.datamanager.CropManager;
import net.momirealms.customcrops.datamanager.MessageManager;
import net.momirealms.customcrops.datamanager.SprinklerManager;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
@@ -14,17 +15,21 @@ public class TimeCheck extends BukkitRunnable {
public void run() {
ConfigManager.Config.worlds.forEach(world ->{
BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
long time = Bukkit.getWorld(world).getTime();
ConfigManager.Config.cropGrowTimeList.forEach(cropGrowTime -> {
if(time == cropGrowTime){
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> CropManager.CropGrow(world));
}
});
ConfigManager.Config.sprinklerWorkTimeList.forEach(sprinklerTime -> {
if(time == sprinklerTime){
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(world));
}
});
if(Bukkit.getWorld(world) != null){
long time = Bukkit.getWorld(world).getTime();
ConfigManager.Config.cropGrowTimeList.forEach(cropGrowTime -> {
if(time == cropGrowTime){
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> CropManager.CropGrow(world));
}
});
ConfigManager.Config.sprinklerWorkTimeList.forEach(sprinklerTime -> {
if(time == sprinklerTime){
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(world));
}
});
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误! 白名单世界 "+ world +" 不存在!",Bukkit.getConsoleSender());
}
});
}
}