Problem/Bug Error in My Console

Discussion in 'Bukkit Help' started by Blaizerado, May 21, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Blaizerado

    Hey people I have a plugin written indicating an copywriting on a sign jdeoch makes this plugin problems I get the following error.



    Code:
    [20:33:14] [Server thread/INFO]: Plugin is on verion:1.0
    [20:33:14] [Server thread/INFO]: [Build] Enabling Build v1.0
    [20:33:14] [Server thread/ERROR]: Error occurred while enabling Build v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Name cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:1014) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.Bukkit.getWorld(Bukkit.java:496) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at me.build.blaizerado.build.startSign(build.java:204) ~[?:?]
        at me.build.blaizerado.build.onEnable(build.java:38) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_92]


    The Code of the Plugin
    Code:
    package me.build.blaizerado;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class build extends JavaPlugin implements Listener{
    
        HashMap<String, ItemStack[]> inventory = new HashMap<>();
        int high = 11;
        int countdown;
        int time = 30;
       
        String tag = getConfig().getString("Config.tag");
       
        @Override
        public void onDisable() {
            System.out.println("Penis");
            super.onDisable();
        }
    
        public Inventory inv = null;
       
        @Override
        public void onEnable() {
           
            startSign();
            registerEvents();
            lcomand();
            loadConfig();
           
            this.getServer().getPluginManager().registerEvents(this, this);
           
            System.out.println("§4Plugin is On");
            super.onEnable();
        }
    
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String cmdlabel, String[] args) {
            Player p = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("info")) {
                if(p.hasPermission("build.info")) {
                    p.sendMessage("§4Build:");
                    p.sendMessage("§2Version: 1.0");
                    p.setHealth(20);
                    p.setFoodLevel(20);
                    p.sendMessage( tag + "Dein Leben & Essen wurden auf 20 gesetzt");
                    return true;
                }   
               
            }
            if(cmd.getName().equalsIgnoreCase("clear")) {
                if(p.hasPermission("build.clear")) {
                    p.getInventory().clear();
                    p.sendMessage(tag + "Du hast dein Inventory Gecleart");
                    return true;
                }
            }
            if(cmd.getName().equalsIgnoreCase("medien")) {
                if(args.length == 0) {
                    p.sendMessage(tag + "Benutze: /medien youtube|ts3");
                    return true;
                }
                if(args.length == 1) {
                if(p.hasPermission("build.media")) {
                    if(args[0].equalsIgnoreCase("youtube")) {
                        p.sendMessage(tag + "youtube/blaizerado");
                        return true;
                    }
                    if(args[0].equalsIgnoreCase("ts")) {
                        p.sendMessage(tag + "Ts3 ip: ts.Blaiz-Tay.net");
                        return true;
                    }else {
                        p.sendMessage(tag + "Benutze: /medien youtube|ts3");
                        return true;
                    }
                }
            }else {
                p.sendMessage(tag + "Benutze: /medien youtube|ts3");
                return true;
            }
        }
        if(cmd.getName().equalsIgnoreCase("inv")) {
            if(args.length==0) {
                p.sendMessage( tag + "Benutze: /inv weg|wieder");
            }
            if(args.length == 1) {
            if(p.hasPermission("build.inv")) {
                if(args[0].equalsIgnoreCase("weg")) {
                    p.sendMessage( tag + "Du hast dein Inventar verstaut.");
                    inventory.put(p.getName(), p.getInventory().getContents());
                    p.getInventory().clear();
                    return true;
                }
                if(args[0].equalsIgnoreCase("wieder")) {
                    p.sendMessage(tag + "Du hast dein Inventar wieder hervor gehollt.");
                    ItemStack[] contents = inventory.get(p.getName());
                    p.getInventory().setContents(contents);
                    return true;
                }
            }
          }
        }
        if(cmd.getName().equalsIgnoreCase("back")) {
            final Location loc = p.getLocation();
            p.sendMessage(tag + "In 5 Sekunden gehts back.");
            if(p.hasPermission("build.back")) {
                Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
                    @Override
                    public void run() {
                        p.teleport(loc);
                        p.sendMessage("§2[Build]§6 Willkommen back XD.");
                    }
                }, 20*5);
                return true;
            }
        }
        if(cmd.getName().equalsIgnoreCase("gmevent")) {
            if(p.hasPermission("build.gmevemt")) {
                p.sendMessage(tag + " Du hast den Countdown gestartet");
                countdown = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                    @Override
                    public void run() {
                        if(high != 0) {
                            high--;
                            p.sendMessage(tag + "Zeit:" + high +"§6 Sekunden");
                            p.setLevel(high);
                        }else {
                            p.sendMessage(tag + "Dein Gamemode wurde geandert");
                            p.setGameMode(GameMode.CREATIVE);
                            Bukkit.getScheduler().cancelTask(countdown);
                           
                            int herz = getConfig().getInt("Config.lives");
                            p.setHealth(herz);
                           
                        }
                    }
                   
                }, 0, 20);
            }
        }
        return false;
        }
        public void loadConfig() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
        public void registerEvents() {
            new joinlist(this);
            new onLeav(this);
            new OnKick(this);
            new ArrowExplode(this);
            new InteractivListener(this);
            new iteminvlistener(this);
        }
        public void lcomand() {
            healcommand chealcommand = new healcommand(this);
            getCommand("heal").setExecutor(chealcommand);
           
            Item cItem = new Item(this);
            getCommand("item").setExecutor(cItem);
           
            CreatSpawn cCreatSpawn = new CreatSpawn(this);
            getCommand("mob").setExecutor(cCreatSpawn);
           
            FireworkCommand cFireworkCommand = new FireworkCommand(this);
            getCommand("firework").setExecutor(cFireworkCommand);
           
            Teleportcommand cTeleportcommand = new Teleportcommand(this);
            getCommand("teleport").setExecutor(cTeleportcommand);
           
            homecmd chomecmd = new homecmd(this);
            getCommand("sethome").setExecutor(chomecmd);
           
            mchomecmd cmchomecmd = new mchomecmd(this);
            getCommand("home").setExecutor(cmchomecmd);
           
            gmcommand gmcommand = new gmcommand(this);
            getCommand("gm").setExecutor(gmcommand);
           
            signcmd csigncmd = new signcmd(this);
            getCommand("gm").setExecutor(csigncmd);
        }
        public void startSign() {
            String world = this.getConfig().getString("Sign.world");
            double x = this.getConfig().getDouble("Sign.x");
            double y = this.getConfig().getDouble("Sign.y");
            double z = this.getConfig().getDouble("Sign.z");
           
            Location loc = new Location(Bukkit.getWorld(world),x,y,z);
            Block b = loc.getBlock();
           
            if(b.getState() instanceof Sign) {
                final Sign s = (Sign) b.getState();
               
                Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                    @Override
                    public void run() {
                        if(time != 0) {
                            time --;
                        }
                        if(time ==29) {
                            s.setLine(1,"Ts:Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==28) {
                            s.setLine(1,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==27) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==26) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==25) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==24) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }   
                        if(time ==23) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==22) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==21) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==20) {
                            s.setLine(1, "     Kein VIP !");
                            s.update();
                            time = 30;
                        }
                       
                    }
                   
                }, 8, 8);
               
            }
        }
    }
    

    M.F.G
    Blaizerado
    ps.
    who can speak German can also write in German
     
  2. Offline

    I Al Istannen

    @Blaizerado
    Apart from not following the naming conventions and probably some/many other things, the error is here:
    Code:
    Location loc = new Location(Bukkit.getWorld(world),x,y,z);
    The error says this here:
    " at me.build.blaizerado.build.startSign(build.java:204) ~[?:?]"

    The type of the error is a
    It was thrown by
    Vaildate.notNull is a utility function to throw an exception if you pass it a null value. It is used to catch potential errors and then throw a more fitting error message. In this case it says: "Name cannot be null" (the thing from above). This means exactly that. The world name can not be null.
    If you now look where the world name is specified, it is here:
    Conclusion: "Sign.world" in the config is not set. Check the spelling and if you ever save it.

    German (open)

    Abgesehen davon, dass du die Naming conventions nicht beachtest (und wahrscheinlich vieles mher), ist der Fehler hier:
    Code:
    Location loc = new Location(Bukkit.getWorld(world),x,y,z);
    Das steht im Fehlerbericht (wird oft stacktrace genannt. Warum ist ersteinmal egal :) Lernst du später noch.) hier:
    " at me.build.blaizerado.build.startSign(build.java:204) ~[?:?]"
    Dies ist einfach das erste Mal von OBEN, wo eine Klasse aus deinem Projekt auftaucht. Die methode die ganz oben steht, hat den Fehler verursacht. Die methoden darunter, haben jeweils die Methode darüber aufgerufen. So kann man hieraus:
    sehen, dass onEnable startSign aufgerufen hat. Da startSign der letze Code aus deinen Klassen ist, muss der Fehler also dort aufgetreten sein.

    Der Fehler ist dieser hier:
    Er wurde von
    "geworfen". Validate.notNull ist eine Hilfsmethode aus der Apachge Common library, die einfach überprüft, ob ein Paramter/Argument null ist. Wenn dies dier Fall ist, wirft sie eine neue Exception, aber mit einer anderen Nachricht. In diesem Fall: "Name cannot be null". Nun schauen wir uns einmal die Code Zeile an, die dafür verantwortlich ist (diese steht hinter Klasse im Stacktrace, in diesem fall 204):
    Der Fehler wird von der Bukkit.getWorld Methode geworfen, da der Weltname null ist. Nun müssen wir schauen, wo dieser definiert ist. Dies ist in zeile 199 der Fall:
    Der einzige Grund warum hier world null sein kann ist, wenn der pfad "Sign.world" nicht existiert. Überprüfe die Rechtschreibung und ob du das irgenwann davor einmal speicherst.
     
  3. Offline

    Blaizerado

    i have the Problem, the problem was the try catch

    i have the problem the problem was the try catch.

    Thanks I'm really sorry to ask but I can not grade java very well but thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  4. Offline

    I Al Istannen

    @Blaizerado
    I don't see a simgle try catch there? What did you do? You should PREVENT exceptions not catch them. This is the concept of an exception: It is exceptional. Catching exceptions (apart from the forced ones) often means your logic / program flow is faulty.
     
  5. Offline

    Blaizerado

    Code:
        public void startSign() {
            try {
            String world = this.getConfig().getString("sign.world");
            double x = this.getConfig().getDouble("sign.x");
            double y = this.getConfig().getDouble("sign.y");
            double z = this.getConfig().getDouble("sign.z");
            Location loc = new Location(Bukkit.getWorld(world),x,y,z);
            Block b = loc.getBlock();
            if(b.getState() instanceof Sign) {
                final Sign s = (Sign) b.getState();
              
                Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                    @Override
                    public void run() {
                        if(time != 0) {
                            time --;
                        }
                        if(time ==29) {
                            s.setLine(1,"Ts:Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==28) {
                            s.setLine(1,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==27) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==26) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==25) {
                            s.setLine(1,"      Willkommen");
                            s.setLine(2,"             auf");
                            s.setLine(3,"   Blaiz-tay.net");
                            s.update();
                        }
                        if(time ==24) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }  
                        if(time ==23) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==22) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==21) {
                            s.setLine(1,"    Wir wünschen");
                            s.setLine(2,"            euch");
                            s.setLine(3,"      Viel Spass");
                            s.update();
                        }
                        if(time ==20) {
                            s.setLine(1, "     Kein VIP !");
                            s.update();
                            time = 30;
                        }
                      
                    }
                  
                }, 20, 3);
              
            }
            } catch(Exception e) {
              
            }
     
    Last edited by a moderator: May 22, 2016
  6. Offline

    I Al Istannen

    @Blaizerado
    I am still not quite sure if you mean "cache" (Zwischenspeicher) or "catch" (try-catch block, catching exceptions, Fehler/Ausnahmen-Behandlung). But I know for sure, that this is bad:
    Code:
            } catch(Exception e) {
              
            }
    Catching everything and not outputting a single thing, will come back to bite you later. If a different error occurs, you will never see a trace of it.

    If you want to prevent the error you had, check if the path exists using MemorySection#contains(String path). Just if(!config.contains("sign.world")) { return; }. This way it will just do nothing if the path doesn't exist.

    Since 1.8 you can also just use config#set(path, Location) directly. You don't need to split it in world, x , y, and z. If you want to run it on 1.7 servers you will still need to do it though.
     
Thread Status:
Not open for further replies.

Share This Page