mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2024-11-22 18:45:26 +01:00
Fixed a lot of things.
This commit is contained in:
parent
ec175e4fd1
commit
2341d9e3eb
@ -43,7 +43,7 @@ public class Greenhouses extends Addon {
|
||||
recipes = new RecipeManager(this);
|
||||
// Load manager
|
||||
manager = new GreenhouseManager(this);
|
||||
// Register commands for
|
||||
// Register commands for
|
||||
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
||||
.filter(gm -> settings.getGameModes().contains(gm.getDescription().getName()))
|
||||
.forEach(gm -> {
|
||||
@ -66,6 +66,7 @@ public class Greenhouses extends Addon {
|
||||
public void onDisable() {
|
||||
if (manager != null) {
|
||||
manager.saveGreenhouses();
|
||||
manager.getEcoMgr().cancel();
|
||||
}
|
||||
if (settings != null) {
|
||||
new Config<>(this, Settings.class).saveConfigObject(settings);
|
||||
|
@ -13,6 +13,7 @@ import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -329,6 +330,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
return getRandomPlant().map(p -> {
|
||||
if (bl.getY() != 0 && p.getPlantGrownOn().map(m -> m.equals(bl.getRelative(BlockFace.DOWN).getType())).orElse(true)) {
|
||||
bl.setType(p.getPlantMaterial());
|
||||
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
import world.bentobox.greenhouses.data.Greenhouse;
|
||||
|
||||
@ -88,19 +89,19 @@ public class GreenhouseEvents implements Listener {
|
||||
// to is a greenhouse
|
||||
if (to.isPresent() && from.isPresent() && !to.equals(from)) {
|
||||
// Leaving greenhouse, entering another
|
||||
user.sendRawMessage("Leaving " + to.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendRawMessage("Entering " + from.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendMessage("greenhouses.event.leaving", "[biome]", to.get().getBiomeRecipe().getFriendlyName());
|
||||
user.sendMessage("greenhouses.event.entering", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
||||
return;
|
||||
}
|
||||
// from is a greenhouse
|
||||
if (from.isPresent() && !to.isPresent()) {
|
||||
// Exiting
|
||||
user.sendRawMessage("Leaving " + from.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendMessage("greenhouses.event.leaving", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
||||
return;
|
||||
}
|
||||
if (!from.isPresent()) {
|
||||
// Entering
|
||||
user.sendRawMessage("Entering " + to.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendMessage("greenhouses.event.entering", "[biome]", to.get().getBiomeRecipe().getFriendlyName());
|
||||
}
|
||||
|
||||
}
|
||||
@ -130,8 +131,8 @@ public class GreenhouseEvents implements Listener {
|
||||
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMinZ()
|
||||
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMaxZ() - 1
|
||||
) {
|
||||
user.sendMessage("greenhouses.broken");
|
||||
plugin.getManager().getMap().removeGreenhouse(g);
|
||||
user.sendMessage("greenhouses.event.broke", "[biome]", Util.prettifyText(g.getOriginalBiome().name()));
|
||||
plugin.getManager().removeGreenhouse(g);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
class EcoSystemManager {
|
||||
public class EcoSystemManager {
|
||||
|
||||
private final Greenhouses addon;
|
||||
private final GreenhouseManager g;
|
||||
@ -101,7 +101,6 @@ class EcoSystemManager {
|
||||
// Spawn something if chance says so
|
||||
if (gh.getBiomeRecipe().spawnMob(it.next())) {
|
||||
// Add a mob to the sum in the greenhouse
|
||||
addon.log("spawned mob");
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
@ -143,8 +142,8 @@ class EcoSystemManager {
|
||||
private List<Block> getAvailableBlocks(Greenhouse gh) {
|
||||
List<Block> result = new ArrayList<>();
|
||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
||||
for (int z = (int)gh.getBoundingBox().getMinY() + 1; z < (int)gh.getBoundingBox().getMaxY(); z++) {
|
||||
for (int y = gh.getCeilingHeight() - 1; y >= gh.getFloorHeight(); y--) {
|
||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
|
||||
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
|
||||
if (!b.getType().equals(Material.AIR) && b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
||||
result.add(b.getRelative(BlockFace.UP));
|
||||
|
@ -53,6 +53,7 @@ public class GreenhouseManager implements Listener {
|
||||
// Greenhouses
|
||||
private final GreenhouseMap map;
|
||||
private final Database<Greenhouse> handler;
|
||||
private EcoSystemManager ecoMgr;
|
||||
|
||||
public GreenhouseManager(Greenhouses addon) {
|
||||
this.addon = addon;
|
||||
@ -64,7 +65,7 @@ public class GreenhouseManager implements Listener {
|
||||
public void startManager(BentoBoxReadyEvent e) {
|
||||
loadGreenhouses();
|
||||
// Start ecosystems
|
||||
new EcoSystemManager(addon, this);
|
||||
ecoMgr = new EcoSystemManager(addon, this);
|
||||
// Register listeners
|
||||
addon.registerListener(new SnowTracker(addon));
|
||||
addon.registerListener(new GreenhouseEvents(addon));
|
||||
@ -79,6 +80,7 @@ public class GreenhouseManager implements Listener {
|
||||
* Load all known greenhouses
|
||||
*/
|
||||
private void loadGreenhouses() {
|
||||
map.clear();
|
||||
addon.log("Loading greenhouses...");
|
||||
handler.loadObjects().forEach(g -> {
|
||||
GreenhouseResult result = map.addGreenhouse(g);
|
||||
@ -112,12 +114,13 @@ public class GreenhouseManager implements Listener {
|
||||
* @param g - greenhouse
|
||||
*/
|
||||
public void removeGreenhouse(Greenhouse g) {
|
||||
handler.deleteObject(g);
|
||||
map.removeGreenhouse(g);
|
||||
addon.log("Returning biome to original state: " + g.getOriginalBiome().toString());
|
||||
if (g.getOriginalBiome().equals(Biome.NETHER) || g.getOriginalBiome().equals(Biome.DESERT)
|
||||
|| g.getOriginalBiome().equals(Biome.DESERT_HILLS)) {
|
||||
for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x++) {
|
||||
for (int z = (int)g.getBoundingBox().getMinY(); z<= (int)g.getBoundingBox().getMinY(); z++) {
|
||||
for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMinZ(); z++) {
|
||||
// Set back to the original biome
|
||||
g.getLocation().getWorld().setBiome(x, z, g.getOriginalBiome());
|
||||
for (int y = g.getFloorHeight(); y< g.getCeilingHeight(); y++) {
|
||||
@ -160,6 +163,7 @@ public class GreenhouseManager implements Listener {
|
||||
finder.getGh().setBiomeRecipe(greenhouseRecipe);
|
||||
resultSet.add(map.addGreenhouse(finder.getGh()));
|
||||
activateGreenhouse(finder.getGh());
|
||||
handler.saveObject(finder.getGh());
|
||||
}
|
||||
return new GhResult().setFinder(finder).setResults(resultSet);
|
||||
}
|
||||
@ -171,6 +175,7 @@ public class GreenhouseManager implements Listener {
|
||||
// Success - set recipe and add to map
|
||||
finder.getGh().setBiomeRecipe(r);
|
||||
activateGreenhouse(finder.getGh());
|
||||
handler.saveObject(finder.getGh());
|
||||
return map.addGreenhouse(finder.getGh());
|
||||
}).orElse(GreenhouseResult.FAIL_NO_RECIPE_FOUND));
|
||||
return new GhResult().setFinder(finder).setResults(resultSet);
|
||||
@ -233,4 +238,11 @@ public class GreenhouseManager implements Listener {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ecoMgr
|
||||
*/
|
||||
public EcoSystemManager getEcoMgr() {
|
||||
return ecoMgr;
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,13 @@ public class GreenhouseMap {
|
||||
}).orElse(GreenhouseResult.FAIL_NO_ISLAND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the greenhouse map
|
||||
*/
|
||||
public void clear() {
|
||||
greenhouses.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get greenhouse at location
|
||||
* @param location - location
|
||||
@ -91,7 +98,7 @@ public class GreenhouseMap {
|
||||
* Removes the greenhouse from the map
|
||||
* @param greenhouse - greenhouse
|
||||
*/
|
||||
public void removeGreenhouse(Greenhouse greenhouse) {
|
||||
protected void removeGreenhouse(Greenhouse greenhouse) {
|
||||
addon.getIslands().getIslandAt(greenhouse.getLocation()).ifPresent(i -> {
|
||||
greenhouses.putIfAbsent(i, new ArrayList<>());
|
||||
greenhouses.get(i).remove(greenhouse);
|
||||
|
@ -20,32 +20,37 @@ public class Panel {
|
||||
}
|
||||
|
||||
public void ShowPanel(User user) {
|
||||
PanelBuilder pb = new PanelBuilder().name("Greenhouses");
|
||||
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("greenhouses.general.greenhouses"));
|
||||
for (BiomeRecipe br : addon.getRecipes().getBiomeRecipes()) {
|
||||
if (user.hasPermission(br.getPermission())) {
|
||||
pb.item(new PanelItemBuilder()
|
||||
.name(br.getFriendlyName()).icon(br.getIcon())
|
||||
.description(getDescription(br))
|
||||
.description(getDescription(user, br))
|
||||
.clickHandler(new PanelClick(addon, br)).build());
|
||||
}
|
||||
}
|
||||
pb.user(user).build();
|
||||
}
|
||||
|
||||
private List<String> getDescription(BiomeRecipe br) {
|
||||
private List<String> getDescription(User user, BiomeRecipe br) {
|
||||
List<String> d = new ArrayList<>();
|
||||
// Make description
|
||||
d.add("Make a " + Util.prettifyText(br.getBiome().toString()));
|
||||
d.add("Greenhouse. Requires:");
|
||||
d.addAll(br.getRecipeBlocks());
|
||||
d.add(user.getTranslation("greenhouses.recipe.title", "[biome]", Util.prettifyText(br.getBiome().toString())));
|
||||
if (!br.getRecipeBlocks().isEmpty()) {
|
||||
d.add(user.getTranslation("greenhouses.recipe.minimumblockstitle"));
|
||||
br.getRecipeBlocks().forEach(b -> d.add(user.getTranslation("greenhouses.recipe.blockscolor") + b));
|
||||
}
|
||||
if (br.getWaterCoverage() > 0) {
|
||||
d.add("Water coverage = " + br.getWaterCoverage() + "%");
|
||||
d.add(user.getTranslation("greenhouses.recipe.watermustbe", "[coverage]", String.valueOf(br.getWaterCoverage())));
|
||||
}
|
||||
if (br.getLavaCoverage() > 0) {
|
||||
d.add("Lava coverage = " + br.getLavaCoverage() + "%");
|
||||
d.add(user.getTranslation("greenhouses.recipe.lavamustbe", "[coverage]", String.valueOf(br.getLavaCoverage())));
|
||||
}
|
||||
if (br.getIceCoverage() > 0) {
|
||||
d.add("Ice coverage = " + br.getIceCoverage() + "%");
|
||||
d.add(user.getTranslation("greenhouses.recipe.icemustbe", "[coverage]", String.valueOf(br.getIceCoverage())));
|
||||
}
|
||||
if (br.getRecipeBlocks().isEmpty()) {
|
||||
d.add(user.getTranslation("greenhouses.recipe.nootherbocks"));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ class MakeCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
GhResult result = ((Greenhouses)this.getAddon()).getManager().tryToMakeGreenhouse(location, br);
|
||||
getAddon().getPlugin().logDebug(result);
|
||||
if (result.getResults().contains(GreenhouseResult.SUCCESS)) {
|
||||
// Success
|
||||
user.sendMessage("greenhouses.commands.user.make.success", "[biome]", result.getFinder().getGh().getBiomeRecipe().getFriendlyName());
|
||||
|
@ -12,6 +12,9 @@ protection:
|
||||
&bcontrol greenhouses
|
||||
|
||||
greenhouses:
|
||||
general:
|
||||
greenhouses: "Greenhouses"
|
||||
|
||||
errors:
|
||||
move: "Move to a greenhouse you own first."
|
||||
no-rank: "&cYou do not have rank to do that."
|
||||
@ -21,6 +24,21 @@ greenhouses:
|
||||
alreadyexists: "Greenhouse already exists!"
|
||||
norecipe: "Cannot make a greenhouse!"
|
||||
|
||||
event:
|
||||
broke: "You broke this greenhouse! Reverting biome to [biome]!"
|
||||
entering: "Entering [biome] greenhouse"
|
||||
leaving: "Leaving [biome] greenhouse"
|
||||
|
||||
recipe:
|
||||
blockscolor: "&f"
|
||||
title: "[[biome] recipe]"
|
||||
watermustbe: "Water > [coverage]% of floor area."
|
||||
icemustbe: "Ice blocks > [coverage]% of floor area."
|
||||
lavamustbe: "Lava > [coverage]% of floor area."
|
||||
minimumblockstitle: "[Minimum blocks required]"
|
||||
nootherblocks: "No other blocks required."
|
||||
missing: "Greenhouse is missing"
|
||||
|
||||
commands:
|
||||
user:
|
||||
remove:
|
||||
@ -58,12 +76,7 @@ greenhouses:
|
||||
&Egreenhouse to make one successfully.
|
||||
|
||||
|
||||
general:
|
||||
notavailable: "Greenhouses are not available in this world"
|
||||
greenhouses: "Greenhouses"
|
||||
biome: "Biome"
|
||||
owner: "Owner"
|
||||
|
||||
######### Old locale for reference
|
||||
help:
|
||||
help: "help"
|
||||
make: "Tries to make a greenhouse"
|
||||
@ -108,7 +121,7 @@ info:
|
||||
&EPlace &F1 hopper &Ein a wall or roof and add water buckets.
|
||||
&Eto make snow and/or bonemeal to grow plants automatically.
|
||||
&ECheck the biome recipes for what blocks must be inside a
|
||||
&Egreenhouse to make one successfully."
|
||||
&Egreenhouse to make one successfully.
|
||||
info: "[Greenhouse Info]"
|
||||
none: "None"
|
||||
nomore: "&4You cannot build any more greenhouses!"
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.greenhouses.greenhouse;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
Loading…
Reference in New Issue
Block a user