Skip to content

Commit

Permalink
Added "MAGIC_COBBLESTONE_GENERATOR" flag (SETTING)
Browse files Browse the repository at this point in the history
Implemented #11
  • Loading branch information
Poslovitch committed Dec 15, 2019
1 parent d825e1a commit e981e84
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.List;
import java.util.Optional;

import org.bukkit.Material;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.level.Level;
import world.bentobox.magiccobblestonegenerator.commands.StoneGeneratorMainCommand;
Expand Down Expand Up @@ -84,12 +86,16 @@ public void onEnable() {
this.vaultHook = vault.get();
}


// Register the listener.
this.registerListener(new MainGeneratorListener(this));

// Register Flags
// this.getPlugin().getFlagsManager().registerFlag(FLAG_NAME);
flag = new Flag.Builder("MAGIC_COBBLESTONE_GENERATOR", Material.DIAMOND_PICKAXE)
.type(Flag.Type.SETTING)
.defaultSetting(true)
.addon(this)
.build();
getPlugin().getFlagsManager().registerFlag(flag);

// Register Request Handlers
// this.registerRequestHandler(REQUEST_HANDLER);
Expand Down Expand Up @@ -186,6 +192,15 @@ public boolean isLevelProvided() {
return levelAddon != null;
}

/**
* Returns the Flag that allows players to toggle on/off the Magic Cobblestone Generator on their islands.
* @return the Flag that allows players to toggle on/off the Magic Cobblestone Generator on their islands.
* @since 1.9.0
*/
public Flag getFlag() {
return flag;
}


// ---------------------------------------------------------------------
// Section: Variables
Expand Down Expand Up @@ -220,4 +235,10 @@ public boolean isLevelProvided() {
* Level addon.
*/
private Level levelAddon;

/**
* Flag that toggles on/off the Magic Cobblestone Generator.
* @since 1.9.0
*/
private Flag flag;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public void onBlockFromToEvent(BlockFromToEvent event)
return;
}

// if flag is toggled off, return
if(addon.getIslands().getIslandAt(eventToBlock.getLocation())
.map(island -> !island.isAllowed(addon.getFlag())).orElse(!addon.getFlag().isSetForWorld(eventToBlock.getWorld()))) {
return;
}

// Stone generator could be used to get much better elements than cobble generator
if (this.canGenerateStone(liquid, eventToBlock))
{
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ stonegenerator:
island-level: "&2Your island level is &6[level]&2!"
errors:
cannot-find-any-generators: "&cCannot find any Magic Cobblestone Generator tier for the current world."

protection:
flags:
MAGIC_COBBLESTONE_GENERATOR:
name: "Magic Cobblestone Generator"
description: "Toggle the Magic Cobblestone Generator"

0 comments on commit e981e84

Please sign in to comment.