Skip to content

Commit

Permalink
Implement ability to set biomes outside island (via world protection …
Browse files Browse the repository at this point in the history
…flag) (#26)

Add GUI closing after biome changing (#22)
Rework GUIs (not with Oblivian as it looks dead) (#7)

Add finalName with the same config as it is in BentoBox.
  • Loading branch information
BONNe committed May 20, 2019
1 parent 85dce21 commit 3db3e45
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 53 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
</dependencies>

<build>
<!-- By default ${revision} is ${build.version}-SNAPSHOT -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will be only ${build.version}. -->

<!-- By default ${build.number} is -LOCAL. -->
<!-- If the BUILD_NUMBER variable is set, then it will be -b[number]. -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will be the empty string. -->
<finalName>${project.name}-${revision}${build.number}</finalName>

<defaultGoal>clean package</defaultGoal>
<resources>
<resource>
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/world/bentobox/biomes/BiomesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.biomes.commands.admin.AdminCommand;
import world.bentobox.biomes.commands.user.BiomesCommand;
import world.bentobox.biomes.listeners.ChangeOwnerListener;
Expand Down Expand Up @@ -59,8 +61,6 @@ public void onEnable()

this.hooked = false;

List<GameModeAddon> hookedGameModes = new ArrayList<>();

this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName()))
{
Expand All @@ -76,8 +76,8 @@ public void onEnable()
}

// Add FLAGS
//BIOMES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
//BIOMES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
BIOMES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
BIOMES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
}
});

Expand Down Expand Up @@ -120,8 +120,8 @@ public void onEnable()
this.registerListener(new ChangeOwnerListener(this));

// Register Flags
//this.getPlugin().getFlagsManager().registerFlag(BIOMES_WORLD_PROTECTION);
//this.getPlugin().getFlagsManager().registerFlag(BIOMES_ISLAND_PROTECTION);
this.getPlugin().getFlagsManager().registerFlag(BIOMES_WORLD_PROTECTION);
this.getPlugin().getFlagsManager().registerFlag(BIOMES_ISLAND_PROTECTION);

// Register Request Handlers
//this.registerRequestHandler(YOUR_REQUEST_HANDLER);
Expand Down Expand Up @@ -299,6 +299,27 @@ public boolean isLevelProvided()
private boolean levelProvided;


// ---------------------------------------------------------------------
// Section: Flags
// ---------------------------------------------------------------------


/**
* This flag allows to change biomes in any part of the world. It will not limit
* player to their island. Useful for skygrid without protection flags.
*/
public static Flag BIOMES_WORLD_PROTECTION =
new Flag.Builder("BIOMES_WORLD_PROTECTION", Material.GRASS_BLOCK).type(Flag.Type.WORLD_SETTING).defaultSetting(true).build();

/**
* This flag allows to define which users can change biomes. F.e. it can be set
* that only Island owner can change biomes.
* By default it is set to Visitor.
*/
public static Flag BIOMES_ISLAND_PROTECTION =
new Flag.Builder("BIOMES_ISLAND_PROTECTION", Material.GRASS_BLOCK).defaultRank(RanksManager.VISITOR_RANK).build();


// ---------------------------------------------------------------------
// Section: Constants
// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
import world.bentobox.biomes.database.objects.BiomesObject;
import world.bentobox.biomes.config.Settings.UpdateMode;
Expand Down Expand Up @@ -127,12 +128,17 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>

break;
case 5:
// Create suggestions with all biomes that is available for users.

// Create suggestions with all update modes that is available for users.
Arrays.stream(UpdateMode.values()).
map(Enum::name).
forEach(returnList::add);

if (!BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.getWorld()))
{
// Do not suggest island as it is not valid option
returnList.remove(UpdateMode.ISLAND.name());
}

break;
case 6:
if (lastString.isEmpty() || lastString.matches("[0-9]*"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.commands.ExpandedCompositeCommand;
import world.bentobox.biomes.database.objects.BiomesObject;
import world.bentobox.biomes.config.Settings.UpdateMode;
Expand Down Expand Up @@ -96,11 +97,17 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>

break;
case 4:
// Create suggestions with all biomes that is available for users.
// Create suggestions with all update modes that is available for users.
Arrays.stream(UpdateMode.values()).
map(Enum::name).
forEach(returnList::add);

if (!BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.getWorld()))
{
// Do not suggest island as it is not valid option
returnList.remove(UpdateMode.ISLAND.name());
}

break;
case 5:
if (lastString.isEmpty() || lastString.matches("[0-9]*"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand All @@ -20,6 +18,7 @@

import world.bentobox.biomes.panel.CommonGUI;

import world.bentobox.biomes.config.Settings.UpdateMode;
import world.bentobox.biomes.config.Settings.VisibilityMode;
import world.bentobox.biomes.utils.GuiUtils;

Expand Down Expand Up @@ -184,11 +183,32 @@ private PanelItem createBiomeIcon(BiomesObject biome)
}

arguments.add(biome.getUniqueId());
arguments.add(settings.getDefaultMode().name());
arguments.add(Integer.toString(settings.getDefaultSize()));

if (BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
{
arguments.add(settings.getDefaultMode().name());
arguments.add(Integer.toString(settings.getDefaultSize()));
}
else
{
// This fix issues when admin disables Advanced GUI and sets
// incompatible options

if (settings.getDefaultMode().equals(UpdateMode.ISLAND))
{
arguments.add(UpdateMode.SQUARE.name());
arguments.add(Integer.toString(this.addon.getPlugin().getIWM().getIslandDistance(this.world)));
}
else
{
arguments.add(settings.getDefaultMode().name());
arguments.add(Integer.toString(settings.getDefaultSize()));
}
}

this.callCommand(SET, arguments);

this.user.closeInventory();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.database.objects.BiomesObject;

import world.bentobox.biomes.panel.CommonGUI;
Expand Down Expand Up @@ -41,6 +42,14 @@ public UpdateModeGUI(CommonGUI parentGui, User target, BiomesObject biome)

this.updateMode = this.addon.getSettings().getDefaultMode();
this.distanceValue = this.addon.getSettings().getDefaultSize();

if (this.updateMode.equals(UpdateMode.ISLAND) &&
!BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
{
// Fix default mode and size if WORLD flag is disabled.
this.updateMode = UpdateMode.SQUARE;
this.distanceValue = this.addon.getPlugin().getIWM().getIslandDistance(this.world);
}
}


Expand All @@ -57,8 +66,14 @@ public void build()

// Map at the top of the GUI
panelBuilder.item(4, this.createButton(Button.HEADER));

// Choose Update Mode Type
panelBuilder.item(12, this.createButton(Button.ISLAND));
if (BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world))
{
// Island mode should be available only if world protection is enabled.
panelBuilder.item(12, this.createButton(Button.ISLAND));
}

panelBuilder.item(13, this.createButton(Button.CHUNK));
panelBuilder.item(14, this.createButton(Button.SQUARE));

Expand Down

0 comments on commit 3db3e45

Please sign in to comment.