How can I add settings to my config

Discussion in 'Plugin Development' started by DeadInside, Dec 5, 2018.

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

    DeadInside

    So I tried to add special settings to my config.yml

    Heres what I tried bit it didnt seem to work as theres no settings for this in the config:

    Thats what I tried (open)
    Code:
                                p.sendMessage(plugin.prefix + "§8Du bekommst 2 Diamanten weil du es geschafft hast!");
                                p.getInventory().addItem(new ItemStack(Material.DIAMOND, 2));
    
                                FileConfiguration cfg = plugin.getConfig();
                                cfg.set("Material", Material.DIAMOND);
                                plugin.saveConfig();


    Thats what he should change via config.yml (the material)
    Code:
                                p.getInventory().addItem(new ItemStack(Material.DIAMOND, 2));
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    DeadInside

    Nah theres no Errors and I thought I made it but like in the config theres only the Spawns for the beginning of the JumpNRun
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    DeadInside

    Okay its now in the config the string but how to update it automatic and like the text need to be updated to like from 2 Diamonds to 2 Iron or somethin like that.

    Code:
    CustomString: p.sendMessage(plugin.prefix + "§8Du bekommst 2 Diamanten weil du es geschafft hast!");
    CustomString: p.getInventory().addItem(new ItemStack(Material.DIAMOND, 2));
    
    I made it like this in the config.yml

    But theres only the last Customstring

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 5, 2018
  6. Offline

    timtower Administrator Administrator Moderator

    @DeadInside Configs are key value pairs (like a map)
    You can make a list though.
     
  7. Offline

    DeadInside

    Config (open)

    Code:
    materials:
      - IRON_CHESTPLATE
      - DIAMOND
      - IRON_INGOT
      - IRON_LEGGINGS
      - IRON_HELMET
      - IRON_BOOTS
      - LEATHER_BOOTS
      - LEATHER_CHESTPLATE
      - LEATHER_HELMET
      - LEATHER_LEGGINGS
      - LEGACY_CHAINMAIL_BOOTS
      - LEGACY_CHAINMAIL_CHESTPLATE
      - LEGACY_CHAINMAIL_HELMET
      - LEGACY_CHAINMAIL_LEGGINGS
      - LEGACY_DIAMOND_SWORD
      - LEGACY_DIAMOND_SPADE
      - LEGACY_DIAMOND_PICKAXE
      - LEGACY_DIAMOND_ORE
      - LEGACY_DIAMOND_LEGGINGS
      - LEGACY_DIAMOND_HOE
      - LEGACY_DIAMOND_HELMET
      - LEGACY_DIAMOND_CHESTPLATE
      - LEGACY_DIAMOND_BOOTS
      - LEGACY_DIAMOND_BLOCK
      - LEGACY_DIAMOND_BARDING
      - LEGACY_DIAMOND_AXE
      - LEGACY_DIAMOND
      - LEGACY_DRAGON_EGG
    amount:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 10
      - 11
      - 12
      - 13
      - 14
      - 15
      - 16
      - 17
      - 18
      - 19
      - 20
      - 21
      - 22
      - 23
      - 24
      - 25
      - 26
      - 27
      - 28
      - 29
      - 30
      - 31
      - 32
      - 33
      - 34
      - 35
      - 36
      - 37
      - 38
      - 39
      - 40
      - 41
      - 42
      - 43
      - 44
      - 45
      - 46
      - 47
      - 48
      - 49
      - 50
      - 51
      - 52
      - 53
      - 54
      - 55
      - 56
      - 57
      - 58
      - 59
      - 60
      - 61
      - 62
      - 63
      - 64

    like this ? and now the last question how can I add this to the listener so he is requesting the amount and material ?
    I did it like this now

    Code:
                                p.sendMessage(plugin.prefix + "§8Du bekommst 2 Diamanten weil du es geschafft hast!");
                                p.getInventory().addItem(new ItemStack(Material.materials, 1));
    
                                List<String> materials = this.plugin.config.getStringList("materials");
                                List<String> amount = this.plugin.config.getStringList("amount");
    but now I have this error in the console:

    Error (open)
    Code:
    Could not pass event PlayerInteractEvent to Enojump v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:724) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.base/java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            at java.base/java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
            at classes.Listeners.onSignInteract(Listeners.java:124) ~[?:?]
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
            ... 16 more
     
    Last edited: Dec 5, 2018
  8. Offline

    timtower Administrator Administrator Moderator

    @DeadInside And what is on Listeners line 124? Mark it with a comment in the code and post the entire method.
     
  9. Offline

    DeadInside


    Thats the method. (open)
    Code:
                                List<String> materials = this.plugin.config.getStringList("null");
                                List<String> amount = this.plugin.config.getStringList("null");
                                if (ItemStack.getType() == null || ItemStack.getType().equals(Material.AIR) || !ItemStack.hasItemMeta()) {
                                    Bukkit.broadcastMessage("INVALID MATERIAL");
                                    return;



    Main class (open)
    Code:
        @Override
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            this.reloadConfig();
            System.out.println("[EnoJump] Plugin version +!" + this.getDescription().getVersion() + " loaded!");
            new Listeners(this);
            getCommand("enojump").setExecutor(new Commands(this));
        }
    
        @Override
        public void onDisable() {
            System.out.println("[EnoJump] Plugin deaktiviert!");
    
        }


    config (open)
    Code:
    loc:
      world:
      x:
      y:
      z:
    materials:
      - 'IRON_CHESTPLATE'
      - 'DIAMOND'
      - 'IRON_INGOT'
      - 'IRON_LEGGINGS'
      - 'IRON_HELMET'
      - 'IRON_BOOTS'
      - 'LEATHER_BOOTS'
      - 'LEATHER_CHESTPLATE'
      - 'LEATHER_HELMET'
      - 'LEATHER_LEGGINGS'
      - 'LEGACY_CHAINMAIL_BOOTS'
      - 'LEGACY_CHAINMAIL_CHESTPLATE'
      - 'LEGACY_CHAINMAIL_HELMET'
      - 'LEGACY_CHAINMAIL_LEGGINGS'
      - 'LEGACY_DIAMOND_SWORD'
      - 'LEGACY_DIAMOND_SPADE'
      - 'LEGACY_DIAMOND_PICKAXE'
      - 'LEGACY_DIAMOND_ORE'
      - 'LEGACY_DIAMOND_LEGGINGS'
      - 'LEGACY_DIAMOND_HOE'
      - 'LEGACY_DIAMOND_HELMET'
      - 'LEGACY_DIAMOND_CHESTPLATE'
      - 'LEGACY_DIAMOND_BOOTS'
      - 'LEGACY_DIAMOND_BLOCK'
      - 'LEGACY_DIAMOND_BARDING'
      - 'LEGACY_DIAMOND_AXE'
      - 'LEGACY_DIAMOND'
      - 'LEGACY_DRAGON_EGG'
    amount:
      - '1'
      - '2'
      - '3'
      - '4'
      - '5'
      - '6'
      - '7'
      - '8'
      - '9'
      - '10'
      - '11'
      - '12'
      - '13'
      - '14'
      - '15'
      - '16'
      - '17'
      - '18'
      - '19'
      - '20'
      - '21'
      - '22'
      - '23'
      - '24'
      - '25'
      - '26'
      - '27'
      - '28'
      - '29'
      - '30'
      - '31'
      - '32'
      - '33'
      - '34'
      - '35'
      - '36'
      - '37'
      - '38'
      - '39'
      - '40'
      - '41'
      - '42'
      - '43'
      - '44'
      - '45'
      - '46'
      - '47'
      - '48'
      - '49'
      - '50'
      - '51'
      - '52'
      - '53'
      - '54'
      - '55'
      - '56'
      - '57'
      - '58'
      - '59'
      - '60'
      - '61'
      - '62'
      - '63'
      - '64'
     
  10. Offline

    timtower Administrator Administrator Moderator

    @DeadInside 1. That is not the entire method, I am looking for public ... till the last }
    2. You didn't mark line 124
     
  11. Offline

    DeadInside


    Im sorry.
    Heres the method the whole and the one
    List<String> materials = this.plugin.config.getStringList("null"); starts thats the 124 line


    Show Spoiler
    Code:
        @EventHandler
        public void onSignInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if(plugin.inJump.contains(p.getName())) {
                if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    if(event.getClickedBlock().getState() instanceof Sign) {
                        Sign s = (Sign) event.getClickedBlock().getState();
    
                        if(s.getLine(0).equalsIgnoreCase("§b§oEnojump")) {
                            if(s.getLine(1).equalsIgnoreCase("§4§lZiel")) {
    
                                plugin.inJump.remove(p.getName());
    
                                p.getInventory().clear();
                                ItemStack[] old = plugin.oldItems.get(p.getName());
                                p.getInventory().setContents(old);
                                p.updateInventory();
    
                                Location loc = plugin.oldLoc.get(p.getName());
                                p.teleport(loc);
    
                                p.sendMessage(plugin.prefix + "§8Du bekommst 2 Diamanten weil du es geschafft hast!");
                                p.getInventory().addItem(new ItemStack(Material.DIAMOND, 1));
    
                                List<String> materials = this.plugin.config.getStringList("null");
                                List<String> amount = this.plugin.config.getStringList("null");
                                if (ItemStack.getType() == null || ItemStack.getType().equals(Material.AIR) || !ItemStack.hasItemMeta()) {
                                    Bukkit.broadcastMessage("INVALID MATERIAL");
                                    return;
    
     
  12. Offline

    timtower Administrator Administrator Moderator

    @DeadInside My bet is that config is null, and you might want to change those key names.
     
  13. Offline

    DeadInside

    Okay now I changed it to materials and amount. Now I get those Errors

    Code:
    Error:/126, 42) java: non-static method getType() cannot be referenced from a static context
    Error:/126, 42) java: non-static method getType() cannot be referenced from a static context
    Error:/126, 73) java: non-static method getType() cannot be referenced from a static context
    heres the line.

    Code:
                                if (ItemStack.getType() == null || ItemStack.getType().equals(Material.AIR) || !ItemStack.hasItemMeta()) {
    //EDIT
    I really dont try to get the code from you and I really wanna learn java bukkit but like Im sittin here for 3 days and cant get a solution... Im always on google and youtube but theres no solution...
     
    Last edited: Dec 6, 2018
  14. Offline

    timtower Administrator Administrator Moderator

    @DeadInside What is ItemStack here? Where is the variable?
     
  15. Offline

    DeadInside

    Code:
                                p.getInventory().addItem(new ItemStack(Material.DIAMOND, 1));
    theres the variable
     
  16. Offline

    timtower Administrator Administrator Moderator

    That is not a variable.
    That is a method that calls a constructor. Your code doesn't know about that ItemStack anymore.
     
  17. Offline

    DeadInside

    My head is like exploding rn. For real like I dunno anymore Im done. :D
    So like Intellij tells me to make it like this:
    else if (!ItemStack.hasItemMeta) would this help ?
     
  18. Offline

    timtower Administrator Administrator Moderator

    No, you need to make a variable.
     
  19. Offline

    DeadInside

    Theres a Hashmap for the oldItems could I do a Hashmap ? And when I can do a Hashmap how ?
     
  20. Offline

    timtower Administrator Administrator Moderator

    Why do you need a Hashmap for a single ItemStack?
    An ItemStack variable would do just fine.
     
  21. Offline

    DeadInside

    .
     
    Last edited: Dec 6, 2018
Thread Status:
Not open for further replies.

Share This Page