Skip to content

Commit

Permalink
Implement new features in admin menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jan 11, 2022
1 parent 8cf0c4e commit ca228b6
Show file tree
Hide file tree
Showing 11 changed files with 1,490 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ public boolean execute(User user, String label, List<String> args)
user.sendMessage("biomes.information.description",
"[description]", BiomesCommand.this.getSingleLineDescription(biomesObject.getDescription()));
user.sendMessage("biomes.information.level",
"[level]", Long.toString(biomesObject.getRequiredLevel()));
"[level]", Long.toString(biomesObject.getUnlockLevel()));
user.sendMessage("biomes.information.cost",
"[cost]", Double.toString(biomesObject.getRequiredCost()));
"[cost]", Double.toString(biomesObject.getUnlockCost()));

biomesObject.getRequiredPermissions().forEach(s ->
biomesObject.getUnlockPermissions().forEach(s ->
user.sendMessage("biomes.information.permission", "[permission]", s));

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public Object handle(Map<String, Object> metaData)
biomesDataMap.put("icon", biome.getIcon());
biomesDataMap.put("order", biome.getOrder());

biomesDataMap.put("cost", biome.getRequiredCost());
biomesDataMap.put("level", biome.getRequiredLevel());
biomesDataMap.put("permissions", biome.getRequiredPermissions());
biomesDataMap.put("cost", biome.getUnlockCost());
biomesDataMap.put("level", biome.getUnlockLevel());
biomesDataMap.put("permissions", biome.getUnlockPermissions());
}

return biomesDataMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public void onTeamSetOwnerEvent(TeamSetownerEvent event)
{
defaultBiomeObject = new BiomesObject();
defaultBiomeObject.setBiome(biome);
defaultBiomeObject.setRequiredCost(0);
defaultBiomeObject.setRequiredLevel(0);
}

// Forcefully update biome on whole user island.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,25 @@ public void wipeBundle(BiomesBundleObject bundle)
// ---------------------------------------------------------------------


/**
* Gets island data.
*
* @param world the world
* @param user the user
* @return the island data
*/
@Nullable
public BiomesIslandDataObject getIslandData(@Nullable World world, @Nullable User user)
{
if (world == null || user == null)
{
return null;
}

return this.getIslandData(this.addon.getIslandsManager().getIsland(world, user));
}


/**
* Gets island data.
*
Expand Down Expand Up @@ -571,9 +590,9 @@ public void checkBiomesUnlockStatus(Island island, @Nullable User user, @Nullabl
filter(BiomesObject::isValid).
filter(BiomesObject::isDeployed).
filter(biome -> !dataObject.getUnlockedBiomes().contains(biome.getUniqueId())).
filter(biome -> biome.getRequiredLevel() <= islandLevel).
filter(biome -> biome.getRequiredPermissions().isEmpty() ||
owner != null && owner.isOnline() && Utils.matchAllPermissions(owner, biome.getRequiredPermissions())).
filter(biome -> biome.getUnlockLevel() <= islandLevel).
filter(biome -> biome.getUnlockPermissions().isEmpty() ||
owner != null && owner.isOnline() && Utils.matchAllPermissions(owner, biome.getUnlockPermissions())).
forEach(biome -> this.unlockBiome(dataObject, user, island, biome));
}

Expand Down Expand Up @@ -649,7 +668,7 @@ public boolean canApplyBiome(@NotNull User user,
}
else if (!islandData.getPurchasedBiomes().contains(biomesObject.getUniqueId()) &&
this.addon.isEconomyProvided() &&
biomesObject.getRequiredCost() > 0)
biomesObject.getUnlockCost() > 0)
{
// Generator is not purchased. Return false.
Utils.sendMessage(user,
Expand Down Expand Up @@ -708,7 +727,7 @@ public void unlockBiome(@NotNull BiomesIslandDataObject dataObject,
}

// Send message to user
if (this.addon.isEconomyProvided() && biomesObject.getRequiredCost() > 0)
if (this.addon.isEconomyProvided() && biomesObject.getUnlockCost() > 0)
{
// Send message that biomesObject is available for purchase.

Expand Down Expand Up @@ -767,20 +786,20 @@ else if (!island.isAllowed(BiomesAddon.BIOMES_ISLAND_PROTECTION))
user.getTranslation(this.addon.getPlugin().getRanksManager().getRank(island.getRank(user)))));
return false;
}
else if (biomesObject.getRequiredLevel() > this.getIslandLevel(island))
else if (biomesObject.getUnlockLevel() > this.getIslandLevel(island))
{
// Biome is not unlocked. Return false.
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "island-level-not-reached",
Constants.PARAMETER_BIOME, biomesObject.getFriendlyName(),
TextVariables.NUMBER, String.valueOf(biomesObject.getRequiredLevel())));
TextVariables.NUMBER, String.valueOf(biomesObject.getUnlockLevel())));
return false;
}
else if (!biomesObject.getRequiredPermissions().isEmpty() &&
else if (!biomesObject.getUnlockPermissions().isEmpty() &&
(owner == null || !owner.isPlayer() ||
!biomesObject.getRequiredPermissions().stream().allMatch(owner::hasPermission)))
!biomesObject.getUnlockPermissions().stream().allMatch(owner::hasPermission)))
{
Optional<String> missingPermission = biomesObject.getRequiredPermissions().stream().
Optional<String> missingPermission = biomesObject.getUnlockPermissions().stream().
filter(permission -> owner == null || !owner.isPlayer() || !owner.hasPermission(permission)).
findAny();

Expand All @@ -794,19 +813,19 @@ else if (!biomesObject.getRequiredPermissions().isEmpty() &&
}
else
{
if (this.addon.isEconomyProvided() && biomesObject.getRequiredCost() > 0)
if (this.addon.isEconomyProvided() && biomesObject.getUnlockCost() > 0)
{
// Return true only if user has enough money and its removal was successful.
if (this.addon.getVaultHook().has(user, biomesObject.getRequiredCost()) &&
this.addon.getVaultHook().withdraw(user, biomesObject.getRequiredCost()).transactionSuccess())
if (this.addon.getVaultHook().has(user, biomesObject.getUnlockCost()) &&
this.addon.getVaultHook().withdraw(user, biomesObject.getUnlockCost()).transactionSuccess())
{
return true;
}
else
{
Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "no-credits-buy",
TextVariables.NUMBER, String.valueOf(biomesObject.getRequiredCost())));
TextVariables.NUMBER, String.valueOf(biomesObject.getUnlockCost())));
return false;
}
}
Expand Down Expand Up @@ -980,8 +999,8 @@ public List<BiomesObject> getBiomes(World world, User user)
// Filter out undeployed biomes if visibility mode is set to only deployed
filter(BiomesObject::isDeployed).
// Filter out biomes which does user not have permissions
filter(biomesObject -> biomesObject.getRequiredPermissions().isEmpty() ||
biomesObject.getRequiredPermissions().stream().allMatch(user::hasPermission)).
filter(biomesObject -> biomesObject.getUnlockPermissions().isEmpty() ||
biomesObject.getUnlockPermissions().stream().allMatch(user::hasPermission)).
forEach(returnBiomesList::add);

return returnBiomesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ private int importBiomes(ConfigurationSection reader, World world)
newBiomeObject.setDescription(Arrays.stream(details.getString("description", "").split("\n")).toList());
newBiomeObject.setIcon(ItemParser.parse(details.getString("icon")));

newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0));
newBiomeObject.setRequiredCost(details.getDouble("cost", 0.0));
newBiomeObject.setUnlockLevel(details.getLong("islandLevel", 0));
newBiomeObject.setUnlockCost(details.getDouble("cost", 0.0));

String environmentValue = details.getString("environment", "normal").toUpperCase();

Expand All @@ -247,11 +247,11 @@ private int importBiomes(ConfigurationSection reader, World world)

if (permissions.isEmpty())
{
newBiomeObject.setRequiredPermissions(Collections.emptySet());
newBiomeObject.setUnlockPermissions(Collections.emptySet());
}
else
{
newBiomeObject.setRequiredPermissions(new HashSet<>(permissions));
newBiomeObject.setUnlockPermissions(new HashSet<>(permissions));
}

if (this.addon.getAddonManager().loadBiomes(newBiomeObject, false, null, true))
Expand Down

0 comments on commit ca228b6

Please sign in to comment.