@Override public void enableScoreboard() { final Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); final Objective obj = board.registerNewObjective("Spigotboard", "dummy"); obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', Main.instance.getConfig().getString("title"))); new BukkitRunnable() { @Override public void run() { for(Player p : Bukkit.getOnlinePlayers()) { int count = Main.instance.getConfig().getList("text").size(); PlaceholderUtils placeholders = new PlaceholderUtils(p); for(Object text : Main.instance.getConfig().getList("text")){ obj.getScore(ChatColor.translateAlternateColorCodes('&', placeholders.replace(text.toString()))).setScore(count); count--; } p.setScoreboard(board); } } }.runTaskTimer(Main.instance, 0, 20); }
public void setTemporarySidebar(final SidebarProvider provider, final long expiration) { if (this.removed.get()) { throw new IllegalStateException("Cannot update whilst board is removed"); } this.temporaryProvider = provider; this.updateObjective(); new BukkitRunnable() { public void run() { if (PlayerBoard.this.removed.get()) { this.cancel(); return; } if (PlayerBoard.this.temporaryProvider == provider) { PlayerBoard.access$4(PlayerBoard.this, null); PlayerBoard.this.updateObjective(); } } }.runTaskLaterAsynchronously((Plugin)this.plugin, expiration); }
@EventHandler public void onPlayerRespawn(PlayerRespawnEvent event) { final Gamer g = Gamer.get(event.getPlayer()); new BukkitRunnable() { @Override public void run() { Team t = Nexus.getRotary().getCurrentMap().getTeam(g); if (t == null) { g.teleport(Nexus.getRotary().getCurrentMap().getSpawnLocation()); return; } g.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 20 * 5, 3)); g.teleport(t.getSpawnLocation()); g.run("give-kit"); } }.runTaskLater(Nexus.getPlugin(), 1); }
public void lobbyScoreboard() { ScoreboardUtil board = new ScoreboardUtil(PAData.LOBBY.getPrefix(), "lobby"); new BukkitRunnable() { @Override public void run() { if (u.getPlayer() == null) { board.reset(); cancel(); return; } if (!u.isOnline()) { board.reset(); cancel(); return; } board.setName(PAData.LOBBY.getOldPrefix()); board.text(3, "§d "); board.text(2, "Rango: §" + PACmd.Grupo.groupColor(u.getUserData().getGrupo()) + u.getUserData().getGrupo().toString()); board.text(1, "§d "); board.text(0, PACore.getIP().replace('&', '§')); board.build(u.getPlayer()); } }.runTaskTimer(PALobby.getInstance(), 1, 20); }
@Override public void onGameStart() { this.allowPVP = true; new BukkitRunnable() { public void run() { if(getAPI().getGameManager().getGameState() != GameState.INGAME) { this.cancel(); return; } for(Player player : Bukkit.getOnlinePlayers()) { if(!getAPI().getGameManager().isAlive(player)) continue; if(hill.contains(player.getLocation())) { ScoreSidebar scoreSidebar = (ScoreSidebar) getSidebar(); scoreSidebar.setScore(player, (scoreSidebar.getScore(player)+1)); } } } }.runTaskTimer(this.getAPI().getPlugin(), 0, 20L); }
@EventHandler(priority = EventPriority.MONITOR) public void afterEquipChange(final InventoryDragEvent event) { final Player player = (Player) event.getWhoClicked(); if (!InventoryManager.playerIsLoaded(player)) { return; } new BukkitRunnable() { @Override public void run() { InventoryView inventoryView = event.getView(); for (int slot : event.getRawSlots()) { ItemStack item = inventoryView.getItem(slot); if (CustomItem.isCustomItem(item)) { ItemManager.updateStats((Player) event.getWhoClicked()); } } } }.runTaskLater(RPGInventory.getInstance(), 1); }
public void spawn(OpenPlayer player) { PlayerConnection connection = player.getConnection(); connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, this.entity)); connection.sendPacket(new PacketPlayOutNamedEntitySpawn(this.entity)); // if (this.sleeping) { // connection.sendPacket(new PacketPlayOutBed(this.entity, new BlockPosition(this.entity.locX, this.entity.locY - 1, this.entity.locZ))); // } new BukkitRunnable() { @Override public void run() { connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity)); } }.runTaskLater(Main.getInstance(), 20 * 5); }
/** * Start game: discovery or get ready to start. */ public void game_start() { if (state == GameState.PRELOBBY) { event_game_preStart(); if (settings.hasDiscovery) { OMGPlayer.link.values().forEach(p -> gamePreparer.player_start_discovery(p)); event_game_discovery(); state = GameState.DISCOVERY; broadcast(ChatColor.AQUA + "You have " + (settings.discoveryLength / 20) + " seconds to discover the map."); discoveryStartDelay = new BukkitRunnable() { public void run() { game_readyToStart(); } }; discoveryStartDelay.runTaskLater(this, settings.discoveryLength); } else { OMGPlayer.link.values().forEach(p -> gamePreparer.player_start_nonDiscovery(p)); game_readyToStart(); } } }
@Override public void displayOn(Inventory inventory, int locX, int locY) { frames[0].displayOn(inventory, locX, locY); new BukkitRunnable(){ private int iterator; @Override public void run() { if (inventory.getViewers().isEmpty()) { this.cancel(); } else { nextFrame().displayOn(inventory, locX, locY); } } private final Element nextFrame() { iterator = iterator + 1 < frames.length ? iterator + 1 : 0; return frames[iterator]; } }.runTaskTimer(plugin, 1, period); }
public PlayerTab(Player player) { this.player = player; entries = new ArrayList<>(); clear(); if (!player.getScoreboard().equals(Bukkit.getScoreboardManager().getMainScoreboard())) { scoreboard = player.getScoreboard(); assemble(); } else { new BukkitRunnable() { @Override public void run() { scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); player.setScoreboard(scoreboard); assemble(); } }.runTask(PracticePlugin.getInstance()); } playerTabs.add(this); }
private void walk(Location location, Runnable callback) { this.graou.getGraouEntity().getPathfinderGoalWalkToTile().setTileToWalk(location.getX(), location.getY(), location.getZ()); new BukkitRunnable() { @Override public void run() { Optional<Entity> entity = ProximityUtils.getNearbyEntities(location, 3.0D).stream() .filter(e -> e.getUniqueId() != null) .filter(e -> e.getUniqueId() == OpeningAnimationRunnable.this.graou.getGraouEntity().getUniqueID()) .findAny(); if (entity.isPresent()) { OpeningAnimationRunnable.this.graou.getGraouEntity().getPathfinderGoalWalkToTile().cancel(); OpeningAnimationRunnable.this.hub.getServer().getScheduler().runTask(OpeningAnimationRunnable.this.hub, callback); this.cancel(); } } }.runTaskTimer(this.hub, 5L, 5L); }
public static void sendMessage(final String channel, final String msg) { if (!connected) { return; } Jedis jedis = pool.getResource(); new BukkitRunnable(){ public void run() { if (!Main.connected) { return; } try { jedis.publish(channel, msg); } catch (Exception e) { e.printStackTrace(); } jedis.close(); } }.runTaskAsynchronously(plugin); }
/** * Stop the game and reload OMGPI. */ public void game_stop() { if (state == GameState.INGAME) { OMGPlayer.link.values().forEach(p -> { if (p.team != spectatorTeam) { p.setTeam(spectatorTeam); if (p.played) player_reward(p, "winner"); } else if (p.played) player_reward(p, "loser"); p.play_sound_levelup(); }); broadcast(ChatColor.AQUA + "You will be sent to the prelobby in 10 seconds."); state = GameState.ENDING; if (infoBar != null) infoBar.removeAll(); new BukkitRunnable() { public void run() { event_game_stop(); OMGPI.instance.reload(); } }.runTaskLater(OMGPI.instance, 200L); } }
@EventHandler(ignoreCancelled=true, priority=EventPriority.LOW) /* */ public void onPlayerDeath(PlayerDeathEvent event) { /* 99 */ final Player player = event.getEntity(); /* 100 */ final Deathban deathban = this.plugin.getDeathbanManager().applyDeathBan(player, event.getDeathMessage()); /* 101 */ long remaining = deathban.getRemaining(); /* 102 */ if ((remaining <= 0L) || (player.hasPermission("hcf.deathban.bypass"))) { /* 103 */ return; /* */ } /* */ /* 106 */ if ((RESPAWN_KICK_DELAY_MILLIS <= 0L) || (remaining < RESPAWN_KICK_DELAY_MILLIS)) { /* 107 */ handleKick(player, deathban); /* 108 */ return; /* */ } /* */ /* */ /* 112 */ this.respawnTickTasks.put(player.getUniqueId(), new BukkitRunnable() /* */ { /* */ public void run() { /* 115 */ DeathbanListener.this.handleKick(player, deathban); /* */ } /* 117 */ }.runTaskLater(this.plugin, RESPAWN_KICK_DELAY_TICKS).getTaskId()); /* */ }
@Override public void postSpawn(HCF plugin) { if (this.world.addEntity((Entity)this)) { Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.GOLD + "Combat logger of " + this.getName() + " has spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ)); MinecraftServer.getServer().getPlayerList().playerFileData.load((EntityHuman)this); } else { Bukkit.getConsoleSender().sendMessage(String.format((Object)ChatColor.RED + "Combat logger of " + this.getName() + " failed to spawned at %.2f, %.2f, %.2f", this.locX, this.locY, this.locZ)); } this.removalTask = new BukkitRunnable(){ public void run() { MinecraftServer.getServer().getPlayerList().sendAll((Packet)PacketPlayOutPlayerInfo.removePlayer((EntityPlayer)LoggerEntityHuman.this.getBukkitEntity().getHandle())); LoggerEntityHuman.this.destroy(); } }.runTaskLater((Plugin)plugin, SettingsYML.COMBAT_LOG_DESPAWN_TICKS); }
@EventHandler public void onPlayerResourcePackStatus(PlayerResourcePackStatusEvent event) { if (!this.expected.contains(event.getPlayer().getUniqueId()) || event.getStatus() != PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) return; this.playMusic(event.getPlayer()); new BukkitRunnable() { @Override public void run() { if (expected.contains(event.getPlayer().getUniqueId())) playMusic(event.getPlayer()); else this.cancel(); } }.runTaskTimer(this.hub, MUSIC_LENGTH, MUSIC_LENGTH); }
@Override public void displayOn(Inventory inventory) { frames[0].displayOn(inventory); new BukkitRunnable(){ private int iterator; @Override public void run() { if (inventory.getViewers().isEmpty()) { this.cancel(); } else { nextFrame().displayOn(inventory); } } private final Pane nextFrame() { iterator = iterator + 1 < frames.length ? iterator + 1 : 0; return frames[iterator]; } }.runTaskTimer(plugin, 1, period); }
public void startListing() { if ( !active ) { scheduler = new BukkitRunnable() { @Override public void run() { if ( ( inventory.getContents()[slot] == null ) == ( lastItemStack == null ) ) { if ( lastItemStack != null && !lastItemStack.equals( inventory.getContents()[slot] ) ) { update( inventory.getContents()[slot] ); } } else { update( inventory.getContents()[slot] ); } } }; scheduler.runTaskTimer(plugin, 1L, 1L ); active = true; } }
private void doVersionCheck() { new BukkitRunnable() { @Override public void run() { try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(SPIGET_LINK).openStream()))){ JsonObject object = GSON.fromJson(reader, JsonObject.class); String currentVersion = getDescription().getVersion(); String recentVersion = object.get("name").getAsString(); if (!currentVersion.equals(recentVersion)) { getLogger().info("New version available. Your Version = " + currentVersion + ". New Version = " + recentVersion); newVersionAvailable = true; newVersion = recentVersion; } } catch (IOException e) { getLogger().info("Could not check for a new version. Perhaps the website is down?"); } } }.runTaskAsynchronously(this); }
public void setDefaultSidebar(final FSidebarProvider provider, int updateInterval) { if (!isSupportedByServer()) { return; } defaultProvider = provider; if (temporaryProvider == null) { // We have no temporary provider; update the BufferedObjective! updateObjective(); } new BukkitRunnable() { @Override public void run() { if (removed || provider != defaultProvider) { cancel(); return; } if (temporaryProvider == null) { updateObjective(); } } }.runTaskTimer(plugin, updateInterval, updateInterval); }
@EventHandler public void onPlayerTabCreateEvent(PlayerTabCreateEvent event) { if (!PracticeConfiguration.USE_TAB) { return; } PlayerTab playerTab = event.getPlayerTab(); new BukkitRunnable() { public void run() { if (playerTab == null || playerTab.getPlayer() == null || !playerTab.getPlayer().isOnline()) { this.cancel(); return; } try { updateTab(playerTab); } catch (Exception e) { e.printStackTrace(); this.cancel(); playerTab.getPlayer().sendMessage(ChatColor.RED + "Failed to load your tab info, re-join if you want to re-attempt to load it."); } } }.runTaskTimerAsynchronously(PracticePlugin.getInstance(), 0L, 10L); }
@EventHandler public void onArenaStatusUpdateEvent(final ArenaStatusUpdateEvent event){ // give every player the items of their kits if the arena is starting if(BedwarsAddonKits.kits.size() >= 1 && event.getStatusBefore() == ArenaStatus.Lobby && event.getStatus() == ArenaStatus.Running){ // wait a secound before giving him his items because if we would give them him now, they would disappear new BukkitRunnable(){ @Override public void run(){ for(Player player:event.getArena().getPlayers()){ for(ItemStack is:BedwarsAddonKits.selectedKits.get(player).getItems()) player.getInventory().addItem(is); } } }.runTaskLater(BedwarsAddonKits.plugin, 20); } }
public static void storeInventory(Player player, boolean dead) { List<String> effects = new ArrayList<>(); player.getActivePotionEffects().forEach(effect -> effects.add(effect.getType().getName() + " " + effect.getAmplifier() + " (" + TimeUtil.formatSeconds(effect.getDuration() / 20) + ")")); CachedInventory inv = getCachedInventory(player, dead); if (inventories.containsKey(player.getUniqueId())) { inventories.replace(player.getUniqueId(), inv); } else { inventories.put(player.getUniqueId(), inv); } new BukkitRunnable() { public void run() { if (inventories.containsKey(player.getUniqueId()) && inventories.get(player.getUniqueId()).getIdentifier().equals(inv.getIdentifier())) { inventories.remove(player.getUniqueId()); } } }.runTaskLater(PracticePlugin.getInstance(), 20L * 60); }
/** * Teleport a {@link FakeEndercrystal} to a specific {@link Location} in certain intervals, which is visible for all Players * * @param p the {@link Player} to teleport the {@link FakeEndercrystal} for * @param to the {@link Location} where the {@link FakeEndercrystal} should be teleported to * @param teleportCount the amount of teleportation that should be made * @param wait the amount of time to wait 'till the next teleport starts * @param endercrystal the {@link FakeEndercrystal} which should be teleported */ public static void splitTeleportBigItem(final Player p, final Location to, final int teleportCount, final long wait, final FakeEndercrystal endercrystal) { final Location currentLocation = endercrystal.getCurrentlocation(); Vector between = to.toVector().subtract(currentLocation.toVector()); final double toMoveInX = between.getX() / teleportCount; final double toMoveInY = between.getY() / teleportCount; final double toMoveInZ = between.getZ() / teleportCount; SPLIT_MAP.put(p.getName(), new BukkitRunnable() { public void run() { if (!LocationUtil.isSameLocation(currentLocation, to)) { teleportEndercrystal(p, currentLocation.add(new Vector(toMoveInX, toMoveInY, toMoveInZ)), endercrystal); } else this.cancel(); } }.runTaskTimer(AlphaLibary.getInstance(), 0, wait)); }
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { final Gamer g = Gamer.get(event.getPlayer()); if (g.getVariable("spectator") != null) return; if (g.getVariable("kit") != Kit.get("tank")) return; g.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1, 100), true); if (g.getPlayer().isSprinting()) { new BukkitRunnable() { public void run() { g.getPlayer().setSprinting(false); } }.runTaskLater(Nexus.getPlugin(), 1); } }
/** * Teleport a {@link FakeMob} to a specific {@link Location} in certain intervals, which is visible for all Players * * @param p the {@link Player} to teleport the {@link FakeMob} for * @param to the {@link Location} where the {@link FakeMob} should be teleported to * @param teleportCount the amount of teleportation that should be made * @param wait the amount of time to wait 'till the next teleport starts * @param mob the {@link FakeMob} which should be teleported */ public static void splitTeleportMob(final Player p, final Location to, final int teleportCount, final long wait, final FakeMob mob) { final Location currentLocation = mob.getCurrentlocation(); Vector between = to.toVector().subtract(currentLocation.toVector()); final double toMoveInX = between.getX() / teleportCount; final double toMoveInY = between.getY() / teleportCount; final double toMoveInZ = between.getZ() / teleportCount; SPLIT_MAP.put(p.getName(), new BukkitRunnable() { public void run() { if (!LocationUtil.isSameLocation(currentLocation, to)) { teleportMob(p, currentLocation.add(new Vector(toMoveInX, toMoveInY, toMoveInZ)), mob); } else this.cancel(); } }.runTaskTimer(AlphaLibary.getInstance(), 0, wait)); }
/** * Teleport a {@link FakeBigItem} to a specific {@link Location} in certain intervals, which is visible for all Players * * @param p the {@link Player} to teleport the {@link FakeBigItem} for * @param to the {@link Location} where the {@link FakeBigItem} should be teleported to * @param teleportCount the amount of teleportation that should be made * @param wait the amount of time to wait 'till the next teleport starts * @param item the {@link FakeBigItem} which should be teleported */ public static void splitTeleportBigItem(final Player p, final Location to, final int teleportCount, final long wait, final FakeBigItem item) { final Location currentLocation = item.getCurrentlocation(); Vector between = to.toVector().subtract(currentLocation.toVector()); final double toMoveInX = between.getX() / teleportCount; final double toMoveInY = between.getY() / teleportCount; final double toMoveInZ = between.getZ() / teleportCount; SPLIT_MAP.put(p.getName(), new BukkitRunnable() { public void run() { if (!LocationUtil.isSameLocation(currentLocation, to)) { teleportBigItem(p, currentLocation.add(new Vector(toMoveInX, toMoveInY, toMoveInZ)), item); } else this.cancel(); } }.runTaskTimer(AlphaLibary.getInstance(), 0, wait)); }
private void playTimeCounter() { new BukkitRunnable() { @Override public void run() { for (UUID uuid : playtime.keySet()) { playtime.put(uuid, playtime.get(uuid) + 1); if (playtime.get(uuid) % 3600 == 0) { if (RankManager.isPrisoner(Bukkit.getPlayer(uuid))) { Bukkit.getPlayer(uuid).setTotalExperience(Bukkit.getPlayer(uuid).getTotalExperience() + 100); } } } } }.runTaskTimer(this, 0, 20); }
private void finishEditing(Player player) { this.editKits.remove(player.getUniqueId()); ManagerHandler.getEntityHider().showAllPlayers(player); PracticeProfile profile = ManagerHandler.getPlayerManager().getPlayerProfile(player); profile.setStatus(PlayerStatus.LOBBY); GameUtils.resetPlayer(player); player.updateInventory(); new BukkitRunnable() { public void run() { player.getInventory().setContents(GameUtils.getLobbyInventory()); player.updateInventory(); } }.runTaskLater(PracticePlugin.getInstance(), 2L); ManagerHandler.getConfig().teleportToSpawn(player); player.sendMessage(ChatColor.GRAY + "You have been returned to spawn."); }
private void startTask() { this.queueTask = new BukkitRunnable() { public void run() { if (playingAmount < 0) { playingAmount = 0; } Iterator<QueueData> iterator = searchList.iterator(); while (iterator.hasNext()) { QueueData search = iterator.next(); if (!iterator.hasNext()) { continue; } QueueData found = iterator.next(); createMatch(search, found); } } }.runTaskTimer(PracticePlugin.getInstance(), 0L, 2L); }
private synchronized void createTables() { new BukkitRunnable() { public void run() { Connection connection = null; try { connection = poolManager.getConnection(); connection.prepareStatement("CREATE TABLE IF NOT EXISTS `practice_profiles` (`id` INT(11) NOT NULL AUTO_INCREMENT, `player_name` VARCHAR(16) NOT NULL, `player_uuid` VARCHAR(36) NOT NULL, `playtime` BIGINT(20) NOT NULL DEFAULT '0', `ranked_wins` INT(11) NOT NULL DEFAULT '0', `ranked_losses` INT(11) NOT NULL DEFAULT '0', `unranked_wins` INT(11) NOT NULL DEFAULT '0', `unranked_losses` INT(11) NOT NULL DEFAULT '0', `matches_played` INT(11) NOT NULL DEFAULT '0', `global_rating` INT(11) NOT NULL DEFAULT '1000', PRIMARY KEY (`id`), UNIQUE (`player_uuid`));").executeUpdate(); connection.prepareStatement("CREATE TABLE IF NOT EXISTS `practice_matches` (`id` int(11) NOT NULL AUTO_INCREMENT, `match_uuid` varchar(36) NOT NULL, `winner_name` varchar(16) NOT NULL, `winner_uuid` varchar(36) NOT NULL, `loser_name` varchar(16) NOT NULL, `loser_uuid` varchar(36) NOT NULL, `ladder` varchar(64) NOT NULL, `competitive` varchar(32) NOT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `elo_change` int(5) NOT NULL, PRIMARY KEY (`id`));").executeUpdate(); } catch (SQLException e) { if (!e.getMessage().contains("already exists")) { PracticePlugin.getInstance().getLogger().severe("Failed createTables"); e.printStackTrace(); } } finally { poolManager.close(connection, null, null); } } }.runTaskAsynchronously(PracticePlugin.getInstance()); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Deathban deathban = plugin.getDeathbanManager().applyDeathBan(player, event.getDeathMessage()); long remaining = deathban.getRemaining(); if (remaining <= 0L || player.hasPermission(DeathbanListener.DEATH_BAN_BYPASS_PERMISSION)) { return; } if (DeathbanListener.RESPAWN_KICK_DELAY_MILLIS <= 0L || remaining < DeathbanListener.RESPAWN_KICK_DELAY_MILLIS) { this.handleKick(player, deathban); return; } // Let the player see the death screen for 10 seconds this.respawnTickTasks.put(player.getUniqueId(), new BukkitRunnable() { @Override public void run() { DeathbanListener.this.handleKick(player, deathban); } }.runTaskLater(plugin, DeathbanListener.RESPAWN_KICK_DELAY_TICKS).getTaskId()); }
public SQLManager() { new BukkitRunnable() { @Override public void run() { if (loadList.size() <= 0) { return; } Iterator<String> iter = loadList.iterator(); while (iter.hasNext()) { try { Player p = Bukkit.getPlayer(UUID.fromString(iter.next())); if (p == null || !p.isOnline()) { iter.remove(); continue; } } catch (Exception e) { iter.remove(); continue; } } } }.runTaskTimer(Core.getInstance(), 0, 10); }
private void onItemDisappeared(PlayerEvent event, ItemStack item) { final Player player = event.getPlayer(); final PlayerInventory inventory = player.getInventory(); final int slotId = inventory.getHeldItemSlot(); if (!InventoryManager.playerIsLoaded(player)) { return; } if (ItemUtils.isEmpty(inventory.getItemInMainHand()) || item.equals(inventory.getItemInMainHand())) { final Slot slot = InventoryManager.getQuickSlot(slotId); if (slot != null) { new BukkitRunnable() { @Override public void run() { InventoryUtils.heldFreeSlot(player, slotId, InventoryUtils.SearchType.NEXT); inventory.setItem(slotId, slot.getCup()); } }.runTaskLater(RPGInventory.getInstance(), 1); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onInventoryClick(InventoryClickEvent event) { HumanEntity humanEntity = event.getWhoClicked(); if (humanEntity instanceof Player) { Player player = (Player) humanEntity; PearlNameFaker pearlNameFaker = itemNameFakes.get(player.getUniqueId()); if (pearlNameFaker == null) return; // Required to prevent ghost items. int heldSlot = player.getInventory().getHeldItemSlot(); if (event.getSlot() == heldSlot) { pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(player.getItemInHand()), heldSlot); } else if (event.getHotbarButton() == heldSlot) { pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(event.getCurrentItem()), event.getSlot()); new BukkitRunnable() { @Override public void run() { player.updateInventory(); } }.runTask(plugin); } } }
public boolean update(final String query) { new BukkitRunnable() { @Override public void run() { Statement statement = null; try { statement = connection.createStatement(); statement.executeUpdate(query); } catch (SQLException e) { Chat.log("MySQL update failed: " + query); e.printStackTrace(); } } }.runTaskAsynchronously(MCZone.getInstance()); return true; }
public void loadWorld() { new BukkitRunnable() { @Override public void run() { Bukkit.createWorld(new WorldCreator(getWorldName())); getWorld().setTime(6000 - (20 * 20)); for (Location l : getSpawns()) l.setWorld(getWorld()); getSpecSpawn().setWorld(getWorld()); for (Gamer g : Game.getTributes()) { g.clearVariable("parkour"); g.setVariable("moveable", true); Location next = getNextSpawn(g.getPlayer()); g.setVariable("spawn-block", next); g.teleport(next); g.setInvisible(false); g.setVariable("moveable", false); g.getPlayer().setHealth(20); g.clearInventory(); g.clearScoreboard(); } } }.runTask(SurvivalGames.getInstance()); }
public static void sendActionBar(final Player player, final String message, int duration) { sendActionBar(player, message); if (duration >= 0) { // Sends empty message at the end of the duration. Allows messages // shorter than 3 seconds, ensures precision. new BukkitRunnable() { @Override public void run() { sendActionBar(player, ""); } }.runTaskLater(plugin, duration + 1); } // Re-sends the messages every 3 seconds so it doesn't go away from the // player's screen. while (duration > 60) { duration -= 60; int sched = duration % 60; new BukkitRunnable() { @Override public void run() { sendActionBar(player, message); } }.runTaskLater(plugin, (long) sched); } }
private void handleInvisibility(Player player, Rune rune) { for(Player p : Bukkit.getOnlinePlayers()) { p.hidePlayer(player); } new BukkitRunnable() { public void run() { if(player != null && player.isOnline()) { finish(player, true); } } }.runTaskLater(plugin, 100L); }