Change method of getting loaded chunks

This commit is contained in:
Eric 2020-03-19 15:22:43 +01:00
parent 6d16b39597
commit 4a907ee309
2 changed files with 8 additions and 15 deletions

View File

@ -5,10 +5,8 @@ import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -195,12 +193,10 @@ public class ShopChestImpl extends ShopChest {
}
);
List<Chunk> chunks = new ArrayList<>();
for (World world : getServer().getWorlds()) {
chunks.addAll(Arrays.asList(world.getLoadedChunks()));
}
Chunk[] chunks = getServer().getWorlds().stream().map(World::getLoadedChunks)
.flatMap(Stream::of).toArray(Chunk[]::new);
((ShopManagerImpl) getShopManager()).loadShops(chunks.toArray(new Chunk[chunks.size()]),
((ShopManagerImpl) getShopManager()).loadShops(chunks,
shops -> {
getServer().getPluginManager().callEvent(new ShopLoadedEvent(shops));
Logger.info("Loaded {0} shops from the database", shops.size());

View File

@ -1,18 +1,17 @@
package de.epiceric.shopchest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.Chunk;
import org.bukkit.Location;
@ -235,12 +234,10 @@ public class ShopManagerImpl implements ShopManager {
@Override
public void reloadShops(Consumer<Integer> callback, Consumer<Throwable> errorCallback) {
List<Chunk> chunks = new ArrayList<>();
for (World world : plugin.getServer().getWorlds()) {
chunks.addAll(Arrays.asList(world.getLoadedChunks()));
}
Chunk[] chunks = plugin.getServer().getWorlds().stream().map(World::getLoadedChunks)
.flatMap(Stream::of).toArray(Chunk[]::new);
loadShops(chunks.toArray(new Chunk[chunks.size()]),
loadShops(chunks,
shops -> callback.accept(shops.size()),
errorCallback
);