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();
}
}
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();
}
}
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 ");
}
}
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);
}
}
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();
}
Aggregations