Skip to content

Commit

Permalink
Update from useless long to int
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume-Lebegue committed May 23, 2020
1 parent e5bd3ab commit 24bd3de
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
28 changes: 14 additions & 14 deletions src/main/java/world/bentobox/upgrades/UpgradesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ public boolean canOperateInWorld(World world) {
return addon.isPresent() && this.hookedGameModes.contains(addon.get().getDescription().getName());
}

public long getIslandLevel(Island island) {
public int getIslandLevel(Island island) {
if (!this.addon.isLevelProvided())
return 0L;
return 0;

return this.addon.getLevelAddon().getIslandLevel(island.getWorld(), island.getOwner());
return (int) this.addon.getLevelAddon().getIslandLevel(island.getWorld(), island.getOwner());
}

public List<Settings.RangeUpgradeTier> getAllRangeUpgradeTiers(World world) {
public List<Settings.UpgradeTier> getAllRangeUpgradeTiers(World world) {
String name = this.addon.getPlugin().getIWM().getAddon(world).map(a -> a.getDescription().getName()).orElse(null);
if (name == null) return Collections.emptyList();

Map<String, Settings.RangeUpgradeTier> defaultTiers = this.addon.getSettings().getDefaultRangeUpgradeTierMap();
Map<String, Settings.RangeUpgradeTier> customAddonTiers = this.addon.getSettings().getAddonRangeUpgradeTierMap(name);
Map<String, Settings.UpgradeTier> defaultTiers = this.addon.getSettings().getDefaultRangeUpgradeTierMap();
Map<String, Settings.UpgradeTier> customAddonTiers = this.addon.getSettings().getAddonRangeUpgradeTierMap(name);

List<Settings.RangeUpgradeTier> tierList;
List<Settings.UpgradeTier> tierList;

if (customAddonTiers.isEmpty())
tierList = new ArrayList<>(defaultTiers.values());
Expand All @@ -62,18 +62,18 @@ public List<Settings.RangeUpgradeTier> getAllRangeUpgradeTiers(World world) {
if (tierList.isEmpty())
return Collections.emptyList();

tierList.sort(Comparator.comparingInt(Settings.RangeUpgradeTier::getMaxLevel));
tierList.sort(Comparator.comparingInt(Settings.UpgradeTier::getMaxLevel));

return tierList;
}

public Settings.RangeUpgradeTier getRangeUpgradeTier(long rangeLevel, World world) {
List<Settings.RangeUpgradeTier> tierList = this.getAllRangeUpgradeTiers(world);
public Settings.UpgradeTier getRangeUpgradeTier(int rangeLevel, World world) {
List<Settings.UpgradeTier> tierList = this.getAllRangeUpgradeTiers(world);

if (tierList.isEmpty())
return null;

Settings.RangeUpgradeTier rangeUpgradeTier = tierList.get(0);
Settings.UpgradeTier rangeUpgradeTier = tierList.get(0);

if (rangeUpgradeTier.getMaxLevel() < 0)
return rangeUpgradeTier;
Expand All @@ -86,8 +86,8 @@ public Settings.RangeUpgradeTier getRangeUpgradeTier(long rangeLevel, World worl
return null;
}

public Map<String, Integer> getRangeUpgradeInfos(long rangeLevel, long islandLevel, long numberPeople, World world) {
Settings.RangeUpgradeTier rangeUpgradeTier = this.getRangeUpgradeTier(rangeLevel, world);
public Map<String, Integer> getRangeUpgradeInfos(int rangeLevel, int islandLevel, int numberPeople, World world) {
Settings.UpgradeTier rangeUpgradeTier = this.getRangeUpgradeTier(rangeLevel, world);

if (rangeUpgradeTier == null)
return null;
Expand All @@ -96,7 +96,7 @@ public Map<String, Integer> getRangeUpgradeInfos(long rangeLevel, long islandLev

info.put("islandMinLevel", (int) rangeUpgradeTier.calculateIslandMinLevel(rangeLevel, islandLevel, numberPeople));
info.put("vaultCost", (int) rangeUpgradeTier.calculateVaultCost(rangeLevel, islandLevel, numberPeople));
info.put("upgradeRange", (int) rangeUpgradeTier.calculateUpgradeRange(rangeLevel, islandLevel, numberPeople));
info.put("upgradeRange", (int) rangeUpgradeTier.calculateUpgrade(rangeLevel, islandLevel, numberPeople));

return info;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/world/bentobox/upgrades/api/Upgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,33 @@ public UpgradeValues(Integer islandLevel, Integer moneyCost, Integer upgradeValu
this.upgradeValue = upgradeValue;
}

public Long getIslandLevel() {
public int getIslandLevel() {
return islandLevel;
}

public void setIslandLevel(long islandLevel) {
public void setIslandLevel(int islandLevel) {
this.islandLevel = islandLevel;
}

public Long getMoneyCost() {
public int getMoneyCost() {
return moneyCost;
}

public void setMoneyCost(long moneyCost) {
public void setMoneyCost(int moneyCost) {
this.moneyCost = moneyCost;
}

public Long getUpgradeValue() {
public int getUpgradeValue() {
return upgradeValue;
}

public void setUpgradeValue(long upgradeValue) {
public void setUpgradeValue(int upgradeValue) {
this.upgradeValue = upgradeValue;
}

private long islandLevel;
private long moneyCost;
private long upgradeValue;
private int islandLevel;
private int moneyCost;
private int upgradeValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class UpgradesData implements DataObject {
private String uniqueId;

@Expose
private Map<String, Long> upgradesLevels;
private Map<String, Integer> upgradesLevels;

public UpgradesData() {}

public UpgradesData(String uniqueId, Map<String, Long> upgradesLevel) {
public UpgradesData(String uniqueId, Map<String, Integer> upgradesLevel) {
this.uniqueId = uniqueId;
this.upgradesLevels = upgradesLevel;
}
Expand All @@ -38,12 +38,12 @@ public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}

public long getUpgradeLevel(String name) {
this.upgradesLevels.putIfAbsent(name, (long) 0);
public int getUpgradeLevel(String name) {
this.upgradesLevels.putIfAbsent(name, 0);
return this.upgradesLevels.get(name);
}

public void setUpgradeLevel(String name, long value) {
public void setUpgradeLevel(String name, int value) {
this.upgradesLevels.put(name, value);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/world/bentobox/upgrades/ui/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Panel(UpgradesAddon addon) {

public void showPanel(User user) {
Island island = this.addon.getIslands().getIsland(user.getWorld(), user);
long islandLevel = this.addon.getUpgradesManager().getIslandLevel(island);
int islandLevel = this.addon.getUpgradesManager().getIslandLevel(island);

PanelBuilder pb = new PanelBuilder().name(user.getTranslation("upgrades.ui.upgradepanel.title"));

Expand All @@ -37,19 +37,19 @@ public void showPanel(User user) {
pb.user(user).build();
}

private List<String> getDescription(User user, Upgrade upgrade, long islandLevel) {
private List<String> getDescription(User user, Upgrade upgrade, int islandLevel) {
List<String> descrip = new ArrayList<>();
if (upgrade.getUpgradeValues() == null)
descrip.add(user.getTranslation("upgrades.ui.upgradepanel.maxlevel"));
else {
boolean hasMoney = this.addon.getVaultHook().has(user, upgrade.getUpgradeValues().getMoneyCost());
descrip.add((upgrade.getUpgradeValues().getIslandLevel() <= islandLevel ? "§a" : "§c") +
user.getTranslation("upgrades.ui.upgradepanel.islandneed",
"[islandlevel]", upgrade.getUpgradeValues().getIslandLevel().toString()));
"[islandlevel]", Integer.toString(upgrade.getUpgradeValues().getIslandLevel())));

descrip.add((hasMoney ? "§a" : "§c") +
user.getTranslation("upgrades.ui.upgradepanel.moneycost",
"[cost]", upgrade.getUpgradeValues().getMoneyCost().toString()));
"[cost]", Integer.toString(upgrade.getUpgradeValues().getMoneyCost())));

if (upgrade.getUpgradeValues().getIslandLevel() > islandLevel) {
descrip.add("§8" + user.getTranslation("upgrades.ui.upgradepanel.tryreloadlevel"));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/world/bentobox/upgrades/upgrades/RangeUpgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public void updateUpgradeValue(User user, Island island) {
// Get the data from IslandUpgrade
UpgradesData islandData = islandAddon.getUpgradesLevels(island.getUniqueId());
// The level of this upgrade
long upgradeLevel = islandData.getUpgradeLevel(getName());
int upgradeLevel = islandData.getUpgradeLevel(getName());
// The number of members on the island
long numberPeople = island.getMemberSet().size();
int numberPeople = island.getMemberSet().size();
// The level of the island from Level Addon
long islandLevel;
int islandLevel;

// If level addon is provided
if (islandAddon.isLevelProvided())
islandLevel = islandAddon.getUpgradesManager().getIslandLevel(island);
else
islandLevel = 0L;
islandLevel = 0;

// Get upgrades infos of range upgrade from settings
Map<String, Integer> upgradeInfos = islandAddon.getUpgradesManager().getRangeUpgradeInfos(upgradeLevel, islandLevel, numberPeople, island.getWorld());
Expand All @@ -67,7 +67,7 @@ public void updateUpgradeValue(User user, Island island) {
} else {
// get lang message
newDisplayName = user.getTranslation("islandupgrades.ui.upgradepanel.rangeupgrade",
"[rangelevel]", upgrade.getUpgradeValue().toString());
"[rangelevel]", Integer.toString(upgrade.getUpgradeValue()));
}

this.setDisplayName(newDisplayName);
Expand Down Expand Up @@ -109,7 +109,7 @@ public boolean doUpgrade(User user, Island island) {
.build();

user.sendMessage("upgrades.ui.upgradepanel.rangeupgradedone",
"[rangelevel]", this.getUpgradeValues().getUpgradeValue().toString());
"[rangelevel]", Integer.toString(this.getUpgradeValues().getUpgradeValue()));

return true;
}
Expand Down

0 comments on commit 24bd3de

Please sign in to comment.