@Override public boolean isMainThread() { return Sponge.getServer().isMainThread(); }
public static void runOnMain(Runnable runnable) throws WebApplicationException { if (Sponge.getServer().isMainThread()) { runnable.run(); } else { CompletableFuture future = CompletableFuture.runAsync(runnable, WebAPI.syncExecutor); try { future.get(); } catch (InterruptedException ignored) { } catch (ExecutionException e) { // Rethrow any web application exceptions we get, because they're handled by the servlets if (e.getCause() instanceof WebApplicationException) throw (WebApplicationException)e.getCause(); e.printStackTrace(); WebAPI.sentryCapture(e); throw new InternalServerErrorException(e.getMessage()); } } } public static <T> T runOnMain(Supplier<T> supplier) throws WebApplicationException {
public static <T> T runOnMain(Supplier<T> supplier) throws WebApplicationException { if (Sponge.getServer().isMainThread()) { Timings.RUN_ON_MAIN.startTiming(); T obj = supplier.get(); Timings.RUN_ON_MAIN.stopTiming(); return obj; } else { CompletableFuture<T> future = CompletableFuture.supplyAsync(supplier, WebAPI.syncExecutor); try { return future.get(); } catch (InterruptedException e) { throw new InternalServerErrorException(e.getMessage()); } catch (ExecutionException e) { // Rethrow any web application exceptions we get, because they're handled by the servlets if (e.getCause() instanceof WebApplicationException) throw (WebApplicationException)e.getCause(); e.printStackTrace(); WebAPI.sentryCapture(e); throw new InternalServerErrorException(e.getMessage()); } } }
public void updateCommands() { assert Sponge.getServer().isMainThread(); commands.clear(); Collection<CommandMapping> newCommands = Sponge.getCommandManager().getAll().values(); for (CommandMapping cmd : newCommands) { if (commands.containsKey(cmd.getPrimaryAlias())) continue; commands.put(cmd.getPrimaryAlias(), new CachedCommand(cmd)); } }
public void updatePlugins() { assert Sponge.getServer().isMainThread();
/** * Updates the internal representation of the passed player and returns it. * @param player The player which will be updated. * @return The updated cached player. */ public CachedPlayer updatePlayer(Player player) { assert Sponge.getServer().isMainThread(); Timings.CACHE_PLAYER.startTiming(); CachedPlayer p = new CachedPlayer(player); players.put(p.getUUID(), p); Timings.CACHE_PLAYER.stopTiming(); return p; }
/** * Updates a world according to the passed world properties (used for unloaded worlds). * * @param world The world which will be updated. * @return The updated cached world. */ public CachedWorld updateWorld(WorldProperties world) { assert Sponge.getServer().isMainThread(); Timings.CACHE_WORLD.startTiming(); CachedWorld w = new CachedWorld(world); worlds.put(world.getUniqueId(), w); Timings.CACHE_WORLD.stopTiming(); return w; }
/** * Updates the internal representation of the passed user and returns it. * @param user The user which will be updated. * @return The updated cached user. */ public CachedPlayer updatePlayer(User user) { assert Sponge.getServer().isMainThread(); Timings.CACHE_PLAYER.startTiming(); CachedPlayer p = new CachedPlayer(user); players.put(p.getUUID(), p); Timings.CACHE_PLAYER.stopTiming(); return p; }
/** * Updates the internal representation of the passed world and returns it. * * @param world The world which will be updated. * @return The updated cached world. */ public CachedWorld updateWorld(World world) { assert Sponge.getServer().isMainThread(); Timings.CACHE_WORLD.startTiming(); CachedWorld w = new CachedWorld(world); worlds.put(world.getUniqueId(), w); Timings.CACHE_WORLD.stopTiming(); return w; }