mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-13 06:07:26 +01:00
Use a constant instead of 10 throughout code.
This commit is contained in:
parent
e0736fca4c
commit
eba7e1d531
@ -42,6 +42,9 @@ import world.bentobox.level.requests.TopTenRequestHandler;
|
||||
*/
|
||||
public class Level extends Addon implements Listener {
|
||||
|
||||
// The 10 in top ten
|
||||
public static final int TEN = 10;
|
||||
|
||||
// Settings
|
||||
private ConfigSettings settings;
|
||||
private Config<ConfigSettings> configObject = new Config<>(this, ConfigSettings.class);
|
||||
@ -201,16 +204,16 @@ public class Level extends Addon implements Listener {
|
||||
|
||||
String getRankName(World world, int rank) {
|
||||
if (rank < 1) rank = 1;
|
||||
if (rank > 10) rank = 10;
|
||||
return getPlayers().getName(getManager().getTopTen(world, 10).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||
if (rank > TEN) rank = TEN;
|
||||
return getPlayers().getName(getManager().getTopTen(world, TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
String getRankLevel(World world, int rank) {
|
||||
if (rank < 1) rank = 1;
|
||||
if (rank > 10) rank = 10;
|
||||
if (rank > TEN) rank = TEN;
|
||||
return getManager()
|
||||
.formatLevel(getManager()
|
||||
.getTopTen(world, 10)
|
||||
.getTopTen(world, TEN)
|
||||
.values()
|
||||
.stream()
|
||||
.skip(rank - 1L)
|
||||
|
@ -241,7 +241,7 @@ public class LevelsManager {
|
||||
*/
|
||||
public void getGUI(World world, final User user) {
|
||||
// Check world
|
||||
Map<UUID, Long> topTen = getTopTen(world, 10);
|
||||
Map<UUID, Long> topTen = getTopTen(world, Level.TEN);
|
||||
|
||||
PanelBuilder panel = new PanelBuilder()
|
||||
.name(user.getTranslation("island.top.gui-title"))
|
||||
@ -418,11 +418,11 @@ public class LevelsManager {
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)));
|
||||
}
|
||||
|
||||
|
||||
void createAndCleanRankings(@NonNull World world) {
|
||||
topTenLists.computeIfAbsent(world, TopTenData::new);
|
||||
// Remove player from top ten if they are online and do not have the perm
|
||||
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
|
||||
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,12 +441,12 @@ public class LevelsManager {
|
||||
public int getRank(@NonNull World world, UUID uuid) {
|
||||
createAndCleanRankings(world);
|
||||
Stream<Entry<UUID, Long>> stream = topTenLists.get(world).getTopTen().entrySet().stream()
|
||||
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
||||
.filter(l -> l.getValue() > 0)
|
||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
||||
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
||||
.filter(l -> l.getValue() > 0)
|
||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
||||
return takeWhile(stream, x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Java 8's version of Java 9's takeWhile
|
||||
* @param stream
|
||||
@ -457,7 +457,7 @@ public class LevelsManager {
|
||||
CustomSpliterator<T> customSpliterator = new CustomSpliterator<>(stream.spliterator(), predicate);
|
||||
return StreamSupport.stream(customSpliterator, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if player has the correct top ten perm to have their level saved
|
||||
* @param world
|
||||
|
@ -30,7 +30,7 @@ public class AdminTopCommand extends CompositeCommand {
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendMessage("island.top.gui-title");
|
||||
int rank = 0;
|
||||
for (Map.Entry<UUID, Long> topTen : levelPlugin.getManager().getTopTen(getWorld(), 10).entrySet()) {
|
||||
for (Map.Entry<UUID, Long> topTen : levelPlugin.getManager().getTopTen(getWorld(), Level.TEN).entrySet()) {
|
||||
Island island = getPlugin().getIslands().getIsland(getWorld(), topTen.getKey());
|
||||
if (island != null) {
|
||||
rank++;
|
||||
|
@ -59,7 +59,7 @@ public class AdminTopRemoveCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
return Optional.of(addon.getManager().getTopTen(getWorld(), 10).keySet().stream().map(addon.getPlayers()::getName)
|
||||
return Optional.of(addon.getManager().getTopTen(getWorld(), Level.TEN).keySet().stream().map(addon.getPlayers()::getName)
|
||||
.filter(n -> !n.isEmpty()).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,6 @@ public class TopTenRequestHandler extends AddonRequestHandler {
|
||||
}
|
||||
|
||||
// No null check required
|
||||
return addon.getManager().getTopTen(Bukkit.getWorld((String) map.get(WORLD_NAME)), 10);
|
||||
return addon.getManager().getTopTen(Bukkit.getWorld((String) map.get(WORLD_NAME)), Level.TEN);
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ public class LevelsManagerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetTopTenEmpty() {
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, 10);
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
|
||||
assertTrue(tt.isEmpty());
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ public class LevelsManagerTest {
|
||||
@Test
|
||||
public void testGetTopTen() {
|
||||
testLoadTopTens();
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, 10);
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
|
||||
assertFalse(tt.isEmpty());
|
||||
assertEquals(1, tt.size());
|
||||
assertEquals(1, lm.getTopTen(world, 1).size());
|
||||
@ -360,7 +360,7 @@ public class LevelsManagerTest {
|
||||
public void testGetTopTenNoOwners() {
|
||||
when(im.isOwner(eq(world), any())).thenReturn(false);
|
||||
testLoadTopTens();
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, 10);
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
|
||||
assertTrue(tt.isEmpty());
|
||||
}
|
||||
|
||||
@ -394,10 +394,10 @@ public class LevelsManagerTest {
|
||||
@Test
|
||||
public void testRemoveEntry() {
|
||||
testLoadTopTens();
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, 10);
|
||||
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
|
||||
assertTrue(tt.containsKey(uuid));
|
||||
lm.removeEntry(world, uuid);
|
||||
tt = lm.getTopTen(world, 10);
|
||||
tt = lm.getTopTen(world, Level.TEN);
|
||||
assertFalse(tt.containsKey(uuid));
|
||||
}
|
||||
|
||||
@ -414,8 +414,8 @@ public class LevelsManagerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSetInitialIslandLevel() {
|
||||
lm.setInitialIslandLevel(island, 10);
|
||||
assertEquals(10, lm.getInitialLevel(island));
|
||||
lm.setInitialIslandLevel(island, Level.TEN);
|
||||
assertEquals(Level.TEN, lm.getInitialLevel(island));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -443,7 +443,7 @@ public class LevelsManagerTest {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.LevelsManager#getRank(World, UUID)}
|
||||
*/
|
||||
@ -453,7 +453,7 @@ public class LevelsManagerTest {
|
||||
Map<World, TopTenData> ttl = lm.getTopTenLists();
|
||||
Map<UUID, Long> tt = ttl.get(world).getTopTen();
|
||||
for (long i = 100; i < 150; i++) {
|
||||
tt.put(UUID.randomUUID(), i);
|
||||
tt.put(UUID.randomUUID(), i);
|
||||
}
|
||||
// Put player as lowest rank
|
||||
tt.put(uuid, 10L);
|
||||
|
Loading…
Reference in New Issue
Block a user