Random Items in Cheats, nothing happens while right clicking the block

Discussion in 'Spigot Plugin Development' started by GoRoK, Jun 13, 2016.

  1. Hey!
    So i tried to do the "Random Chests" plugin, but when i click EMERALD_BLOCK, for me. Nothing happens
    Heres the "Main.class"
    And heres the Listener:
     
  2. 1. Learn java (I told you x-times)
    2. I do not recommend you "lonzbonz". He doesn't know java too.
    3. You forgot to register your listener.
    4. Use in the next time code tags
     
  3. 1. Learn java (I told you x-times) im trying.
    2. I do not recommend you "lonzbonz". He doesn't know java too. i searched on the internet and tried to do it.
    3. You forgot to register your listener. i cant. message: "The constructor ChestListener() is undefined" with the command:
    Code (Text):
     getServer().getPluginManager().registerEvents(new ChestListener(), this);
    4. Use in the next time code tags Thanks for the tip
     
  4. Choco

    Moderator

    1. No you are not. You are attempting to learn the Bukkit/Spigot API. That is Java, yes, but it is not the basics of Java. If you knew the basics of Java, #3 would not be an issue for you
    2. It's best to use books as a resource as those are documented properly. Javadocs are also a thing; both for Java and for Spigot
    3. You have a constructor in the listener class that takes an instance parameter of your main class. new ChestListener(this). Again... if you knew Java, you would have known that
    4. Yea... nothing much on that :p I agree
     
  5. Thanks for the Infos, already ordered a book for Java, still dont know the problem in here... I removed the Constructor
    Code (Text):
     
    private Main plugin;
       
        public ChestListener(Main plugin)
        {
            this.plugin = plugin;
        }
     
    And added the
    Code (Text):
     getServer().getPluginManager().registerEvents(new ChestListener(), this);
    Im feeling dumb, so, you dont have to tell me. Thanks. Still needing help
     
  6. Choco

    Moderator

    Put the constructor back :p You want it
    To register it, use instead
    The constructor has a necessary parameter of an instance of your main class. That's why you're putting "this" because that's what you're passing in as an instance
     
  7. Thanks for the Help, but still doesnt work, ti think the Plugin isnt even loading correctly. Because in onEnable there is:
    Code (Text):

    public void OnEnable()
        {
            super.onEnable();
            loadConfig();
           
           
           
           
           
            // Commands
            new ChestListener(this);
           
           
           
            //Commandsend
            String pluginName = this.getDescription().getName();
            String Version = this.getDescription().getVersion();
            String website = this.getDescription().getWebsite();
            System.out.println(pluginName + " geladen, " + "Version: " + Version);
            System.out.println("Website: " + website);
        }
    # Edited a bit
     
    But in the Console there is just "[NIROXKISTEN] ENABLING NIROXKISTEN v1.0.0"
     
  8. The method name should be "onEnable"..
     
  9. Changed it thanks, still not working though.

    Error.. Dont know what to do, again..
    Code (Text):

    [17:10:19 ERROR]: [NIROXKISTEN] Cannot load configuration from jar
    org.bukkit.configuration.InvalidConfigurationException: Top level is not a Map.
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:59) ~[spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:214) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:162) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at me.gorok.sgkisten.Main.loadConfig(Main.java:41) [niroxkisten.jar:?]
            at me.gorok.sgkisten.Main.onEnable(Main.java:14) [niroxkisten.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:746) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot_server.jar:git-Spigot-550ebac-7019900]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
     
     
  10. Error is out, emerald block click still doesnt work..
     
    #11 GoRoK, Jun 13, 2016
    Last edited: Jun 13, 2016
  11. The problem should be in your config.
    Write in onEnable only "saveDefaultConfig();" and create a config.yml file (like plugin.yml). Write the values in this file.
     
  12. And how do i write in that File then? Im sorry for dumbness.. :(
     
  13. Google is your best friend.
     
  14. why have public void onDisable() if there is nothing in there?


    Learn java my tip
     
    • Funny Funny x 1
  15. Code (Text):
    Test:
      - Example
      - Example
      - Example
    I really do not want to write codes..
     
  16. this Is a code for public void onDisable()



    Code (Text):
    public void onDisable() {



    getLogger().info('ANYTHING");


    }
     
     
  17. Im like this now:

    Code (Text):

        public void onEnable()
        {
            super.onEnable();
            saveDefaultConfig();
           
                File myFile = new File(getDataFolder(), "chestinventory.yml");
            if (!myFile.exists()) {
                try {  myFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); }}
           
           
           


           //Ignore this below





            // Commands
           
            new ChestListener(this);
           
           
           
            //Commandsend
            String pluginName = this.getDescription().getName();
            String Version = this.getDescription().getVersion();
            String website = this.getDescription().getWebsite();
            System.out.println(pluginName + " geladen, " + "Version: " + Version);
            System.out.println("Website: " + website);
        }
     
    But how do i write and read in / from that file?
     
  18. Take out the
    Code (Text):
    super.onEnable();
    That's pointless. If you decompile spigot and look in JavaPlugin onEnable() is just an empty method. It's only there so you can override it with your own code.
     
  19. Tip: Write a LIST if you want to have a LIST in your file. I hope you know the basics of writing to a File.