mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.4.3 worlds fix
This commit is contained in:
@@ -22,11 +22,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if(sender instanceof Player && !sender.isOp()){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length<1) return true;
|
||||
//重载插件
|
||||
if(args[0].equalsIgnoreCase("reload")){
|
||||
|
||||
@@ -41,6 +37,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
//设置季节
|
||||
if(args[0].equalsIgnoreCase("setseason")){
|
||||
if(args.length<2) return true;
|
||||
if(ConfigManager.Config.season){
|
||||
|
||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||
@@ -84,7 +81,8 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
//强制生长
|
||||
if(args[0].equalsIgnoreCase("forcegrow")){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, CropManager::CropGrow);
|
||||
if(args.length<2) return true;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> CropManager.CropGrow(args[1]));
|
||||
if(sender instanceof Player){
|
||||
MessageManager.playerMessage(ConfigManager.Config.prefix + ConfigManager.Config.force_grow, (Player) sender);
|
||||
}else {
|
||||
@@ -94,7 +92,8 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
//强制洒水
|
||||
if(args[0].equalsIgnoreCase("forcewater")){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, SprinklerManager::SprinklerWork);
|
||||
if(args.length<2) return true;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(args[1]));
|
||||
if(sender instanceof Player){
|
||||
MessageManager.playerMessage(ConfigManager.Config.prefix + ConfigManager.Config.force_water, (Player) sender);
|
||||
}else {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package net.momirealms.customcrops.commands;
|
||||
|
||||
import net.momirealms.customcrops.datamanager.ConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,6 +22,9 @@ public class CommandTabComplete implements TabCompleter {
|
||||
if(args[0].equalsIgnoreCase("setseason")){
|
||||
return Arrays.asList("spring","summer","autumn","winter");
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("forcegrow") || args[0].equalsIgnoreCase("forcewater")){
|
||||
return ConfigManager.Config.worlds;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ public class ConfigManager {
|
||||
Config.summer = configuration.getString("messages.summer");
|
||||
Config.autumn = configuration.getString("messages.autumn");
|
||||
Config.winter = configuration.getString("messages.winter");
|
||||
Config.winter = configuration.getString("messages.noperm");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -66,17 +67,11 @@ public class CropManager {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
添加农作物实例
|
||||
*/
|
||||
public static void putInstance(Location location, String crop) {
|
||||
CROPS.put(location, crop);
|
||||
}
|
||||
|
||||
/*
|
||||
生长部分
|
||||
*/
|
||||
public static void CropGrow() {
|
||||
public static void CropGrow(String worldName) {
|
||||
/*
|
||||
阶段1:更新数据
|
||||
*/
|
||||
@@ -97,154 +92,150 @@ public class CropManager {
|
||||
阶段2:清理数据内无效的农作物并让有效农作物生长
|
||||
*/
|
||||
long start2 = System.currentTimeMillis();
|
||||
ConfigManager.Config.worlds.forEach(worldName ->{
|
||||
if(data.contains(worldName)){
|
||||
if(data.contains(worldName)){
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
data.getConfigurationSection(worldName).getKeys(false).forEach(key ->{
|
||||
String[] coordinate = StringUtils.split(key,",");
|
||||
//先判断区块是否加载,未加载则不进行下一步计算
|
||||
if (world.isChunkLoaded(Integer.parseInt(coordinate[0])/16, Integer.parseInt(coordinate[2])/16)){
|
||||
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
data.getConfigurationSection(worldName).getKeys(false).forEach(key ->{
|
||||
Location sLoc = new Location(world,Double.parseDouble(coordinate[0]),Double.parseDouble(coordinate[1]),Double.parseDouble(coordinate[2]));
|
||||
CustomBlock seedBlock = CustomBlock.byAlreadyPlaced(sLoc.getBlock());
|
||||
|
||||
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){
|
||||
if(seedBlock == null){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}else{
|
||||
String namespacedID = seedBlock.getNamespacedID();
|
||||
/*
|
||||
对之前旧版本的一些兼容
|
||||
以及一些意料之外的情况,防止报错
|
||||
*/
|
||||
if(namespacedID.equalsIgnoreCase(ConfigManager.Config.dead)){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}else{
|
||||
String namespacedID = seedBlock.getNamespacedID();
|
||||
/*
|
||||
对之前旧版本的一些兼容
|
||||
以及一些意料之外的情况,防止报错
|
||||
*/
|
||||
if(namespacedID.equalsIgnoreCase(ConfigManager.Config.dead)){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
return;
|
||||
}
|
||||
if(namespacedID.contains("_stage_")){
|
||||
return;
|
||||
}
|
||||
if(namespacedID.contains("_stage_")){
|
||||
|
||||
Location potLoc = sLoc.clone().subtract(0,1,0);
|
||||
Block potBlock = potLoc.getBlock();
|
||||
CustomBlock pot = CustomBlock.byAlreadyPlaced(potBlock);
|
||||
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)){
|
||||
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]);
|
||||
String[] split = StringUtils.split(namespacedID,":");
|
||||
String[] cropNameList = StringUtils.split(split[1],"_");
|
||||
Crop crop = ConfigManager.CONFIG.get(cropNameList[0]);
|
||||
|
||||
//季节判断
|
||||
Label_out:
|
||||
if(ConfigManager.Config.season){
|
||||
if(ConfigManager.Config.greenhouse){
|
||||
for(int i = 1; i <= ConfigManager.Config.range; i++){
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(sLoc.clone().add(0,i,0).getBlock());
|
||||
if (cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.glass)){
|
||||
break Label_out;
|
||||
}
|
||||
//季节判断
|
||||
Label_out:
|
||||
if(ConfigManager.Config.season){
|
||||
if(ConfigManager.Config.greenhouse){
|
||||
for(int i = 1; i <= ConfigManager.Config.range; i++){
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(sLoc.clone().add(0,i,0).getBlock());
|
||||
if (cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.glass)){
|
||||
break Label_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean ws = true;
|
||||
for(String season : crop.getSeasons()){
|
||||
if (Objects.equals(season, ConfigManager.Config.current)) {
|
||||
ws = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(ws){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () -> {
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(ConfigManager.Config.dead, sLoc);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
boolean ws = true;
|
||||
for(String season : crop.getSeasons()){
|
||||
if (Objects.equals(season, ConfigManager.Config.current)) {
|
||||
ws = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//下一阶段判断
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
if (CustomBlock.getInstance(split[0] +":"+cropNameList[0] + "_stage_" + nextStage) != null) {
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () ->{
|
||||
CustomBlock.remove(potLoc);
|
||||
CustomBlock.place(ConfigManager.Config.pot, potLoc);
|
||||
if(Math.random()< crop.getChance()){
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(split[0] + ":" + cropNameList[0] + "_stage_" + nextStage, sLoc);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
//巨大化判断
|
||||
else if(crop.getWillGiant()){
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () ->{
|
||||
CustomBlock.remove(potLoc);
|
||||
CustomBlock.place(ConfigManager.Config.pot, potLoc);
|
||||
if(crop.getGiantChance() > Math.random()){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(crop.getGiant(), sLoc);
|
||||
}
|
||||
if(ws){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () -> {
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(ConfigManager.Config.dead, sLoc);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
是干燥的种植盆吗
|
||||
*/
|
||||
else if(potName.equalsIgnoreCase(ConfigManager.Config.pot)){
|
||||
if(ConfigManager.Config.season) {
|
||||
if(ConfigManager.Config.greenhouse){
|
||||
for(int i = 1; i <= ConfigManager.Config.range; i++){
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(sLoc.clone().add(0,i,0).getBlock());
|
||||
if (cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.glass)){
|
||||
return;
|
||||
}
|
||||
//下一阶段判断
|
||||
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
|
||||
if (CustomBlock.getInstance(split[0] +":"+cropNameList[0] + "_stage_" + nextStage) != null) {
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () ->{
|
||||
CustomBlock.remove(potLoc);
|
||||
CustomBlock.place(ConfigManager.Config.pot, potLoc);
|
||||
if(Math.random()< crop.getChance()){
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(split[0] + ":" + cropNameList[0] + "_stage_" + nextStage, sLoc);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
//巨大化判断
|
||||
else if(crop.getWillGiant()){
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () ->{
|
||||
CustomBlock.remove(potLoc);
|
||||
CustomBlock.place(ConfigManager.Config.pot, potLoc);
|
||||
if(crop.getGiantChance() > Math.random()){
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(crop.getGiant(), sLoc);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
/*
|
||||
是干燥的种植盆吗
|
||||
*/
|
||||
else if(potName.equalsIgnoreCase(ConfigManager.Config.pot)){
|
||||
if(ConfigManager.Config.season) {
|
||||
if(ConfigManager.Config.greenhouse){
|
||||
for(int i = 1; i <= ConfigManager.Config.range; i++){
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(sLoc.clone().add(0,i,0).getBlock());
|
||||
if (cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.glass)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean ws = true;
|
||||
Crop crop = ConfigManager.CONFIG.get(StringUtils.split(StringUtils.split(namespacedID,":")[1],"_")[0]);
|
||||
for (String season : crop.getSeasons()) {
|
||||
if (Objects.equals(season, ConfigManager.Config.current)) {
|
||||
ws = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ws) {
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () -> {
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(ConfigManager.Config.dead, sLoc);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
boolean ws = true;
|
||||
Crop crop = ConfigManager.CONFIG.get(StringUtils.split(StringUtils.split(namespacedID,":")[1],"_")[0]);
|
||||
for (String season : crop.getSeasons()) {
|
||||
if (Objects.equals(season, ConfigManager.Config.current)) {
|
||||
ws = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ws) {
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, () -> {
|
||||
CustomBlock.remove(sLoc);
|
||||
CustomBlock.place(ConfigManager.Config.dead, sLoc);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CROPS.remove(sLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
long finish2 = System.currentTimeMillis();
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7农作物生长耗时&a" + (finish2 - start2) + "&fms",Bukkit.getConsoleSender());
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.customcrops.datamanager;
|
||||
|
||||
import net.momirealms.customcrops.Libs.minedown.MineDown;
|
||||
import net.momirealms.customcrops.libs.minedown.MineDown;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -6,16 +6,28 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NextSeason {
|
||||
|
||||
public static void changeSeason(){
|
||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||
String currentSeason = ConfigManager.Config.current;
|
||||
String nextSeason = switch (Objects.requireNonNull(currentSeason)) {
|
||||
case "spring" -> "summer";
|
||||
case "summer" -> "autumn";
|
||||
case "autumn" -> "winter";
|
||||
case "winter" -> "spring";
|
||||
default -> null;
|
||||
};
|
||||
String nextSeason;
|
||||
switch (Objects.requireNonNull(currentSeason)) {
|
||||
case "spring":
|
||||
nextSeason = "summer";
|
||||
break;
|
||||
case "summer":
|
||||
nextSeason = "autumn";
|
||||
break;
|
||||
case "autumn":
|
||||
nextSeason = "winter";
|
||||
break;
|
||||
case "winter":
|
||||
nextSeason = "spring";
|
||||
break;
|
||||
default:
|
||||
nextSeason = null;
|
||||
break;
|
||||
}
|
||||
if(nextSeason != null){
|
||||
config.set("current-season", nextSeason);
|
||||
ConfigManager.Config.current = nextSeason;
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SprinklerManager {
|
||||
|
||||
public static ConcurrentHashMap<Location, String> SPRINKLERS;
|
||||
static ConcurrentHashMap<Location, String> SPRINKLERS;
|
||||
/*
|
||||
开服的时候将文件的数据读入
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ public class SprinklerManager {
|
||||
SPRINKLERS.put(location, type);
|
||||
}
|
||||
|
||||
public static void SprinklerWork() {
|
||||
public static void SprinklerWork(String worldName) {
|
||||
/*
|
||||
阶段1:更新数据
|
||||
*/
|
||||
@@ -78,45 +78,47 @@ public class SprinklerManager {
|
||||
data.set(entry.getKey().getWorld().getName() + "." + entry.getKey().getBlockX() + "," + entry.getKey().getBlockY()+ ","+entry.getKey().getBlockZ(), entry.getValue());
|
||||
}
|
||||
long finish1 = System.currentTimeMillis();
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据更新耗时&a" + String.valueOf(finish1-start1) + "&fms",Bukkit.getConsoleSender());
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据更新耗时&a" + (finish1-start1) + "&fms",Bukkit.getConsoleSender());
|
||||
/*
|
||||
阶段2:清理数据内无效的洒水器并工作
|
||||
*/
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance,()->{
|
||||
long start2 = System.currentTimeMillis();
|
||||
//检测碰撞体积需要同步
|
||||
ConfigManager.Config.worlds.forEach(worldName ->{
|
||||
if(data.contains(worldName)){
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
data.getConfigurationSection(worldName).getKeys(false).forEach(key ->{
|
||||
String[] coordinate = StringUtils.split(key,",");
|
||||
if (world.isChunkLoaded(Integer.parseInt(coordinate[0])/16, Integer.parseInt(coordinate[2])/16)){
|
||||
Location tempLoc = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||
if(!IAFurniture.getFromLocation(tempLoc, world)){
|
||||
SPRINKLERS.remove(tempLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}else {
|
||||
String type = data.getString(worldName + "." + coordinate[0] + "," + coordinate[1] + "," + coordinate[2]);
|
||||
if(type.equals("s1")){
|
||||
for(int i = -1; i <= 1;i++){
|
||||
for (int j = -1; j <= 1; j++){
|
||||
waterPot(tempLoc.clone().add(i,-1,j));
|
||||
}
|
||||
if(data.contains(worldName)){
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
data.getConfigurationSection(worldName).getKeys(false).forEach(key ->{
|
||||
String[] coordinate = StringUtils.split(key,",");
|
||||
if (world.isChunkLoaded(Integer.parseInt(coordinate[0])/16, Integer.parseInt(coordinate[2])/16)){
|
||||
Location tempLoc = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||
if(!IAFurniture.getFromLocation(tempLoc, world)){
|
||||
SPRINKLERS.remove(tempLoc);
|
||||
data.set(worldName+"."+coordinate[0]+","+coordinate[1]+","+coordinate[2], null);
|
||||
}else {
|
||||
String type = data.getString(worldName + "." + coordinate[0] + "," + coordinate[1] + "," + coordinate[2]);
|
||||
if(type == null){
|
||||
MessageManager.consoleMessage("错误数据位于"+ worldName + coordinate[0] + "," + coordinate[1] + "," + coordinate[2], Bukkit.getConsoleSender());
|
||||
return;
|
||||
}
|
||||
if(type.equalsIgnoreCase("s1")){
|
||||
for(int i = -1; i <= 1;i++){
|
||||
for (int j = -1; j <= 1; j++){
|
||||
waterPot(tempLoc.clone().add(i,-1,j));
|
||||
}
|
||||
}else{
|
||||
for(int i = -2; i <= 2;i++){
|
||||
for (int j = -2; j <= 2; j++){
|
||||
waterPot(tempLoc.clone().add(i,-1,j));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for(int i = -2; i <= 2;i++){
|
||||
for (int j = -2; j <= 2; j++){
|
||||
waterPot(tempLoc.clone().add(i,-1,j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
long finish2 = System.currentTimeMillis();
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器工作耗时&a" + String.valueOf(finish2-start2) + "&fms",Bukkit.getConsoleSender());
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器工作耗时&a" + (finish2-start2) + "&fms",Bukkit.getConsoleSender());
|
||||
|
||||
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance,()->{
|
||||
/*
|
||||
@@ -130,19 +132,17 @@ public class SprinklerManager {
|
||||
CustomCrops.instance.getLogger().warning("洒水器数据保存出错!");
|
||||
}
|
||||
long finish3 = System.currentTimeMillis();
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据保存耗时&a" + String.valueOf(finish3-start3) + "&fms",Bukkit.getConsoleSender());
|
||||
MessageManager.consoleMessage("&#ccfbff-#ef96c5&[CustomCrops] &7洒水器数据保存耗时&a" + (finish3-start3) + "&fms",Bukkit.getConsoleSender());
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
private static void waterPot(Location tempLoc) {
|
||||
if(CustomBlock.byAlreadyPlaced(tempLoc.getBlock()) != null){
|
||||
if(CustomBlock.byAlreadyPlaced(tempLoc.getBlock()).getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
|
||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance,()->{
|
||||
CustomBlock.remove(tempLoc);
|
||||
CustomBlock.place((ConfigManager.Config.watered_pot), tempLoc);
|
||||
return null;
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ 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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customcrops.Libs.minedown;
|
||||
package net.momirealms.customcrops.libs.minedown;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Max Lee (https://github.com/Phoenix616)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customcrops.Libs.minedown;
|
||||
package net.momirealms.customcrops.libs.minedown;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Max Lee (https://github.com/Phoenix616)
|
||||
@@ -50,11 +50,11 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.COLOR_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.FONT_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.FORMAT_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.HOVER_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.INSERTION_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.COLOR_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.FONT_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.FORMAT_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.HOVER_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.INSERTION_PREFIX;
|
||||
|
||||
public class MineDownParser {
|
||||
private static final String RAINBOW = "rainbow";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customcrops.Libs.minedown;
|
||||
package net.momirealms.customcrops.libs.minedown;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Max Lee (https://github.com/Phoenix616)
|
||||
@@ -44,11 +44,11 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.COLOR_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.FONT_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.FORMAT_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.HOVER_PREFIX;
|
||||
import static net.momirealms.customcrops.Libs.minedown.MineDown.INSERTION_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.COLOR_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.FONT_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.FORMAT_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.HOVER_PREFIX;
|
||||
import static net.momirealms.customcrops.libs.minedown.MineDown.INSERTION_PREFIX;
|
||||
|
||||
public class MineDownStringifier {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customcrops.Libs.minedown;
|
||||
package net.momirealms.customcrops.libs.minedown;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Max Lee (https://github.com/Phoenix616)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.momirealms.customcrops.Libs.minedown;
|
||||
package net.momirealms.customcrops.libs.minedown;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Max Lee (https://github.com/Phoenix616)
|
||||
|
||||
@@ -37,7 +37,4 @@ public class MaxSprinklersPerChunk {
|
||||
}
|
||||
return n > maxAmount;
|
||||
}
|
||||
public static boolean alreadyPlaced(Location location){
|
||||
return IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public class BreakCrops implements Listener {
|
||||
String namespacedId = CustomStack.byItemStack(((Item) entity).getItemStack()).getNamespacedID();
|
||||
if(namespacedId.equalsIgnoreCase(ConfigManager.Config.sprinkler_1)){
|
||||
entity.remove();
|
||||
entity.getWorld().dropItem(entity.getLocation() ,CustomStack.getInstance(namespacedId + "_item").getItemStack());
|
||||
entity.getWorld().dropItem(entity.getLocation() ,CustomStack.getInstance(ConfigManager.Config.sprinkler_1i).getItemStack());
|
||||
}else if(namespacedId.equalsIgnoreCase(ConfigManager.Config.sprinkler_2)){
|
||||
entity.remove();
|
||||
entity.getWorld().dropItem(entity.getLocation() ,CustomStack.getInstance(namespacedId + "_item").getItemStack());
|
||||
entity.getWorld().dropItem(entity.getLocation() ,CustomStack.getInstance(ConfigManager.Config.sprinkler_2i).getItemStack());
|
||||
}else if(namespacedId.contains("_stage_")){
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class RightClickBlock implements Listener {
|
||||
return;
|
||||
}
|
||||
//此位置是否已有洒水器
|
||||
if(MaxSprinklersPerChunk.alreadyPlaced(location)){
|
||||
if(IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld())){
|
||||
return;
|
||||
}
|
||||
//区块上限
|
||||
|
||||
@@ -4,8 +4,6 @@ import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
||||
import net.momirealms.customcrops.datamanager.ConfigManager;
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.datamanager.CropManager;
|
||||
import net.momirealms.customcrops.limits.MaxCropsPerChunk;
|
||||
import net.momirealms.customcrops.integrations.IntegrationCheck;
|
||||
import net.momirealms.customcrops.datamanager.MessageManager;
|
||||
@@ -19,13 +17,12 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class RightClickCustomBlock implements Listener {
|
||||
import static net.momirealms.customcrops.datamanager.CropManager.CROPS;
|
||||
|
||||
BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
|
||||
public class RightClickCustomBlock implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void rightClickCustomBlock(CustomBlockInteractEvent event){
|
||||
@@ -238,7 +235,7 @@ public class RightClickCustomBlock implements Listener {
|
||||
return false;
|
||||
}
|
||||
//添加到缓存中
|
||||
CropManager.putInstance(locUp, key);
|
||||
CROPS.put(locUp, key);
|
||||
//放置自定义农作物
|
||||
CustomBlock.place(namespacedID.replace("_seeds","_stage_1"),locUp);
|
||||
return true;
|
||||
@@ -246,77 +243,69 @@ public class RightClickCustomBlock implements Listener {
|
||||
private void waterPot(ItemStack itemStack, Player player, Location location){
|
||||
//是否为IA物品
|
||||
if(CustomStack.byItemStack(itemStack) == null) return;
|
||||
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance,()-> {
|
||||
//获取IA物品
|
||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||
String namespacedId = customStack.getNamespacedID();
|
||||
World world = player.getWorld();
|
||||
int x;
|
||||
int z;
|
||||
if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_1)) {
|
||||
//获取IA物品
|
||||
CustomStack customStack = CustomStack.byItemStack(itemStack);
|
||||
String namespacedId = customStack.getNamespacedID();
|
||||
World world = player.getWorld();
|
||||
int x;
|
||||
int z;
|
||||
if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_1)) {
|
||||
x = 0;
|
||||
z = 0;
|
||||
} else if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_2)){
|
||||
x = 2;
|
||||
z = 2;
|
||||
} else if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_3)){
|
||||
x = 4;
|
||||
z = 4;
|
||||
} else return;
|
||||
//判断耐久度
|
||||
if(customStack.getDurability() > 0){
|
||||
CustomStack.byItemStack(itemStack).setDurability(CustomStack.byItemStack(itemStack).getDurability() - 1);
|
||||
}else return;
|
||||
//播放洒水音效
|
||||
world.playSound(player.getLocation(),Sound.BLOCK_WATER_AMBIENT,1,1);
|
||||
//获取玩家朝向
|
||||
float yaw = player.getLocation().getYaw();
|
||||
//根据朝向确定浇水方向
|
||||
if (yaw <= 45 && yaw >= -135) {
|
||||
if (yaw > -45) {
|
||||
x = 0;
|
||||
z = 0;
|
||||
} else if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_2)){
|
||||
x = 2;
|
||||
z = 2;
|
||||
} else if (namespacedId.equalsIgnoreCase(ConfigManager.Config.watering_can_3)){
|
||||
x = 4;
|
||||
z = 4;
|
||||
} else return;
|
||||
//判断耐久度
|
||||
if(customStack.getDurability() > 0){
|
||||
CustomStack.byItemStack(itemStack).setDurability(CustomStack.byItemStack(itemStack).getDurability() - 1);
|
||||
}else return;
|
||||
//播放洒水音效
|
||||
world.playSound(player.getLocation(),Sound.BLOCK_WATER_AMBIENT,1,1);
|
||||
//获取玩家朝向
|
||||
float yaw = player.getLocation().getYaw();
|
||||
//根据朝向确定浇水方向
|
||||
if (yaw <= 45 && yaw >= -135) {
|
||||
if (yaw > -45) {
|
||||
x = 0;
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
for (int i = 0; i <= x; i++) {
|
||||
for (int j = 0; j <= z; j++) {
|
||||
Location tempLoc = location.clone().add(i, 0, j);
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
|
||||
if(cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
|
||||
//同步替换方块
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance,()->{
|
||||
CustomBlock.remove(tempLoc);
|
||||
CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (yaw < 135 && yaw > 45) {
|
||||
z= 0;
|
||||
} else {
|
||||
x= 0;
|
||||
}
|
||||
for (int i = 0; i <= x; i++) {
|
||||
for (int j = 0; j <= z; j++) {
|
||||
Location tempLoc = location.clone().subtract(i, 0, j);
|
||||
CustomBlock cb = CustomBlock.byAlreadyPlaced(tempLoc.getBlock());
|
||||
if(cb != null){
|
||||
if(cb.getNamespacedID().equalsIgnoreCase(ConfigManager.Config.pot)){
|
||||
//同步替换方块
|
||||
bukkitScheduler.callSyncMethod(CustomCrops.instance,()->{
|
||||
CustomBlock.remove(tempLoc);
|
||||
CustomBlock.place(ConfigManager.Config.watered_pot,tempLoc);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
z = 0;
|
||||
}
|
||||
for (int i = 0; i <= x; i++) {
|
||||
for (int j = 0; j <= z; j++) {
|
||||
Location tempLoc = location.clone().add(i, 0, j);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (yaw < 135 && yaw > 45) {
|
||||
z= 0;
|
||||
} else {
|
||||
x= 0;
|
||||
}
|
||||
for (int i = 0; i <= x; i++) {
|
||||
for (int j = 0; j <= z; j++) {
|
||||
Location tempLoc = location.clone().subtract(i, 0, j);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,22 +10,19 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
public class TimeCheck extends BukkitRunnable {
|
||||
|
||||
BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
|
||||
|
||||
@Override
|
||||
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);
|
||||
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> CropManager.CropGrow(world));
|
||||
}
|
||||
});
|
||||
ConfigManager.Config.sprinklerWorkTimeList.forEach(sprinklerTime -> {
|
||||
if(time == sprinklerTime){
|
||||
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, SprinklerManager::SprinklerWork);
|
||||
bukkitScheduler.runTaskAsynchronously(CustomCrops.instance, () -> SprinklerManager.SprinklerWork(world));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,11 +58,11 @@ config:
|
||||
greenhouse-glass: customcrops:greenhouse_glass
|
||||
#洒水器的家具
|
||||
sprinkler-1: customcrops:sprinkler_1
|
||||
#洒水器的方块的物品(请以_item结尾)
|
||||
#洒水器的方块的2D物品
|
||||
sprinkler-1-item: customcrops:sprinkler_1_item
|
||||
#优质洒水器的家具
|
||||
sprinkler-2: customcrops:sprinkler_2
|
||||
#优质洒水器的方块的物品(请以_item结尾)
|
||||
#优质洒水器的方块的2D物品
|
||||
sprinkler-2-item: customcrops:sprinkler_2_item
|
||||
#农作物枯萎后变成的方块,物品ID中请保留stage以保持其下方方块被破坏时,枯萎作物也被破坏的特性
|
||||
dead-crop: customcrops:crop_stage_death
|
||||
@@ -111,3 +111,4 @@ messages:
|
||||
summer: '&f夏'
|
||||
autumn: '&f秋'
|
||||
winter: '&f冬'
|
||||
noperm: '&f权限不足'
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
crops:
|
||||
#在IA配置文件中命名农作物时请以_seeds和_stage_X结尾,否则会无法生长和种植
|
||||
#只要遵循正确的命名规则,你可以无限自定义农作物阶段数量
|
||||
tomato:
|
||||
#在IA配置文件中命名农作物时请以_seeds和_stage_X结尾,否则会无法生长和种植
|
||||
#只要遵循正确的命名规则,你可以无限自定义农作物阶段数量
|
||||
|
||||
#每个生长点生长一个阶段的概率
|
||||
#此项目必填(0-1)
|
||||
grow-chance: 0.4
|
||||
@@ -11,12 +10,23 @@ crops:
|
||||
#若启用季节则必须填写此项目
|
||||
#季节之间用逗号分隔
|
||||
#可用的季节类型spring,summer,autumn,winter
|
||||
#season: spring,summer
|
||||
season: spring,summer
|
||||
|
||||
#空手收获后返回第几个生长状态
|
||||
#不填写此项目则无法重复收获
|
||||
#return: customcrops:tomato_stage_1
|
||||
return: customcrops:tomato_stage_1
|
||||
|
||||
#巨大化植物,以极低的概率生长为另一种形态
|
||||
#gigantic: customcrops:gigantic_tomato
|
||||
#gigantic-chance: 0.01
|
||||
gigantic: customcrops:gigantic_tomato
|
||||
gigantic-chance: 0.01
|
||||
|
||||
cabbage:
|
||||
grow-chance: 0.8
|
||||
season: summer,autumn
|
||||
gigantic: customcrops:gigantic_cabbage
|
||||
gigantic-chance: 0.02
|
||||
|
||||
grape:
|
||||
grow-chance: 0.5
|
||||
season: autumn
|
||||
return: customcrops:grape_stage_4
|
||||
@@ -1,10 +1,12 @@
|
||||
name: CustomCrops
|
||||
version: '1.4.0'
|
||||
version: '1.4.3'
|
||||
main: net.momirealms.customcrops.CustomCrops
|
||||
api-version: 1.16
|
||||
depend: [ ItemsAdder , ProtocolLib ]
|
||||
depend: [ ItemsAdder ]
|
||||
softdepend: [ PlaceholderAPI ]
|
||||
authors: [ XiaoMoMi ]
|
||||
commands:
|
||||
customcrops:
|
||||
permission-message: No Permission
|
||||
usage: /customcrops <args>
|
||||
permission-message: No Permission
|
||||
permission: customcrops.admin
|
||||
Reference in New Issue
Block a user