Search in sources :

Example 1 with TaskScheduler

use of net.md_5.bungee.api.scheduler.TaskScheduler in project Bukkit_Bungee_PluginLib by GeorgH93.

the class TestObjects method initMockedPlugin.

public static void initMockedPlugin() {
    File mockedFile = mock(File.class);
    when(mockedFile.getParentFile()).thenReturn(new File(""));
    when(mockedFile.getName()).thenReturn("FileName");
    TaskScheduler mockedTaskScheduler = mock(TaskScheduler.class);
    when(mockedTaskScheduler.runAsync(any(Plugin.class), any(Runnable.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ((Runnable) invocationOnMock.getArguments()[1]).run();
            return null;
        }
    });
    ProxyServer mockedProxyServer = mock(ProxyServer.class);
    when(mockedProxyServer.getPluginsFolder()).thenReturn(new File(""));
    when(mockedProxyServer.getScheduler()).thenReturn(mockedTaskScheduler);
    PluginDescription mockedPluginDescription = mock(PluginDescription.class);
    when(mockedPluginDescription.getName()).thenReturn("TestPlugin");
    when(mockedPluginDescription.getVersion()).thenReturn("1.0");
    when(mockedPluginDescription.getFile()).thenReturn(mockedFile);
    mockedPlugin = mock(Plugin.class);
    when(mockedPlugin.getProxy()).thenReturn(mockedProxyServer);
    when(mockedPlugin.getDescription()).thenReturn(mockedPluginDescription);
    when(mockedPlugin.getLogger()).thenReturn(Logger.getLogger("TestLogger"));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) TaskScheduler(net.md_5.bungee.api.scheduler.TaskScheduler) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginDescription(net.md_5.bungee.api.plugin.PluginDescription) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Plugin(net.md_5.bungee.api.plugin.Plugin) ProxyServer(net.md_5.bungee.api.ProxyServer)

Example 2 with TaskScheduler

use of net.md_5.bungee.api.scheduler.TaskScheduler in project Parties by AlessioDP.

the class BungeeMetrics method startSubmitting.

private void startSubmitting() {
    // We use a timer cause want to be independent from the server tps
    final Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            // The data collection (e.g. for custom graphs) is done sync
            // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
            TaskScheduler scheduler = plugin.getProxy().getScheduler();
            scheduler.schedule(plugin, new Runnable() {

                @Override
                public void run() {
                    submitData();
                }
            }, 0L, TimeUnit.SECONDS);
        }
    }, 1000 * 60 * 2, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 2 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) TaskScheduler(net.md_5.bungee.api.scheduler.TaskScheduler)

Aggregations

TaskScheduler (net.md_5.bungee.api.scheduler.TaskScheduler)2 File (java.io.File)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 ProxyServer (net.md_5.bungee.api.ProxyServer)1 Plugin (net.md_5.bungee.api.plugin.Plugin)1 PluginDescription (net.md_5.bungee.api.plugin.PluginDescription)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1