mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-09-14 02:18:21 +02:00
Merge branch 'dev'
This commit is contained in:
commit
f5bfbe2281
@ -2,12 +2,28 @@ package com.bgsoftware.wildloaders.api.hooks;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface TickableProvider {
|
||||
|
||||
/**
|
||||
* Simulate a tick on a list of provided chunks.
|
||||
*
|
||||
* @param chunks The chunks to tick.
|
||||
* @deprecated See {@link #tick(Collection)}
|
||||
*/
|
||||
@Deprecated
|
||||
default void tick(Chunk[] chunks) {
|
||||
throw new UnsupportedOperationException("TickableProvider#tick is not supported anymore");
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a tick on a list of provided chunks.
|
||||
*
|
||||
* @param chunks The chunks to tick.
|
||||
*/
|
||||
void tick(Chunk[] chunks);
|
||||
default void tick(Collection<Chunk> chunks) {
|
||||
tick(chunks.toArray(new Chunk[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.bgsoftware.wildloaders.api.hooks;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface WorldsProvider {
|
||||
|
||||
/**
|
||||
* Load a world.
|
||||
*
|
||||
* @param worldName The name of the world
|
||||
* @return The loaded world, or null if couldn't load the world.
|
||||
*/
|
||||
@Nullable
|
||||
World loadWorld(String worldName);
|
||||
|
||||
}
|
@ -34,9 +34,17 @@ public interface ChunkLoader {
|
||||
|
||||
/**
|
||||
* Get the chunks that this chunk-loader is loading.
|
||||
*
|
||||
* @deprecated See {@link #getLoadedChunksCollection()}
|
||||
*/
|
||||
@Deprecated
|
||||
Chunk[] getLoadedChunks();
|
||||
|
||||
/**
|
||||
* Get the chunks that this chunk-loader is loading.
|
||||
*/
|
||||
Collection<Chunk> getLoadedChunksCollection();
|
||||
|
||||
/**
|
||||
* Get the NPC of this chunk loader.
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@ package com.bgsoftware.wildloaders.api.managers;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
|
||||
import com.bgsoftware.wildloaders.api.hooks.WorldsProvider;
|
||||
|
||||
public interface ProvidersManager {
|
||||
|
||||
@ -17,4 +18,11 @@ public interface ProvidersManager {
|
||||
*/
|
||||
void addTickableProvider(TickableProvider tickableProvider);
|
||||
|
||||
/**
|
||||
* Add a worlds provider to the plugin.
|
||||
*
|
||||
* @param worldsProvider The worlds provider to add.
|
||||
*/
|
||||
void addWorldsProvider(WorldsProvider worldsProvider);
|
||||
|
||||
}
|
||||
|
19
Hooks/AdvancedSlimePaper/build.gradle
Normal file
19
Hooks/AdvancedSlimePaper/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
group 'Hooks:AdvancedSlimePaper'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.infernalsuite:AdvancedSlimePaper:1.19.4-R0.1'
|
||||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
if (project.hasProperty('hook.compile_advancedslimepaper') &&
|
||||
!Boolean.valueOf(project.findProperty("hook.compile_advancedslimepaper").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||
import com.bgsoftware.wildloaders.api.hooks.WorldsProvider;
|
||||
import com.infernalsuite.aswm.api.SlimePlugin;
|
||||
import com.infernalsuite.aswm.api.loaders.SlimeLoader;
|
||||
import com.infernalsuite.aswm.api.world.SlimeWorld;
|
||||
import com.infernalsuite.aswm.api.world.properties.SlimePropertyMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldsProvider_AdvancedSlimePaper implements WorldsProvider {
|
||||
|
||||
private static final List<String> WORLD_LOADERS = Arrays.asList("file", "mysql", "mongodb", "redis", "api");
|
||||
private static final SlimePropertyMap EMPTY_PROPERTIES = new SlimePropertyMap();
|
||||
|
||||
private final SlimePlugin slimePlugin;
|
||||
|
||||
public WorldsProvider_AdvancedSlimePaper() {
|
||||
this.slimePlugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World loadWorld(String worldName) {
|
||||
for (String loaderName : WORLD_LOADERS) {
|
||||
SlimeLoader slimeLoader = this.slimePlugin.getLoader(loaderName);
|
||||
try {
|
||||
if (slimeLoader != null && slimeLoader.worldExists(worldName)) {
|
||||
SlimeWorld slimeWorld = slimePlugin.loadWorld(slimeLoader, worldName, false, EMPTY_PROPERTIES);
|
||||
if (slimeWorld != null) {
|
||||
slimePlugin.loadWorld(slimeWorld);
|
||||
World bukkitWorld = Bukkit.getWorld(slimeWorld.getName());
|
||||
if (bukkitWorld != null)
|
||||
return bukkitWorld;
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
WildLoadersPlugin.log("An error occurred while trying to load world " + worldName);
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
19
Hooks/AdvancedSlimeWorldManager/build.gradle
Normal file
19
Hooks/AdvancedSlimeWorldManager/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
group 'Hooks:AdvancedSlimeWorldManager'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.grinderwolf:slimeworldmanager-api:2.10.0"
|
||||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
if (project.hasProperty('hook.compile_advancedslimeworldmanager') &&
|
||||
!Boolean.valueOf(project.findProperty("hook.compile_advancedslimeworldmanager").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||
import com.bgsoftware.wildloaders.api.hooks.WorldsProvider;
|
||||
import com.grinderwolf.swm.api.SlimePlugin;
|
||||
import com.grinderwolf.swm.api.loaders.SlimeLoader;
|
||||
import com.grinderwolf.swm.api.world.SlimeWorld;
|
||||
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldsProvider_AdvancedSlimeWorldManager implements WorldsProvider {
|
||||
|
||||
private static final List<String> WORLD_LOADERS = Arrays.asList("file", "mysql", "mongodb", "redis", "api");
|
||||
private static final SlimePropertyMap EMPTY_PROPERTIES = new SlimePropertyMap();
|
||||
|
||||
private final SlimePlugin slimePlugin;
|
||||
|
||||
public WorldsProvider_AdvancedSlimeWorldManager() {
|
||||
this.slimePlugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World loadWorld(String worldName) {
|
||||
for (String loaderName : WORLD_LOADERS) {
|
||||
SlimeLoader slimeLoader = this.slimePlugin.getLoader(loaderName);
|
||||
try {
|
||||
if (slimeLoader != null && slimeLoader.worldExists(worldName)) {
|
||||
SlimeWorld slimeWorld = slimePlugin.loadWorld(slimeLoader, worldName, false, EMPTY_PROPERTIES);
|
||||
if (slimeWorld != null) {
|
||||
World bukkitWorld = Bukkit.getWorld(slimeWorld.getName());
|
||||
if (bukkitWorld != null)
|
||||
return bukkitWorld;
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
WildLoadersPlugin.log("An error occurred while trying to load world " + worldName);
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -5,25 +5,26 @@ import com.songoda.epicspawners.EpicSpawners;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TickableProvider_EpicSpawners6 implements TickableProvider {
|
||||
|
||||
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void tick(Chunk[] chunks) {
|
||||
public void tick(Collection<Chunk> chunks) {
|
||||
if (EpicSpawners.getInstance().getSpawnerManager() == null)
|
||||
return;
|
||||
|
||||
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList());
|
||||
Set<Long> chunkKeys = new HashSet<>();
|
||||
chunks.forEach(chunk -> chunkKeys.add(pair(chunk.getX(), chunk.getZ())));
|
||||
|
||||
EpicSpawners.getInstance().getSpawnerManager().getSpawners().stream()
|
||||
.filter(spawner -> chunkList.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.filter(spawner -> chunkKeys.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.forEach(spawner -> {
|
||||
Location location = spawner.getLocation();
|
||||
TickDelay tickDelay = spawnerDelays.get(location);
|
||||
|
@ -5,25 +5,26 @@ import com.songoda.epicspawners.EpicSpawners;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TickableProvider_EpicSpawners7 implements TickableProvider {
|
||||
|
||||
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void tick(Chunk[] chunks) {
|
||||
public void tick(Collection<Chunk> chunks) {
|
||||
if (EpicSpawners.getInstance().getSpawnerManager() == null)
|
||||
return;
|
||||
|
||||
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList());
|
||||
Set<Long> chunkKeys = new HashSet<>();
|
||||
chunks.forEach(chunk -> chunkKeys.add(pair(chunk.getX(), chunk.getZ())));
|
||||
|
||||
EpicSpawners.getInstance().getSpawnerManager().getSpawners().stream()
|
||||
.filter(spawner -> chunkList.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.filter(spawner -> chunkKeys.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.forEach(spawner -> {
|
||||
Location location = spawner.getLocation();
|
||||
TickDelay tickDelay = spawnerDelays.get(location);
|
||||
|
@ -5,25 +5,26 @@ import com.craftaro.epicspawners.api.EpicSpawnersApi;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TickableProvider_EpicSpawners8 implements TickableProvider {
|
||||
|
||||
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void tick(Chunk[] chunks) {
|
||||
public void tick(Collection<Chunk> chunks) {
|
||||
if (EpicSpawnersApi.getSpawnerManager() == null)
|
||||
return;
|
||||
|
||||
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList());
|
||||
Set<Long> chunkKeys = new HashSet<>();
|
||||
chunks.forEach(chunk -> chunkKeys.add(pair(chunk.getX(), chunk.getZ())));
|
||||
|
||||
EpicSpawnersApi.getSpawnerManager().getSpawners().stream()
|
||||
.filter(spawner -> chunkList.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.filter(spawner -> chunkKeys.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
|
||||
.forEach(spawner -> {
|
||||
Location location = spawner.getLocation();
|
||||
TickDelay tickDelay = spawnerDelays.get(location);
|
||||
|
22
Hooks/Folia/build.gradle
Normal file
22
Hooks/Folia/build.gradle
Normal file
@ -0,0 +1,22 @@
|
||||
group 'Hooks:Folia'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url 'https://repo.papermc.io/repository/maven-public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT'
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
if (project.hasProperty('hook.compile_folia') &&
|
||||
!Boolean.valueOf(project.findProperty("hook.compile_folia").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.bgsoftware.wildloaders.scheduler;
|
||||
|
||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FoliaSchedulerImplementation implements ISchedulerImplementation {
|
||||
|
||||
public static final FoliaSchedulerImplementation INSTANCE = new FoliaSchedulerImplementation();
|
||||
|
||||
private static final WildLoadersPlugin plugin = WildLoadersPlugin.getPlugin();
|
||||
|
||||
private FoliaSchedulerImplementation() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegionScheduler() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledTask scheduleTask(World world, int chunkX, int chunkZ, Runnable task, long delay) {
|
||||
io.papermc.paper.threadedregions.scheduler.ScheduledTask handle;
|
||||
if (delay <= 0) {
|
||||
handle = Bukkit.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, v -> task.run());
|
||||
} else {
|
||||
handle = Bukkit.getServer().getRegionScheduler().runDelayed(plugin, world, chunkX, chunkZ, v -> task.run(), delay);
|
||||
}
|
||||
return new FoliaScheduledTask(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledTask scheduleTask(Entity entity, Runnable task, long delay) {
|
||||
io.papermc.paper.threadedregions.scheduler.ScheduledTask handle;
|
||||
if (delay <= 0) {
|
||||
handle = entity.getScheduler().run(plugin, v -> task.run(), task);
|
||||
} else {
|
||||
handle = entity.getScheduler().runDelayed(plugin, v -> task.run(), task, delay);
|
||||
}
|
||||
return new FoliaScheduledTask(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledTask scheduleTask(Runnable task, long delay) {
|
||||
io.papermc.paper.threadedregions.scheduler.ScheduledTask handle;
|
||||
if (delay <= 0) {
|
||||
handle = Bukkit.getServer().getGlobalRegionScheduler().run(plugin, v -> task.run());
|
||||
} else {
|
||||
handle = Bukkit.getServer().getGlobalRegionScheduler().runDelayed(plugin, v -> task.run(), delay);
|
||||
}
|
||||
|
||||
return new FoliaScheduledTask(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledTask scheduleAsyncTask(Runnable task, long delay) {
|
||||
io.papermc.paper.threadedregions.scheduler.ScheduledTask handle;
|
||||
if (delay <= 0) {
|
||||
handle = Bukkit.getServer().getAsyncScheduler().runNow(plugin, v -> task.run());
|
||||
} else {
|
||||
handle = Bukkit.getServer().getAsyncScheduler().runDelayed(plugin, v -> task.run(), delay * 50L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
return new FoliaScheduledTask(handle);
|
||||
}
|
||||
|
||||
private static class FoliaScheduledTask implements ScheduledTask {
|
||||
|
||||
private final io.papermc.paper.threadedregions.scheduler.ScheduledTask handle;
|
||||
|
||||
public FoliaScheduledTask(io.papermc.paper.threadedregions.scheduler.ScheduledTask handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (!handle.isCancelled())
|
||||
handle.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
13
Hooks/SlimeWorldManager/build.gradle
Normal file
13
Hooks/SlimeWorldManager/build.gradle
Normal file
@ -0,0 +1,13 @@
|
||||
group 'Hooks:SlimeWorldManager'
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.grinderwolf:slimeworldmanager-api:2.2.1"
|
||||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
if (project.hasProperty('hook.compile_slimeworldmanager') &&
|
||||
!Boolean.valueOf(project.findProperty("hook.compile_slimeworldmanager").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||
import com.bgsoftware.wildloaders.api.hooks.WorldsProvider;
|
||||
import com.grinderwolf.swm.api.SlimePlugin;
|
||||
import com.grinderwolf.swm.api.loaders.SlimeLoader;
|
||||
import com.grinderwolf.swm.api.world.SlimeWorld;
|
||||
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldsProvider_SlimeWorldManager implements WorldsProvider {
|
||||
|
||||
private static final List<String> WORLD_LOADERS = Arrays.asList("file", "mysql", "mongodb", "redis", "api");
|
||||
private static final SlimePropertyMap EMPTY_PROPERTIES = new SlimePropertyMap();
|
||||
|
||||
private final SlimePlugin slimePlugin;
|
||||
|
||||
public WorldsProvider_SlimeWorldManager() {
|
||||
this.slimePlugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World loadWorld(String worldName) {
|
||||
for (String loaderName : WORLD_LOADERS) {
|
||||
SlimeLoader slimeLoader = this.slimePlugin.getLoader(loaderName);
|
||||
try {
|
||||
if (slimeLoader != null && slimeLoader.worldExists(worldName)) {
|
||||
SlimeWorld slimeWorld = slimePlugin.loadWorld(slimeLoader, worldName, false, EMPTY_PROPERTIES);
|
||||
if (slimeWorld != null) {
|
||||
World bukkitWorld = Bukkit.getWorld(slimeWorld.getName());
|
||||
if (bukkitWorld != null)
|
||||
return bukkitWorld;
|
||||
}
|
||||
}
|
||||
} catch (Exception error) {
|
||||
WildLoadersPlugin.log("An error occurred while trying to load world " + worldName);
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_12_R1;
|
||||
|
||||
import com.bgsoftware.common.reflection.ReflectField;
|
||||
import com.bgsoftware.common.reflection.ReflectMethod;
|
||||
import com.bgsoftware.wildloaders.handlers.NPCHandler;
|
||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@ -38,6 +40,11 @@ import java.util.UUID;
|
||||
|
||||
public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC {
|
||||
|
||||
private static final ReflectMethod<Void> PLAYER_SET_VIEW_DISTANCE = new ReflectMethod<>(
|
||||
EntityPlayer.class, "setViewDistance", int.class);
|
||||
private static final ReflectField<Boolean> PLAYER_AFFECTS_SPAWNING = new ReflectField<>(
|
||||
EntityPlayer.class, boolean.class, "affectsSpawning");
|
||||
|
||||
private final AxisAlignedBB boundingBox;
|
||||
private final AdvancementDataPlayer advancements;
|
||||
|
||||
@ -53,8 +60,15 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
|
||||
this.advancements = new DummyPlayerAdvancements(server, this);
|
||||
|
||||
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
|
||||
if (PLAYER_SET_VIEW_DISTANCE.isValid())
|
||||
PLAYER_SET_VIEW_DISTANCE.invoke(this, 0);
|
||||
if (PLAYER_AFFECTS_SPAWNING.isValid())
|
||||
PLAYER_AFFECTS_SPAWNING.set(this, true);
|
||||
|
||||
spawnIn(world);
|
||||
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_12_R1.loader.TileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Chunk;
|
||||
@ -113,18 +114,10 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
|
||||
world.tileEntityListTick.add(tileEntityChunkLoader);
|
||||
|
||||
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);
|
||||
if (TILE_ENTITY_LOAD.isValid()) {
|
||||
TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound);
|
||||
} else {
|
||||
tileEntity.a(nbtTagCompound);
|
||||
}
|
||||
});
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setSpawnersRangeForLoader(chunkLoader, true));
|
||||
} else {
|
||||
setSpawnersRangeForLoader(chunkLoader, true);
|
||||
}
|
||||
|
||||
return tileEntityChunkLoader;
|
||||
@ -147,18 +140,30 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
if (spawnParticle)
|
||||
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setSpawnersRangeForLoader(chunkLoader, false));
|
||||
} else {
|
||||
setSpawnersRangeForLoader(chunkLoader, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSpawnersRangeForLoader(ChunkLoader chunkLoader, boolean loaded) {
|
||||
short requiredPlayerRange = (short) (loaded ? -1 : 16);
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
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);
|
||||
if (TILE_ENTITY_LOAD.isValid()) {
|
||||
TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound);
|
||||
} else {
|
||||
tileEntity.a(nbtTagCompound);
|
||||
|
||||
for (TileEntity tileEntity : chunk.tileEntities.values()) {
|
||||
if (tileEntity instanceof TileEntityMobSpawner) {
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
tileEntity.save(nbtTagCompound);
|
||||
nbtTagCompound.setShort("RequiredPlayerRange", requiredPlayerRange);
|
||||
if (TILE_ENTITY_LOAD.isValid()) {
|
||||
TILE_ENTITY_LOAD.invoke(tileEntity, nbtTagCompound);
|
||||
} else {
|
||||
tileEntity.a(nbtTagCompound);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import java.util.UUID;
|
||||
|
||||
public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC {
|
||||
|
||||
|
||||
private final AxisAlignedBB boundingBox;
|
||||
private final AdvancementDataPlayer advancements;
|
||||
|
||||
@ -57,9 +58,16 @@ public final class ChunkLoaderNPC extends EntityPlayer implements com.bgsoftware
|
||||
this.advancements = new DummyPlayerAdvancements(server, this);
|
||||
|
||||
this.playerInteractManager.setGameMode(EnumGamemode.CREATIVE);
|
||||
clientViewDistance = 1;
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
clientViewDistance = 0;
|
||||
|
||||
try {
|
||||
// Paper
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
spawnIn(world);
|
||||
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
@ -4,6 +4,7 @@ import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_16_R3.loader.TileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.server.v1_16_R3.Block;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_16_R3.Chunk;
|
||||
@ -14,6 +15,7 @@ import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagList;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagLong;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagString;
|
||||
import net.minecraft.server.v1_16_R3.TileEntity;
|
||||
import net.minecraft.server.v1_16_R3.TileEntityMobSpawner;
|
||||
import net.minecraft.server.v1_16_R3.World;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
@ -114,12 +116,10 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
TileEntityChunkLoader tileEntityChunkLoader = new TileEntityChunkLoader(chunkLoader, world, blockPosition);
|
||||
world.tileEntityListTick.add(tileEntityChunkLoader);
|
||||
|
||||
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);
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, world, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, world, true);
|
||||
}
|
||||
|
||||
return tileEntityChunkLoader;
|
||||
@ -143,12 +143,25 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
if (spawnParticle)
|
||||
world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
|
||||
|
||||
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);
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, world, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, world, false);
|
||||
}
|
||||
}
|
||||
|
||||
world.setForceLoaded(chunk.getPos().x, chunk.getPos().z, false);
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, WorldServer worldServer, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
|
||||
for (TileEntity tileEntity : chunk.tileEntities.values()) {
|
||||
if (tileEntity instanceof TileEntityMobSpawner)
|
||||
((TileEntityMobSpawner) tileEntity).getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkCoordIntPair chunkCoord = chunk.getPos();
|
||||
worldServer.setForceLoaded(chunkCoord.x, chunkCoord.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.6.0"
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -5,6 +5,7 @@ import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_17.loader.ChunkLoaderBlockEntity;
|
||||
import com.bgsoftware.wildloaders.nms.v1_17.npc.ChunkLoaderNPCWrapper;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
@ -105,16 +106,10 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
ChunkLoaderBlockEntity ChunkLoaderBlockEntity = new ChunkLoaderBlockEntity(chunkLoader, serverLevel, blockPos);
|
||||
serverLevel.addBlockEntityTicker(ChunkLoaderBlockEntity.getTicker());
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
LevelChunk levelChunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = -1;
|
||||
});
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, true);
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, true);
|
||||
}
|
||||
|
||||
return ChunkLoaderBlockEntity;
|
||||
@ -142,16 +137,25 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
if (spawnParticle)
|
||||
serverLevel.levelEvent(null, 2001, blockPos, Block.getId(serverLevel.getBlockState(blockPos)));
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, ServerLevel serverLevel, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
LevelChunk levelChunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = 16;
|
||||
});
|
||||
|
||||
for (BlockEntity blockEntity : levelChunk.getBlockEntities().values()) {
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, false);
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,16 @@ public final class ChunkLoaderPlayer extends ServerPlayer {
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
clientViewDistance = 1;
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
clientViewDistance = 0;
|
||||
|
||||
try {
|
||||
// Paper
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.6.0"
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -58,9 +58,16 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
clientViewDistance = 1;
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
clientViewDistance = 0;
|
||||
|
||||
try {
|
||||
// Paper
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
@ -4,6 +4,7 @@ import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_18.loader.ChunkLoaderBlockEntity;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
@ -104,16 +105,10 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
ChunkLoaderBlockEntity ChunkLoaderBlockEntity = new ChunkLoaderBlockEntity(chunkLoader, serverLevel, blockPos);
|
||||
serverLevel.addBlockEntityTicker(ChunkLoaderBlockEntity.getTicker());
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
LevelChunk levelChunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = -1;
|
||||
});
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, true);
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, true);
|
||||
}
|
||||
|
||||
return ChunkLoaderBlockEntity;
|
||||
@ -141,16 +136,25 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
if (spawnParticle)
|
||||
serverLevel.levelEvent(null, 2001, blockPos, Block.getId(serverLevel.getBlockState(blockPos)));
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, ServerLevel serverLevel, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
LevelChunk levelChunk = ((CraftChunk) bukkitChunk).getHandle();
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = 16;
|
||||
});
|
||||
|
||||
for (BlockEntity blockEntity : levelChunk.getBlockEntities().values()) {
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, false);
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "1.6.0"
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -60,9 +60,16 @@ public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoade
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
clientViewDistance = 1;
|
||||
|
||||
fallDistance = 0.0F;
|
||||
fauxSleeping = true;
|
||||
clientViewDistance = 0;
|
||||
|
||||
try {
|
||||
// Paper
|
||||
affectsSpawning = true;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_19;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.holograms.Hologram;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@ -15,6 +16,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftArmorStand;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
|
||||
@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram {
|
||||
|
||||
@Override
|
||||
public void removeHologram() {
|
||||
super.remove(RemovalReason.DISCARDED);
|
||||
if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) {
|
||||
World world = level.getWorld();
|
||||
int chunkX = getBlockX() >> 4;
|
||||
int chunkZ = getBlockZ() >> 4;
|
||||
Scheduler.runTask(world, chunkX, chunkZ, () -> super.remove(RemovalReason.DISCARDED));
|
||||
} else {
|
||||
super.remove(RemovalReason.DISCARDED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@ import com.bgsoftware.wildloaders.api.loaders.ChunkLoader;
|
||||
import com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader;
|
||||
import com.bgsoftware.wildloaders.nms.NMSAdapter;
|
||||
import com.bgsoftware.wildloaders.nms.v1_19.loader.ChunkLoaderBlockEntity;
|
||||
import com.bgsoftware.wildloaders.scheduler.Scheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
@ -103,16 +104,10 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
ChunkLoaderBlockEntity ChunkLoaderBlockEntity = new ChunkLoaderBlockEntity(chunkLoader, serverLevel, blockPos);
|
||||
serverLevel.addBlockEntityTicker(ChunkLoaderBlockEntity.getTicker());
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
LevelChunk levelChunk = serverLevel.getChunk(bukkitChunk.getX(), bukkitChunk.getZ());
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = -1;
|
||||
});
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, true);
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, true));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, true);
|
||||
}
|
||||
|
||||
return ChunkLoaderBlockEntity;
|
||||
@ -140,16 +135,25 @@ public final class NMSAdapterImpl implements NMSAdapter {
|
||||
if (spawnParticle)
|
||||
serverLevel.levelEvent(null, 2001, blockPos, Block.getId(serverLevel.getBlockState(blockPos)));
|
||||
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
|
||||
if (Scheduler.isRegionScheduler()) {
|
||||
Scheduler.runTask(() -> setChunksForcedForLoader(chunkLoader, serverLevel, false));
|
||||
} else {
|
||||
setChunksForcedForLoader(chunkLoader, serverLevel, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setChunksForcedForLoader(ChunkLoader chunkLoader, ServerLevel serverLevel, boolean forced) {
|
||||
int requiredPlayerRange = forced ? -1 : 16;
|
||||
for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunksCollection()) {
|
||||
LevelChunk levelChunk = serverLevel.getChunk(bukkitChunk.getX(), bukkitChunk.getZ());
|
||||
levelChunk.getBlockEntities().values().stream()
|
||||
.filter(blockEntity -> blockEntity instanceof SpawnerBlockEntity)
|
||||
.forEach(blockEntity -> {
|
||||
((SpawnerBlockEntity) blockEntity).getSpawner().requiredPlayerRange = 16;
|
||||
});
|
||||
|
||||
for (BlockEntity blockEntity : levelChunk.getBlockEntities().values()) {
|
||||
if (blockEntity instanceof SpawnerBlockEntity spawnerBlockEntity)
|
||||
spawnerBlockEntity.getSpawner().requiredPlayerRange = requiredPlayerRange;
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = levelChunk.getPos();
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, false);
|
||||
serverLevel.setChunkForced(chunkPos.x, chunkPos.z, forced);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_19.loader;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.TickingBlockEntity;
|
||||
|
||||
@ -27,4 +28,8 @@ public record ChunkLoaderBlockEntityTicker(
|
||||
return BlockEntityType.getKey(chunkLoaderBlockEntity.getType()) + "";
|
||||
}
|
||||
|
||||
public BlockEntity getTileEntity() {
|
||||
return chunkLoaderBlockEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,237 +0,0 @@
|
||||
package com.bgsoftware.wildloaders.nms.v1_20_1;
|
||||
|
||||
import com.bgsoftware.common.reflection.ReflectMethod;
|
||||
import com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC;
|
||||
import com.bgsoftware.wildloaders.handlers.NPCHandler;
|
||||
import com.bgsoftware.wildloaders.npc.DummyChannel;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ChunkLoaderNPCImpl extends ServerPlayer implements ChunkLoaderNPC {
|
||||
|
||||
private static final ReflectMethod<Void> SET_GAMEMODE = new ReflectMethod<>(ServerPlayerGameMode.class,
|
||||
1, GameType.class, GameType.class);
|
||||
|
||||
private final ServerLevel serverLevel;
|
||||
private final AABB boundingBox;
|
||||
private final PlayerAdvancements advancements;
|
||||
|
||||
private boolean dieCall = false;
|
||||
|
||||
public ChunkLoaderNPCImpl(MinecraftServer minecraftServer, Location location, UUID uuid) {
|
||||
super(minecraftServer, ((CraftWorld) location.getWorld()).getHandle(),
|
||||
new GameProfile(uuid, NPCHandler.getName(location.getWorld().getName())));
|
||||
|
||||
this.serverLevel = serverLevel();
|
||||
this.boundingBox = new AABB(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
|
||||
this.connection = new DummyServerGamePacketListenerImpl(minecraftServer, this);
|
||||
|
||||
this.advancements = new DummyPlayerAdvancements(minecraftServer, this);
|
||||
|
||||
SET_GAMEMODE.invoke(this.gameMode, GameType.CREATIVE, null);
|
||||
clientViewDistance = 1;
|
||||
|
||||
fauxSleeping = true;
|
||||
|
||||
spawnIn(this.serverLevel);
|
||||
moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
||||
|
||||
this.serverLevel.addNewPlayer(this);
|
||||
|
||||
super.setBoundingBox(this.boundingBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return super.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling() {
|
||||
return this.boundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(RemovalReason removalReason) {
|
||||
if (!dieCall) {
|
||||
dieCall = true;
|
||||
this.serverLevel.removePlayerImmediately(this, RemovalReason.UNLOADED_WITH_PLAYER);
|
||||
dieCall = false;
|
||||