Fixes code smells

This commit is contained in:
tastybento 2019-10-30 16:29:42 -07:00
parent 01dd6597d4
commit dda2e66548
4 changed files with 25 additions and 27 deletions

View File

@ -128,17 +128,16 @@ public class TopTen implements Listener {
private PanelItem getHead(int rank, long level, UUID playerUUID, User asker, World world) {
final String name = addon.getPlayers().getName(playerUUID);
List<String> description = new ArrayList<>();
if (name != null) {
description.add(asker.getTranslation("island.top.gui-heading", "[name]", name, "[rank]", String.valueOf(rank)));
description.add(asker.getTranslation("island.top.island-level","[level]", addon.getLevelPresenter().getLevelString(level)));
if (addon.getIslands().inTeam(world, playerUUID)) {
List<String> memberList = new ArrayList<>();
for (UUID members : addon.getIslands().getMembers(world, playerUUID)) {
memberList.add(ChatColor.AQUA + addon.getPlayers().getName(members));
}
description.addAll(memberList);
description.add(asker.getTranslation("island.top.gui-heading", "[name]", name, "[rank]", String.valueOf(rank)));
description.add(asker.getTranslation("island.top.island-level","[level]", addon.getLevelPresenter().getLevelString(level)));
if (addon.getIslands().inTeam(world, playerUUID)) {
List<String> memberList = new ArrayList<>();
for (UUID members : addon.getIslands().getMembers(world, playerUUID)) {
memberList.add(ChatColor.AQUA + addon.getPlayers().getName(members));
}
description.addAll(memberList);
}
PanelItemBuilder builder = new PanelItemBuilder()
.icon(name)
.name(name)

View File

@ -31,8 +31,8 @@ import world.bentobox.level.Level;
public class CalcIslandLevel {
private final int MAX_CHUNKS;
private final long SPEED;
private final int maxChunks;
private final long speed;
private static final String LINE_BREAK = "==================================";
private boolean checking;
private final BukkitTask task;
@ -80,8 +80,8 @@ public class CalcIslandLevel {
// Set the initial island handicap
result.initialLevel = addon.getInitialIslandLevel(island);
SPEED = addon.getSettings().getUpdateTickDelay();
MAX_CHUNKS = addon.getSettings().getChunksPerTick();
speed = addon.getSettings().getUpdateTickDelay();
maxChunks = addon.getSettings().getChunksPerTick();
// Get chunks to scan
chunksToScan = getChunksToScan(island);
@ -100,15 +100,15 @@ public class CalcIslandLevel {
return;
}
// Add chunk snapshots to the list
while (it.hasNext() && chunkSnapshot.size() < MAX_CHUNKS) {
while (it.hasNext() && chunkSnapshot.size() < maxChunks) {
Pair<Integer, Integer> pair = it.next();
for (World world : worlds) {
if (!world.isChunkLoaded(pair.x, pair.z)) {
world.loadChunk(pair.x, pair.z);
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
world.unloadChunk(pair.x, pair.z);
for (World worldToScan : worlds) {
if (!worldToScan.isChunkLoaded(pair.x, pair.z)) {
worldToScan.loadChunk(pair.x, pair.z);
chunkSnapshot.add(worldToScan.getChunkAt(pair.x, pair.z).getChunkSnapshot());
worldToScan.unloadChunk(pair.x, pair.z);
} else {
chunkSnapshot.add(world.getChunkAt(pair.x, pair.z).getChunkSnapshot());
chunkSnapshot.add(worldToScan.getChunkAt(pair.x, pair.z).getChunkSnapshot());
}
}
it.remove();
@ -117,7 +117,7 @@ public class CalcIslandLevel {
checking = false;
checkChunksAsync(chunkSnapshot);
}
}, 0L, SPEED);
}, 0L, speed);
}
private void checkChunksAsync(final Set<ChunkSnapshot> chunkSnapshot) {

View File

@ -32,9 +32,7 @@ public class JoinLeaveListener implements Listener {
if (addon.getSettings().isLogin()) {
addon.getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> addon.getSettings().getGameModes().contains(gm.getDescription().getName()))
.forEach(gm -> {
addon.calculateIslandLevel(gm.getOverWorld(), null, e.getPlayer().getUniqueId());
});
.forEach(gm -> addon.calculateIslandLevel(gm.getOverWorld(), null, e.getPlayer().getUniqueId()));
}
}

View File

@ -16,6 +16,7 @@ import world.bentobox.level.objects.TopTenData;
*/
public class TopTenRequestHandler extends AddonRequestHandler {
private static final String WORLD_NAME = "world-name";
/**
* The level addon field.
*/
@ -48,13 +49,13 @@ public class TopTenRequestHandler extends AddonRequestHandler {
*/
if (map == null || map.isEmpty()
|| map.get("world-name") == null || !(map.get("world-name") instanceof String)
|| Bukkit.getWorld((String) map.get("world-name")) == null) {
|| map.get(WORLD_NAME) == null || !(map.get(WORLD_NAME) instanceof String)
|| Bukkit.getWorld((String) map.get(WORLD_NAME)) == null) {
return Collections.emptyMap();
}
// Null-point check.
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get("world-name")));
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get(WORLD_NAME)));
return data != null ? data.getTopTen() : Collections.emptyMap();
}
}