mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 00:49:33 +00:00
1.5.22
This commit is contained in:
@@ -133,12 +133,12 @@ public class SprinklerManager {
|
|||||||
String[] split = StringUtils.split(chunk,",");
|
String[] split = StringUtils.split(chunk,",");
|
||||||
if (world.isChunkLoaded(Integer.parseInt(split[0]), Integer.parseInt(split[1]))) {
|
if (world.isChunkLoaded(Integer.parseInt(split[0]), Integer.parseInt(split[1]))) {
|
||||||
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
||||||
|
if (value instanceof MemorySection map){
|
||||||
String[] coordinate = StringUtils.split(key, ",");
|
String[] coordinate = StringUtils.split(key, ",");
|
||||||
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||||
if (value instanceof MemorySection map){
|
|
||||||
bukkitScheduler.runTask(CustomCrops.instance, ()->{
|
bukkitScheduler.runTask(CustomCrops.instance, ()->{
|
||||||
int water = (int) map.get("water");
|
int water = (int) map.get("water");
|
||||||
int range = (int) map.get("range");
|
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
|
||||||
if(!IAFurniture.getFromLocation(location, world)){
|
if(!IAFurniture.getFromLocation(location, world)){
|
||||||
data.set(worldName + "." + chunk + "." + key, null);
|
data.set(worldName + "." + chunk + "." + key, null);
|
||||||
return;
|
return;
|
||||||
@@ -196,7 +196,7 @@ public class SprinklerManager {
|
|||||||
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||||
bukkitScheduler.callSyncMethod(CustomCrops.instance, ()->{
|
bukkitScheduler.callSyncMethod(CustomCrops.instance, ()->{
|
||||||
int water = (int) map.get("water");
|
int water = (int) map.get("water");
|
||||||
int range = (int) map.get("range");
|
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
|
||||||
if (water > 0){
|
if (water > 0){
|
||||||
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
||||||
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
||||||
@@ -241,11 +241,11 @@ public class SprinklerManager {
|
|||||||
String[] split = StringUtils.split(chunk,",");
|
String[] split = StringUtils.split(chunk,",");
|
||||||
if (world.isChunkLoaded(Integer.parseInt(split[0]), Integer.parseInt(split[1]))) {
|
if (world.isChunkLoaded(Integer.parseInt(split[0]), Integer.parseInt(split[1]))) {
|
||||||
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
||||||
String[] coordinate = StringUtils.split(key, ",");
|
|
||||||
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
|
||||||
if (value instanceof MemorySection map){
|
if (value instanceof MemorySection map){
|
||||||
int water = (int) map.get("water");
|
int water = (int) map.get("water");
|
||||||
int range = (int) map.get("range");
|
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
|
||||||
|
String[] coordinate = StringUtils.split(key, ",");
|
||||||
|
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||||
bukkitScheduler.runTask(CustomCrops.instance, ()->{
|
bukkitScheduler.runTask(CustomCrops.instance, ()->{
|
||||||
if(!IAFurniture.getFromLocation(location, world)){
|
if(!IAFurniture.getFromLocation(location, world)){
|
||||||
data.set(worldName + "." + chunk + "." + key, null);
|
data.set(worldName + "." + chunk + "." + key, null);
|
||||||
@@ -275,11 +275,11 @@ public class SprinklerManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!players.contains(player)) return;
|
if (!players.contains(player)) return;
|
||||||
|
int water = (int) map.get("water");
|
||||||
|
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
|
||||||
|
if (water > 0){
|
||||||
String[] coordinate = StringUtils.split(key, ",");
|
String[] coordinate = StringUtils.split(key, ",");
|
||||||
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||||
int water = (int) map.get("water");
|
|
||||||
int range = (int) map.get("range");
|
|
||||||
if (water > 0){
|
|
||||||
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
||||||
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
||||||
for(int i = -range; i <= range; i++){
|
for(int i = -range; i <= range; i++){
|
||||||
@@ -319,12 +319,12 @@ public class SprinklerManager {
|
|||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
||||||
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
data.getConfigurationSection(worldName + "." + chunk).getValues(false).forEach((key, value) -> {
|
||||||
String[] coordinate = StringUtils.split(key, ",");
|
|
||||||
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
|
||||||
if (value instanceof MemorySection map){
|
if (value instanceof MemorySection map){
|
||||||
int water = (int) map.get("water");
|
int water = (int) map.get("water");
|
||||||
int range = (int) map.get("range");
|
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
|
||||||
if (water > 0){
|
if (water > 0){
|
||||||
|
String[] coordinate = StringUtils.split(key, ",");
|
||||||
|
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
|
||||||
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
|
||||||
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
|
||||||
for(int i = -range; i <= range; i++){
|
for(int i = -range; i <= range; i++){
|
||||||
@@ -348,6 +348,7 @@ public class SprinklerManager {
|
|||||||
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据保存" + (time4-time3) + "ms");
|
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据保存" + (time4-time3) + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有世界的洒水器工作
|
* 所有世界的洒水器工作
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -82,13 +82,14 @@ public class InteractEntity implements Listener {
|
|||||||
}
|
}
|
||||||
sprinkler.setWater(currentWater);
|
sprinkler.setWater(currentWater);
|
||||||
}else {
|
}else {
|
||||||
String path = world + "." + x / 16 + "," + z / 16 + "." + x + "," + location.getBlockY() + "," + z + ".water";
|
String path = world + "." + x / 16 + "," + z / 16 + "." + x + "," + location.getBlockY() + "," + z ;
|
||||||
currentWater = plugin.getSprinklerManager().data.getInt(path);
|
currentWater = plugin.getSprinklerManager().data.getInt(path+ ".water");
|
||||||
currentWater += ConfigReader.Config.sprinklerRefill;
|
currentWater += ConfigReader.Config.sprinklerRefill;
|
||||||
if (currentWater > maxWater){
|
if (currentWater > maxWater){
|
||||||
currentWater = maxWater;
|
currentWater = maxWater;
|
||||||
}
|
}
|
||||||
plugin.getSprinklerManager().data.set(path, currentWater);
|
plugin.getSprinklerManager().data.set(path + ".water", currentWater);
|
||||||
|
plugin.getSprinklerManager().data.set(path + ".range", config.getRange());
|
||||||
}
|
}
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.addWaterToSprinklerSource, ConfigReader.Sounds.addWaterToSprinklerKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.addWaterToSprinklerSource, ConfigReader.Sounds.addWaterToSprinklerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ public class RightClick implements Listener {
|
|||||||
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit)));
|
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
CropManager.Cache.put(location, player.getName());
|
CropManager.Cache.put(location, player.getName());
|
||||||
CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location);
|
CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location);
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.plantSeedSource, ConfigReader.Sounds.plantSeedKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.plantSeedSource, ConfigReader.Sounds.plantSeedKey);
|
||||||
@@ -244,18 +246,24 @@ public class RightClick implements Listener {
|
|||||||
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant);
|
||||||
return;
|
return;
|
||||||
}else {
|
}else {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
||||||
addFertilizer(fertilizerConfig, block.getLocation());
|
addFertilizer(fertilizerConfig, block.getLocation());
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
||||||
addFertilizer(fertilizerConfig, block.getLocation());
|
addFertilizer(fertilizerConfig, block.getLocation());
|
||||||
}
|
}
|
||||||
}else if (namespacedID.contains("_stage_")){
|
}else if (namespacedID.contains("_stage_")){
|
||||||
if (!fertilizerConfig.isBefore()){
|
if (!fertilizerConfig.isBefore()){
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
addFertilizer(fertilizerConfig, block.getLocation().subtract(0,1,0));
|
addFertilizer(fertilizerConfig, block.getLocation().subtract(0,1,0));
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.useFertilizerSource, ConfigReader.Sounds.useFertilizerKey);
|
||||||
}else {
|
}else {
|
||||||
@@ -280,7 +288,9 @@ public class RightClick implements Listener {
|
|||||||
}
|
}
|
||||||
Sprinkler sprinklerData = new Sprinkler(sprinkler.getRange(), 0);
|
Sprinkler sprinklerData = new Sprinkler(sprinkler.getRange(), 0);
|
||||||
sprinklerData.setPlayer(player.getName());
|
sprinklerData.setPlayer(player.getName());
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
SimpleLocation simpleLocation = SimpleLocation.fromLocation(location.add(0,1,0));
|
SimpleLocation simpleLocation = SimpleLocation.fromLocation(location.add(0,1,0));
|
||||||
SprinklerManager.Cache.put(simpleLocation, sprinklerData);
|
SprinklerManager.Cache.put(simpleLocation, sprinklerData);
|
||||||
SprinklerManager.RemoveCache.remove(simpleLocation);
|
SprinklerManager.RemoveCache.remove(simpleLocation);
|
||||||
@@ -334,7 +344,9 @@ public class RightClick implements Listener {
|
|||||||
String next = StringUtils.chop(namespacedID) + nextStage;
|
String next = StringUtils.chop(namespacedID) + nextStage;
|
||||||
if (CustomBlock.getInstance(next) != null){
|
if (CustomBlock.getInstance(next) != null){
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE){
|
||||||
itemStack.setAmount(itemStack.getAmount() - 1);
|
itemStack.setAmount(itemStack.getAmount() - 1);
|
||||||
|
}
|
||||||
AdventureManager.playerSound(player, ConfigReader.Sounds.boneMealSource, ConfigReader.Sounds.boneMealKey);
|
AdventureManager.playerSound(player, ConfigReader.Sounds.boneMealSource, ConfigReader.Sounds.boneMealKey);
|
||||||
if (Math.random() < ConfigReader.Config.boneMealChance){
|
if (Math.random() < ConfigReader.Config.boneMealChance){
|
||||||
CustomBlock.remove(location);
|
CustomBlock.remove(location);
|
||||||
|
|||||||
Reference in New Issue
Block a user