#[HELP] Interclass Code Errors

1 messages · Page 1 of 1 (latest)

hardy spire
#

Console Error:

[BUNCH OF GIBBERISH I WONT WRITE]
Caused by: java.lang.NullPointerException: Cannot invoke "me.assailent.infancyminigames.TipQueue.tipQueueTrigger()" because "this.tipqueue" is null
        at me.assailent.infancyminigames.JoinCommand.onCommand(JoinCommand.java:26) ~[InfancyMinigames.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        ... 23 more

Join Command Code:

package me.assailent.infancyminigames;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

public class JoinCommand implements CommandExecutor {
    private final InfancyMinigames plugin;
    private TipQueue tipqueue;
    BukkitScheduler scheduler = Bukkit.getScheduler();

    public JoinCommand(InfancyMinigames plugin) {
        this.plugin = plugin;
    }


    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
        if (strings.length >= 1) {
            if (strings[0].equals("tip")) {
                Bukkit.getLogger().info("This happened immediately!");
                tipqueue.tipQueueTrigger();
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
#

TipQueue Code:

package me.assailent.infancyminigames;

import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

public class TipQueue {

    private final InfancyMinigames plugin;
    private boolean tipQueueEnabled = false;

    public TipQueue(InfancyMinigames plugin) {
        this.plugin = plugin;
    }


    int tipQueueTimerVal = 60;
    public void setTimer() {
        tipQueueTimerVal = 60;
    }
    public void tipQueueTrigger() {
        if (!tipQueueEnabled) {
            tipQueueEnabled = true;
            setTimer();
            this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, new Runnable() {
                public void run() {
                    tipQueueTimerVal--;
                    Bukkit.getLogger().info(String.valueOf(tipQueueTimerVal));
                }
            }, 0L, 20L);
        }
    }
}
#

Also I'd love to have some help with this

vague moss
#

Your tipqueue is null because you haven't initialized it?

hardy spire
vague moss
#

on your JoinCommand constructor tipqueue = new TipQueue(plugin);

hardy spire
#

Thanks that seems to have fixed it

#

@vague moss While I still got you, How do I disable a Bukkit Schedulers runTaskTimer?

vague moss
#

u can call cancel()

hardy spire
#

Thanks!

hardy spire
# vague moss u can call `cancel()`

when i put cancel in here it goes red?
Sorry for pinging you so much btw.

package me.assailent.infancyminigames;

import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

public class TipQueue {

    private final InfancyMinigames plugin;
    private boolean tipQueueEnabled = false;
    private boolean tipEnabled = false;
    public TipQueue(InfancyMinigames plugin) {
        this.plugin = plugin;
    }


    int tipQueueTimerVal = 60;
    public void setTimer() {
        tipQueueTimerVal = 60;
    }
    public void tipQueueTrigger() {
        if (!tipQueueEnabled & !tipEnabled) {
            tipQueueEnabled = true;
            setTimer();
            this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, new Runnable() {
                public void run() {
                    plugin.getLogger().info("Tip Queue Timer: " + String.valueOf(tipQueueTimerVal));
                    if (tipQueueTimerVal <= 0) {
                      cancel();
                    }
                }
            }, 0L, 20L);
        }
    }
}
vague moss
#

then change your new Runnable() to task -> and call task.cancel(); also remove run method, dont need to override.