Skip to content

Commit

Permalink
Uses gamemode flags API
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 12, 2019
1 parent eaa1d7b commit 23a08f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/world/bentobox/greenhouses/Greenhouses.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package world.bentobox.greenhouses;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Material;
import org.bukkit.World;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.util.Util;
import world.bentobox.greenhouses.managers.GreenhouseManager;
import world.bentobox.greenhouses.managers.RecipeManager;
import world.bentobox.greenhouses.ui.user.UserCommand;
Expand All @@ -23,7 +26,7 @@ public class Greenhouses extends Addon {
private Settings settings;
private RecipeManager recipes;
private final List<World> activeWorlds = new ArrayList<>();
public final static Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS).build();
public Map<World, Flag> flags = new HashMap<>();

/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
Expand Down Expand Up @@ -51,11 +54,14 @@ public void onEnable() {
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
// Store active world
activeWorlds.add(gm.getOverWorld());
// Register protection flag with BentoBox
Flag fl = new Flag.Builder(gm.getDescription().getName() + "_GREENHOUSE", Material.GREEN_STAINED_GLASS).setGameMode(gm).build();
getPlugin().getFlagsManager().registerFlag(fl);
flags.put(gm.getOverWorld(), fl);
});
// Register greenhouse manager
this.registerListener(manager);
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(GREENHOUSES);


}

Expand Down Expand Up @@ -97,4 +103,7 @@ public List<World> getActiveWorlds() {
return activeWorlds;
}

public Flag getFlag(World world) {
return flags.get(Util.getWorld(world));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ public void setup() {
*/
@Override
public boolean execute(User user, String label, List<String> args) {
Greenhouses addon = (Greenhouses)getAddon();
// 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, addon.getFlag(getWorld()))).orElse(false)) {
user.sendMessage("greenhouses.errors.no-rank");
return false;
}
// Find the physical the greenhouse
Location location = user.getLocation().add(new Vector(0,1,0));
// Check if there's a gh here already
if (((Greenhouses)this.getAddon()).getManager().getMap().getGreenhouse(location).isPresent()) {
if (addon.getManager().getMap().getGreenhouse(location).isPresent()) {
user.sendMessage("greenhouses.commands.user.make.error.already");
return false;
}
GhResult result = ((Greenhouses)this.getAddon()).getManager().tryToMakeGreenhouse(location, null);
GhResult result = addon.getManager().tryToMakeGreenhouse(location, null);

if (result.getResults().contains(GreenhouseResult.SUCCESS)) {
// Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public void setup() {
*/
@Override
public boolean execute(User user, String label, List<String> args) {
Greenhouses addon = (Greenhouses)getAddon();
// 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, addon.getFlag(getWorld()))).orElse(false)) {
user.sendMessage("greenhouses.errors.no-rank");
return false;
}
Greenhouses addon = ((Greenhouses)this.getAddon());
// Remove greenhouse if it exists
if (!addon.getManager().getMap().getGreenhouse(user.getLocation()).map(gh -> {
user.sendMessage("general.success");
Expand Down

0 comments on commit 23a08f3

Please sign in to comment.