9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-23 08:59:28 +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); BackUp.backUp(crop_data,cropBackUp);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
CustomCrops.instance.getLogger().warning("crop-data.yml备份出错!");
} }
try { try {
BackUp.backUp(sprinkler_data,sprinklerBackUp); BackUp.backUp(sprinkler_data,sprinklerBackUp);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
CustomCrops.instance.getLogger().warning("sprinkler-data.yml备份出错!");
} }
} }

View File

@@ -163,6 +163,7 @@ public class ConfigManager {
YamlConfiguration cropConfig = getConfig("crops.yml"); YamlConfiguration cropConfig = getConfig("crops.yml");
Set<String> keys = cropConfig.getConfigurationSection("crops").getKeys(false); Set<String> keys = cropConfig.getConfigurationSection("crops").getKeys(false);
keys.forEach(key -> { keys.forEach(key -> {
if(cropConfig.getConfigurationSection("crops."+key).contains("grow-chance")){
double chance = cropConfig.getDouble("crops."+key+".grow-chance"); double chance = cropConfig.getDouble("crops."+key+".grow-chance");
Crop crop = new Crop(key, chance); Crop crop = new Crop(key, chance);
if(cropConfig.getConfigurationSection("crops."+key).contains("return")){ if(cropConfig.getConfigurationSection("crops."+key).contains("return")){
@@ -192,6 +193,9 @@ public class ConfigManager {
crop.setWillGiant(false); crop.setWillGiant(false);
} }
CONFIG.put(key, crop); CONFIG.put(key, crop);
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误!未设置农作物 &f"+ key +" &c的生长概率!", Bukkit.getConsoleSender());
}
}); });
if(keys.size() == CONFIG.size()){ if(keys.size() == CONFIG.size()){
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &f成功载入 &a" + CONFIG.size() + " &f种农作物", Bukkit.getConsoleSender()); MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &f成功载入 &a" + CONFIG.size() + " &f种农作物", Bukkit.getConsoleSender());

View File

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

View File

@@ -129,7 +129,7 @@ public class SprinklerManager {
data.save(file); data.save(file);
}catch (IOException e){ }catch (IOException e){
e.printStackTrace(); e.printStackTrace();
CustomCrops.instance.getLogger().warning("洒水器数据保存出错!"); CustomCrops.instance.getLogger().warning("sprinkler-data.yml保存出错!");
} }
long finish3 = System.currentTimeMillis(); long finish3 = System.currentTimeMillis();
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据保存耗时&a" + (finish3-start3) + "&fms",Bukkit.getConsoleSender()); 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; import org.bukkit.entity.Player;
public class ResidenceIntegrations { public class ResidenceIntegrations {
public static boolean checkResBuild(Location location, Player player){ public static boolean checkResBuild(Location location, Player player){
FlagPermissions.addFlag("build"); FlagPermissions.addFlag("build");
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location); ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);

View File

@@ -280,7 +280,6 @@ public class RightClickCustomBlock implements Listener {
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock()); CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
if(cb != null){ if(cb != null){
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){ if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
//同步替换方块
CustomBlock.remove(tempLoc); CustomBlock.remove(tempLoc);
CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc); CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc);
} }
@@ -299,7 +298,6 @@ public class RightClickCustomBlock implements Listener {
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock()); CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
if(cb != null){ if(cb != null){
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){ if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
//同步替换方块
CustomBlock.remove(tempLoc); CustomBlock.remove(tempLoc);
CustomBlock.place(ConfigManager.Config.watered_pot,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.datamanager.ConfigManager;
import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.datamanager.CropManager; import net.momirealms.customcrops.datamanager.CropManager;
import net.momirealms.customcrops.datamanager.MessageManager;
import net.momirealms.customcrops.datamanager.SprinklerManager; import net.momirealms.customcrops.datamanager.SprinklerManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@@ -14,6 +15,7 @@ public class TimeCheck extends BukkitRunnable {
public void run() { public void run() {
ConfigManager.Config.worlds.forEach(world ->{ ConfigManager.Config.worlds.forEach(world ->{
BukkitScheduler bukkitScheduler = Bukkit.getScheduler(); BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
if(Bukkit.getWorld(world) != null){
long time = Bukkit.getWorld(world).getTime(); long time = Bukkit.getWorld(world).getTime();
ConfigManager.Config.cropGrowTimeList.forEach(cropGrowTime -> { ConfigManager.Config.cropGrowTimeList.forEach(cropGrowTime -> {
if(time == cropGrowTime){ if(time == cropGrowTime){
@@ -25,6 +27,9 @@ public class TimeCheck extends BukkitRunnable {
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(world)); bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(world));
} }
}); });
}else {
MessageManager.consoleMessage("&c[CustomCrops] 错误! 白名单世界 "+ world +" 不存在!",Bukkit.getConsoleSender());
}
}); });
} }
} }

View File

@@ -75,8 +75,8 @@ config:
#每个区块最大农作物数量和洒水器数量 #每个区块最大农作物数量和洒水器数量
#是否启用限制 #是否启用限制
enable-limit: true enable-limit: true
max-crops: 32 max-crops: 64
max-sprinklers: 4 max-sprinklers: 8
#插件兼容 #插件兼容
@@ -94,11 +94,11 @@ config:
messages: messages:
prefix: '&#ccfbff-#ef96c5&[CustomCrops] ' prefix: '&#ccfbff-#ef96c5&[CustomCrops] '
not-a-good-place: '&f这个地方太高/太低了,请换个地方试试吧!' not-a-good-place: '&f这个地方太高/太低了,请换个地方试试吧!'
reload: '&f插件已重载' reload: '&f插件已重载.'
force-save: '&f成功强制保存缓存信息' force-save: '&f成功强制保存缓存信息!'
no-such-seed: '&f此种子未在配置文件中配置!' no-such-seed: '&f此种子未在配置文件中配置!'
wrong-season: '&f这个季节不适合这种农作物生长!' wrong-season: '&f这个季节不适合这种农作物生长!'
season-set: '&f成功设置季节为{Season}' season-set: '&f成功设置季节为{Season}.'
nextseason: '&f已切换到下一季节' nextseason: '&f已切换到下一季节'
season-disabled: '&f季节系统未启用.' season-disabled: '&f季节系统未启用.'
force-grow: '&f已强制生长!' force-grow: '&f已强制生长!'
@@ -111,4 +111,4 @@ messages:
summer: '&f夏' summer: '&f夏'
autumn: '&f秋' autumn: '&f秋'
winter: '&f冬' winter: '&f冬'
noperm: '&f权限不足' noperm: '&f权限不足.'