Skip to content

Commit

Permalink
Added the tier name, current and max level message (#30)
Browse files Browse the repository at this point in the history
* Update en-US.yml

* Added Tier name, current and max massages to gui.

* Update en-US.yml

change ' to ".

* Update fr.yml

added tier name, current and max message.

* Update ja.yml

added tier name, current and max message.

* Update en-US.yml

* Update ja.yml

* Update fr.yml

* Update en-US.yml

Co-authored-by: king-glitch <tiger2.yaowawit@gmail.com>
  • Loading branch information
king-glitch and king-glitch committed Nov 12, 2020
1 parent 1b30bb0 commit 6be38bd
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 221 deletions.
106 changes: 53 additions & 53 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>world.bentobox</groupId>
<artifactId>upgrades</artifactId>
<version>${revision}</version>
<name>Upgrades</name>
<description>BentoBox Addon for buying upgrade for island with vault money</description>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>world.bentobox</groupId>
<artifactId>upgrades</artifactId>
<version>${revision}</version>

<name>Upgrades</name>
<description>BentoBox Addon for buying upgrade for island with vault money</description>
<url>https://github.com/BentoBoxWorld/Upgrades</url>
<inceptionYear>2020</inceptionYear>

Expand Down Expand Up @@ -40,17 +40,17 @@
</repository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>

<spigot.version>1.16.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<level.version>2.0.0</level.version>
<limits.version>1.13.0-SNAPSHOT</limits.version>
<vault.version>1.7</vault.version>

<revision>${build.version}-SNAPSHOT</revision>

<!-- This allows to change between versions. -->
Expand All @@ -59,7 +59,7 @@
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
</properties>
</properties>

<profiles>
<profile>
Expand Down Expand Up @@ -102,55 +102,55 @@
</profile>
</profiles>

<repositories>
<repository>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>${bentobox.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>${bentobox.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>level</artifactId>
<version>${level.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>limits</artifactId>
<version>${limits.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>${vault.version}</version>
<scope>provided</scope>
</dependency>
</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}. -->
Expand Down Expand Up @@ -291,5 +291,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;


import world.bentobox.limits.listeners.BlockLimitsListener;
import world.bentobox.upgrades.UpgradesAddon;
import world.bentobox.upgrades.api.Upgrade;
Expand All @@ -22,44 +21,46 @@ public BlockLimitsUpgrade(UpgradesAddon addon, Material block) {
super(addon, "LimitsUpgrade-" + block.toString(), block.toString() + " limits Upgrade", block);
this.block = block;
}

@Override
public void updateUpgradeValue(User user, Island island) {
UpgradesAddon upgradeAddon = this.getUpgradesAddon();
UpgradesData islandData = upgradeAddon.getUpgradesLevels(island.getUniqueId());
int upgradeLevel = islandData.getUpgradeLevel(getName());
int numberPeople = island.getMemberSet().size();
int islandLevel = upgradeAddon.getUpgradesManager().getIslandLevel(island);

Map<String, Integer> upgradeInfos = upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeInfos(this.block, upgradeLevel, islandLevel, numberPeople, island.getWorld());

Map<String, Integer> upgradeInfos = upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeInfos(this.block,
upgradeLevel, islandLevel, numberPeople, island.getWorld());
UpgradeValues upgrade;

// Get new description
String description = upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeTierName(this.block, upgradeLevel, island.getWorld()) + " (" + upgradeLevel + "/" +
upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeMax(this.block, island.getWorld()) + ")";
String description = user.getTranslation("upgrades.ui.upgradepanel.tiernameandlevel", "[name]", upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeTierName(this.block, upgradeLevel,
island.getWorld()), "[current]", Integer.toString(upgradeLevel), "[max]", Integer.toString(upgradeAddon.getUpgradesManager().getBlockLimitsUpgradeMax(this.block, island.getWorld())));
// Set new description
this.setOwnDescription(user, description);

if (upgradeInfos == null)
upgrade = null;
else
upgrade = new UpgradeValues(upgradeInfos.get("islandMinLevel"), upgradeInfos.get("vaultCost"), upgradeInfos.get("upgrade"));

upgrade = new UpgradeValues(upgradeInfos.get("islandMinLevel"), upgradeInfos.get("vaultCost"),
upgradeInfos.get("upgrade"));

this.setUpgradeValues(user, upgrade);

String newDisplayName;

if (upgrade == null) {
newDisplayName = user.getTranslation("upgrades.ui.upgradepanel.nolimitsupgrade",
"[block]", this.block.toString());
newDisplayName = user.getTranslation("upgrades.ui.upgradepanel.nolimitsupgrade", "[block]",
this.block.toString());
} else {
newDisplayName = user.getTranslation("upgrades.ui.upgradepanel.limitsupgrade",
"[block]", this.block.toString(), "[level]", Integer.toString(upgrade.getUpgradeValue()));
newDisplayName = user.getTranslation("upgrades.ui.upgradepanel.limitsupgrade", "[block]",
this.block.toString(), "[level]", Integer.toString(upgrade.getUpgradeValue()));
}

this.setDisplayName(newDisplayName);
}

@Override
public boolean isShowed(User user, Island island) {
// Get the addon
Expand All @@ -69,81 +70,84 @@ public boolean isShowed(User user, Island island) {
// Get level of the upgrade
int upgradeLevel = islandData.getUpgradeLevel(this.getName());
// Permission level required
int permissionLevel = upgradesAddon.getUpgradesManager().getBlockLimitsPermissionLevel(this.block, upgradeLevel, island.getWorld());

int permissionLevel = upgradesAddon.getUpgradesManager().getBlockLimitsPermissionLevel(this.block, upgradeLevel,
island.getWorld());

// If default permission, then true
if (permissionLevel == 0)
return true;

Player player = user.getPlayer();
String gamemode = island.getGameMode();
String permissionStart = gamemode + ".upgrades." + this.getName() + ".";
permissionStart = permissionStart.toLowerCase();

// For each permission of the player
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
// If permission is the one we search

// If permission is the one we search
if (!perms.getValue() || !perms.getPermission().startsWith(permissionStart))
continue;

if (perms.getPermission().contains(permissionStart + "*")) {
this.logError(player.getName(), perms.getPermission(), "Wildcards are not allowed.");
return false;
}

String[] split = perms.getPermission().split("\\.");
if (split.length != 4) {
logError(player.getName(), perms.getPermission(), "format must be '" + permissionStart + "LEVEL'");
return false;
}

if (!NumberUtils.isDigits(split[3])) {
logError(player.getName(), perms.getPermission(), "The last part must be a number");
return false;
}

if (permissionLevel <= Integer.parseInt(split[3]))
return true;
}

return false;
}

private void logError(String name, String perm, String error) {
this.getUpgradesAddon().logError("Player " + name + " has permission: '" + perm + "' but " + error + " Ignoring...");
}

this.getUpgradesAddon()
.logError("Player " + name + " has permission: '" + perm + "' but " + error + " Ignoring...");
}

@Override
public boolean doUpgrade(User user, Island island) {
UpgradesAddon islandAddon = this.getUpgradesAddon();

if (!islandAddon.isLimitsProvided())
return false;

BlockLimitsListener bLListener = islandAddon.getLimitsAddon().getBlockLimitListener();
Map<Material, Integer> materialLimits = bLListener.getMaterialLimits(island.getWorld(), island.getUniqueId());

if (!materialLimits.containsKey(this.block) || materialLimits.get(this.block) == -1) {
this.getUpgradesAddon().logWarning("User tried to upgrade " + this.block.toString() + " limits but it has no limits. This is probably a configuration problem.");
this.getUpgradesAddon().logWarning("User tried to upgrade " + this.block.toString()
+ " limits but it has no limits. This is probably a configuration problem.");
user.sendMessage("upgrades.error.increasenolimits");
return false;
}

if (!super.doUpgrade(user, island))
return false;
int oldCount = materialLimits.get(this.block);

int oldCount = materialLimits.get(this.block);
int newCount = (int) (oldCount + this.getUpgradeValues(user).getUpgradeValue());

bLListener.getIsland(island.getUniqueId()).setBlockLimit(this.block, newCount);
user.sendMessage("upgrades.ui.upgradepanel.limitsupgradedone",
"[block]", this.block.toString(), "[level]", Integer.toString(this.getUpgradeValues(user).getUpgradeValue()));

user.sendMessage("upgrades.ui.upgradepanel.limitsupgradedone", "[block]", this.block.toString(), "[level]",
Integer.toString(this.getUpgradeValues(user).getUpgradeValue()));

return true;
}

private Material block;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public void updateUpgradeValue(User user, Island island) {

Map<String, Integer> upgradeInfos = upgradesAddon.getUpgradesManager().getCommandUpgradeInfos(this.cmdId, upgradeLevel, islandLevel, numberPeople, island.getWorld());
UpgradeValues upgrade;

String description = upgradesAddon.getUpgradesManager().getCommandUpgradeTierName(this.cmdId, upgradeLevel, island.getWorld()) + " (" + upgradeLevel + "/" +
upgradesAddon.getUpgradesManager().getCommandUpgradeMax(this.cmdId, island.getWorld()) + ")";

String description = user.getTranslation("upgrades.ui.upgradepanel.tiernameandlevel", "[name]", upgradesAddon.getUpgradesManager().getCommandUpgradeTierName(this.cmdId, upgradeLevel, island.getWorld()), "[current]", Integer.toString(upgradeLevel), "[max]", Integer.toString(upgradesAddon.getUpgradesManager().getCommandUpgradeMax(this.cmdId, island.getWorld())));

this.setOwnDescription(user, description);

Expand Down

0 comments on commit 6be38bd

Please sign in to comment.