use of net.glowstone.scheduler.GlowScheduler in project Glowstone by GlowstoneMC.
the class GlowPlayerTest method setUp.
@Before
@Override
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class);
super.setUp();
when(Bukkit.getServer()).thenReturn(server);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
opsListFile = File.createTempFile("test-ops-list", "");
opsList = new UuidListFile(opsListFile);
when(server.getSessionRegistry()).thenReturn(sessionRegistry);
when(server.getPluginManager()).thenReturn(pluginManager);
when(server.getMaterialValueManager()).thenReturn(materialValueManager);
scheduler = new GlowScheduler(server, worldScheduler);
when(session.getServer()).thenReturn(server);
when(server.getScheduler()).thenReturn(scheduler);
when(server.getOpsList()).thenReturn(opsList);
when(server.getPlayerStatisticIoService()).thenReturn(statisticIoService);
when(world.getSpawnLocation()).thenReturn(location);
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
when(world.getBlockAt(any(Location.class))).thenReturn(block);
when(world.getChunkManager()).thenReturn(chunkManager);
when(world.newChunkLock(anyString())).thenReturn(chunkLock);
when(block.getLocation()).thenReturn(location);
when(block.getType()).thenReturn(Material.AIR);
when(block.getRelative(any(BlockFace.class))).thenReturn(block);
when(block.getMaterialValues()).thenCallRealMethod();
when(block.getWorld()).thenReturn(world);
fishingRodItem = new ItemStack(Material.FISHING_ROD);
entity = entityCreator.apply(location);
entity.setItemInHand(fishingRodItem);
entity.setDigging(null);
entity.setLevel(1);
when(session.getPlayer()).thenReturn(entity);
when(session.getChannel()).thenReturn(null);
when(world.getRawPlayers()).thenReturn(Collections.singletonList(entity));
EventFactory.setInstance(eventFactory);
when(eventFactory.callEvent(any(Event.class))).thenAnswer(returnsFirstArg());
}
use of net.glowstone.scheduler.GlowScheduler in project Glowstone by GlowstoneMC.
the class EventFactory method callEvent.
/**
* Calls an event through the plugin manager.
*
* @param event The event to throw.
* @param <T> The type of the event.
* @return the called event
*/
public <T extends Event> T callEvent(T event) {
if (event.getHandlers().getRegisteredListeners().length == 0) {
return event;
}
Server server = ServerProvider.getServer();
if (event.isAsynchronous()) {
server.getPluginManager().callEvent(event);
return event;
} else {
FutureTask<T> task = new FutureTask<>(() -> server.getPluginManager().callEvent(event), event);
BukkitScheduler scheduler = server.getScheduler();
((GlowScheduler) scheduler).scheduleInTickExecution(task);
try {
return task.get();
} catch (InterruptedException e) {
ConsoleMessages.Warn.Event.INTERRUPTED.log(e, event.getClass().getSimpleName());
return event;
} catch (CancellationException e) {
ConsoleMessages.Warn.Event.SHUTDOWN.log(event.getClass().getSimpleName());
return event;
} catch (ExecutionException e) {
// No checked exceptions declared for callEvent
throw new RuntimeException(e);
}
}
}
Aggregations