mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-02-08 08:11:23 +01:00
WIP
This commit is contained in:
parent
148c92ecf8
commit
b90cba0b60
@ -203,7 +203,7 @@ public class Greenhouse implements DataObject {
|
|||||||
/**
|
/**
|
||||||
* @return the world
|
* @return the world
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@Nullable
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return this.getLocation().getWorld();
|
return this.getLocation().getWorld();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package world.bentobox.greenhouses.managers;
|
package world.bentobox.greenhouses.managers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||||
import world.bentobox.bentobox.database.Database;
|
import world.bentobox.bentobox.database.Database;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
@ -167,12 +170,17 @@ public class GreenhouseManager implements Listener {
|
|||||||
}
|
}
|
||||||
// Check if the greenhouse meets the requested recipe
|
// Check if the greenhouse meets the requested recipe
|
||||||
if (greenhouseRecipe != null) {
|
if (greenhouseRecipe != null) {
|
||||||
checkRecipe(finder, greenhouseRecipe, resultSet).thenAccept(r::complete);
|
checkRecipe(finder, greenhouseRecipe, resultSet).thenAccept(rs -> {
|
||||||
|
r.complete(rs);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try ordered recipes
|
// Try ordered recipes
|
||||||
findRecipe(finder, resultSet);
|
findRecipe(finder).thenAccept(rs -> {
|
||||||
r.complete(new GhResult().setFinder(finder).setResults(resultSet));
|
resultSet.addAll(rs);
|
||||||
|
r.complete(new GhResult().setFinder(finder).setResults(resultSet));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -182,18 +190,29 @@ public class GreenhouseManager implements Listener {
|
|||||||
* @param finder - finder object
|
* @param finder - finder object
|
||||||
* @param resultSet - result set from find
|
* @param resultSet - result set from find
|
||||||
*/
|
*/
|
||||||
private void findRecipe(GreenhouseFinder finder, Set<GreenhouseResult> resultSet) {
|
private CompletableFuture<Set<GreenhouseResult>> findRecipe(GreenhouseFinder finder) {
|
||||||
// TODO
|
CompletableFuture<Set<GreenhouseResult>> r = new CompletableFuture<>();
|
||||||
/*
|
// Get sorted list of all recipes
|
||||||
resultSet.add(addon.getRecipes().getBiomeRecipes().stream().sorted()
|
List<BiomeRecipe> list = addon.getRecipes().getBiomeRecipes().stream().sorted().collect(Collectors.toList());
|
||||||
.filter(r -> r.checkRecipe(finder.getGh()).isEmpty()).findFirst()
|
findRecipe(r, list, finder);
|
||||||
.map(r -> {
|
return r;
|
||||||
// Success - set recipe and add to map
|
}
|
||||||
finder.getGh().setBiomeRecipe(r);
|
|
||||||
activateGreenhouse(finder.getGh());
|
private void findRecipe(CompletableFuture<Set<GreenhouseResult>> r, List<BiomeRecipe> list,
|
||||||
handler.saveObjectAsync(finder.getGh());
|
GreenhouseFinder finder) {
|
||||||
return map.addGreenhouse(finder.getGh());
|
if (list.isEmpty()) {
|
||||||
}).orElse(GreenhouseResult.FAIL_NO_RECIPE_FOUND));*/
|
r.complete(Collections.singleton(GreenhouseResult.FAIL_NO_RECIPE_FOUND));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BiomeRecipe br = list.get(0);
|
||||||
|
list.remove(0);
|
||||||
|
br.checkRecipe(finder.getGh()).thenAccept(results -> {
|
||||||
|
if (results.isEmpty()) {
|
||||||
|
findRecipe(r, list, finder);
|
||||||
|
} else {
|
||||||
|
r.complete(results);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,6 +86,11 @@ class MakeCommand extends CompositeCommand {
|
|||||||
.collect(Collectors.toMap(br -> br.getName(), br -> br));
|
.collect(Collectors.toMap(br -> br.getName(), br -> br));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param user - user
|
||||||
|
* @param br requested biome recipe, or null to try anything
|
||||||
|
* @return true if successful
|
||||||
|
*/
|
||||||
private boolean makeGreenhouse(User user, BiomeRecipe br) {
|
private boolean makeGreenhouse(User user, BiomeRecipe br) {
|
||||||
// Check flag
|
// Check flag
|
||||||
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) {
|
if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) {
|
||||||
|
@ -75,13 +75,13 @@ public class AsyncWorldCache {
|
|||||||
if (cache.containsKey(key)) {
|
if (cache.containsKey(key)) {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
}
|
}
|
||||||
ChunkSnapshot cs;
|
ChunkSnapshot cs = null;
|
||||||
try {
|
try {
|
||||||
// Block on getting the chunk because this is running async
|
// Block on getting the chunk because this is running async
|
||||||
cs = getAChunk(key.x, key.z).get();
|
cs = getAChunk(key.x, key.z).get();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
// Try again...
|
Greenhouses.getInstance().logError("Could not get chunk! " + e);
|
||||||
return getSnap(x,z);
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// Store in cache
|
// Store in cache
|
||||||
cache.put(key, cs);
|
cache.put(key, cs);
|
||||||
|
Loading…
Reference in New Issue
Block a user