/** * @see Server#isPrimaryThread() */ public static boolean isPrimaryThread() { return server.isPrimaryThread(); }
/** * Calls an event with the given details. * <p> * This method only synchronizes when the event is not asynchronous. * * @param event Event details */ public void callEvent(Event event) { if (event.isAsynchronous()) { if (Thread.holdsLock(this)) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code."); } if (server.isPrimaryThread()) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread."); } fireEvent(event); } else { synchronized (this) { fireEvent(event); } } }
@Override public boolean isServerThread() { return Bukkit.getServer().isPrimaryThread(); }
/** * @see Server#isPrimaryThread() */ public static boolean isPrimaryThread() { return server.isPrimaryThread(); }
@Nonnull public static synchronized Thread getMainThread() { if (mainThread == null) { if (Bukkit.getServer().isPrimaryThread()) { mainThread = Thread.currentThread(); } } return mainThread; }
@Nonnull public static synchronized Thread getMainThread() { if (mainThread == null) { if (Bukkit.getServer().isPrimaryThread()) { mainThread = Thread.currentThread(); } } return mainThread; }
/** * Calls an event with the given details. * <p> * This method only synchronizes when the event is not asynchronous. * * @param event Event details */ public void callEvent(Event event) { if (event.isAsynchronous()) { if (Thread.holdsLock(this)) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code."); } if (server.isPrimaryThread()) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread."); } fireEvent(event); } else { synchronized (this) { fireEvent(event); } } }
private void tidyUp(Entity entity, String failureMessage) { // Nothing left to check and still not canceled task.cancel(); // Check portal if (portal && bestSpot != null) { // No portals found, teleport to the best spot we found teleportEntity(bestSpot); if (overrideGamemode && entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) { ((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld())); } } else if (entity instanceof Player && !failureMessage.isEmpty()) { // Failed, no safe spot entity.sendMessage(failureMessage); if (overrideGamemode && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) { if (plugin.getIWM().inWorld(entity.getLocation())) { ((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld())); } else { // Last resort ((Player)entity).setGameMode(GameMode.SURVIVAL); if (Bukkit.getServer().isPrimaryThread()) { ((Player)entity).performCommand("spawn"); } else { Bukkit.getScheduler().runTask(plugin, () -> ((Player)entity).performCommand("spawn")); } } } } }