Why is my Scoreboard not Working?

Discussion in 'Plugin Development' started by Ver_Flix, Jan 30, 2019.

Thread Status:
Not open for further replies.
  1. I watched tons of Videos "How to write an own Plugin" and almost lerned enogh to programm my first little Plugin, but now i´m trying to use a Scoreboard but I´m not get it working......
    I´m using Windows 10 x64bit, java version 1.8.0 and the craftbukkit-1.6.4-R2.0.jar

    Main class:
    Code:
    package Minecraft.aotbt.ian;
    
    import [...]
    
    
    public class Projekt01 extends JavaPlugin {
     
     
     
        @Override
        public void onEnable() {
            this.getLogger().info("Das Plugin ist aktiviert #DankeFelix");
         
            Config();
         
         
            new EventListener(this);
        }
        public void onDisable() {
            this.getLogger().info("#Ianistsüß  XDD");
         
        }
     
        private void Config() {
            this.reloadConfig();
            this.getConfig().addDefault("Punkte.Hoellenhunde", 0);
            this.getConfig().addDefault("Punkte.Pinguine", 0 );
            this.getConfig().addDefault("Meilenstein.normal.block.block", false);
         
            this.getConfig().addDefault("Meilenstein.normal.block.punkte", 3);
         
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
            System.out.println("Config Datei wurde geladen");
        }
     
        void displayScoreboard(Player p) {
            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective obj = board.registerNewObjective("Punkte", "dummy");
         
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName(ChatColor.LIGHT_PURPLE +"Punkte:");
         
            obj.getScore(Bukkit.getOfflinePlayer( ChatColor.GOLD+"Hoellenhunde")).setScore(4);
            obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + Integer.toString( this.getConfig().getInt("Punkte.Hoellenhunde")))).setScore(3);
            obj.getScore(Bukkit.getOfflinePlayer("==============")).setScore(2);
            obj.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD +"Pinguine")).setScore(1);
            obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + Integer.toString( this.getConfig().getInt("Punkte.pinguine")) +" ")).setScore(0);
         
         
            p.setScoreboard(board);
        }
    @Override
    public boolean onCommand(Command sender, Command cmd, String commandLabel, String[] args){
    [.....]
       }
    }
    Event Listener class:
    Code:
    package Minecraft.aotbt.ian;
    
    import [...]
    
    
    public class EventListener implements Listener {
     
        Projekt01 Pr01 = new Projekt01();
        int sched;
        public EventListener(Projekt01 Pr) {
        Pr.getServer().getPluginManager().registerEvents(this, Pr);
     
        }
        @EventHandler
        public void OnJoin(PlayerJoinEvent e) {
            Pr01.displayScoreboard(e.getPlayer());
         
            if(!Bukkit.getScheduler().isCurrentlyRunning(sched)) {
                sched = Bukkit.getScheduler().scheduleSyncRepeatingTask(Pr01, new Runnable(){
                    @Override
                    public void run() {
                        Pr01.displayScoreboard(e.getPlayer());
                    }
                }, 20, 20);
            }
        }
     
    
    }
    I can Join the Server but everytime I do, I get an error :/

    Code:
    19:39:06 [INFORMATION] Ver_Flix[/127.0.0.1:53262] logged in with entity id 341 at ([world] -79.9227217467842, 100.30018066426732, 234.5465218142107)
    19:39:06 [SCHWERWIEGEND] Could not pass event PlayerJoinEvent to Projekt01 v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
            at net.minecraft.server.v1_6_R3.PlayerList.c(PlayerList.java:207)
            at net.minecraft.server.v1_6_R3.PlayerList.a(PlayerList.java:103)
            at net.minecraft.server.v1_6_R3.PendingConnection.e(PendingConnection.java:132)
            at net.minecraft.server.v1_6_R3.PendingConnection.d(PendingConnection.java:43)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:29)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:203)
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
            at Minecraft.aotbt.ian.Projekt01.displayScoreboard(Projekt01.java:63)
            at Minecraft.aotbt.ian.EventListener.OnJoin(EventListener.java:30)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
            ... 14 more
    
     
  2. In your EventListener constructor define Pr01 as the Project01 that you pass to the constructor. So
    Code:
    Pr01 = Pr;
    and do not define Pr01 as a new Project01
     
Thread Status:
Not open for further replies.

Share This Page