Search in sources :

Example 1 with StackingThread

use of dev.rosewood.rosestacker.stack.StackingThread in project RoseStacker by Rosewood-Development.

the class ClearlagListener method onClear.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onClear(EntityRemoveEvent event) {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    StackingThread stackingThread = stackManager.getStackingThread(event.getWorld());
    if (stackingThread == null)
        return;
    if (Setting.MISC_CLEARLAG_CLEAR_ENTITIES.getBoolean() && stackManager.isEntityStackingEnabled())
        stackingThread.removeAllEntityStacks();
    if (Setting.MISC_CLEARLAG_CLEAR_ITEMS.getBoolean() && stackManager.isItemStackingEnabled())
        stackingThread.removeAllItemStacks();
}
Also used : StackingThread(dev.rosewood.rosestacker.stack.StackingThread) StackManager(dev.rosewood.rosestacker.manager.StackManager) EventHandler(org.bukkit.event.EventHandler)

Example 2 with StackingThread

use of dev.rosewood.rosestacker.stack.StackingThread in project RoseStacker by Rosewood-Development.

the class StackManager method unloadWorld.

/**
 * Removes a World's StackingThread
 *
 * @param world to remove the StackingThread of
 */
public void unloadWorld(World world) {
    UUID worldUUID = world.getUID();
    StackingThread stackingThread = this.stackingThreads.get(worldUUID);
    if (stackingThread != null) {
        stackingThread.close();
        this.stackingThreads.remove(worldUUID);
    }
}
Also used : StackingThread(dev.rosewood.rosestacker.stack.StackingThread) UUID(java.util.UUID)

Example 3 with StackingThread

use of dev.rosewood.rosestacker.stack.StackingThread in project RoseStacker by Rosewood-Development.

the class StackManager method preStackEntities.

@Override
public void preStackEntities(EntityType entityType, int amount, Location location, SpawnReason spawnReason) {
    World world = location.getWorld();
    if (world == null)
        return;
    StackingThread stackingThread = this.getStackingThread(world);
    if (stackingThread == null)
        return;
    stackingThread.preStackEntities(entityType, amount, location, spawnReason);
}
Also used : StackingThread(dev.rosewood.rosestacker.stack.StackingThread) World(org.bukkit.World)

Example 4 with StackingThread

use of dev.rosewood.rosestacker.stack.StackingThread in project RoseStacker by Rosewood-Development.

the class StackManager method addEntityStack.

@Override
public void addEntityStack(StackedEntity stackedEntity) {
    StackingThread stackingThread = this.getStackingThread(stackedEntity.getEntity().getWorld());
    if (stackingThread == null)
        return;
    stackingThread.addEntityStack(stackedEntity);
}
Also used : StackingThread(dev.rosewood.rosestacker.stack.StackingThread)

Example 5 with StackingThread

use of dev.rosewood.rosestacker.stack.StackingThread in project RoseStacker by Rosewood-Development.

the class StackManager method reload.

@Override
public void reload() {
    // Load a new StackingThread per world
    Bukkit.getWorlds().forEach(this::loadWorld);
    if (Setting.LEGACY_DATA_MIGRATION.getBoolean())
        this.pendingChunkTask = Bukkit.getScheduler().runTaskTimer(this.rosePlugin, this::processPendingChunks, 0L, 3L);
    this.processingChunks = false;
    this.processingChunksTime = System.currentTimeMillis();
    // Load all existing stacks
    for (StackingThread stackingThread : this.stackingThreads.values()) {
        for (Chunk chunk : stackingThread.getTargetWorld().getLoadedChunks()) {
            stackingThread.loadChunkBlocks(chunk);
            stackingThread.loadChunkEntities(chunk, Arrays.asList(chunk.getEntities()));
            this.pendingLoadChunks.put(chunk, System.nanoTime());
        }
    }
    // Kick off autosave task if enabled
    long autosaveFrequency = Setting.AUTOSAVE_FREQUENCY.getLong();
    if (autosaveFrequency > 0) {
        long interval = autosaveFrequency * 20 * 60;
        this.autosaveTask = Bukkit.getScheduler().runTaskTimer(this.rosePlugin, () -> this.saveAllData(false), interval, interval);
    }
}
Also used : StackingThread(dev.rosewood.rosestacker.stack.StackingThread) Chunk(org.bukkit.Chunk)

Aggregations

StackingThread (dev.rosewood.rosestacker.stack.StackingThread)11 World (org.bukkit.World)4 Chunk (org.bukkit.Chunk)2 StackManager (dev.rosewood.rosestacker.manager.StackManager)1 UUID (java.util.UUID)1 Entity (org.bukkit.entity.Entity)1 EntityType (org.bukkit.entity.EntityType)1 EventHandler (org.bukkit.event.EventHandler)1