Search in sources :

Example 1 with BlockStorage

use of me.mrCookieSlime.Slimefun.api.BlockStorage in project Slimefun4 by Slimefun.

the class Slimefun method onDisable.

/**
 * This method gets called when the {@link Plugin} gets disabled.
 * Most often it is called when the {@link Server} is shutting down or reloading.
 */
@Override
public void onDisable() {
    // Slimefun never loaded successfully, so we don't even bother doing stuff here
    if (instance() == null || minecraftVersion == MinecraftVersion.UNIT_TEST) {
        return;
    }
    // Cancel all tasks from this plugin immediately
    Bukkit.getScheduler().cancelTasks(this);
    // Finishes all started movements/removals of block data
    try {
        ticker.halt();
        ticker.run();
    } catch (Exception x) {
        getLogger().log(Level.SEVERE, x, () -> "Something went wrong while disabling the ticker task for Slimefun v" + getDescription().getVersion());
    }
    // Kill our Profiler Threads
    profiler.kill();
    // Save all Player Profiles that are still in memory
    PlayerProfile.iterator().forEachRemaining(profile -> {
        if (profile.isDirty()) {
            profile.save();
        }
    });
    // Save all registered Worlds
    for (Map.Entry<String, BlockStorage> entry : getRegistry().getWorlds().entrySet()) {
        try {
            entry.getValue().saveAndRemove();
        } catch (Exception x) {
            getLogger().log(Level.SEVERE, x, () -> "An Error occurred while saving Slimefun-Blocks in World '" + entry.getKey() + "' for Slimefun " + getVersion());
        }
    }
    // Save all "universal" inventories (ender chests for example)
    for (UniversalBlockMenu menu : registry.getUniversalInventories().values()) {
        menu.save();
    }
    // Create a new backup zip
    if (config.getBoolean("options.backup-data")) {
        backupService.run();
    }
    // Close and unload any resources from our Metrics Service
    metricsService.cleanUp();
    // Terminate our Plugin instance
    setInstance(null);
    /**
     * Close all inventories on the server to prevent item dupes
     * (Incase some idiot uses /reload)
     */
    for (Player p : Bukkit.getOnlinePlayers()) {
        p.closeInventory();
    }
}
Also used : Player(org.bukkit.entity.Player) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) Map(java.util.Map) TagMisconfigurationException(io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException) UniversalBlockMenu(me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu)

Example 2 with BlockStorage

use of me.mrCookieSlime.Slimefun.api.BlockStorage in project Slimefun4 by Slimefun.

the class TickerTask method run.

@Override
public void run() {
    try {
        // If this method is actually still running... DON'T
        if (running) {
            return;
        }
        running = true;
        Slimefun.getProfiler().start();
        Set<BlockTicker> tickers = new HashSet<>();
        // Remove any deleted blocks
        Iterator<Map.Entry<Location, Boolean>> removals = deletionQueue.entrySet().iterator();
        while (removals.hasNext()) {
            Map.Entry<Location, Boolean> entry = removals.next();
            BlockStorage.deleteLocationInfoUnsafely(entry.getKey(), entry.getValue());
            removals.remove();
        }
        // Fixes #2576 - Remove any deleted instances of BlockStorage
        Iterator<BlockStorage> worlds = Slimefun.getRegistry().getWorlds().values().iterator();
        while (worlds.hasNext()) {
            BlockStorage storage = worlds.next();
            if (storage.isMarkedForRemoval()) {
                worlds.remove();
            }
        }
        // Run our ticker code
        if (!halted) {
            for (Map.Entry<ChunkPosition, Set<Location>> entry : tickingLocations.entrySet()) {
                tickChunk(entry.getKey(), tickers, entry.getValue());
            }
        }
        // Move any moved block data
        Iterator<Map.Entry<Location, Location>> moves = movingQueue.entrySet().iterator();
        while (moves.hasNext()) {
            Map.Entry<Location, Location> entry = moves.next();
            BlockStorage.moveLocationInfoUnsafely(entry.getKey(), entry.getValue());
            moves.remove();
        }
        // Start a new tick cycle for every BlockTicker
        for (BlockTicker ticker : tickers) {
            ticker.startNewTick();
        }
        reset();
        Slimefun.getProfiler().stop();
    } catch (Exception | LinkageError x) {
        Slimefun.logger().log(Level.SEVERE, x, () -> "An Exception was caught while ticking the Block Tickers Task for Slimefun v" + Slimefun.getVersion());
        reset();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChunkPosition(io.github.bakedlibs.dough.blocks.ChunkPosition) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Example 3 with BlockStorage

use of me.mrCookieSlime.Slimefun.api.BlockStorage in project DynaTech by ProfElements.

the class DynaTech method onEnable.

@Override
public void onEnable() {
    instance = this;
    final int TICK_TIME = Slimefun.getTickerTask().getTickRate();
    exoticGardenInstalled = Bukkit.getServer().getPluginManager().isPluginEnabled("ExoticGarden");
    infinityExpansionInstalled = Bukkit.getServer().getPluginManager().isPluginEnabled("InfinityExpansion");
    saveDefaultConfig();
    new Metrics(this, 9689);
    if (!getConfig().getBoolean("options.disable-dimensionalhome-world")) {
        WorldCreator worldCreator = new WorldCreator("dimensionalhome");
        worldCreator.generator(new DimensionalHomeDimension());
        World dimensionalHome = worldCreator.createWorld();
        new BlockStorage(dimensionalHome);
    }
    DynaTechItemsSetup.setup(this);
    new PicnicBasketListener(this, (PicnicBasket) DynaTechItems.PICNIC_BASKET.getItem());
    new ElectricalStimulatorListener(this, (ElectricalStimulator) DynaTechItems.ELECTRICAL_STIMULATOR.getItem());
    new InventoryFilterListener(this, (InventoryFilter) DynaTechItems.INVENTORY_FILTER.getItem());
    // Tasks
    getServer().getScheduler().runTaskTimerAsynchronously(DynaTech.getInstance(), new ItemBandTask(), 0L, 5 * 20L);
    getServer().getScheduler().runTaskTimer(DynaTech.getInstance(), () -> this.tickInterval++, 0, TICK_TIME);
    if (getConfig().getBoolean("options.auto-update", true) && getDescription().getVersion().startsWith("DEV - ")) {
        new GitHubBuildsUpdater(this, getFile(), "ProfElements/DynaTech/master").start();
    }
    if (System.getProperty("java.version").startsWith("1.8")) {
        getLogger().log(Level.WARNING, "           DynaTech will be switching to JAVA 11        ");
        getLogger().log(Level.WARNING, "                Please Update to JAVA 11                ");
    }
}
Also used : ItemBandTask(me.profelements.dynatech.tasks.ItemBandTask) Metrics(org.bstats.bukkit.Metrics) WorldCreator(org.bukkit.WorldCreator) DimensionalHomeDimension(me.profelements.dynatech.items.misc.DimensionalHomeDimension) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) GitHubBuildsUpdater(io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater) ElectricalStimulatorListener(me.profelements.dynatech.listeners.ElectricalStimulatorListener) World(org.bukkit.World) PicnicBasketListener(me.profelements.dynatech.listeners.PicnicBasketListener) InventoryFilterListener(me.profelements.dynatech.listeners.InventoryFilterListener)

Example 4 with BlockStorage

use of me.mrCookieSlime.Slimefun.api.BlockStorage in project Slimefun4 by Slimefun.

the class SlimefunStartupTask method run.

@Override
public void run() {
    runnable.run();
    // Load all items
    PostSetup.loadItems();
    // Load all worlds
    Slimefun.getWorldSettingsService().load(Bukkit.getWorlds());
    for (World world : Bukkit.getWorlds()) {
        try {
            new BlockStorage(world);
        } catch (Exception x) {
            Slimefun.logger().log(Level.SEVERE, x, () -> "An Error occurred while trying to load World \"" + world.getName() + "\" for Slimefun v" + Slimefun.getVersion());
        }
    }
    // Load/Unload Worlds, only after all plugins have started up. Fixes #2862
    new WorldListener(this.plugin);
    // Only load this Listener if the corresponding items are enabled
    if (isEnabled("ELEVATOR_PLATE", "GPS_ACTIVATION_DEVICE_SHARED", "GPS_ACTIVATION_DEVICE_PERSONAL")) {
        new TeleporterListener(plugin);
    }
}
Also used : TeleporterListener(io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterListener) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) WorldListener(io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener) World(org.bukkit.World)

Example 5 with BlockStorage

use of me.mrCookieSlime.Slimefun.api.BlockStorage in project Slimefun4 by Slimefun.

the class AutoSavingService method saveAllBlocks.

/**
 * This method saves the data of every {@link Block} marked dirty by {@link BlockStorage}.
 */
private void saveAllBlocks() {
    Set<BlockStorage> worlds = new HashSet<>();
    for (World world : Bukkit.getWorlds()) {
        BlockStorage storage = BlockStorage.getStorage(world);
        if (storage != null) {
            storage.computeChanges();
            if (storage.getChanges() > 0) {
                worlds.add(storage);
            }
        }
    }
    if (!worlds.isEmpty()) {
        Slimefun.logger().log(Level.INFO, "Auto-saving block data... (Next auto-save: {0}m)", interval);
        for (BlockStorage storage : worlds) {
            storage.save();
        }
    }
    BlockStorage.saveChunks();
}
Also used : BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) World(org.bukkit.World) HashSet(java.util.HashSet)

Aggregations

BlockStorage (me.mrCookieSlime.Slimefun.api.BlockStorage)5 World (org.bukkit.World)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ChunkPosition (io.github.bakedlibs.dough.blocks.ChunkPosition)1 TagMisconfigurationException (io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException)1 TeleporterListener (io.github.thebusybiscuit.slimefun4.implementation.listeners.TeleporterListener)1 WorldListener (io.github.thebusybiscuit.slimefun4.implementation.listeners.WorldListener)1 GitHubBuildsUpdater (io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BlockTicker (me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker)1 UniversalBlockMenu (me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu)1 DimensionalHomeDimension (me.profelements.dynatech.items.misc.DimensionalHomeDimension)1 ElectricalStimulatorListener (me.profelements.dynatech.listeners.ElectricalStimulatorListener)1 InventoryFilterListener (me.profelements.dynatech.listeners.InventoryFilterListener)1 PicnicBasketListener (me.profelements.dynatech.listeners.PicnicBasketListener)1 ItemBandTask (me.profelements.dynatech.tasks.ItemBandTask)1 Metrics (org.bstats.bukkit.Metrics)1 Location (org.bukkit.Location)1