How to fix IllegalArgumentException: Cannot translate null text?

Discussion in 'Plugin Development' started by Lynden Sylver, Jul 4, 2021.

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

    Lynden Sylver

    Hi,

    I've been working on fetching stuff from a config file, but a few lines return null text despite there being legitimate text.

    What am I doing wrong?

    Here's what I've been doing:

    Event file:
    Code:
        @SuppressWarnings({ })
        @EventHandler
        publicvoidspawn(EntitySpawnEventevent) {
    
            Entity entity = event.getEntity();
    
            if ((entity instanceof Skeleton) && (plugin.getConfig().getBoolean("Spawn_Custom_Mobs.spawn") == true)) {        Bukkit.broadcastMessage(Utils.chat(plugin.getConfig().getString("Summon_Messages.Melon_Minion.melon_spawn"))); // <-- Returns null text (when it should return 'Melon Minion!')
    
                EntityEquipment  ee = ((Skeleton)entity).getEquipment();
                ee.setHelmet(new ItemStack(Material.MELON));
                ee.setHelmetDropChance(100);
            }
    
            if ((entity instanceof Zombie) && (plugin.getConfig().getBoolean("Spawn_Custom_Mobs.spawn") == true)) {
         Bukkit.broadcastMessage(Utils.chat(plugin.getConfig().getString("Summon_Messages.Pumpkin_Minion.pumpkin_spawn"))); // <-- Returns null text (when it should return 'Pumpkin Minion!')
    
                EntityEquipment  ee = ((Zombie)entity).getEquipment();
                ee.setHelmet(new ItemStack(Material.PUMPKIN));
                ee.setHelmetDropChance(100);
            }
    
            if (plugin.getConfig().getBoolean("Spawn_Custom_Mobs.spawn") == false) {
                Bukkit.broadcastMessage(Utils.chat(plugin.getConfig().getString("Spawn_Custom_Mobs.mobs")));
            }
       }
    
    Config File:
    Code:
    Summon_Messages:
    
      # Broadcast messages for the Melon Minion
      Melon_Minion:
      - melon_fail:'&c<player> &7has failed &esummoning &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
    
      - melon_success:'&a<player> &7 has &esummoned &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
    
      - melon_spawn:'Melon Minion!'
    
      # Broadcast messages for the Pumpkin Minion
      Pumpkin_Minion:
    
      - pumpkin_fail:'&c<player> &7has failed &esummoning &7a &6p&8u&6m&8p&6k&8i&6n &8M&6i&8n&6i&8o&6n&8!'
    
      - pumpkin_success:'&a<player> &7 has &esummoned &7a &6p&8u&6m&8p&6k&8i&6n &8M&6i&8n&6i&8o&6n&8!'
    
      - pumpkin_spawn:'Pumpkin Minion!'
    
    # Toggle custom spawns on/off
    Spawn_Custom_Mobs:
    
      spawn:true
    
      mobs:'Custom mobs are turned off!'
    
     
  2. Offline

    c7dev

    Which lines return null? Are there any errors in the console? From first glance the lines that get info from the config look correct, so it might be something to do with your main class instance (where you define the plugin object). Has the plugin saved a config.yml in its plugin file upon being started for the first time?
     
  3. Offline

    Lynden Sylver

    Figured out that the .yml only takes 2 layers, not 3.

    It works now, but it creates console spam. I think it's either because of all the mobs spawning in when I start the world, or it is due to a notoriously true statement.

    Not sure which though.
     
  4. Offline

    Shqep

    @Lynden Sylver
    I'm pretty sure the errors are because of your YAML formatting. YAMLs can have as many layers as you need.
    You are using the hyphen thing "-":
    Code:
    Melon_Minion:
    - melon_fail:'&c<player> &7has failed &esummoning &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
    - melon_success:'&a<player> &7 has &esummoned &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
    - melon_spawn:'Melon Minion!'
    This made the YAML parser think that the key "Melon_Minion" holds a List of Strings with values "melon_fail:'...", "melon_success:..." and "melon_spawn:...".
    All you have to do is remove the hyphen. And of course, some proper indentation.

    Code:
    Melon_Minion:
      melon_fail: '&c<player> &7has failed &esummoning &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
      melon_success: '&a<player> &7 has &esummoned &7a &2M&4e&2l&4o&2n &4M&2i&4n&2i&4o&2n&4!'
      melon_spawn: 'Melon Minion!'
    Also add a space before the value and after the colon:
    Code:
    # Like this.
    key: value
    
    # Not
    key:value
     
Thread Status:
Not open for further replies.

Share This Page