Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
#	src/main/java/world/bentobox/biomes/BiomesAddon.java
#	src/main/java/world/bentobox/biomes/BiomesPladdon.java
#	src/main/java/world/bentobox/biomes/commands/player/BiomesCommand.java
#	src/main/java/world/bentobox/biomes/config/Settings.java
#	src/main/java/world/bentobox/biomes/managers/BiomesAddonManager.java
#	src/main/java/world/bentobox/biomes/panels/admin/IslandEditPanel.java
#	src/main/java/world/bentobox/biomes/panels/admin/IslandManagePanel.java
#	src/main/java/world/bentobox/biomes/panels/user/AdvancedPanel.java
#	src/main/java/world/bentobox/biomes/panels/user/BiomesPanel.java
#	src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
#	src/main/java/world/bentobox/biomes/utils/Utils.java
#	src/main/resources/config.yml
#	src/main/resources/locales/en-US.yml
#	src/main/resources/locales/lv.yml
#	src/main/resources/locales/zh-CN.yml
#	src/main/resources/panels/advanced_panel.yml
  • Loading branch information
BONNe committed Jan 5, 2023
2 parents 9094221 + 0977b13 commit 14c38ef
Show file tree
Hide file tree
Showing 18 changed files with 1,909 additions and 405 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<java.version>17</java.version>
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.20.0-SNAPSHOT</bentobox.version>
<spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.21.0</bentobox.version>
<bank.version>1.4.0</bank.version>
<level.version>2.5.0</level.version>
<greenhouses.version>1.4.0-SNAPSHOT</greenhouses.version>
Expand All @@ -56,7 +56,7 @@
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>2.0.0</build.version>
<build.version>2.1.0</build.version>
<build.number>-LOCAL</build.number>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_Biomes</sonar.projectKey>
Expand Down Expand Up @@ -379,4 +379,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
8 changes: 6 additions & 2 deletions src/main/java/world/bentobox/biomes/BiomesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void allLoaded()
this.log("Biomes Addon hooked into Bank addon.");
}, () ->
{
this.levelAddon = null;
this.bankAddon = null;
});

// Try to find Level addon and if it does not exist, display a warning
Expand Down Expand Up @@ -237,7 +237,11 @@ public void onDisable()
{
if (this.hooked)
{
this.biomeUpdateQueue.getTask().cancel();
if (this.biomeUpdateQueue != null)
{
this.biomeUpdateQueue.getTask().cancel();
}

this.getLogger().info("Biomes addon disabled.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/biomes/BiomesPladdon.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author tastybento
*/
@Plugin(name = "Pladdon", version = "1.0")
@ApiVersion(ApiVersion.Target.v1_17)
@ApiVersion(ApiVersion.Target.v1_19)
@Dependency(value = "BentoBox")
public class BiomesPladdon extends Pladdon
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,43 @@ public boolean execute(User user, String label, List<String> args)
return false;
}

if (!data.isUnlocked(biomesObject))
{
// Check biome unlock status.
if (addonManager.canUnlockBiome(data, island, biomesObject))
{
// Unlock biome as it is marked as valid.
addonManager.unlockBiome(data, user, island, biomesObject);
}
else
{
// Do not allow to buy non-unlocked biomes.
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "biome-not-unlocked",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName()));
return false;
}
}

if (!addonManager.hasPriceSet(biomesObject))
{
// If price is not set check if addon should send notification to the user.
if (!this.<BiomesAddon>getAddon().getSettings().isNotifyUnlockedBiomes())
{
// Notify user that biome is available if notify on unlock is disabled.
Utils.sendUnlockMessage(user.getUniqueId(),
island,
biomesObject,
this.getAddon(),
true);
}

return true;
}

if (addonManager.canPurchaseBiome(user, island, data, biomesObject))
{
// Purchase biome.
addonManager.purchaseBiome(user, island, data, biomesObject);
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/world/bentobox/biomes/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,28 @@ public void setUseChunkRefresh(boolean useChunkRefresh)
}


/**
* Is use single menu boolean.
*
* @return the boolean
*/
public boolean isUseSingleMenu()
{
return useSingleMenu;
}


/**
* Sets use single menu.
*
* @param useSingleMenu the use single menu
*/
public void setUseSingleMenu(boolean useSingleMenu)
{
this.useSingleMenu = useSingleMenu;
}


// ---------------------------------------------------------------------
// Section: Enums used for Settings.
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -528,6 +550,12 @@ public static UpdateMode getMode(String parameter)
@SuppressWarnings("javadoc")
private boolean useChunkRefresh = true;

@ConfigComment("Use single GUI. This will allow to disable buy panel, and use main panel to buy biomes.")
@ConfigComment("BUY action need to be added to the main panel biome button.")
@ConfigComment("Default value = false")
@ConfigEntry(path = "use-single-menu")
private boolean useSingleMenu = false;

@ConfigComment("Player main sub-command to access the addon.")
@ConfigComment("This command label will be required to write after gamemode player command label, f.e. /[label] biomes")
@ConfigComment("Each alias must be separated with an empty space.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public void loadUserIslands(UUID uniqueId)
filter(Objects::nonNull).
forEach(island ->
{
if (island.getOwner() == uniqueId)
if (uniqueId.equals(island.getOwner()))
{
// Owner island must be validated.
this.validateIslandData(island, User.getInstance(uniqueId));
Expand Down Expand Up @@ -708,41 +708,54 @@ else if (islandData.getIslandBundle() != null &&


/**
* This method checks if given user can apply given biome.
* This method checks if biome can be unlocked based on biome object and island data.
* This method is silent, it does not report missing stuff.
*
* @param user User who will pay for activating.
* @param islandData Data that stores island biomes.
* @param biomesObject Biome that need to be changed.
* @return {@code true} if can apply, {@code false} otherwise.
* @param dataObject DataObject where all data will be saved.
* @param island Island that need to unlock Biome.
* @param biomesObject Biome that must be unlocked.
*
* @return {@code true} if biome can be unlocked, {@code false} otherwise.
*/
public boolean canApplyBiome(@NotNull User user,
@NotNull BiomesIslandDataObject islandData,
@NotNull BiomesObject biomesObject)
public boolean canUnlockBiome(BiomesIslandDataObject dataObject, Island island, BiomesObject biomesObject)
{
if (!islandData.getUnlockedBiomes().contains(biomesObject.getUniqueId()))
if (!biomesObject.isValid() || !biomesObject.isDeployed())
{
// Generator is not unlocked. Return false.
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "biome-not-unlocked",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName()));

// Fast exit. Biome object that is not valid and is not deployed cannot be unlocked.
return false;
}
else if (!islandData.getPurchasedBiomes().contains(biomesObject.getUniqueId()) &&
this.addon.isEconomyProvided() &&
biomesObject.getUnlockCost() > 0)

// Update owner bundle, as it may influence island generators.
this.updateOwnerBundle(island, dataObject);

// Check if biome is part of available biomes.
if (!this.getIslandBiomes(island.getWorld(), dataObject).contains(biomesObject))
{
// Generator is not purchased. Return false.
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "biome-not-purchased",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName()));
// Biome is not in island bundle list.
return false;
}

// Get island level from the addon.
final long islandLevel = this.getIslandLevel(island);
final User owner = island.getOwner() == null ? null : User.getInstance(island.getOwner());

if (biomesObject.getUnlockLevel() > islandLevel)
{
// Not allowed by level.
return false;
}
else

if (!biomesObject.getUnlockPermissions().isEmpty() &&
(owner == null ||
!owner.isOnline() ||
!Utils.matchAllPermissions(owner, biomesObject.getUnlockPermissions())))
{
return true;
// If permissions are set, then biome unlock status can be validated only if owner is online.
return false;
}

// More unlocking stuff can be added here.
return true;
}


Expand Down Expand Up @@ -884,6 +897,7 @@ else if (!biomesObject.getUnlockPermissions().isEmpty() &&
// Not enough money.
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "no-credits-buy-bank",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName(),
TextVariables.NUMBER, String.valueOf(biomesObject.getUnlockCost())));
return false;
}
Expand All @@ -893,7 +907,8 @@ else if (!this.addon.getVaultHook().has(user, biomesObject.getUnlockCost()))
// Not enough money.

Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "no-credits-buy-bank",
user.getTranslation(Constants.MESSAGES + "no-credits-buy",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName(),
TextVariables.NUMBER, String.valueOf(biomesObject.getUnlockCost())));
return false;
}
Expand Down Expand Up @@ -979,7 +994,7 @@ public void purchaseBiome(@NotNull User user,
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "biome-purchased",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName()));
islandData.getPurchasedBiomes().add(biomesObject.getUniqueId());
islandData.purchaseBiome(biomesObject.getUniqueId());

// Save object.
this.saveIslandData(islandData);
Expand Down Expand Up @@ -1483,9 +1498,22 @@ public long getIslandLevel(User user)
public boolean isPurchased(BiomesIslandDataObject islandData, BiomesObject biomesObject)
{
return islandData.isPurchased(biomesObject) ||
islandData.isUnlocked(biomesObject) &&
biomesObject.getUnlockItems().isEmpty() &&
(!this.addon.isEconomyProvided() || biomesObject.getUnlockCost() == 0);
islandData.isUnlocked(biomesObject) && !this.hasPriceSet(biomesObject);
}


/**
* This method returns if biome has price set or it should be given for free.
* @param biomesObject Biome object that need to be checked.
* @return {@code true} if biome has price set, {@code false} otherwise.
*/
public boolean hasPriceSet(BiomesObject biomesObject)
{
// If unlock items are not set and/or there are no unlock cost associated to the biome, then
// it is purchased by default.

return !biomesObject.getUnlockItems().isEmpty() ||
this.addon.isEconomyProvided() && biomesObject.getUnlockCost() != 0;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private PanelItem createButton(Button button)

for (UUID uuid : members)
{
if (uuid != this.island.getOwner())
if (!uuid.equals(this.island.getOwner()))
{
builder.append("\n").append(this.user.getTranslation(reference + "value",
Constants.PARAMETER_PLAYER, this.addon.getPlayers().getName(uuid)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected PanelItem createElementButton(Island island)

for (UUID uuid : members)
{
if (uuid != island.getOwner())
if (!uuid.equals(island.getOwner()))
{
builder.append("\n").append(this.user.getTranslation(reference + "element",
Constants.PARAMETER_PLAYER, this.addon.getPlayers().getName(uuid)));
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/world/bentobox/biomes/panels/user/AdvancedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package world.bentobox.biomes.panels.user;


import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -95,6 +96,9 @@ private PanelItem createModeButton(ItemTemplateRecord template, TemplatedPanel.I
String update = (String) template.dataMap().getOrDefault("value",
Settings.UpdateMode.ISLAND.name());

int minValue = (int) template.dataMap().getOrDefault("min-value", 1);
int maxValue = (int) template.dataMap().getOrDefault("max-value", Integer.MAX_VALUE);

PanelItemBuilder builder = new PanelItemBuilder();

if (template.icon() != null)
Expand All @@ -117,6 +121,12 @@ private PanelItem createModeButton(ItemTemplateRecord template, TemplatedPanel.I
builder.clickHandler((panel, user, clickType, i) ->
{
this.updateMode = Settings.UpdateMode.getMode(update.toUpperCase());

this.minValue = Math.min(minValue, maxValue);
this.maxValue = Math.max(minValue, maxValue);

this.range = Math.max(Math.min(this.range, this.maxValue), this.minValue);

this.build();

// Always return true.
Expand Down Expand Up @@ -176,10 +186,16 @@ private PanelItem createIncreaseButton(ItemTemplateRecord template, TemplatedPan
Constants.PARAMETER_NUMBER, String.valueOf(increaseValue)));
}

if (this.range >= this.maxValue)
{
// Change icon as max value has been reached.
builder.icon(Material.BARRIER);
}

// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) ->
{
this.range += increaseValue;
this.range = Math.min(this.range + increaseValue, this.maxValue);
this.build();

// Always return true.
Expand Down Expand Up @@ -237,10 +253,16 @@ private PanelItem createReduceButton(ItemTemplateRecord template, TemplatedPanel
Constants.PARAMETER_NUMBER, String.valueOf(decreaseValue)));
}

if (this.range <= this.minValue)
{
// Change icon as max value has been reached.
builder.icon(Material.BARRIER);
}

// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) ->
{
this.range = Math.max(this.range - decreaseValue, 1);
this.range = Math.max(this.range - decreaseValue, this.minValue);
this.build();

// Always return true.
Expand Down Expand Up @@ -323,8 +345,8 @@ private PanelItem createValueButton(ItemTemplateRecord template, TemplatedPanel.
ConversationUtils.createNumericInput(numberConsumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "input-number"),
1,
2000);
this.minValue,
this.maxValue);
}
else if ("ACCEPT".equalsIgnoreCase(actionRecords.actionType()))
{
Expand Down Expand Up @@ -510,4 +532,14 @@ public static void open(@NotNull CommonPanel parentPanel,
* This variable stores update mode
*/
private Settings.UpdateMode updateMode;

/**
* This variable stores the minimal update size that can be set.
*/
private int minValue = 1;

/**
* This variable stores the maximal update size that can be set.
*/
private int maxValue = Integer.MAX_VALUE;
}
Loading

0 comments on commit 14c38ef

Please sign in to comment.