Skip to content

Commit

Permalink
hiding Range Upgrade when not in config #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume-Lebegue committed Jul 13, 2020
1 parent 24a134e commit d1a3862
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/world/bentobox/upgrades/UpgradesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onEnable() {

Optional<VaultHook> vault = this.getPlugin().getVault();
if (!vault.isPresent()) {
this.logWarning("Vault plugin not found si Upgrades won't look for money");
this.logWarning("Vault plugin not found so Upgrades won't look for money");
this.vault = null;
} else
this.vault = vault.get();
Expand All @@ -96,7 +96,8 @@ public void onEnable() {

this.getSettings().getCommandUpgrade().forEach(cmd -> this.registerUpgrade(new CommandUpgrade(this, cmd, this.getSettings().getCommandIcon(cmd))));

this.registerUpgrade(new RangeUpgrade(this));
if (this.getSettings().getHasRangeUpgrade())
this.registerUpgrade(new RangeUpgrade(this));

this.registerListener(new IslandChangeListener(this));

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/world/bentobox/upgrades/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public Settings(UpgradesAddon addon) {
this.addon = addon;
this.addon.saveDefaultConfig();

this.hasRangeUpgrade = true;

this.disabledGameModes = new HashSet<>(this.addon.getConfig().getStringList("disabled-gamemodes"));

if (this.addon.getConfig().isSet("range-upgrade")) {
Expand All @@ -33,6 +35,8 @@ public Settings(UpgradesAddon addon) {

if (this.maxRangeUpgrade < newUpgrade.getMaxLevel())
this.maxRangeUpgrade = newUpgrade.getMaxLevel();

this.hasRangeUpgrade = true;
this.rangeUpgradeTierMap.put(key, newUpgrade);
}
}
Expand Down Expand Up @@ -93,6 +97,8 @@ else if (mat == null)
if (this.customMaxRangeUpgrade.get(gameMode) == null || this.customMaxRangeUpgrade.get(gameMode) < newUpgrade.getMaxLevel())
this.customMaxRangeUpgrade.put(gameMode, newUpgrade.getMaxLevel());

this.hasRangeUpgrade = true;

this.customRangeUpgradeTierMap.computeIfAbsent(gameMode, k -> new HashMap<>()).put(key, newUpgrade);
}
}
Expand Down Expand Up @@ -298,6 +304,10 @@ public Set<String> getDisabledGameModes() {
return disabledGameModes;
}

public boolean getHasRangeUpgrade() {
return this.hasRangeUpgrade;
}

public int getMaxRangeUpgrade(String addon) {
return this.customMaxRangeUpgrade.getOrDefault(addon, this.maxRangeUpgrade);
}
Expand Down Expand Up @@ -413,6 +423,8 @@ public String getCommandName(String command) {

private int maxRangeUpgrade = 0;

private boolean hasRangeUpgrade;

private Map<String, Integer> customMaxRangeUpgrade = new HashMap<>();

private Map<String, UpgradeTier> rangeUpgradeTierMap = new HashMap<>();
Expand Down

0 comments on commit d1a3862

Please sign in to comment.