Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
Modification in api: New isShowed function
  • Loading branch information
Guillaume-Lebegue committed Jun 29, 2020
1 parent 7d481a6 commit 204b0d4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<revision>${build.version}-SNAPSHOT</revision>

<!-- This allows to change between versions. -->
<build.version>0.1.0</build.version>
<build.version>0.2.0</build.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/world/bentobox/upgrades/api/Upgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ public Upgrade(Addon addon, String name, String displayName, Material icon) {
}

/**
* This fonction is called every times a user open the interface
* This function is called every times a user open the interface
* You should make it update the upgradeValues
*
* @param user: This is the user that ask for the interface
* @param island: This is the island concerned by the interface
*/
public abstract void updateUpgradeValue(User user, Island island);

/**
* This function is called every times a user open the interface
* If it return false, the upgrade won't be showed to the user
*
* @param user: This is the user that ask for the interface
* @param island: This is the island concerned by the interface
* @return If true, then upgrade is shown else, it is hided
*/
public boolean isShowed(User user, Island island) {
return true;
}

/**
* This function return true if the user can upgrade for this island.
* You can override it and call the super.
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/world/bentobox/upgrades/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ private UpgradeTier addUpgradeSection(ConfigurationSection section, String key)
else
upgradeTier.setVaultCost(parse("0", upgradeTier.getExpressionVariable()));

if (tierSection.isSet("permission-level"))
upgradeTier.setPermissionLevel(tierSection.getInt("permission-level"));

return upgradeTier;

}
Expand Down Expand Up @@ -351,6 +354,20 @@ public int getMaxLevel() {
public void setMaxLevel(int maxLevel) {
this.maxLevel = maxLevel;
}

/**
* @return the level of permission
*/
public Integer getPermissionLevel() {
return this.permissionLevel;
}

/**
* @param level of permission to set
*/
public void setPermissionLevel(Integer level) {
this.permissionLevel = level;
}

/**
* @return the upgradeRange
Expand Down Expand Up @@ -439,6 +456,8 @@ public double calculateVaultCost(double level, double islandLevel, double number
private int maxLevel = -1;

private String tierName;

private Integer permissionLevel = 0;

private Expression upgrade;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/world/bentobox/upgrades/ui/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void showPanel(User user) {

this.addon.getAvailableUpgrades().forEach(upgrade -> {
upgrade.updateUpgradeValue(user, this.island);

if (!upgrade.isShowed(user, this.island))
return;

String ownDescription = upgrade.getOwnDescription(user);
List<String> fullDescription = new ArrayList<>();

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ disabled-gamemodes: []
# Each tier must contain:
# max-level: Upgrade level up to which tier apply
# upgrade-range: How much block is added to the range with each upgrade
#
# Each tier can contain:
# island-min-level: Minimum level required to upgrade (if level addon is provided)
# vault-cost: Money cost of upgrade
# permission-level: Is the level of permission needed to upgrade
# permission: "[GAMEMODE].upgrades.[UPGRADE].[LEVEL]"
# Exemple for bskyblock with range-upgrade with a permission level of 2
# "bskyblock.upgrades.range-upgrade.2"
#
# Note: for upgrade-range, island-min-level and vault-cost:
# Mathematical expression can be used (+,-,*,/,^,(,))
# Mathematical function can be used (sqrt,sin,cost,tan)
Expand Down Expand Up @@ -43,6 +50,7 @@ block-limits-upgrade:
upgrade: "1"
island-min-level: "4"
vault-cost: "([level]-2)*[numberPlayer]*700"
permission-level: 1

entity-limits-upgrade:
CHICKEN:
Expand All @@ -56,6 +64,7 @@ entity-limits-upgrade:
upgrade: "1"
island-min-level: "4"
vault-cost: "([level]-2)*[numberPlayer]*700"
permission-level: 3

# GameMode differences
# List any tiers that you want to add
Expand Down

0 comments on commit 204b0d4

Please sign in to comment.