#Plugin already initialized! with BukkitRunnable timer

52 messages · Page 1 of 1 (latest)

raven flint
#

I tried to call a method in class every some time and this error pop up: https://pastebin.com/Le5D3QDW

I already tried to fix it, as you can see in the code, but it didn't work.

onEnable method and other stuff with the instance:


    @Override
    public void onEnable() {

        Scoreboard.INSTANCE = this;

        getCommand("stats").setExecutor(new commands());

        PluginManager pm = Bukkit.getServer().getPluginManager();
        pm.registerEvents(this, this);

        if (!getConfig().contains("MapClear")) {
            getConfig().set("MapClear.ClearHour", 0);
            getConfig().set("MapClear.ClearMinute", 0);

        }

        BukkitTask holoTask = new HoloTask().runTaskTimer(this, 60L, 12000);
        BukkitTask clearMapTask = new ClearMapTask().runTaskTimer(this, 60L, 1200);

    }

    public static Scoreboard getInstance() {
        return Scoreboard.INSTANCE;
    }```


ClearMapTask class:
```package me.vzduchovka.scoreboard.schedule;

import me.vzduchovka.scoreboard.Scoreboard;
import me.vzduchovka.scoreboard.functions.ClearMap;
import org.bukkit.scheduler.BukkitRunnable;

public class ClearMapTask extends BukkitRunnable {

    private static ClearMapTask INSTANCE;

    Scoreboard plugin;
    public void clearmaptask(Scoreboard plugin) {
        this.plugin = plugin;
    }

    @Override
    public void run() {
        ClearMapTask.INSTANCE = this;
        ClearMap clearmap = new ClearMap();
        clearmap.ClearMapCount();
    }

    public static ClearMapTask getInstance() {
        return ClearMapTask.INSTANCE;
    }

}```


HoloTask class:
```package me.vzduchovka.scoreboard.schedule;

import me.vzduchovka.scoreboard.Scoreboard;
import me.vzduchovka.scoreboard.functions.CreateTopKillsHologram;
import org.bukkit.scheduler.BukkitRunnable;

public class HoloTask extends BukkitRunnable {

    private static HoloTask INSTANCE;

    Scoreboard plugin;

    public void holotask(Scoreboard plugin) {
        this.plugin = plugin;
    }

    @Override
    public void run() {
        HoloTask.INSTANCE = this;
        CreateTopKillsHologram holo = new CreateTopKillsHologram();
        holo.createTopKillsHologram();
    }

    public static HoloTask getInstance() {
        return HoloTask.INSTANCE;
    }

}```

This should be everything needed. If not, tell me
shadow dockBOT
#

This post has been reserved for your question.

Hey @raven flint! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

frigid jasper
#

Could you give me the full project?

crude radish
frigid jasper
raven flint
frigid jasper
#

i am on it

raven flint
#

thanks

shadow dockBOT
# raven flint thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

frigid jasper
#

Could you provide your config.yml?

raven flint
#

currently it looks like that

  ClearHour: 0
  ClearMinute: 0
Players:
  CraftPlayer{name=vzduchovka}:
    Kills: 0
    Deaths: 0```
plain sparrow
raven flint
plain sparrow
#

I highly doubt it. Why exactly ?

raven flint
#

if I will remove it here, then this will happen

#

if here then this

frigid jasper
#

Ok i think i fixed it

frigid jasper
#

but there is more let me send you the updated version

raven flint
#

ok, but I don't really want to just copy it

#

I would like to learn something you know

frigid jasper
plain sparrow
frigid jasper
#

instead of getConfig do Scoreboard.getInstance().getConfig()

#

also you shouldt use Tread.sleep in a plugin use Bukkit.getScheduler().runTaskLater(instance, () ->{},100);

frigid jasper
#
package me.vzduchovka.scoreboard;

import me.vzduchovka.scoreboard.commands.StatsCommand;
import me.vzduchovka.scoreboard.listeners.Event1PleaseRename;
import me.vzduchovka.scoreboard.schedule.ClearMapTask;
import me.vzduchovka.scoreboard.schedule.HoloTask;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.bukkit.scheduler.BukkitTask;


public final class Scoreboard extends JavaPlugin implements @NotNull Listener {
    public static Scoreboard INSTANCE;
    private Listener ev1;

    @Override
    public void onEnable() {

        INSTANCE = this;

        getCommand("stats").setExecutor(new StatsCommand());
        ev1 = new Event1PleaseRename();
        getServer().getPluginManager().registerEvents(ev1, this);

        if (!getConfig().contains("MapClear")) {
            getConfig().set("MapClear.ClearHour", 0);
            getConfig().set("MapClear.ClearMinute", 0);

        }

        BukkitTask holoTask = new HoloTask().runTaskTimer(this, 60L, 12000);
        BukkitTask clearMapTask = new ClearMapTask().runTaskTimer(this, 60L, 1200);
        //saves the config if it doesn't exist
        saveDefaultConfig();
    }

    public static Scoreboard getInstance() {
        return INSTANCE;
    }
    @Override
    public void onDisable() {
        INSTANCE = this;
    }
}
frigid jasper
#

In this episode, I give you a brief overview of what you can expect in this MC Plugin coding series. #Spigot #MCPlugins #PluginTutorial

Java Tutorial: https://www.youtube.com/playlist?list=PLfu_Bpi_zcDPNy6qznvbkGZi7eP_0EL77
How to Setup a Test Server: https://www.youtube.com/watch?v=58MZ4THF73g&ab_channel=KodySimpson

Discord: https://rebrand.l...

▶ Play video
raven flint
frigid jasper
#

i removed added code but thats defenatly not all

raven flint
#

ok I fell little bad just copying stuff

frigid jasper
#

I used Bukkit scheduler instead of you thread.sleep saved the config on statup if it isnt there

raven flint
#

yeah ok

frigid jasper
#

the most i did was inside Clearmap

#

also i moved your event stuff in a different class

raven flint
#

ok I will go through it and try figure out something I don't understand

frigid jasper
#

ask if you have questions

raven flint
raven flint
shadow dockBOT
# raven flint ok thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

raven flint
#

I will leave this open for now if I will have any

plain sparrow
#

I recommend you have a look at this site, especially the chapters Objects, Classes, Interfaces, Packages, and Inheritance which introduces oop concepts and Classes and Objects which provides more information on classes and how to effectively use them. https://dev.java/learn/

raven flint
raven flint
frigid jasper
#

Without code i cant help

plain sparrow
#
Score l5 = objective.getScore(ChatColor.YELLOW + "☽ " + ChatColor.WHITE + "Next map clear " + ChatColor.GRAY + "- " + ChatColor.of("#fbaeae") + maphourdisplay + ChatColor.WHITE + ":" + ChatColor.of("#fbaeae") + mapminutedisplay);        
Score l5 = objective.getScore(ChatColor.YELLOW + "☽ " + ChatColor.WHITE + "Next map clear " + ChatColor.GRAY + "- " + ChatColor.of("#fbaeae") + maphourdisplay + ChatColor.WHITE + ":" + ChatColor.of("#fbaeae") + mapminutecount);

one of these two statements seems to be responsible for that error. I guess that setScore only accepts Strings smaller than 40 characters, you might need to truncate that statement

raven flint
#

but there isn't 40 character or is there ?

plain sparrow
#

i guess maphourdisplay and mapminutecount add up to 40 characters ?

raven flint
#

uh ok I will try to figure out something on myself