diff --git a/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/ChunkLoader.java b/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/ChunkLoader.java index dd13115..6e0e901 100644 --- a/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/ChunkLoader.java +++ b/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/ChunkLoader.java @@ -1,6 +1,7 @@ package com.bgsoftware.wildloaders.api.loaders; import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; @@ -29,6 +30,11 @@ public interface ChunkLoader { */ Location getLocation(); + /** + * Get the chunks that this chunk-loader is loading. + */ + Chunk[] getLoadedChunks(); + /** * Get the NPC of this chunk loader. */ diff --git a/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/LoaderData.java b/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/LoaderData.java index ab58e82..a105d73 100644 --- a/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/LoaderData.java +++ b/API/src/main/java/com/bgsoftware/wildloaders/api/loaders/LoaderData.java @@ -19,4 +19,19 @@ public interface LoaderData { */ ItemStack getLoaderItem(); + /** + * Set the radius of chunks that the chunk loader will load. + * If the radius is 0, it means only one chunk is loaded. A radius of 1, will load 3x3 chunks, etc. + * Please note: In some versions, when loading one chunk, the nearby chunks are also being loaded! + * @param chunksRadius The chunk radius to set. + */ + void setChunksRadius(int chunksRadius); + + /** + * Get the radius of chunks that the chunk loader will load. + * If the radius is 0, it means only one chunk is loaded. A radius of 1, will load 3x3 chunks, etc. + * Please note: In some versions, when loading one chunk, the nearby chunks are also being loaded! + */ + int getChunksRadius(); + } diff --git a/API/src/main/java/com/bgsoftware/wildloaders/api/managers/LoadersManager.java b/API/src/main/java/com/bgsoftware/wildloaders/api/managers/LoadersManager.java index b06fbc1..d63a26f 100644 --- a/API/src/main/java/com/bgsoftware/wildloaders/api/managers/LoadersManager.java +++ b/API/src/main/java/com/bgsoftware/wildloaders/api/managers/LoadersManager.java @@ -62,7 +62,7 @@ public interface LoadersManager { * @param timeLeft The default amount of time to run. * @param itemStack The item stack to drop upon break. */ - void createLoaderData(String name, long timeLeft, ItemStack itemStack); + LoaderData createLoaderData(String name, long timeLeft, ItemStack itemStack); /** * Remove all the chunk loaders data from cache. diff --git a/src/main/java/com/bgsoftware/wildloaders/handlers/LoadersHandler.java b/src/main/java/com/bgsoftware/wildloaders/handlers/LoadersHandler.java index e0ccb18..ae78c08 100644 --- a/src/main/java/com/bgsoftware/wildloaders/handlers/LoadersHandler.java +++ b/src/main/java/com/bgsoftware/wildloaders/handlers/LoadersHandler.java @@ -72,9 +72,11 @@ public final class LoadersHandler implements LoadersManager { } public WChunkLoader addChunkLoader(LoaderData loaderData, UUID placer, Location location, long timeLeft){ - WChunkLoader chunkLoader = new WChunkLoader(loaderData.getName(), placer, location, timeLeft); + WChunkLoader chunkLoader = new WChunkLoader(loaderData, placer, location, timeLeft); chunkLoaders.put(location, chunkLoader); - chunkLoadersByChunks.put(ChunkPosition.of(location), chunkLoader); + for (Chunk loadedChunk : chunkLoader.getLoadedChunks()) { + chunkLoadersByChunks.put(ChunkPosition.of(loadedChunk), chunkLoader); + } plugin.getNPCs().createNPC(location); return chunkLoader; } @@ -83,7 +85,9 @@ public final class LoadersHandler implements LoadersManager { public void removeChunkLoader(ChunkLoader chunkLoader) { Location location = chunkLoader.getLocation(); chunkLoaders.remove(location); - chunkLoadersByChunks.remove(ChunkPosition.of(location)); + for (Chunk loadedChunk : chunkLoader.getLoadedChunks()) { + chunkLoadersByChunks.remove(ChunkPosition.of(loadedChunk)); + } chunkLoader.getNPC().ifPresent(npc -> plugin.getNPCs().killNPC(npc)); Query.DELETE_CHUNK_LOADER.insertParameters() @@ -92,9 +96,10 @@ public final class LoadersHandler implements LoadersManager { } @Override - public void createLoaderData(String name, long timeLeft, ItemStack itemStack) { + public LoaderData createLoaderData(String name, long timeLeft, ItemStack itemStack) { LoaderData loaderData = new WLoaderData(name, timeLeft, itemStack); loadersData.put(name, loaderData); + return loaderData; } @Override diff --git a/src/main/java/com/bgsoftware/wildloaders/handlers/SettingsHandler.java b/src/main/java/com/bgsoftware/wildloaders/handlers/SettingsHandler.java index 45df3ca..5e5f392 100644 --- a/src/main/java/com/bgsoftware/wildloaders/handlers/SettingsHandler.java +++ b/src/main/java/com/bgsoftware/wildloaders/handlers/SettingsHandler.java @@ -1,14 +1,15 @@ package com.bgsoftware.wildloaders.handlers; import com.bgsoftware.wildloaders.WildLoadersPlugin; +import com.bgsoftware.wildloaders.api.loaders.LoaderData; import com.bgsoftware.wildloaders.utils.items.ItemBuilder; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; import java.io.File; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -34,39 +35,40 @@ public final class SettingsHandler { plugin.getLoaders().removeLoadersData(); for (String name : cfg.getConfigurationSection("chunkloaders").getKeys(false)) { - long timeLeft = cfg.getLong("chunkloaders." + name + ".time", 0); + ConfigurationSection loaderSection = cfg.getConfigurationSection("chunkloaders." + name); + + long timeLeft = loaderSection.getLong("time", 0); ItemBuilder itemBuilder = null; try{ - Material type = Material.valueOf(cfg.getString("chunkloaders." + name + ".type", "")); - short data = (short) cfg.getInt("chunkloaders." + name + ".data", 0); + Material type = Material.valueOf(loaderSection.getString("type", "")); + short data = (short) loaderSection.getInt("data", 0); itemBuilder = new ItemBuilder(type, data); - if(cfg.contains("chunkloaders." + name + ".name")) - itemBuilder.setDisplayName(ChatColor.translateAlternateColorCodes('&', - cfg.getString("chunkloaders." + name + ".name"))); + if(loaderSection.contains("name")) + itemBuilder.setDisplayName(ChatColor.translateAlternateColorCodes('&', loaderSection.getString("name"))); - if(cfg.contains("chunkloaders." + name + ".lore")) { + if(loaderSection.contains("lore")) { List lore = new ArrayList<>(); - cfg.getStringList("chunkloaders." + name + ".lore") - .forEach(line -> lore.add(ChatColor.translateAlternateColorCodes('&', line))); + loaderSection.getStringList("lore").forEach(line -> + lore.add(ChatColor.translateAlternateColorCodes('&', line))); itemBuilder.setLore(lore); } - if(cfg.contains("chunkloaders." + name + ".enchants")) { - for(String line : cfg.getStringList("chunkloaders." + name + ".enchants")){ + if(loaderSection.contains("enchants")) { + for(String line : loaderSection.getStringList("enchants")){ Enchantment enchantment = Enchantment.getByName(line.split(":")[0]); int level = Integer.parseInt(line.split(":")[1]); itemBuilder.addEnchant(enchantment, level); } } - if(cfg.contains("chunkloaders." + name + ".skull")) { - itemBuilder.setTexture(cfg.getString("chunkloaders." + name + ".skull")); + if(loaderSection.contains("skull")) { + itemBuilder.setTexture(loaderSection.getString("skull")); } } catch(Exception ignored){} @@ -75,7 +77,11 @@ public final class SettingsHandler { continue; } - plugin.getLoaders().createLoaderData(name, timeLeft, itemBuilder.build()); + LoaderData loaderData = plugin.getLoaders().createLoaderData(name, timeLeft, itemBuilder.build()); + + if(loaderSection.contains("chunks-radius")) + loaderData.setChunksRadius(loaderSection.getInt("chunks-radius")); + loadersAmount++; } @@ -83,15 +89,4 @@ public final class SettingsHandler { WildLoadersPlugin.log("Loading configuration done (Took " + (System.currentTimeMillis() - startTime) + "ms)"); } - public static void reload(){ - try{ - WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin(); - Field settings = WildLoadersPlugin.class.getDeclaredField("settingsHandler"); - settings.setAccessible(true); - settings.set(plugin, new SettingsHandler(plugin)); - } catch(NoSuchFieldException | IllegalAccessException ex){ - ex.printStackTrace(); - } - } - } diff --git a/src/main/java/com/bgsoftware/wildloaders/loaders/WChunkLoader.java b/src/main/java/com/bgsoftware/wildloaders/loaders/WChunkLoader.java index 7d191cd..28bd0fd 100644 --- a/src/main/java/com/bgsoftware/wildloaders/loaders/WChunkLoader.java +++ b/src/main/java/com/bgsoftware/wildloaders/loaders/WChunkLoader.java @@ -7,11 +7,14 @@ import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; import com.bgsoftware.wildloaders.utils.database.Query; import com.bgsoftware.wildloaders.utils.threads.Executor; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -21,15 +24,17 @@ public final class WChunkLoader implements ChunkLoader { private final UUID whoPlaced; private final Location location; + private final Chunk[] loadedChunks; private final String loaderName; private boolean active = true; private long timeLeft; - public WChunkLoader(String loaderName, UUID whoPlaced, Location location, long timeLeft){ - this.loaderName = loaderName; + public WChunkLoader(LoaderData loaderData, UUID whoPlaced, Location location, long timeLeft){ + this.loaderName = loaderData.getName(); this.whoPlaced = whoPlaced; this.location = location.clone(); + this.loadedChunks = calculateChunks(loaderData, this.location); this.timeLeft = timeLeft; plugin.getNMSAdapter().createLoader(this); } @@ -73,6 +78,11 @@ public final class WChunkLoader implements ChunkLoader { return location.clone(); } + @Override + public Chunk[] getLoadedChunks() { + return loadedChunks; + } + @Override public Optional getNPC() { return plugin.getNPCs().getNPC(location); @@ -97,4 +107,16 @@ public final class WChunkLoader implements ChunkLoader { return plugin.getNMSAdapter().setTag(itemStack, "loader-time", getTimeLeft()); } + private static Chunk[] calculateChunks(LoaderData loaderData, Location original){ + List chunkList = new ArrayList<>(); + + int chunkX = original.getBlockX() >> 4, chunkZ = original.getBlockZ() >> 4; + + for(int x = -loaderData.getChunksRadius(); x <= loaderData.getChunksRadius(); x++) + for(int z = -loaderData.getChunksRadius(); z <= loaderData.getChunksRadius(); z++) + chunkList.add(original.getWorld().getChunkAt(chunkX + x, chunkZ + z)); + + return chunkList.toArray(new Chunk[0]); + } + } diff --git a/src/main/java/com/bgsoftware/wildloaders/loaders/WLoaderData.java b/src/main/java/com/bgsoftware/wildloaders/loaders/WLoaderData.java index d79c461..2806cf3 100644 --- a/src/main/java/com/bgsoftware/wildloaders/loaders/WLoaderData.java +++ b/src/main/java/com/bgsoftware/wildloaders/loaders/WLoaderData.java @@ -12,10 +12,13 @@ public final class WLoaderData implements LoaderData { private final long timeLeft; private final ItemStack loaderItem; + private int chunksRadius; + public WLoaderData(String name, long timeLeft, ItemStack loaderItem){ this.name = name; this.timeLeft = timeLeft; this.loaderItem = plugin.getNMSAdapter().setTag(loaderItem, "loader-name", name); + this.chunksRadius = 0; } @Override @@ -32,4 +35,15 @@ public final class WLoaderData implements LoaderData { public ItemStack getLoaderItem() { return loaderItem.clone(); } + + @Override + public void setChunksRadius(int chunksRadius) { + this.chunksRadius = chunksRadius; + } + + @Override + public int getChunksRadius() { + return chunksRadius; + } + } diff --git a/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter.java b/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter.java index 78b254c..e59fd15 100644 --- a/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter.java +++ b/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter.java @@ -2,7 +2,6 @@ package com.bgsoftware.wildloaders.nms; import com.bgsoftware.wildloaders.api.loaders.ChunkLoader; import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC; -import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/com/bgsoftware/wildloaders/utils/chunks/ChunkPosition.java b/src/main/java/com/bgsoftware/wildloaders/utils/chunks/ChunkPosition.java index c97ef41..8e69a99 100644 --- a/src/main/java/com/bgsoftware/wildloaders/utils/chunks/ChunkPosition.java +++ b/src/main/java/com/bgsoftware/wildloaders/utils/chunks/ChunkPosition.java @@ -2,6 +2,7 @@ package com.bgsoftware.wildloaders.utils.chunks; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.World; import java.util.Objects; @@ -56,4 +57,8 @@ public final class ChunkPosition { return new ChunkPosition(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); } + public static ChunkPosition of(World world, int chunkX, int chunkZ){ + return new ChunkPosition(world.getName(), chunkX, chunkZ); + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c0b695a..561182e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -18,4 +18,12 @@ chunkloaders: name: '&6Chunk Loader &7(Place to load)' lore: - '&7Place this chunk loader to keep' - - '&7the chunk loaded in the next 24 hours!' \ No newline at end of file + - '&7the chunk loaded in the next 24 hours!' + large_loader: + time: 86400 + type: BEACON + chunks-radius: 2 # This will load all chunks in a radius of 2, aka 5x5 chunks + name: '&6Large Chunk Loader &7(Place to load)' + lore: + - '&7Place this chunk loader to keep all chunks' + - '&7in a radius of 2 loaded in the next 24 hours!' \ No newline at end of file diff --git a/v1_10_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_10_R1.java b/v1_10_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_10_R1.java index 2f057cd..b3871db 100644 --- a/v1_10_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_10_R1.java +++ b/v1_10_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_10_R1.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_10_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_10_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override diff --git a/v1_11_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_11_R1.java b/v1_11_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_11_R1.java index 4c449f5..0234ea8 100644 --- a/v1_11_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_11_R1.java +++ b/v1_11_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_11_R1.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_11_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_11_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override diff --git a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java index 8e1d692..1c28fa3 100644 --- a/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java +++ b/v1_12_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_12_R1.java @@ -132,18 +132,20 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - try { - compoundLoadMethod.invoke(tileEntity, nbtTagCompound); - }catch (Throwable ex){ - tileEntity.a(nbtTagCompound); - } - }); + try { + compoundLoadMethod.invoke(tileEntity, nbtTagCompound); + } catch (Throwable ex) { + tileEntity.a(nbtTagCompound); + } + }); + } } @Override @@ -163,18 +165,20 @@ public final class NMSAdapter_v1_12_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - try { - compoundLoadMethod.invoke(tileEntity, nbtTagCompound); - }catch (Throwable ex){ - tileEntity.a(nbtTagCompound); - } - }); + try { + compoundLoadMethod.invoke(tileEntity, nbtTagCompound); + } catch (Throwable ex) { + tileEntity.a(nbtTagCompound); + } + }); + } } @Override diff --git a/v1_13_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R1.java b/v1_13_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R1.java index ff899c7..b0ad7aa 100644 --- a/v1_13_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R1.java +++ b/v1_13_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R1.java @@ -125,9 +125,11 @@ public final class NMSAdapter_v1_13_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + } } @Override @@ -147,9 +149,11 @@ public final class NMSAdapter_v1_13_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + } } @Override diff --git a/v1_13_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R2.java b/v1_13_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R2.java index 9df1fab..336ab34 100644 --- a/v1_13_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R2.java +++ b/v1_13_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_13_R2.java @@ -125,9 +125,11 @@ public final class NMSAdapter_v1_13_R2 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + } } @Override @@ -147,9 +149,11 @@ public final class NMSAdapter_v1_13_R2 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + } } @Override diff --git a/v1_14_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_14_R1.java b/v1_14_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_14_R1.java index 0de2f28..a7faa38 100644 --- a/v1_14_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_14_R1.java +++ b/v1_14_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_14_R1.java @@ -128,11 +128,13 @@ public final class NMSAdapter_v1_14_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override @@ -153,11 +155,13 @@ public final class NMSAdapter_v1_14_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override diff --git a/v1_15_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_15_R1.java b/v1_15_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_15_R1.java index 4f6bb89..76924ad 100644 --- a/v1_15_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_15_R1.java +++ b/v1_15_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_15_R1.java @@ -128,11 +128,13 @@ public final class NMSAdapter_v1_15_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override @@ -153,11 +155,13 @@ public final class NMSAdapter_v1_15_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false); + } } @Override diff --git a/v1_16_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R1.java b/v1_16_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R1.java index ca76f9c..f4ed64f 100644 --- a/v1_16_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R1.java +++ b/v1_16_R1/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R1.java @@ -129,11 +129,13 @@ public final class NMSAdapter_v1_16_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override @@ -154,11 +156,13 @@ public final class NMSAdapter_v1_16_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false); + } } @Override diff --git a/v1_16_R2/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R2.java b/v1_16_R2/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R2.java index dc79b12..c4323cf 100644 --- a/v1_16_R2/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R2.java +++ b/v1_16_R2/src/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_16_R2.java @@ -129,11 +129,13 @@ public final class NMSAdapter_v1_16_R2 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = -1); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override @@ -154,11 +156,13 @@ public final class NMSAdapter_v1_16_R2 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) - .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner) + .forEach(tileEntity -> ((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = 16); - world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, true); + } } @Override diff --git a/v1_7_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R3.java b/v1_7_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R3.java index 4ac7c61..22193f0 100644 --- a/v1_7_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R3.java +++ b/v1_7_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R3.java @@ -118,14 +118,16 @@ public final class NMSAdapter_v1_7_R3 implements NMSAdapter { //noinspection unchecked world.tileEntityList.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()){ + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override @@ -144,14 +146,16 @@ public final class NMSAdapter_v1_7_R3 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, x, y, z, Block.b(world.getType(x, y, z)) + (world.getData(x, y, z) << 12)); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()){ + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override diff --git a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java index d9512cc..5f7265f 100644 --- a/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java +++ b/v1_7_R4/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_7_R4.java @@ -118,14 +118,16 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { //noinspection unchecked world.tileEntityList.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override @@ -144,14 +146,16 @@ public final class NMSAdapter_v1_7_R4 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, x, y, z, Block.getId(world.getType(x, y, z)) + (world.getData(x, y, z) << 12)); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override diff --git a/v1_8_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R1.java b/v1_8_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R1.java index 4a5d8af..1003950 100644 --- a/v1_8_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R1.java +++ b/v1_8_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R1.java @@ -124,14 +124,16 @@ public final class NMSAdapter_v1_8_R1 implements NMSAdapter { //noinspection unchecked world.tileEntityList.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override @@ -151,14 +153,16 @@ public final class NMSAdapter_v1_8_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - //noinspection unchecked - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - ((TileEntity) tileEntity).b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - ((TileEntity) tileEntity).a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + //noinspection unchecked + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + ((TileEntity) tileEntity).b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + ((TileEntity) tileEntity).a(nbtTagCompound); + }); + } } @Override diff --git a/v1_8_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R2.java b/v1_8_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R2.java index 95fd847..c948316 100644 --- a/v1_8_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R2.java +++ b/v1_8_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R2.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_8_R2 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityList.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_8_R2 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override diff --git a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java index 0d77bbb..d4cedb4 100644 --- a/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java +++ b/v1_8_R3/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_8_R3.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityList.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_8_R3 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.b(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.b(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override diff --git a/v1_9_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R1.java b/v1_9_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R1.java index b56f183..6485c3e 100644 --- a/v1_9_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R1.java +++ b/v1_9_R1/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R1.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_9_R1 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_9_R1 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override diff --git a/v1_9_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R2.java b/v1_9_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R2.java index 88d5e56..a00cfc2 100644 --- a/v1_9_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R2.java +++ b/v1_9_R2/src/main/java/com/bgsoftware/wildloaders/nms/NMSAdapter_v1_9_R2.java @@ -123,13 +123,15 @@ public final class NMSAdapter_v1_9_R2 implements NMSAdapter { TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition); world.tileEntityListTick.add(tileEntityChunkLoader); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) -1); + tileEntity.a(nbtTagCompound); + }); + } } @Override @@ -149,13 +151,15 @@ public final class NMSAdapter_v1_9_R2 implements NMSAdapter { if(spawnParticle) world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition))); - Chunk chunk = ((CraftChunk) loaderLoc.getChunk()).getHandle(); - chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - tileEntity.save(nbtTagCompound); - nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); - tileEntity.a(nbtTagCompound); - }); + for(org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) { + Chunk chunk = ((CraftChunk) bukkitChunk).getHandle(); + chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + tileEntity.save(nbtTagCompound); + nbtTagCompound.setShort("RequiredPlayerRange", (short) 16); + tileEntity.a(nbtTagCompound); + }); + } } @Override