mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-26 18:39:17 +00:00
Possibly fix entities on 1.18?
This commit is contained in:
@@ -51,6 +51,7 @@ public class CChunk implements CustomCropsChunk {
|
||||
private long lastLoadedTime;
|
||||
private int loadedSeconds;
|
||||
private int unloadedSeconds;
|
||||
private boolean notified;
|
||||
|
||||
public CChunk(CWorld cWorld, ChunkPos chunkPos) {
|
||||
this.cWorld = cWorld;
|
||||
@@ -60,6 +61,7 @@ public class CChunk implements CustomCropsChunk {
|
||||
this.unloadedSeconds = 0;
|
||||
this.tickedBlocks = Collections.synchronizedSet(new HashSet<>());
|
||||
this.updateLastLoadedTime();
|
||||
this.notified = true;
|
||||
}
|
||||
|
||||
public CChunk(
|
||||
@@ -88,6 +90,7 @@ public class CChunk implements CustomCropsChunk {
|
||||
|
||||
@Override
|
||||
public void notifyOfflineUpdates() {
|
||||
this.notified = true;
|
||||
long current = System.currentTimeMillis();
|
||||
int offlineTimeInSeconds = (int) (current - this.lastLoadedTime) / 1000;
|
||||
CustomCropsPlugin.get().debug(chunkPos.toString() + " Offline seconds: " + offlineTimeInSeconds + "s.");
|
||||
@@ -595,9 +598,15 @@ public class CChunk implements CustomCropsChunk {
|
||||
this.unloadedSeconds = unloadedSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetUnloadedSeconds() {
|
||||
this.unloadedSeconds = 0;
|
||||
this.notified = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPrune() {
|
||||
return loadedSections.size() == 0;
|
||||
return loadedSections.isEmpty();
|
||||
}
|
||||
|
||||
public PriorityQueue<TickTask> getQueue() {
|
||||
@@ -607,4 +616,9 @@ public class CChunk implements CustomCropsChunk {
|
||||
public Set<BlockPos> getTickedBlocks() {
|
||||
return tickedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOfflineTaskNotified() {
|
||||
return notified;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,16 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.event.world.EntitiesLoadEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WorldManagerImpl implements WorldManager, Listener {
|
||||
|
||||
@@ -517,9 +521,12 @@ public class WorldManagerImpl implements WorldManager, Listener {
|
||||
}
|
||||
|
||||
CustomCropsChunk chunk = optionalChunk.get();
|
||||
|
||||
// load the entities if not loaded
|
||||
bukkitChunk.getEntities();
|
||||
chunk.notifyOfflineUpdates();
|
||||
if (bukkitChunk.isEntitiesLoaded()) {
|
||||
chunk.notifyOfflineUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -544,6 +551,30 @@ public class WorldManagerImpl implements WorldManager, Listener {
|
||||
handleChunkUnload(event.getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitiesLoad(EntitiesLoadEvent event) {
|
||||
|
||||
Chunk bukkitChunk = event.getChunk();
|
||||
Optional<CustomCropsWorld> optional = getCustomCropsWorld(bukkitChunk.getWorld());
|
||||
if (optional.isEmpty())
|
||||
return;
|
||||
|
||||
CustomCropsWorld customCropsWorld = optional.get();
|
||||
// offline grow part
|
||||
if (!customCropsWorld.getWorldSetting().isOfflineTick()) return;
|
||||
|
||||
ChunkPos chunkPos = ChunkPos.getByBukkitChunk(bukkitChunk);
|
||||
|
||||
Optional<CustomCropsChunk> optionalChunk = customCropsWorld.getLoadedChunkAt(chunkPos);
|
||||
if (optionalChunk.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!optionalChunk.get().isOfflineTaskNotified()) {
|
||||
optionalChunk.get().notifyOfflineUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChunkToCachedRegion(CustomCropsChunk chunk) {
|
||||
this.worldAdaptor.saveChunkToCachedRegion(chunk);
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldSaveEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
@@ -158,7 +159,7 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
CustomCropsChunk lazyChunk = cWorld.removeLazyChunkAt(chunkPos);
|
||||
if (lazyChunk != null) {
|
||||
CChunk cChunk = (CChunk) lazyChunk;
|
||||
cChunk.setUnloadedSeconds(0);
|
||||
cChunk.resetUnloadedSeconds();
|
||||
cWorld.loadChunk(cChunk);
|
||||
long time2 = System.currentTimeMillis();
|
||||
CustomCropsPlugin.get().debug("Took " + (time2-time1) + "ms to load chunk " + chunkPos + " from lazy chunks");
|
||||
@@ -264,14 +265,14 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
if (worldManager.isMechanicEnabled(event.getWorld())) {
|
||||
worldManager.loadWorld(event.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
if (worldManager.isMechanicEnabled(event.getWorld()))
|
||||
worldManager.unloadWorld(event.getWorld());
|
||||
|
||||
@@ -129,7 +129,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor {
|
||||
CustomCropsChunk lazyChunk = customCropsWorld.removeLazyChunkAt(chunkPos);
|
||||
if (lazyChunk != null) {
|
||||
CChunk cChunk = (CChunk) lazyChunk;
|
||||
cChunk.setUnloadedSeconds(0);
|
||||
cChunk.resetUnloadedSeconds();
|
||||
cWorld.loadChunk(cChunk);
|
||||
long time2 = System.currentTimeMillis();
|
||||
CustomCropsPlugin.get().debug("Took " + (time2-time1) + "ms to load chunk " + chunkPos + " from lazy chunks");
|
||||
|
||||
Reference in New Issue
Block a user