Placeholder disabling after sometime (MVdWPlaceholderAPI)

Discussion in 'Spigot Plugin Development' started by YellowZaki, May 10, 2017.

  1. Hello, I have made a plugin to hook MVdWPlaceholderAPI and ASkyBlock. Here is the code:
    Code (Text):
    package es.yellowzaki.challengeplaceholder;

    import java.util.Map;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.NumberConversions;

    import be.maximvdw.placeholderapi.PlaceholderAPI;
    import be.maximvdw.placeholderapi.PlaceholderReplacer;
    import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
    import com.wasteofplastic.askyblock.ASkyBlockAPI;


    public class ASkyBlockChallengeHook extends JavaPlugin {
     
        @Override
        public void onEnable () {
     
            if ((Bukkit.getPluginManager().isPluginEnabled("MVdWPlaceholderAPI")) && (Bukkit.getPluginManager().isPluginEnabled("ASkyBlock"))) {
             
                PlaceholderAPI.registerPlaceholder(this, "challenges-left",
                        new PlaceholderReplacer() {

                            @Override
                            public String onPlaceholderReplace(
                                    PlaceholderReplaceEvent event) {
                             
                                Player p = event.getPlayer();
                                Map<String, Boolean> challengeStatus = ASkyBlockAPI.getInstance().getChallengeStatus(p.getUniqueId());
                                int incomplete = NumberConversions.toInt(challengeStatus.values().stream()
                                        .filter(complete -> !complete)
                                        .count());
                                return String.valueOf(incomplete);
                            }
                });
                PlaceholderAPI.registerPlaceholder(this, "challenges-done",
                        new PlaceholderReplacer() {

                            @Override
                            public String onPlaceholderReplace(
                                    PlaceholderReplaceEvent event) {
                             
                                Player p = event.getPlayer();
                                Map<String, Boolean> challengeStatus = ASkyBlockAPI.getInstance().getChallengeStatus(p.getUniqueId());
                                int completeChallenge = NumberConversions.toInt(challengeStatus.values().stream()
                                        .filter(complete -> complete)
                                        .count());
                                return String.valueOf(completeChallenge);
                            }
                });
            }
        }
    }
    It works fine on the server (challenges-left and challenges-done placeholders are replaced correctly) but after sometime, it stops working and the console shows this error:

    [10:00:49] [Craft Scheduler Thread - 13/ERROR]: [FeatherBoard] Error in placeholder: {challenges-done}
    [10:00:49] [Craft Scheduler Thread - 13/ERROR]: [FeatherBoard] Error in placeholder: {challenges-left}

    I have noticed that it happens when a user leaves the server/is kicked.
     
    #1 YellowZaki, May 10, 2017
    Last edited: Apr 8, 2018