Java 类org.bukkit.scheduler.BukkitScheduler 实例源码

项目:Minefana    文件:MinefanaBukkit.java   
@Override
public void registerTasks() {
    BukkitScheduler scheduler = getServer().getScheduler();

    TicksPerSecondTask ticksTask = new TicksPerSecondTask();
    scheduler.runTaskTimer(this, ticksTask, 60L, 1L);

    TpsCollector tpsCollector = new TpsCollector(core.getConnector(), ticksTask::getLastTicks);
    scheduler.runTaskTimer(this, tpsCollector, 20L, 20L);

    PingCollector pingTask = new PingCollector(core.getConnector(), () -> Bukkit.getOnlinePlayers()
            .stream()
            .mapToInt(BukkitUtil::getReflectionPing)
            .average()
            .orElse(0));
    scheduler.runTaskTimer(this, pingTask, 40L, 40L);

    scheduler.runTaskTimer(this, new BukkitWorldCollector(core.getConnector()), 5 * 60 * 20L, 5 * 60 * 20L);
    scheduler.runTaskTimer(this, playerCollector, 15 * 60 * 20L, 15 * 60 * 20L);
}
项目:McPlayUHC    文件:McPlayUHC.java   
public void onEnable() {
    registerListeners();
    registerCommands();
    ConfigManager.getInstance().setup(this);

    WorldBorder b = Bukkit.getWorld("world").getWorldBorder();
    b.setCenter(new Location(Bukkit.getWorld("world"), 0, 64, 0));
    b.setSize(SettingsManager.border);

    BukkitScheduler scheduler = getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
        @Override
        public void run() {
            Bukkit.broadcastMessage("loop all players: :kappa:");
            if(GameManager.getGameSituation()) {
                if(GameManager.getStartTime() + 600000 > System.currentTimeMillis()) {
                    b.setSize(b.getSize() - 1);
                }
            }
        }
    }, 0L, 1 * 20L);
}
项目:Damocles    文件:Eyepatch.java   
public void checkForEyepatchEnchant(){
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
       scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {

        @Override
        public void run() {

            for(Player player : Bukkit.getOnlinePlayers()){
                if(player.getInventory().getHelmet() != null){
                    ItemStack item = player.getInventory().getHelmet();
                    if(new ItemType(item).getArmorType().equals(ArmorTypes.HEAD)){
                        Armor detailItem = new Armor(item);
                            HashMap<Enchantments, Integer> enchantments = detailItem.getEnchantsAndLevel();
                            if(enchantments.containsKey(Enchantments.EYEPATCH)){
                                if(player.getActivePotionEffects().contains(PotionEffectType.BLINDNESS)){
                                    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 0, 0));
                                }
                            }
                    }
                }
            }

        }

       }, 0, 1);
}
项目:Breakpoint    文件:SoundManager.java   
public static void playSetForPlayers(Breakpoint plugin, BPSoundSet set, final Game game)
{
    BukkitScheduler scheduler = Bukkit.getScheduler();
    double delay = 0;

    for(final BPSound sound : set.getSounds())
    {
        scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
            @Override
            public void run()
            {
                playSoundForPlayers(game, sound);
            }
        }, (long) (delay * 20L));

        delay += sound.getLengthInSeconds();
    }
}
项目:ExilePearl    文件:PearlDecayTaskTest.java   
@Test
public void testStartStop() {
    final BukkitScheduler scheduler = TestBukkit.getServer().getScheduler();
    reset(scheduler);

    assertFalse(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, 72000, 72000);
    assertTrue(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, 72000, 72000);
    assertTrue(dut.isRunning());

    dut.stop();
    verify(scheduler).cancelTask(anyInt());
    assertFalse(dut.isRunning());
}
项目:ExilePearl    文件:CoreDamageLoggerTest.java   
@Test
public void testStartStop() {
    final BukkitScheduler scheduler = getServer().getScheduler();
    reset(scheduler);

    assertFalse(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, INTERVAL, INTERVAL);
    assertTrue(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, INTERVAL, INTERVAL);
    assertTrue(dut.isRunning());

    dut.stop();
    verify(scheduler).cancelTask(anyInt());
    assertFalse(dut.isRunning());
}
项目:ExilePearl    文件:CoreDamageLoggerTest.java   
@Test
public void testRestart() {
    final BukkitScheduler scheduler = getServer().getScheduler();
    reset(scheduler);

    when(config.getDamageLogInterval()).thenReturn(40);
    dut.loadConfig(config);

    dut.restart();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, 40, 40);
    assertTrue(dut.isRunning());

    dut.restart();
    verify(scheduler).cancelTask(anyInt());
    assertTrue(dut.isRunning());
}
项目:ExilePearl    文件:PlayerSuicideTaskTest.java   
@Test
public void testStartStop() {
    final BukkitScheduler scheduler = TestBukkit.getServer().getScheduler();
    reset(scheduler);

    assertFalse(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, PlayerSuicideTask.TICKS_PER_SECOND, PlayerSuicideTask.TICKS_PER_SECOND);
    assertTrue(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, PlayerSuicideTask.TICKS_PER_SECOND, PlayerSuicideTask.TICKS_PER_SECOND);
    assertTrue(dut.isRunning());

    dut.stop();
    verify(scheduler).cancelTask(anyInt());
    assertFalse(dut.isRunning());
}
项目:ExilePearl    文件:PearlBoundaryTaskTest.java   
@Test
public void testStartStop() {
    final BukkitScheduler scheduler = TestBukkit.getServer().getScheduler();
    reset(scheduler);

    assertFalse(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, PlayerSuicideTask.TICKS_PER_SECOND, PlayerSuicideTask.TICKS_PER_SECOND);
    assertTrue(dut.isRunning());

    dut.start();
    verify(scheduler).scheduleSyncRepeatingTask(pearlApi, dut, PlayerSuicideTask.TICKS_PER_SECOND, PlayerSuicideTask.TICKS_PER_SECOND);
    assertTrue(dut.isRunning());

    dut.stop();
    verify(scheduler).cancelTask(anyInt());
    assertFalse(dut.isRunning());
}
项目:Bukkit_Bungee_PluginLib    文件:TestObjects.java   
public static void initMockedJavaPlugin() throws Exception
{
    BukkitScheduler mockedScheduler = mock(BukkitScheduler.class);
    when(mockedScheduler.runTask(any(org.bukkit.plugin.Plugin.class), any(Runnable.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable
        {
            ((Runnable) invocationOnMock.getArguments()[1]).run();
            return null;
        }
    });
    Server mockedServer = mock(Server.class);
    when(mockedServer.getScheduler()).thenReturn(mockedScheduler);
    mockedJavaPlugin = PowerMockito.mock(JavaPlugin.class);
    when(mockedJavaPlugin.getLogger()).thenReturn(Logger.getLogger("TestLogger"));
    when(mockedJavaPlugin.getDataFolder()).thenReturn(new File(""));
    when(mockedJavaPlugin.getServer()).thenReturn(mockedServer);
}
项目:PerWorldInventory    文件:PerWorldInventoryInitializationTest.java   
@Before
public void setUpPlugin() throws IOException {
    dataFolder = temporaryFolder.newFolder();

    // Wire various Bukkit components
    setField(Bukkit.class, "server", null, server);
    given(server.getLogger()).willReturn(mock(Logger.class));
    given(server.getScheduler()).willReturn(mock(BukkitScheduler.class));
    given(server.getPluginManager()).willReturn(pluginManager);
    given(server.getVersion()).willReturn("1.9.4-RC1");

    // SettingsManager always returns the default
    given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return ((Property<?>) invocation.getArguments()[0]).getDefaultValue();
        }
    });

    // PluginDescriptionFile is final and so cannot be mocked
    PluginDescriptionFile descriptionFile = new PluginDescriptionFile(
        "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName());
    JavaPluginLoader pluginLoader = new JavaPluginLoader(server);
    plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null);
    setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class));
}
项目:Breakpoint    文件:SoundManager.java   
public static void playSetForPlayers(Breakpoint plugin, BPSoundSet set, final Game game)
{
    BukkitScheduler scheduler = Bukkit.getScheduler();
    double delay = 0;

    for(final BPSound sound : set.getSounds())
    {
        scheduler.scheduleSyncDelayedTask(plugin, new Runnable() {
            @Override
            public void run()
            {
                playSoundForPlayers(game, sound);
            }
        }, (long) (delay * 20L));

        delay += sound.getLengthInSeconds();
    }
}
项目:hooks    文件:IRCChannels.java   
@Override
public void init() {
    this.loadConfig();
    if (!this.setUpLanguage()) return;
    this.setUpAPI();
    this.registerModes();
    this.registerStages();
    this.registerCommands();
    final PluginManager pm = this.getChatterbox().getServer().getPluginManager();
    pm.registerEvents(new ChannelListener(this), this.getChatterbox());
    final BukkitScheduler bs = this.getChatterbox().getServer().getScheduler();
    bs.scheduleSyncRepeatingTask(this.getChatterbox(), new SaveChannelsTask(this), 36000L, 36000L);
    // Turn ConfigChannels into IRCConfigChannels
    this.transformConfigChannels();
    // Create saved channels and set modes on config channels
    this.loadFromIRCChannelsConfig();
    // Make sure all players join their previous channels that have just been made
    this.getChatterbox().getServer().getOnlinePlayers().stream()
        .map(player -> this.getChatterboxAPI().getPlayerAPI().getCPlayer(player))
        .forEach(CPlayer::joinPreviousChannels);
    this.getLogger().info("Loaded.");
}
项目:MobSweeper    文件:Region.java   
public void init(Plugin plugin)
{
    BukkitScheduler bs;
    PluginManager   pm;
    String          wn;

    if (radius < 1) {
        for (World w : Bukkit.getWorlds()) {
            wn = w.getName();

            if (worlds.contains(wn))
                subregions.add(new SubRegion(this, wn, 0, 0, true));
        }
    }

    if (event > 0) {
        pm = plugin.getServer().getPluginManager();
        pm.registerEvents(this, plugin);
    }

    if (sweep > 0) {
        bs     = plugin.getServer().getScheduler();
        taskid = bs.scheduleSyncRepeatingTask(plugin, this, sweep, sweep);
    }
}
项目:PerWorldInventory    文件:PerWorldInventoryInitializationTest.java   
@Before
public void setUpPlugin() throws IOException {
    dataFolder = temporaryFolder.newFolder();

    // Wire various Bukkit components
    setField(Bukkit.class, "server", null, server);
    given(server.getLogger()).willReturn(mock(Logger.class));
    given(server.getScheduler()).willReturn(mock(BukkitScheduler.class));
    given(server.getPluginManager()).willReturn(pluginManager);
    given(server.getVersion()).willReturn("1.9.4-RC1");

    // SettingsManager always returns the default
    given(settings.getProperty(any(Property.class))).willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return ((Property<?>) invocation.getArguments()[0]).getDefaultValue();
        }
    });

    // PluginDescriptionFile is final and so cannot be mocked
    PluginDescriptionFile descriptionFile = new PluginDescriptionFile(
        "PerWorldInventory", "N/A", PerWorldInventory.class.getCanonicalName());
    JavaPluginLoader pluginLoader = new JavaPluginLoader(server);
    plugin = new PerWorldInventory(pluginLoader, descriptionFile, dataFolder, null);
    setField(JavaPlugin.class, "logger", plugin, mock(PluginLogger.class));
}
项目:Annihilation    文件:PhaseManager.java   
public void start() {
    if (!isRunning) {
        BukkitScheduler scheduler = plugin.getServer().getScheduler();
        taskID = scheduler.scheduleSyncRepeatingTask(plugin,
                new Runnable() {
                    public void run() {
                        onSecond();
                    }
                }, 20L, 20L);
        isRunning = true;
    }

    time = -startTime;

    for (Player p : Bukkit.getOnlinePlayers())
        BarUtil.setMessageAndPercent(p, ChatColor.GREEN + "Starting in "
                + -time, 1F);

    plugin.getSignHandler().updateSigns(GameTeam.RED);
    plugin.getSignHandler().updateSigns(GameTeam.BLUE);
    plugin.getSignHandler().updateSigns(GameTeam.GREEN);
    plugin.getSignHandler().updateSigns(GameTeam.YELLOW);
}
项目:Stoa    文件:TaskManager.java   
public static void startThreads() {
    BukkitScheduler scheduler = Bukkit.getScheduler();

    // Start sync demigods runnable
    scheduler.scheduleSyncRepeatingTask(StoaPlugin.getInst(), SYNC, 20, 20);
    MessageUtil.sendDebug("Main Demigods SYNC runnable enabled...");

    // Start async demigods runnable
    scheduler.scheduleAsyncRepeatingTask(StoaPlugin.getInst(), ASYNC, 20, 20);
    MessageUtil.sendDebug("Main Demigods ASYNC runnable enabled...");

    // Start favor runnable
    scheduler.scheduleAsyncRepeatingTask(StoaPlugin.getInst(), FAVOR, 20, (StoaPlugin.config().getInt("regeneration_rates.favor") * 20));
    MessageUtil.sendDebug("Favor regeneration runnable enabled...");

    // Enable Deity runnables
    for (Deity deity : Stoa.getMythos().getDeities())
        for (Ability ability : deity.getAbilities())
            if (ability.getRunnable() != null)
                scheduler.scheduleSyncRepeatingTask(StoaPlugin.getInst(), ability.getRunnable(), ability.getDelay(), ability.getRepeat());

    // Triggers
    ThreadUtil.registerSyncAsyncRunnables(StoaPlugin.getInst(), Stoa.getMythos().getSyncAsyncTasks());
}
项目:MagicArenas    文件:ArenaController.java   
public void load() {
    BukkitScheduler scheduler = plugin.getServer().getScheduler();
    if (task != null) {
        task.cancel();
        task = null;
    }
    ConfigurationSection arenaConfiguration = loadDataFile("arenas");
    load(arenaConfiguration);

    ConfigurationSection arenaData = loadDataFile("data");
    loadData(arenaData);

    plugin.reloadConfig();
    Configuration config = plugin.getConfig();
    pathTemplate = config.getString("path_template", pathTemplate);
    tickInterval = config.getInt("tick_interval", 40);

    task = scheduler.runTaskTimer(plugin, this, 1, tickInterval);
}
项目:MagicArenas    文件:Arena.java   
private void countdown(final int time) {
    if (state != ArenaState.COUNTDOWN) {
        return;
    }

    if (time <= 0) {
        start();
        return;
    }

    if (time % 10 == 0 || time <= 5) {
        messageNextRoundPlayers(ChatColor.DARK_AQUA + "Match is starting in " + ChatColor.AQUA + Integer.toString(time) + ChatColor.DARK_AQUA + " seconds");
    }
    BukkitScheduler scheduler = controller.getPlugin().getServer().getScheduler();
    scheduler.runTaskLater(controller.getPlugin(), new Runnable() {
        @Override
        public void run() {
            countdown(time - 1);
        }
    }, 20);
}
项目:CrafterNexus    文件:PhaseManager.java   
public void start() {
    if (!isRunning) {
        BukkitScheduler scheduler = plugin.getServer().getScheduler();
        taskID = scheduler.scheduleSyncRepeatingTask(plugin,
                new Runnable() {
                    @Override
                    public void run() {
                        onSecond();
                    }
                }, 20L, 20L);
        isRunning = true;
    }

    time = -startTime;

    for (Player p : Bukkit.getOnlinePlayers())
        ActionAPI.sendPlayerAnnouncement(p, ChatColor.DARK_AQUA
                + "Welcome to CrafterNexus!");

    plugin.getSignHandler().updateSigns(GameTeam.RED);
    plugin.getSignHandler().updateSigns(GameTeam.BLUE);
    plugin.getSignHandler().updateSigns(GameTeam.GREEN);
    plugin.getSignHandler().updateSigns(GameTeam.YELLOW);
}
项目:tregmine    文件:SpawnCommand.java   
@Override
  public boolean handlePlayer(TregminePlayer player, String[] args)
  {
if (    (player.getWorld().getName().equalsIgnoreCase(tregmine.getRulelessWorld().getName()) ||
        player.getWorld().getName().equalsIgnoreCase(tregmine.getRulelessEnd().getName()) ||
        player.getWorld().getName().equalsIgnoreCase(tregmine.getRulelessNether().getName())) &&
        !player.getRank().canBypassWorld()) {
    if (player.isCombatLogged()) {
        player.sendMessage(ChatColor.RED + "You are combat logged... Please wait!");
        return true;
    }

    player.sendMessage(ChatColor.RED + "Teleporting to spawn... Please wait 30 seconds.");
    player.sendMessage(ChatColor.DARK_BLUE + "Oh, and don't move! Moving will stop the teleportation.");
    BukkitScheduler scheduler = plugin.getServer().getScheduler();
    scheduler.scheduleSyncDelayedTask(tregmine, new SpawnTask(player, player.getWorld().getSpawnLocation(), player.getLocation()), 20*30);
    return true;
}
      player.teleportWithHorse(player.getWorld().getSpawnLocation());
      return true;
  }
项目:MobSweeper    文件:Region.java   
public void init(Plugin plugin)
{
    BukkitScheduler bs;
    PluginManager   pm;
    String          wn;

    if (radius < 1) {
        for (World w : Bukkit.getWorlds()) {
            wn = w.getName();

            if (worlds.contains(wn))
                subregions.add(new SubRegion(this, wn, 0, 0, true));
        }
    }

    if (event > 0) {
        pm = plugin.getServer().getPluginManager();
        pm.registerEvents(this, plugin);
    }

    if (sweep > 0) {
        bs     = plugin.getServer().getScheduler();
        taskid = bs.scheduleSyncRepeatingTask(plugin, this, sweep, sweep);
    }
}
项目:AuthMeReloaded    文件:PurgeTaskTest.java   
@Test
public void shouldStopTaskAndInformConsoleUser() {
    // given
    Set<String> names = newHashSet("name1", "name2");
    PurgeTask task = new PurgeTask(purgeService, permissionsManager, null, names, new OfflinePlayer[0]);

    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitTask.getTaskId()).willReturn(10049);
    ReflectionTestUtils.setField(BukkitRunnable.class, task, "task", bukkitTask);

    Server server = mock(Server.class);
    BukkitScheduler scheduler = mock(BukkitScheduler.class);
    given(server.getScheduler()).willReturn(scheduler);
    ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
    ConsoleCommandSender consoleSender = mock(ConsoleCommandSender.class);
    given(server.getConsoleSender()).willReturn(consoleSender);

    task.run(); // Run for the first time -> results in empty names list

    // when
    task.run();

    // then
    verify(scheduler).cancelTask(task.getTaskId());
    verify(consoleSender).sendMessage(argThat(containsString("Database has been purged successfully")));
}
项目:AutoMessageDisplayer    文件:AutoMessageDisplayer.java   
private void messageManager() {
    Random randomGenerator = new Random();
    List<String> listMessages = getListMessages();
    System.out.println(listMessages.size()+" messages loaded");
    BukkitScheduler scheduler = getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            if(getConfig().getBoolean("Enable")) {
                if(Bukkit.getOnlinePlayers().size() >= getConfig().getInt(MIN_PLAYER_CONFIG)) {
                    if(!getConfig().getBoolean(RANDOM_CONFIG)) {
                        MessageManager.messageDisplayer(getPrefix() + " " + listMessages.get(iMessages));
                        iMessages++;
                        if (iMessages >= listMessages.size())
                            iMessages = 0;
                    } else {
                        MessageManager.messageDisplayer(getPrefix() + " " + listMessages.get(randomGenerator.nextInt(listMessages.size())));
                    }
                }

            }

        }

    }, 0, this.getConfig().getInt("Time")*60*20);
}
项目:ProjectAres    文件:CoreMatchModule.java   
@Override
public void enable() {
    if (this.match.getMapInfo().proto.isOlderThan(MODES_IMPLEMENTATION_VERSION)) {
        CoreConvertMonitor ccm = new CoreConvertMonitor(this);
        BukkitScheduler scheduler = this.match.getServer().getScheduler();
        this.ccmTaskId1 = scheduler.scheduleSyncDelayedTask(this.match.getPlugin(), ccm, 15*60*20); // 15 minutes
        this.ccmTaskId2 = scheduler.scheduleSyncDelayedTask(this.match.getPlugin(), ccm, 20*60*20); // 20 minutes
    }
}
项目:Eldin-Land-Plugin    文件:Main.java   
private void keepAlive() {
    BukkitScheduler scheduler = getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
        @Override
        public void run() {
            try {
                Database.getConnection().prepareStatement("SELECT 1").executeQuery();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }, 0l, 1200L);
}
项目:ADR    文件:mobs.java   
public void MobsTimer() {
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
      scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
          @Override
          public void run() {
            MobsTimerHashMap.clear();
          }
      }, 0L, Integer.valueOf(20 * getConfig().getInt("Config.MobsInSeconds.Secons")));
}
项目:AthenaGM    文件:BroadcastsModule.java   
private void startMessageCycle() {
    if (messages.size() < 1) return;
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
        public void run() {
            printMessage();
        }
    }, 1200L, 6000L);
}
项目:Damocles    文件:Jump.java   
public void checkForJumpEnchant(){
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
       scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {

        @Override
        public void run() {
            for(Player player : Bukkit.getOnlinePlayers()){
                if(player.getInventory().getBoots() != null){
                    ItemStack item = player.getInventory().getBoots();
                    if(new ItemType(item).getArmorType().equals(ArmorTypes.FEET)){
                        Armor detailItem = new Armor(item);
                            HashMap<Enchantments, Integer> enchantments = detailItem.getEnchantsAndLevel();
                            if(enchantments.containsKey(Enchantments.JUMP)){
                                int amp = 0;
                                int level = enchantments.get(Enchantments.JUMP);
                                if(level == 1){
                                    amp = 0;
                                }else if(level == 2){
                                    amp = 1;
                                }else if(level == 3){
                                    amp = 2;
                                }
                                    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, amp));
                            }
                    }
                }
            }
        }

       }, 0, 1);
}
项目:Damocles    文件:Speed.java   
public void checkForSpeedEnchant(){
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
       scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {

        @Override
        public void run() {
            for(Player player : Bukkit.getOnlinePlayers()){
                if(player.getInventory().getBoots() != null){
                    ItemStack item = player.getInventory().getBoots();
                    if(new ItemType(item).getArmorType().equals(ArmorTypes.FEET)){
                        Armor detailItem = new Armor(item);
                            HashMap<Enchantments, Integer> enchantments = detailItem.getEnchantsAndLevel();
                            if(enchantments.containsKey(Enchantments.SPEED)){
                                int amp = 0;
                                int level = enchantments.get(Enchantments.SPEED);
                                if(level == 1){
                                    amp = 0;
                                }else if(level == 2){
                                    amp = 1;
                                }else if(level == 3){
                                    amp = 2;
                                }
                                    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, amp));
                            }
                    }
                }
            }
        }

       }, 0, 1);
}
项目:Damocles    文件:BatVision.java   
public void checkForBatEnchant(){
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
       scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {

        @Override
        public void run() {

            for(Player player : Bukkit.getOnlinePlayers()){
                if(player.getInventory().getHelmet() != null){
                    ItemStack item = player.getInventory().getHelmet();

                    if(new ItemType(item).getArmorType().equals(ArmorTypes.HEAD)){
                        Armor detailItem = new Armor(item);
                        HashMap<Enchantments, Integer> enchantments = detailItem.getEnchantsAndLevel();
                        if(enchantments.containsKey(Enchantments.BAT_VISION)){
                            int amp = 0;
                            int level = enchantments.get(Enchantments.BAT_VISION);
                            if(level == 1){
                                amp = 0;
                            }
                            player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 20, amp));
                        }

                    }
                }
            }

        }

       }, 0, 1);
}
项目:DriveBackup    文件:DriveBackup.java   
/**
 * Starts the backup thread
 */
public static void startThread() {
    if (Config.getBackupDelay() / 60 / 20 != -1) {
        MessageUtil.sendConsoleMessage("Starting the backup thread for every " + Config.getBackupDelay() + " ticks.");
        BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
        scheduler.scheduleSyncRepeatingTask(getInstance(), new UploadThread(), Config.getBackupDelay(), Config.getBackupDelay());
    }
}
项目:DriveBackup    文件:CommandHandler.java   
/**
 * Reloads the configs, and tells the player it has been reloaded
 *
 * @param sender player
 */
public void reloadConfig(CommandSender sender) {
    DriveBackup.reloadLocalConfig();
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    scheduler.cancelTasks(DriveBackup.getInstance());
    DriveBackup.startThread();
    sender.sendMessage(ChatColor.GOLD + "Configs reloaded!");
}
项目:SkullGetter    文件:SkullGetter.java   
@Override
public void onEnable()
{
    instance = this;
    SkullConfigrable sGetter = new SkullConfigrable(this);
    sGetter.loadConfig();
    if ( SkullConfigrable.isEnableEconomy )
    {
        if (!setupEconomy() ) {
            log.severe(String.format("[%s] - Vaultが導入されていません!", getDescription().getName()));
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        setupPermissions();
        setupChat();
    }
    getServer().getPluginManager().registerEvents(this, this);
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();

    scheduler.scheduleSyncRepeatingTask(this, new Runnable() {

        public void run()
        {
            if ( SkullEventer.sInventory != null )
            {
                SkullEventer.sInventory.updateInventory();
            }
        }
    } , 0L, 10L);

}
项目:LagMonitor    文件:TaskInjector.java   
public static void inject(Plugin plugin) {
    BukkitScheduler scheduler = Bukkit.getScheduler();
    List<BukkitTask> pendingTasks = scheduler.getPendingTasks();
    for (BukkitTask pendingTask : pendingTasks) {
        //we could ignore async tasks for now
        if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
            FieldAccessor<Runnable> taskField = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);

            Runnable originalTask = taskField.get(pendingTask);
            TaskInjector taskInjector = new TaskInjector(originalTask);
            taskField.set(pendingTask, taskInjector);
        }
    }
}
项目:LagMonitor    文件:TaskInjector.java   
public static void uninject(Plugin plugin) {
    BukkitScheduler scheduler = Bukkit.getScheduler();
    List<BukkitTask> pendingTasks = scheduler.getPendingTasks();
    for (BukkitTask pendingTask : pendingTasks) {
        //we could ignore async tasks for now
        if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
            FieldAccessor<Runnable> taskField = Reflection.getField(pendingTask.getClass(), "task", Runnable.class);

            Runnable task = taskField.get(pendingTask);
            if (task instanceof TaskInjector) {
                taskField.set(pendingTask, ((TaskInjector) task).originalTask);
            }
        }
    }
}
项目:PerWorldInventory    文件:PWIPlayerManagerTest.java   
@BeforeInjecting
public void initSettings() {
    given(settings.getProperty(PwiProperties.SAVE_INTERVAL)).willReturn(300);

    // Add mocks for Bukkit.getScheduler, called in @PostConstruct method
    Server server = mock(Server.class);
    TestHelper.setField(Bukkit.class, "server", null, server);
    BukkitScheduler scheduler = mock(BukkitScheduler.class);
    given(server.getScheduler()).willReturn(scheduler);
}
项目:MoneyThief    文件:FanfarePlayer.java   
/**
 * Plays a natural note
 *
 * @param player  player
 * @param tone    note
 * @param octave  octave
 * @param instrum instrument
 * @param delay   delay
 */
public void natural(Player player, Tone tone, int octave, Instrument instrum, long delay) {
    final Player play = player;
    final Instrument inst = instrum;
    final Note note = Note.natural(octave, tone);
    final BukkitScheduler scheduler = MoneyThief.plugin.getServer().getScheduler();
    scheduler.scheduleSyncDelayedTask(MoneyThief.plugin, new Runnable() {

        @Override
        public void run() {
            play.playNote(play.getLocation(), inst, note);
        }

    }, delay);
}
项目:MoneyThief    文件:FanfarePlayer.java   
/**
 * Plays a sharp note
 *
 * @param player  player
 * @param tone    note
 * @param octave  octave
 * @param instrum instrument
 * @param delay   delay
 */
public void sharp(Player player, Tone tone, int octave, Instrument instrum, long delay) {
    final Player play = player;
    final Instrument inst = instrum;
    final Note note = Note.sharp(octave, tone);
    final BukkitScheduler scheduler = MoneyThief.plugin.getServer().getScheduler();
    scheduler.scheduleSyncDelayedTask(MoneyThief.plugin, new Runnable() {

        @Override
        public void run() {
            play.playNote(play.getLocation(), inst, note);
        }

    }, delay);
}
项目:MoneyThief    文件:FanfarePlayer.java   
/**
 * Plays a flat note
 *
 * @param player  player
 * @param tone    note
 * @param octave  octave
 * @param instrum instrument
 * @param delay   delay
 */
public void flat(Player player, Tone tone, int octave, Instrument instrum, long delay) {
    final Player play = player;
    final Instrument inst = instrum;
    final Note note = Note.flat(octave, tone);
    final BukkitScheduler scheduler = MoneyThief.plugin.getServer().getScheduler();
    scheduler.scheduleSyncDelayedTask(MoneyThief.plugin, new Runnable() {

        @Override
        public void run() {
            play.playNote(play.getLocation(), inst, note);
        }

    }, delay);
}