Skip to content

Commit

Permalink
Adding Owner placeholder to commands upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume-Lebegue committed Sep 25, 2020
1 parent 96f0dc5 commit e9fb64f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/world/bentobox/upgrades/UpgradesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ public int getCommandUpgradeMax(String cmd, World world) {
return this.addon.getSettings().getMaxCommandUpgrade(cmd, name);
}

public List<String> getCommandList(String cmd, int cmdLevel, World world, String playerName) {
Settings.CommandUpgradeTier cmdUpgradeTier = this.getCommandUpgradeTier(cmd, cmdLevel, world);
public List<String> getCommandList(String cmd, int cmdLevel, Island island, String playerName) {
Settings.CommandUpgradeTier cmdUpgradeTier = this.getCommandUpgradeTier(cmd, cmdLevel, island.getWorld());

if (cmdUpgradeTier == null)
return Collections.emptyList();
return cmdUpgradeTier.getCommandList(playerName, cmdLevel);
return cmdUpgradeTier.getCommandList(playerName, island, cmdLevel);
}

public Boolean isCommantConsole(String cmd, int cmdLevel, World world) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/world/bentobox/upgrades/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.entity.EntityType;
import org.eclipse.jdt.annotation.NonNull;

import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.upgrades.UpgradesAddon;

public class Settings {
Expand Down Expand Up @@ -646,12 +647,14 @@ public void setCommandList(List<String> commandsList) {
this.commandList = commandsList;
}

public List<String> getCommandList(String playerName, int level) {
public List<String> getCommandList(String playerName, Island island, int level) {
List<String> formatedList = new ArrayList<String>(this.commandList.size());
String owner = island.getPlugin().getPlayers().getName(island.getOwner());

this.commandList.forEach(cmd -> {
String fcmd = cmd.replace("[player]", playerName)
.replace("[level]", Integer.toString(level));
.replace("[level]", Integer.toString(level))
.replace("[owner]", owner);
formatedList.add(fcmd);
});
return formatedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean doUpgrade(User user, Island island) {
if (!super.doUpgrade(user, island))
return false;

List<String> commands = upgradeAddon.getUpgradesManager().getCommandList(this.cmdId, upgradeLevel, island.getWorld(), user.getName());
List<String> commands = upgradeAddon.getUpgradesManager().getCommandList(this.cmdId, upgradeLevel, island, user.getName());
Boolean isConsole = upgradeAddon.getUpgradesManager().isCommantConsole(this.cmdId, upgradeLevel, island.getWorld());

commands.forEach(cmd -> {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ entity-limits-upgrade:
# For the command section:
# [player] : is the name of the player
# [level] : is the level of the upgrade
# [owner] : is the name of the island's owner
# Permission upgrade name: command-[NAME] -> In lower case + NAME != name:
command-upgrade:
lambda-upgrade:
Expand Down

0 comments on commit e9fb64f

Please sign in to comment.