Java Code Examples for org.bukkit.Bukkit#getScheduler()

The following examples show how to use org.bukkit.Bukkit#getScheduler() . 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: ListenerNewItemPickup.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: LukkitCommand.java    From Lukkit with MIT License 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String command, String[] args) {
    if (!this.testPermissionSilent(sender)) {
        sender.sendMessage(ERROR_NO_PERMISSION);
        return true;
    }
    try {
        if (args.length > maxArgs && maxArgs >= 0) {
            sender.sendMessage(ERROR_TOO_MANY_ARGS);
        } else if (args.length < minArgs) {
            sender.sendMessage(ERROR_MISSING_ARGS);
        } else {
            if (runAsync) {
                BukkitScheduler scheduler = Bukkit.getScheduler();
                scheduler.runTaskAsynchronously(plugin, () -> function.invoke(new LuaValue[]{new CommandEvent(sender, command, args)}));
            } else {
                function.invoke(new LuaValue[]{new CommandEvent(sender, command, args)});
            }
        }
    } catch (LukkitPluginException e) {
        e.printStackTrace();
        LuaEnvironment.addError(e);
    }
    return true;
}
 
Example 3
Source File: SkullCommand.java    From ChangeSkin with MIT License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        plugin.sendMessage(sender, "no-console");
        return true;
    }

    if (args.length == 0) {
        plugin.sendMessage(sender, "select-noargs");
    } else {
        String targetName = args[0].toLowerCase().replace("skin-", "");
        try {
            Player player = (Player) sender;
            int targetId = Integer.parseInt(targetName);

            BukkitScheduler scheduler = Bukkit.getScheduler();
            scheduler.runTaskAsynchronously(plugin, () -> applySkin(player, plugin.getStorage().getSkin(targetId)));
        } catch (NumberFormatException numberFormatException) {
            plugin.sendMessage(sender, "invalid-skin-name");
        }
    }

    return true;
}
 
Example 4
Source File: NoEntryExpansion.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public final void sendNoEntryMessage(Player player, LivingEntity enemy) {
    if(player == null || enemy == null) return;

    UUID uuid = player.getUniqueId();
    if(noEntryMessageCooldownList.contains(uuid)) return;

    NoEntryHandler handler = getNoEntryHandler();
    TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB);
    String messagePath = handler.getNoEntryMessagePath(tagType);

    ICombatLogX plugin = getPlugin();
    String message = plugin.getLanguageMessageColoredWithPrefix(messagePath);
    plugin.sendMessage(player, message);

    noEntryMessageCooldownList.add(uuid);

    long cooldown = handler.getNoEntryMessageCooldown();
    long delay = (cooldown * 20L);
    BukkitScheduler scheduler = Bukkit.getScheduler();
    scheduler.runTaskLaterAsynchronously(plugin.getPlugin(), () -> noEntryMessageCooldownList.remove(uuid), delay);
}
 
Example 5
Source File: ListenerBlocks.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: ListenerRiptide.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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 7
Source File: ListenerLegacyItemPickup.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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: BossBarManager.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
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 9
Source File: TraitCombatLogX.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@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 10
Source File: ListenerLogin.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@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 11
Source File: ListenerDamageDeath.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: NoEntryExpansion.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
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 13
Source File: FlagAntiCamping.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@FlagInit
public static void initTask(HeavySpleef heavySpleef) {
	BukkitScheduler scheduler = Bukkit.getScheduler();
	
	task = new AntiCampingTask(heavySpleef);
	bukkitTask = scheduler.runTaskTimer(heavySpleef.getPlugin(), task, ONE_SECOND_INTERVAL, ONE_SECOND_INTERVAL);
}
 
Example 14
Source File: CombatLogX.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
private void registerTasks() {
    BukkitScheduler scheduler = Bukkit.getScheduler();

    CombatManager combatManager = getCombatManager();
    scheduler.runTaskTimer(this, combatManager, 0L, 10L);
}
 
Example 15
Source File: EffectManager.java    From EffectLib with MIT License 4 votes vote down vote up
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);
    }
}
 
Example 16
Source File: SimpleBasicTask.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public SimpleBasicTask(Plugin plugin, TaskType taskType, long... taskArgs) {
	this.plugin = plugin;
	this.taskType = taskType;
	this.scheduler = Bukkit.getScheduler();
	this.taskArgs = taskArgs;
}
 
Example 17
Source File: FlagTimeout.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public FlagTimeout() {
	this.scheduler = Bukkit.getScheduler();
}
 
Example 18
Source File: CommandCombatLogX.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
private boolean versionCommand(CommandSender sender, String[] args) {
    if(checkNoPermission(sender, "combatlogx.command.combatlogx.version")) return true;

    if(args.length < 1) {
        Runnable task = () -> checkVersion(sender);
        this.plugin.sendMessage(sender, "Getting version information for CombatLogX...");

        BukkitScheduler scheduler = Bukkit.getScheduler();
        scheduler.runTaskAsynchronously(this.plugin, task);
        return true;
    }

    String expansionName = args[0];
    ExpansionManager expansionManager = this.plugin.getExpansionManager();

    Optional<Expansion> optionalExpansion = expansionManager.getExpansionByName(expansionName);
    if(!optionalExpansion.isPresent()) {
        sender.sendMessage("Could not find an expansion with the name '" + expansionName + "'.");
        return true;
    }
    
    Expansion expansion = optionalExpansion.get();
    State state = expansion.getState();
    ExpansionDescription description = expansion.getDescription();
    
    expansionName = description.getName();
    String displayName = description.getDisplayName();
    String version = description.getVersion();
    String descriptionText = description.getDescription();
    List<String> authorList = description.getAuthors();
    String authorString = String.join(", ", authorList);
    
    List<String> messageList = new ArrayList<>();
    messageList.add(MessageUtil.color("&6&lExpansion Information for &e" + expansionName));
    messageList.add(MessageUtil.color("&6&lState:&e " + state.name()));
    messageList.add(MessageUtil.color("&6&lVersion:&e " + version));
    
    if(displayName != null) messageList.add(MessageUtil.color("&6&lDisplay Name:&e " + displayName));
    if(descriptionText != null) messageList.add(MessageUtil.color("&6&lDescription:&e " + descriptionText));
    if(!authorList.isEmpty()) messageList.add(MessageUtil.color("&6&lAuthors:&e " + authorString));
    
    messageList.forEach(message -> this.plugin.sendMessage(sender, message));
    return true;
}