类org.bukkit.scheduler.BukkitRunnable源码实例Demo

下面列出了怎么用org.bukkit.scheduler.BukkitRunnable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: LuckPerms   文件: PluginMessageMessenger.java
@Override
public void sendOutgoingMessage(@NonNull OutgoingMessage outgoingMessage) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(outgoingMessage.asEncodedString());
    byte[] data = out.toByteArray();

    new BukkitRunnable() {
        @Override
        public void run() {
            Collection<? extends Player> players = PluginMessageMessenger.this.plugin.getBootstrap().getServer().getOnlinePlayers();
            Player p = Iterables.getFirst(players, null);
            if (p == null) {
                return;
            }

            p.sendPluginMessage(PluginMessageMessenger.this.plugin.getBootstrap(), CHANNEL, data);
            cancel();
        }
    }.runTaskTimer(this.plugin.getBootstrap(), 1L, 100L);
}
 
源代码2 项目: EliteMobs   文件: AttackWeb.java
@EventHandler
public void attackWeb(EntityDamageByEntityEvent event) {

    EliteMobEntity eliteMobEntity = EventValidator.getEventEliteMob(this, event);
    if (eliteMobEntity == null) return;
    Player player = EntityFinder.findPlayer(event);
    if (PowerCooldown.isInCooldown(eliteMobEntity, cooldownList)) return;

    Block block = player.getLocation().getBlock();
    Material originalMaterial = block.getType();

    if (!originalMaterial.equals(Material.AIR))
        return;

    block.setType(Material.WEB);

    new BukkitRunnable() {
        @Override
        public void run() {
            block.setType(originalMaterial);
        }
    }.runTaskLater(MetadataHandler.PLUGIN, 20 * 3);

    PowerCooldown.startCooldownTimer(eliteMobEntity, cooldownList, 3 * 20);

}
 
源代码3 项目: PlayerSQL   文件: EventExecutor.java
private void receiveContents(Player player, PlayerSqlProtocol packet) {
    main.debug("recv data_buf");
    DataSupply dataSupply = (DataSupply) packet;
    if (dataSupply.getBuf() == null || dataSupply.getBuf().length == 0 || !group.equals(dataSupply.getGroup())) {
        return;
    }
    PlayerData data = PlayerDataHelper.decode(dataSupply.getBuf());
    BukkitRunnable pend = (BukkitRunnable) pending.remove(dataSupply.getId());
    if (pend == null) {
        main.debug("pending received data_buf");
        pending.put(dataSupply.getId(), data);
    } else {
        main.debug("process received data_buf");
        pend.cancel();
        main.run(() -> {
            manager.pend(player, data);
            runAsync(() -> manager.updateDataLock(dataSupply.getId(), true));
        });
    }
}
 
源代码4 项目: XSeries   文件: XParticle.java
/**
 * A sin/cos based smoothly animated explosion wave.
 * Source: https://www.youtube.com/watch?v=n8W7RxW5KB4
 *
 * @param rate the distance between each cos/sin lines.
 * @since 1.0.0
 */
public static void explosionWave(JavaPlugin plugin, double rate, ParticleDisplay display, ParticleDisplay secDisplay) {
    new BukkitRunnable() {
        final double addition = Math.PI * 0.1;
        final double rateDiv = Math.PI / rate;
        double times = Math.PI / 4;

        public void run() {
            times += addition;
            for (double theta = 0; theta <= PII; theta += rateDiv) {
                double x = times * Math.cos(theta);
                double y = 2 * Math.exp(-0.1 * times) * Math.sin(times) + 1.5;
                double z = times * Math.sin(theta);
                display.spawn(x, y, z);

                theta = theta + Math.PI / 64;
                x = times * Math.cos(theta);
                //y = 2 * Math.exp(-0.1 * times) * Math.sin(times) + 1.5;
                z = times * Math.sin(theta);
                secDisplay.spawn(x, y, z);
            }

            if (times > 20) cancel();
        }
    }.runTaskTimerAsynchronously(plugin, 0L, 1L);
}
 
源代码5 项目: ZombieEscape   文件: Door.java
/**
 * Opens the Door Open at a given sign. The
 * door will stay open for 10 seconds, then
 * will close once more.
 *
 * @param plugin the plugin instance
 * @param sign   the sign that was interacted with
 */
public void open(Plugin plugin, final Sign sign) {
    section.clear();
    sign.setLine(2, Utils.color("&4&lRUN!"));
    sign.update();

    if (nukeroom) {
        Messages.NUKEROOM_OPEN_FOR.broadcast();
    } else {
        Messages.DOOR_OPENED.broadcast();
    }

    new BukkitRunnable() {
        @Override
        public void run() {
            activated = false;
            section.restore();
            sign.setLine(1, "Timer: " + seconds + "s");
            sign.setLine(2, "CLICK TO");
            sign.setLine(3, "ACTIVATE");
            sign.update();
        }
    }.runTaskLater(plugin, 20 * 10);
}
 
源代码6 项目: TabooLib   文件: THologramHandler.java
public static void learn(Player player) {
    NMS.handle().spawn(player.getLocation(), ArmorStand.class, c -> {
        learnTarget = c;
        learnTarget.setMarker(true);
        learnTarget.setVisible(false);
        learnTarget.setCustomName(" ");
        learnTarget.setCustomNameVisible(true);
        learnTarget.setBasePlate(false);
    });
    reset();
    new BukkitRunnable() {
        @Override
        public void run() {
            THologramSchedule schedule = queueSchedule.peek();
            if (schedule == null) {
                cancel();
                learnTarget.remove();
            } else if (schedule.check()) {
                currentSchedule = queueSchedule.poll();
                currentSchedule.before();
            }
        }
    }.runTaskTimer(TabooLib.getPlugin(), 1, 1);
}
 
源代码7 项目: SkyWarsReloaded   文件: DoubleDamageEvent.java
@Override
public void doEvent() {
	if (gMap.getMatchState() == MatchState.PLAYING) {
		this.fired = true;
		sendTitle();
		gMap.setDoubleDamageEnabled(true);
		if (length != -1) {
			br = new BukkitRunnable() {
				@Override
				public void run() {
					endEvent(false);
				}
			}.runTaskLater(SkyWarsReloaded.get(), length * 20L);
		}
	}
}
 
源代码8 项目: QuickShop-Reremake   文件: DatabaseManager.java
/**
 * Queued database manager. Use queue to solve run SQL make server lagg issue.
 *
 * @param plugin plugin main class
 * @param db     database
 */
public DatabaseManager(@NotNull QuickShop plugin, @NotNull Database db) {
    this.plugin = plugin;
    this.warningSender = new WarningSender(plugin, 600000);
    this.database = db;
    this.useQueue = plugin.getConfig().getBoolean("database.queue");

    if (!useQueue) {
        return;
    }
    try {
        task =
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        plugin.getDatabaseManager().runTask();
                    }
                }.runTaskTimerAsynchronously(plugin, 1, plugin.getConfig().getLong("database.queue-commit-interval") * 20);
    } catch (IllegalPluginAccessException e) {
        Util.debugLog("Plugin is disabled but trying create database task, move to Main Thread...");
        plugin.getDatabaseManager().runTask();
    }
}
 
源代码9 项目: NyaaUtils   文件: SitListener.java
@EventHandler
public void onDismount(EntityDismountEvent event) {
    if (event.getDismounted() instanceof ArmorStand) {
        ArmorStand armorStand = (ArmorStand) event.getDismounted();
        if (armorStand.hasMetadata(metadata_key)) {
            for (Entity p : armorStand.getPassengers()) {
                if (p.isValid()) {
                    Location loc = safeLocations.get(p.getUniqueId());
                    safeLocations.remove(p.getUniqueId());
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            if (p.isValid() && loc != null) {
                                p.teleport(loc);
                            }
                        }
                    }.runTask(plugin);
                }
            }
        }
        armorStand.remove();
    }
}
 
源代码10 项目: ce   文件: Tools.java
public static void applyBleed(final Player target, final int bleedDuration) {
    target.sendMessage(ChatColor.RED + "You are Bleeding!");
    target.setMetadata("ce.bleed", new FixedMetadataValue(Main.plugin, null));
    new BukkitRunnable() {

        int seconds = bleedDuration;

        @Override
        public void run() {
            if (seconds >= 0) {
                if (!target.isDead() && target.hasMetadata("ce.bleed")) {
                    target.damage(1 + (((Damageable) target).getHealth() / 15));
                    seconds--;
                } else {
                    target.removeMetadata("ce.bleed", Main.plugin);
                    this.cancel();
                }
            } else {
                target.removeMetadata("ce.bleed", Main.plugin);
                target.sendMessage(ChatColor.GREEN + "You have stopped Bleeding!");
                this.cancel();
            }
        }
    }.runTaskTimer(Main.plugin, 0l, 20l);

}
 
源代码11 项目: ShopChest   文件: ShopUpdateListener.java
@EventHandler
public void onPlayerLeave(PlayerQuitEvent e) {
    // If done without delay, Bukkit#getOnlinePlayers() would still
    // contain the player even though he left, so the shop updater
    // would show the shop again.
    new BukkitRunnable(){
        @Override
        public void run() {
            for (Shop shop : plugin.getShopUtils().getShops()) {
                if (shop.hasItem()) {
                    shop.getItem().resetVisible(e.getPlayer());
                }
                if (shop.hasHologram()) {
                    shop.getHologram().resetVisible(e.getPlayer());
                }
            }
    
            plugin.getShopUtils().resetPlayerLocation(e.getPlayer());
        }
    }.runTaskLater(plugin, 1L);
}
 
源代码12 项目: Crazy-Crates   文件: Main.java
@EventHandler
public void onJoin(PlayerJoinEvent e) {
    Player player = e.getPlayer();
    cc.setNewPlayerKeys(player);
    cc.loadOfflinePlayersKeys(player);
    new BukkitRunnable() {
        @Override
        public void run() {
            if (player.getName().equals("BadBones69")) {
                player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Crates Plugin. " + "&7It is running version &av" + Methods.plugin.getDescription().getVersion() + "&7."));
            }
            if (player.isOp() && updateChecker) {
                Methods.hasUpdate(player);
            }
        }
    }.runTaskLaterAsynchronously(this, 40);
}
 
源代码13 项目: QualityArmory   文件: GunUtil.java
public static void addRecoil(final Player player, final Gun g) {
	if (g.getRecoil() == 0)
		return;
	if (g.getFireRate() >= 4) {
		if (highRecoilCounter.containsKey(player.getUniqueId())) {
			highRecoilCounter.put(player.getUniqueId(),
					highRecoilCounter.get(player.getUniqueId()) + g.getRecoil());
		} else {
			highRecoilCounter.put(player.getUniqueId(), g.getRecoil());
			new BukkitRunnable() {
				@Override
				public void run() {
					if (QAMain.hasProtocolLib && QAMain.isVersionHigherThan(1, 13) && !QAMain.hasViaVersion) {
						addRecoilWithProtocolLib(player, g, true);
					} else
						addRecoilWithTeleport(player, g, true);
				}
			}.runTaskLater(QAMain.getInstance(), 3);
		}
	} else {
		if (QAMain.hasProtocolLib && QAMain.isVersionHigherThan(1, 13)) {
			addRecoilWithProtocolLib(player, g, false);
		} else
			addRecoilWithTeleport(player, g, false);
	}
}
 
源代码14 项目: HoloAPI   文件: SimpleImageLoader.java
private ImageGenerator prepareUrlGenerator(final CommandSender sender, final String key) {
    UnloadedImageStorage data = this.URL_UNLOADED.get(key);
    HoloAPI.LOG.info("Loading custom URL image of key " + key);
    this.URL_UNLOADED.remove(key);
    final ImageGenerator g = new ImageGenerator(key, data.getImagePath(), data.getImageHeight(), data.getCharType(), false, data.requiresBorder());
    new BukkitRunnable() {
        @Override
        public void run() {
            g.loadUrlImage();
            if (sender != null) {
                Lang.IMAGE_LOADED.send(sender, "key", key);
            }
            HoloAPI.LOG.info("Custom URL image '" + key + "' loaded.");
            KEY_TO_IMAGE_MAP.put(key, g);
        }
    }.runTaskAsynchronously(HoloAPI.getCore());
    return g;
}
 
源代码15 项目: PlayerVaults   文件: VaultPreloadListener.java
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    final UUID uuid = event.getPlayer().getUniqueId();
    new BukkitRunnable() {
        @Override
        public void run() {
            vm.cachePlayerVaultFile(uuid.toString());
        }
    }.runTaskAsynchronously(PlayerVaults.getInstance());
}
 
源代码16 项目: BedwarsRel   文件: Game.java
private void startActionBarRunnable() {
  if (BedwarsRel.getInstance().getBooleanConfig("show-team-in-actionbar", false)) {
    try {
      Class<?> clazz = Class.forName("io.github.bedwarsrel.com."
          + BedwarsRel.getInstance().getCurrentVersion().toLowerCase() + ".ActionBar");
      final Method sendActionBar =
          clazz.getDeclaredMethod("sendActionBar", Player.class, String.class);

      BukkitTask task = new BukkitRunnable() {

        @Override
        public void run() {
          for (Team team : Game.this.getTeams().values()) {
            for (Player player : team.getPlayers()) {
              try {
                sendActionBar.invoke(null, player,
                    team.getChatColor() + BedwarsRel._l(player, "ingame.team") + " " + team
                        .getDisplayName());
              } catch (IllegalAccessException | IllegalArgumentException
                  | InvocationTargetException e) {
                BedwarsRel.getInstance().getBugsnag().notify(e);
                e.printStackTrace();
              }
            }
          }
        }
      }.runTaskTimer(BedwarsRel.getInstance(), 0L, 20L);
      this.addRunningTask(task);
    } catch (Exception ex) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      ex.printStackTrace();
    }
  }
}
 
源代码17 项目: ce   文件: Bombardment.java
@SuppressWarnings("deprecation")
   @Override
public void effect(Event e, ItemStack item, final int level) {
	if(e instanceof EntityDamageByEntityEvent) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	Entity target = event.getEntity();

	final World world = target.getWorld();
	Vector vec = new Vector(0, -5, 0);
	Location spawnLocation = new Location(world, target.getLocation().getX(), 255, target.getLocation().getZ());
	final FallingBlock b = world.spawnFallingBlock(spawnLocation, 46, (byte) 0x0);
	b.setVelocity(vec);

	new BukkitRunnable() {

		Location	l	= b.getLocation();

		@Override
		public void run() {
			l = b.getLocation();
			if(b.isDead()) {
				l.getBlock().setType(Material.AIR);
				for(int i = 0; i <= TNTAmount + level; i++) {
					TNTPrimed tnt = world.spawn(l, TNTPrimed.class);
					tnt.setFuseTicks(0);
					if(!Main.createExplosions)
						tnt.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null));
				}
				this.cancel();
			}
			
			EffectManager.playSound(l, "ENTITY_ENDERDRAGON_GROWL", Volume, 2f);
		}
	}.runTaskTimer(getPlugin(), 0l, 5l);
	}
}
 
源代码18 项目: EchoPet   文件: EntityZombiePet.java
public EntityZombiePet(World world, IPet pet) {
    super(world, pet);
    new BukkitRunnable() {
        @Override
        public void run() {
            setEquipment(0, new ItemStack(Items.IRON_SPADE));
        }
    }.runTaskLater(EchoPet.getPlugin(), 5L);
}
 
源代码19 项目: SkyWarsReloaded   文件: GameMap.java
public static void editMap(GameMap gMap, Player player) {
   	if (gMap.isRegistered()) {
		gMap.unregister(true);
		new BukkitRunnable() {
			@Override
			public void run() {
				startEdit(gMap, player);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 20);
	} else {
		startEdit(gMap, player);
	}
}
 
源代码20 项目: BedWars   文件: BungeeUtils.java
public static void movePlayerToBungeeServer(Player player, boolean serverRestart) {
    if (serverRestart) {
        internalMove(player);
        return;
    }

    new BukkitRunnable() {
        public void run() {
           internalMove(player);
        }
    }.runTask(Main.getInstance());
}
 
源代码21 项目: BedWars   文件: BungeeUtils.java
public static void sendPlayerBungeeMessage(Player player, String string) {
    new BukkitRunnable() {
        public void run() {
            ByteArrayDataOutput out = ByteStreams.newDataOutput();

            out.writeUTF("Message");
            out.writeUTF(player.getName());
            out.writeUTF(string);

            Bukkit.getServer().sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray());
        }
    }.runTaskLater(Main.getInstance(), 30L);
}
 
源代码22 项目: SonarPet   文件: AbstractEntityZombiePet.java
@Override
public void initiateEntityPet() {
    super.initiateEntityPet();
    new BukkitRunnable() {
        @Override
        public void run() {
            //noinspection deprecation - 1.8.8 compatibility
            getBukkitEntity().getEquipment().setItemInHand(new ItemStack(getInitialItemInHand()));
        }
    }.runTaskLater(EchoPet.getPlugin(), 5L);
}
 
源代码23 项目: uSkyBlock   文件: uSkyBlock.java
private void generateIsland(final Player player, final PlayerInfo pi, final Location next, final String cSchem) {
    if (!perkLogic.getSchemes(player).contains(cSchem)) {
        player.sendMessage(tr("\u00a7eYou do not have access to that island-schematic!"));
        orphanLogic.addOrphan(next);
        return;
    }
    final PlayerPerk playerPerk = new PlayerPerk(pi, perkLogic.getPerk(player));
    player.sendMessage(tr("\u00a7eGetting your island ready, please be patient, it can take a while."));
    BukkitRunnable createTask = new CreateIslandTask(this, player, playerPerk, next, cSchem);
    IslandInfo tempInfo = islandLogic.createIslandInfo(LocationUtil.getIslandName(next), pi.getPlayerName());
    WorldGuardHandler.protectIsland(this, player, tempInfo);
    islandLogic.clearIsland(next, createTask);
}
 
源代码24 项目: Quests   文件: PermissionTaskType.java
@Override
public void onReady() {
    this.poll = new BukkitRunnable() {
        @Override
        public void run() {
            for (Player player : Bukkit.getOnlinePlayers()) {
                QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
                QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
                for (Quest quest : PermissionTaskType.super.getRegisteredQuests()) {
                    if (questProgressFile.hasStartedQuest(quest)) {
                        QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
                        for (Task task : quest.getTasksOfType(PermissionTaskType.super.getType())) {
                            TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                            if (taskProgress.isCompleted()) {
                                continue;
                            }
                            String permission = (String) task.getConfigValue("permission");
                            if (permission != null) {
                                if (player.hasPermission(permission)) {
                                    taskProgress.setCompleted(true);
                                }
                            }
                        }
                    }
                }
            }
        }
    }.runTaskTimer(Quests.get(), 30L, 30L);
}
 
源代码25 项目: BedWars   文件: RescuePlatform.java
@Override
public void runTask() {
    new BukkitRunnable() {

        @Override
        public void run() {
            livingTime++;
            int time = breakingTime - livingTime;

            if (time < 6 && time > 0) {
                MiscUtils.sendActionBarMessage(
                        player, i18nonly("specials_rescue_platform_destroy").replace("%time%", Integer.toString(time)));
            }

            if (livingTime == breakingTime) {
                for (Block block : platformBlocks) {
                    block.getChunk().load(false);
                    block.setType(Material.AIR);

                    removeBlockFromList(block);
                    game.getRegion().removeBlockBuiltDuringGame(block.getLocation());

                }
                game.unregisterSpecialItem(RescuePlatform.this);
                this.cancel();
            }
        }
    }.runTaskTimer(Main.getInstance(), 20L, 20L);
}
 
源代码26 项目: EnchantmentsEnhance   文件: PlayerStreamListener.java
/**
 * When a player gets kicked off the server, listener saves a player's data
 * from hashmap to file, but will not write to disk.
 *
 * @param e
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onKick(PlayerKickEvent e) {
    if (PlayerStatsManager.getPlayerStats(e.getPlayer().getName()) != null) {
        new BukkitRunnable() {
            @Override
            public void run() {
                PlayerStatsManager.removePlayerStats(e.getPlayer().getName());
            }
        }.runTaskLater(Main.getMain(), 20);
    }
}
 
源代码27 项目: BetonQuest   文件: InventoryConvIO.java
@EventHandler(ignoreCancelled = true)
public void onClose(InventoryCloseEvent event) {
    if (!(event.getPlayer() instanceof Player)) {
        return;
    }
    if (!event.getPlayer().equals(player)) {
        return;
    }

    // allow for closing previous option inventory
    if (switching) {
        return;
    }
    // allow closing when the conversation has finished
    if (allowClose) {
        HandlerList.unregisterAll(this);
        return;
    }
    if (conv.isMovementBlock()) {
        new BukkitRunnable() {
            public void run() {
                player.teleport(loc);
                player.openInventory(inv);
            }
        }.runTask(BetonQuest.getInstance());
    } else {
        conv.endConversation();
        HandlerList.unregisterAll(this);
    }
}
 
源代码28 项目: EliteMobs   文件: Invisibility.java
@Override
public void applyPowers(Entity entity) {
    new BukkitRunnable() {
        @Override
        public void run() {
            ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
        }
    }.runTaskLater(MetadataHandler.PLUGIN, 1);
}
 
源代码29 项目: QualityArmory   文件: QualityArmory.java
public static GunYML createAndLoadNewGun(String name, String displayname, Material material, int id,
		WeaponType type, WeaponSounds sound, boolean hasIronSights, String ammotype, int damage, int maxBullets,
		int cost) {
	File newGunsDir = new File(QAMain.getInstance().getDataFolder(), "newGuns");
	final File gunFile = new File(newGunsDir, name);
	new BukkitRunnable() {
		public void run() {
			GunYMLLoader.loadGuns(QAMain.getInstance(), gunFile);
		}
	}.runTaskLater(QAMain.getInstance(), 1);
	return GunYMLCreator.createNewCustomGun(QAMain.getInstance().getDataFolder(), name, name, displayname, id, null,
			type, sound, hasIronSights, ammotype, damage, maxBullets, cost).setMaterial(material);
}
 
源代码30 项目: SkyWarsReloaded   文件: PlayerQuitListener.java
@EventHandler
   public void onPlayerQuit(final PlayerQuitEvent a1) {
	final String id = a1.getPlayer().getUniqueId().toString();
	Party party = Party.getParty(a1.getPlayer());
	if (party != null) {
		party.removeMember(a1.getPlayer());
	}
	final GameMap gameMap = MatchManager.get().getPlayerMap(a1.getPlayer());
	if (gameMap == null) {
		new BukkitRunnable() {
			@Override
			public void run() {
				PlayerStat.removePlayer(id);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 5);
		return;
	}

	MatchManager.get().playerLeave(a1.getPlayer(), DamageCause.CUSTOM, true, true, true);

	if (PlayerStat.getPlayerStats(id) != null) {
		new BukkitRunnable() {
			@Override
			public void run() {
				PlayerStat.removePlayer(id);
			}
		}.runTaskLater(SkyWarsReloaded.get(), 20);
	}
}
 
 类所在包
 同包方法