Java Code Examples for org.bukkit.scheduler.BukkitScheduler#runTaskLater()
The following examples show how to use
org.bukkit.scheduler.BukkitScheduler#runTaskLater() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerLogin.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); player.setCanPickupItems(false); NPCManager npcManager = this.expansion.getNPCManager(); NPC npc = npcManager.getNPC(player); if(npc != null) npc.despawn(DespawnReason.PLUGIN); Runnable task = () -> { punish(player); player.setCanPickupItems(true); }; JavaPlugin plugin = this.expansion.getPlugin().getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin, task, 1L); }
Example 2
Source File: TraitCombatLogX.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@Override public void run() { if(this.ticksUntilRemove > 0) { this.ticksUntilRemove--; return; } long survivalSeconds = getSurvivalSeconds(); if(survivalSeconds < 0) return; Player enemy = getEnemy(); ICombatLogX plugin = this.expansion.getPlugin(); if(enemy != null && waitUntilEnemyEscape()) { ICombatManager combatManager = plugin.getCombatManager(); if(combatManager.isInCombat(enemy)) return; } Runnable task = () -> { NPC npc = getNPC(); npc.despawn(DespawnReason.PLUGIN); }; JavaPlugin javaPlugin = plugin.getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(javaPlugin, task, 1L); }
Example 3
Source File: BossBarManager.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public void removeBossBar(Player player, boolean onDisable) { ICombatLogX plugin = this.expansion.getPlugin(); MultiVersionHandler<?> multiVersionHandler = plugin.getMultiVersionHandler(); AbstractNMS nmsHandler = multiVersionHandler.getInterface(); BossBarHandler bossBarHandler = nmsHandler.getBossBarHandler(); if(onDisable || isDisabledGlobally() || isDisabled(player)) { bossBarHandler.removeBossBar(player); return; } String message = getEndedMessage(player); String color = getColor(); String style = getStyle(); bossBarHandler.updateBossBar(player, message, 0.0D, color, style); Runnable task = () -> bossBarHandler.removeBossBar(player); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin.getPlugin(), task, 20L); }
Example 4
Source File: ListenerLegacyItemPickup.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.items.no-pickup"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example 5
Source File: ListenerRiptide.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.no-riptide"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example 6
Source File: ListenerBlocks.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessageWithCooldown(Player player, String path) { if(player == null || path == null || path.isEmpty()) return; List<UUID> messageCooldownList = messagePathToCooldownList.getOrDefault(path, Util.newList()); UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix(path); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); messagePathToCooldownList.put(path, messageCooldownList); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> removeCooldown(player, path); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example 7
Source File: ListenerNewItemPickup.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
private void sendMessage(Player player) { if(player == null) return; UUID uuid = player.getUniqueId(); if(messageCooldownList.contains(uuid)) return; String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.items.no-pickup"); this.plugin.sendMessage(player, message); messageCooldownList.add(uuid); BukkitScheduler scheduler = Bukkit.getScheduler(); Runnable task = () -> messageCooldownList.remove(uuid); FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); long messageCooldown = 20L * config.getLong("message-cooldown"); scheduler.runTaskLater(this.plugin.getPlugin(), task, messageCooldown); }
Example 8
Source File: ListenerDamageDeath.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) public void onDespawn(NPCDespawnEvent e) { DespawnReason despawnReason = e.getReason(); if(despawnReason == DespawnReason.PENDING_RESPAWN) return; Logger logger = this.expansion.getLogger(); logger.info("[Debug] Removing NPC for reason '" + despawnReason + "'."); NPC npc = e.getNPC(); NPCManager npcManager = this.expansion.getNPCManager(); if(npcManager.isInvalid(npc)) return; TraitCombatLogX traitCombatLogX = npc.getTrait(TraitCombatLogX.class); OfflinePlayer owner = traitCombatLogX.getOwner(); if(owner == null) return; if(despawnReason == DespawnReason.DEATH) npcManager.dropInventory(npc); npcManager.saveHealth(npc); npcManager.saveLocation(npc); YamlConfiguration data = npcManager.getData(owner); data.set("citizens-compatibility.punish-next-join", true); npcManager.setData(owner, data); JavaPlugin plugin = this.expansion.getPlugin().getPlugin(); BukkitScheduler scheduler = Bukkit.getScheduler(); scheduler.runTaskLater(plugin, npc::destroy, 1L); }
Example 9
Source File: NoEntryExpansion.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
public final void preventEntry(Cancellable e, Player player, Location fromLoc, Location toLoc) { ICombatManager combatManager = getPlugin().getCombatManager(); if(!combatManager.isInCombat(player)) return; LivingEntity enemy = combatManager.getEnemy(player); sendNoEntryMessage(player, enemy); BukkitScheduler scheduler = Bukkit.getScheduler(); NoEntryHandler handler = getNoEntryHandler(); NoEntryMode noEntryMode = handler.getNoEntryMode(); switch(noEntryMode) { case KILL: player.setHealth(0.0D); break; case CANCEL: e.setCancelled(true); break; case TELEPORT: if(enemy != null) player.teleport(enemy); else e.setCancelled(true); break; case KNOCKBACK: e.setCancelled(true); scheduler.runTaskLater(getPlugin().getPlugin(), () -> knockbackPlayer(player, fromLoc, toLoc), 1L); break; case VULNERABLE: case NOTHING: default: break; } }
Example 10
Source File: EffectManager.java From EffectLib with MIT License | 4 votes |
public void start(Effect effect) { if (disposed) { throw new IllegalStateException("EffectManager is disposed and not able to accept any effects."); } if (disposeOnTermination) { throw new IllegalStateException("EffectManager is awaiting termination to dispose and not able to accept any effects."); } if (effects.containsKey(effect)) { effect.cancel(false); } if (!owningPlugin.isEnabled()) return; BukkitScheduler s = Bukkit.getScheduler(); BukkitTask task = null; switch (effect.getType()) { case INSTANT: if(effect.isAsynchronous()) { task = s.runTaskAsynchronously(owningPlugin, effect); } else { task = s.runTask(owningPlugin, effect); } break; case DELAYED: if (effect.isAsynchronous()) { task = s.runTaskLaterAsynchronously(owningPlugin, effect, effect.getDelay()); } else { task = s.runTaskLater(owningPlugin, effect, effect.getDelay()); } break; case REPEATING: if (effect.isAsynchronous()) { task = s.runTaskTimerAsynchronously(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); } else { task = s.runTaskTimer(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); } break; } synchronized (this) { effects.put(effect, task); } }