/** * <b>Asynchronous tasks should never access any API in Bukkit. Great care * should be taken to assure the thread-safety of asynchronous tasks.</b> * <p> * Schedules this in the Bukkit scheduler to run asynchronously. * * @param plugin the reference to the plugin scheduling task * @return a BukkitTask that contains the id number * @throws IllegalArgumentException if plugin is null * @throws IllegalStateException if this was already scheduled * @see BukkitScheduler#runTaskAsynchronously(Plugin, Runnable) */ public synchronized BukkitTask runTaskAsynchronously(Plugin plugin) throws IllegalArgumentException, IllegalStateException { checkState(); return setupId(Bukkit.getScheduler().runTaskAsynchronously(plugin, (Runnable) this)); }
@Override public void getChunkAtAsync(int x, int z, ChunkLoadCallback cb) { ServerProvider.getServer().getScheduler() .runTaskAsynchronously(null, () -> cb.onLoad(chunkManager.getChunk(x, z))); }
/** * Saves the players current location, health, inventory, motion, and other information into the * username.dat file, in the world/player folder. * * @param async if true, save asynchronously; if false, block until saved */ public void saveData(boolean async) { if (async) { Bukkit.getScheduler().runTaskAsynchronously(null, () -> { server.getPlayerDataService().writeData(GlowPlayer.this); server.getPlayerStatisticIoService().writeStatistics(GlowPlayer.this); }); } else { server.getPlayerDataService().writeData(this); server.getPlayerStatisticIoService().writeStatistics(this); } }
&& !hiddenEntities.contains(entity.getUniqueId())) .forEach((entity) -> Bukkit.getScheduler() .runTaskAsynchronously(null, () -> { worldLock.readLock().lock(); try {
.runTaskAsynchronously(null, noise::release);
@Override protected void runAsync(@Nonnull Runnable task) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, task); } }
/** * Save PlayerStats async. * * @param stats PlayerStats data */ public void saveAsync(PlayerStats stats) { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> save(Lists.newArrayList(stats))); }
/** * Run a task in a separate thread. * * @param runnable the task. */ public static void async(Runnable runnable) { Bukkit.getScheduler().runTaskAsynchronously(PlugMan.getInstance(), runnable); }
private void setSkin(CommandSender sender, Player targetPlayer, String toSkin, boolean keepSkin) { //Minecraft player names has the max length of 16 characters so it could be the uuid if (toSkin.length() > 16) { setSkinUUID(sender, targetPlayer, toSkin, keepSkin); } else { Runnable nameResolver = new NameResolver(plugin, sender, toSkin, targetPlayer, keepSkin); Bukkit.getScheduler().runTaskAsynchronously(plugin, nameResolver); } }
@Override public void execute(Runnable runnable) { Bukkit.getScheduler().runTaskAsynchronously(LoaderUtils.getPlugin(), wrapRunnable(runnable)); } }
@Override public void execute(Runnable runnable) { Bukkit.getScheduler().runTaskAsynchronously(LoaderUtils.getPlugin(), wrapRunnable(runnable)); } }
/** * Inserts data into an SQLite database table. This method executes the SQL in a separate thread. * * @param table the database table name to insert the data into. * @param data a HashMap<String, Object> of table fields and values to insert. */ public void doInsert(String table, HashMap<String, Object> data) { TARDISSQLInsert insert = new TARDISSQLInsert(plugin, table, data); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, insert); }
/** * Inserts or updates data in a database table. This method executes the SQL in a separate thread. * * @param id the database table name to insert the data into. * @param type the type of control to insert. * @param l the string location of the control * @param s what level the control is (1 primary, 2 secondary, 3 tertiary) */ public void insertControl(int id, int type, String l, int s) { TARDISSQLInsertControl control = new TARDISSQLInsertControl(plugin, id, type, l, s); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, control); }
/** * Removes condenser block counts from an SQLite database table. This method executes the SQL in a separate thread. * * @param amount the amount of blocks to remove * @param where a HashMap<String, Object> of table fields and values to select the records to alter. */ public void alterCondenserBlockCount(int amount, HashMap<String, Object> where) { TARDISSQLCondenserUpdate condense = new TARDISSQLCondenserUpdate(plugin, amount, where); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, condense); }
public void loadConfiguration(CommandSender sender, boolean forceSynchronous) { ConfigurationLoadTask loadTask = new ConfigurationLoadTask(this, sender); if (initialized && !forceSynchronous) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, loadTask); } else { loadTask.runNow(); } }
@Override public TaskId runAsync(Runnable runnable) { if (isPluginEnabled()) { return new BukkitTaskId(getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId()); } else { asyncQueuedTasks.add(runnable); return new BukkitTaskId(null); } }
@Override public void chat(String msg) { AsyncPlayerChatEvent eventAsync = new AsyncPlayerChatEvent(false, this, msg, new HashSet<>(Bukkit.getOnlinePlayers())); PlayerChatEvent eventSync = new PlayerChatEvent(this, msg); Bukkit.getScheduler().runTaskAsynchronously(null, () -> { Bukkit.getPluginManager().callEvent(eventAsync); }); Bukkit.getPluginManager().callEvent(eventSync); }
protected boolean onMagicRegister(Player player, final String code) { Plugin plugin = controller.getPlugin(); Bukkit.getScheduler().runTaskAsynchronously(controller.getPlugin(), new RegisterTask(plugin, player, code)); player.sendMessage(ChatColor.AQUA + "Sending registration code..."); return true; }
@EventHandler public void onLocaleChange(PlayerLocaleChangeEvent event) { if (TranslationAPI.isBuiltInLoaderEnabled()) { String locale = event.getLocale(); if (TranslationAPI.getBuiltInTranslations().contains(locale) && !TranslationAPI.isTranslationRegistered(locale)) { Bukkit.getScheduler().runTaskAsynchronously(ProtocolSupport.getInstance(), () -> TranslationAPI.loadBuiltTranslation(locale)); } } }
@EventHandler public void onJoin(PlayerJoinEvent e) { if (UpdateTask.isHaveUpdate() && e.getPlayer().hasPermission("taboolib.update.notify")) { TLocale.Logger.sendTo(e.getPlayer(), "UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(UpdateTask.getNewVersion())); } if (TranslateUUID.isEnabled()) { Bukkit.getScheduler().runTaskAsynchronously(Main.getInst(), () -> TranslateUUID.updateUsername(e.getPlayer().getUniqueId(), e.getPlayer().getName())); } }