Make island levels/points longs instead of ints

This commit is contained in:
Esophose 2019-03-23 09:33:23 -06:00
parent 581193b431
commit 0c97942596
12 changed files with 66 additions and 66 deletions

View File

@ -17,28 +17,28 @@ public class IslandLevel {
/**
* @return Points of the Island from gathered materials
*/
public int getPoints() {
public long getPoints() {
return this.handle.getIsland().getLevel().getPoints();
}
/**
* @return Level of the Island from points
*/
public int getLevel() {
public long getLevel() {
return this.handle.getIsland().getLevel().getLevel();
}
/**
* @return Last calculated points of the Island
*/
public int getLastCalculatedPoints() {
public long getLastCalculatedPoints() {
return this.handle.getIsland().getLevel().getLastCalculatedPoints();
}
/**
* @return Last calculated level of the Island
*/
public int getLastCalculatedLevel() {
public long getLastCalculatedLevel() {
return this.handle.getIsland().getLevel().getLastCalculatedLevel();
}
@ -62,7 +62,7 @@ public class IslandLevel {
/**
* @return The amount of a Material from the Island
*/
public int getMaterialAmount(Material material) {
public long getMaterialAmount(Material material) {
Preconditions.checkArgument(material != null, "Cannot get material amount to null material");
Materials materials = Materials.fromString(material.name());
@ -78,7 +78,7 @@ public class IslandLevel {
/**
* @return The amount of a Material from the Island
*/
public int getMaterialAmount(Material material, byte data) {
public long getMaterialAmount(Material material, byte data) {
Preconditions.checkArgument(material != null, "Cannot get material amount to null material");
Materials materials = Materials.requestMaterials(material.name(), data);
@ -94,7 +94,7 @@ public class IslandLevel {
/**
* @return The points earned for a Material from the Island
*/
public int getMaterialPoints(Material material) {
public long getMaterialPoints(Material material) {
Preconditions.checkArgument(material != null, "Cannot get material points to null material");
return this.handle.getIsland().getLevel().getMaterialPoints(Materials.fromString(material.name()).name());
}
@ -102,7 +102,7 @@ public class IslandLevel {
/**
* @return The points earned for a Material from the Island
*/
public int getMaterialPoints(Material material, byte data) {
public long getMaterialPoints(Material material, byte data) {
Preconditions.checkArgument(material != null, "Cannot get material points to null material");
return this.handle.getIsland().getLevel()
.getMaterialPoints(Materials.requestMaterials(material.name(), data).name());

View File

@ -17,10 +17,10 @@ public class IslandLevel {
private UUID ownerUUID;
private int lastCalculatedLevel = 0;
private int lastCalculatedPoints = 0;
private long lastCalculatedLevel = 0;
private long lastCalculatedPoints = 0;
private Map<String, Integer> materials;
private Map<String, Long> materials;
public IslandLevel(UUID ownerUUID, SkyBlock skyblock) {
this.skyblock = skyblock;
@ -30,12 +30,12 @@ public class IslandLevel {
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
Map<String, Integer> materials = new HashMap<>();
Map<String, Long> materials = new HashMap<>();
if (configLoad.getString("Levelling.Materials") != null) {
for (String materialList : configLoad.getConfigurationSection("Levelling.Materials").getKeys(false)) {
if (configLoad.getString("Levelling.Materials." + materialList + ".Amount") != null) {
materials.put(materialList, configLoad.getInt("Levelling.Materials." + materialList + ".Amount"));
materials.put(materialList, configLoad.getLong("Levelling.Materials." + materialList + ".Amount"));
}
}
}
@ -47,17 +47,17 @@ public class IslandLevel {
this.ownerUUID = ownerUUID;
}
public int getPoints() {
public long getPoints() {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
int pointsEarned = 0;
long pointsEarned = 0;
for (String materialList : this.materials.keySet()) {
int materialAmount = this.materials.get(materialList);
long materialAmount = this.materials.get(materialList);
if (configLoad.getString("Materials." + materialList + ".Points") != null) {
int pointsRequired = config.getFileConfiguration().getInt("Materials." + materialList + ".Points");
long pointsRequired = config.getFileConfiguration().getLong("Materials." + materialList + ".Points");
if (pointsRequired != 0) {
pointsEarned = pointsEarned + (materialAmount * pointsRequired);
@ -68,17 +68,17 @@ public class IslandLevel {
return pointsEarned;
}
public int getMaterialPoints(String material) {
public long getMaterialPoints(String material) {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
int pointsEarned = 0;
long pointsEarned = 0;
if (this.materials.containsKey(material)) {
int materialAmount = this.materials.get(material);
long materialAmount = this.materials.get(material);
if (configLoad.getString("Materials." + materials + ".Points") != null) {
int pointsRequired = config.getFileConfiguration().getInt("Materials." + materials + ".Points");
long pointsRequired = config.getFileConfiguration().getLong("Materials." + materials + ".Points");
if (pointsRequired != 0) {
pointsEarned = materialAmount * pointsRequired;
@ -89,9 +89,9 @@ public class IslandLevel {
return pointsEarned;
}
public int getLevel() {
int division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getInt("Island.Levelling.Division");
public long getLevel() {
long division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getLong("Island.Levelling.Division");
if (division == 0) {
division = 1;
@ -100,7 +100,7 @@ public class IslandLevel {
return getPoints() / division;
}
public void setMaterialAmount(String material, int amount) {
public void setMaterialAmount(String material, long amount) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"),
ownerUUID.toString() + ".yml"))
@ -109,7 +109,7 @@ public class IslandLevel {
this.materials.put(material, amount);
}
public int getMaterialAmount(String material) {
public long getMaterialAmount(String material) {
if (this.materials.containsKey(material)) {
return this.materials.get(material);
}
@ -126,7 +126,7 @@ public class IslandLevel {
this.materials.remove(material);
}
public void setMaterials(Map<String, Integer> materials) {
public void setMaterials(Map<String, Long> materials) {
Config config = skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
@ -152,23 +152,23 @@ public class IslandLevel {
return true;
}
public Map<String, Integer> getMaterials() {
public Map<String, Long> getMaterials() {
return this.materials;
}
public void setLastCalculatedPoints(int lastCalculatedPoints) {
public void setLastCalculatedPoints(long lastCalculatedPoints) {
this.lastCalculatedPoints = lastCalculatedPoints;
}
public int getLastCalculatedPoints() {
public long getLastCalculatedPoints() {
return this.lastCalculatedPoints;
}
public void setLastCalculatedLevel(int lastCalculatedLevel) {
public void setLastCalculatedLevel(long lastCalculatedLevel) {
this.lastCalculatedLevel = lastCalculatedLevel;
}
public int getLastCalculatedLevel() {
public long getLastCalculatedLevel() {
return this.lastCalculatedLevel;
}

View File

@ -47,8 +47,8 @@ public class LeaderboardManager {
islandVotes.add(new LeaderboardPlayer(ownerUUID, visit.getVoters().size()));
}
islandLevels.sort(Comparator.comparingInt(LeaderboardPlayer::getValue).reversed());
islandVotes.sort(Comparator.comparingInt(LeaderboardPlayer::getValue).reversed());
islandLevels.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed());
islandVotes.sort(Comparator.comparingLong(LeaderboardPlayer::getValue).reversed());
for (int i = 0; i < 10; i++) {
if (!islandVotes.isEmpty() && i < islandVotes.size()) {

View File

@ -5,9 +5,9 @@ import java.util.UUID;
public class LeaderboardPlayer {
private UUID uuid;
private int value;
private long value;
public LeaderboardPlayer(UUID uuid, int value) {
public LeaderboardPlayer(UUID uuid, long value) {
this.uuid = uuid;
this.value = value;
}
@ -16,7 +16,7 @@ public class LeaderboardPlayer {
return uuid;
}
public int getValue() {
public long getValue() {
return value;
}
}

View File

@ -66,7 +66,7 @@ public class LevellingManager {
}
}
Map<LevellingData, Integer> levellingData = new HashMap<>();
Map<LevellingData, Long> levellingData = new HashMap<>();
for (ChunkSnapshot chunkSnapshotList : chunk.getChunkSnapshots()) {
for (int x = 0; x < 16; x++) {
@ -109,7 +109,7 @@ public class LevellingManager {
if (blockMaterial == org.bukkit.Material.AIR)
continue;
int amount = 1;
long amount = 1;
if (blockMaterial == Materials.SPAWNER.parseMaterial()
&& Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
World world = Bukkit.getWorld(chunkSnapshotList.getWorldName());
@ -130,8 +130,8 @@ public class LevellingManager {
}
LevellingData data = new LevellingData(blockMaterial, (byte)blockData);
Integer totalAmountInteger = levellingData.get(data);
int totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount;
Long totalAmountInteger = levellingData.get(data);
long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount;
levellingData.put(data, totalAmount);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
@ -142,9 +142,9 @@ public class LevellingManager {
}
}
Map<String, Integer> materials = new HashMap<>();
Map<String, Long> materials = new HashMap<>();
for (LevellingData data : levellingData.keySet()) {
int amount = levellingData.get(data);
long amount = levellingData.get(data);
if (data.getMaterials() != null) {
materials.put(data.getMaterials().name(), amount);
}
@ -185,7 +185,7 @@ public class LevellingManager {
if (!material.isAvailable() || material.getPostItem() == null) continue;
if (!containsMaterial(material)) {
addMaterial(material, configLoad.getInt("Materials." + materialKey + ".Points"));
addMaterial(material, configLoad.getLong("Materials." + materialKey + ".Points"));
}
} catch (Exception e) {
Bukkit.getServer().getLogger().log(Level.WARNING, "SkyBlock | Error: The material '" + materialKey
@ -199,7 +199,7 @@ public class LevellingManager {
materialStorage.clear();
}
public void addMaterial(Materials materials, int points) {
public void addMaterial(Materials materials, long points) {
materialStorage.add(new LevellingMaterial(materials, points));
}

View File

@ -7,9 +7,9 @@ import me.goodandevil.skyblock.utils.version.Materials;
public class LevellingMaterial {
private Materials materials;
private int points;
private long points;
public LevellingMaterial(Materials materials, int points) {
public LevellingMaterial(Materials materials, long points) {
this.materials = materials;
this.points = points;
}
@ -18,11 +18,11 @@ public class LevellingMaterial {
return materials;
}
public void setPoints(int points) {
public void setPoints(long points) {
this.points = points;
}
public int getPoints() {
public long getPoints() {
return points;
}

View File

@ -107,7 +107,7 @@ public class Block implements Listener {
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {
int materialAmount = level.getMaterialAmount(materials.name());
long materialAmount = level.getMaterialAmount(materials.name());
if (materialAmount - droppedAmount <= 0) {
level.removeMaterial(materials.name());
@ -148,7 +148,7 @@ public class Block implements Listener {
if (!level.hasMaterial(materials.name())) return;
int materialAmount = level.getMaterialAmount(materials.name());
long materialAmount = level.getMaterialAmount(materials.name());
if (materialAmount - 1 <= 0) {
level.removeMaterial(materials.name());
@ -229,7 +229,7 @@ public class Block implements Listener {
Materials materials = Materials.getMaterials(block.getType(), block.getData());
if (materials == null) return;
int materialAmount = 0;
long materialAmount = 0;
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {

View File

@ -452,7 +452,7 @@ public class Entity implements Listener {
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {
int materialAmount = level.getMaterialAmount(materials.name());
long materialAmount = level.getMaterialAmount(materials.name());
if (materialAmount - 1 <= 0) {
level.removeMaterial(materials.name());
@ -478,7 +478,7 @@ public class Entity implements Listener {
}
if (materials != null) {
int materialAmount = 0;
long materialAmount = 0;
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {
@ -517,7 +517,7 @@ public class Entity implements Listener {
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {
int materialAmount = level.getMaterialAmount(materials.name());
long materialAmount = level.getMaterialAmount(materials.name());
if (materialAmount - 1 <= 0) {
level.removeMaterial(materials.name());

View File

@ -88,7 +88,7 @@ public class Interact implements Listener {
Materials materials = Materials.getMaterials(block.getType(), block.getData());
if (materials == null) return;
int materialAmount = 0;
long materialAmount = 0;
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {

View File

@ -193,8 +193,8 @@ public class Levelling {
Island island = islandManager.getIsland(player);
IslandLevel level = island.getLevel();
Map<String, Integer> testIslandMaterials = level.getMaterials();
Map<String, Integer> islandMaterials = new HashMap<>();
Map<String, Long> testIslandMaterials = level.getMaterials();
Map<String, Long> islandMaterials = new HashMap<>();
Config mainConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
Config settingsConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
@ -210,7 +210,7 @@ public class Levelling {
Materials materials = Materials.fromString(materialName);
ItemStack is = materials.parseItem();
is.setAmount(Math.min(testIslandMaterials.get(materialName), 64));
is.setAmount(Math.min(Math.toIntExact(testIslandMaterials.get(materialName)), 64));
is.setType(MaterialUtil.correctMaterial(is.getType()));
if (is == null || is.getItemMeta() == null) continue;
@ -271,7 +271,7 @@ public class Levelling {
Materials materials = Materials.fromString(material);
if (materials != null) {
int materialAmount = islandMaterials.get(material);
long materialAmount = islandMaterials.get(material);
if (mainConfig.getFileConfiguration().getString("Materials." + material + ".Points") != null) {
int pointsMultiplier = mainConfig.getFileConfiguration().getInt("Materials." + material + ".Points");
@ -279,10 +279,10 @@ public class Levelling {
if (settingsConfig.getFileConfiguration().getBoolean("Island.Levelling.IncludeEmptyPointsInList") || pointsMultiplier != 0) {
inventorySlot++;
int pointsEarned = materialAmount * pointsMultiplier;
long pointsEarned = materialAmount * pointsMultiplier;
ItemStack is = materials.parseItem();
is.setAmount(Math.min(materialAmount, 64));
is.setAmount(Math.min(Math.toIntExact(materialAmount), 64));
is.setType(MaterialUtil.correctMaterial(is.getType()));
List<String> lore = configLoad.getStringList("Menu.Levelling.Item.Material.Lore");

View File

@ -349,7 +349,7 @@ public class Visit {
return Integer.valueOf(playersAtIsland2).compareTo(playersAtIsland1);
} else if (sort == Visit.Sort.Level) {
return Integer.valueOf(visit2.getLevel().getLevel()).compareTo(visit1.getLevel().getLevel());
return Long.valueOf(visit2.getLevel().getLevel()).compareTo(visit1.getLevel().getLevel());
} else if (sort == Visit.Sort.Members) {
return Integer.valueOf(visit2.getMembers()).compareTo(visit1.getMembers());
} else if (sort == Visit.Sort.Visits) {

View File

@ -5,7 +5,7 @@ import java.util.Date;
public final class NumberUtil {
public static String formatNumber(int number) {
public static String formatNumber(long number) {
return String.format("%,d", number);
}
@ -21,12 +21,12 @@ public final class NumberUtil {
withDecimal = "";
}
int itemCostWithoutDecimalValue = Integer.valueOf(withoutDecimal);
long itemCostWithoutDecimalValue = Long.valueOf(withoutDecimal);
return formatNumber(itemCostWithoutDecimalValue) + withDecimal;
}
public static String formatNumberBySuffix(int number) {
public static String formatNumberBySuffix(long number) {
if (number < 1000) {
return "" + number;
}