Solved Problems getting a string from my config

Discussion in 'Plugin Development' started by xXShadowGuy3Xx, Jun 29, 2013.

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

    xXShadowGuy3Xx

    Ok so i'm trying to make a simple command where you type /hello and it returns the message specified in the config, There are no errors in the code or in console, it just doesn't send the message anyway


    Main.java
    Show Spoiler
    Code:
    package com.gmail.yyamiyyugi;
     
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
     
        @Override
        public void onEnable() {
            getLogger().info("SlashPotion has been enabled");
            getConfig().options().copyDefaults(true);
            saveConfig();
            getCommand("haste").setExecutor(new SlashPotionCommandExecuter(this));
            getCommand("JumpBoost").setExecutor(
                    new SlashPotionCommandExecuter(this));
           
           
     
        }
     
        @Override
        public void onDisable() {
            getLogger().info("SlashPotion has been disabled D:");
     
        }
     
    }


    SlashPotionCommandExecutor.java
    Show Spoiler

    Code:
    package com.gmail.yyamiyyugi;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class SlashPotionCommandExecuter implements CommandExecutor {
     
     
        private Main plugin;
        public SlashPotionCommandExecuter(Main plugin) {
            this.plugin = plugin;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
     
            CommandSender player = sender;
            Player player1 = (Player) sender;
     
            if (cmd.getName().equalsIgnoreCase("haste")) {
                if (player.hasPermission("Slash.Haste")) {
                    sender.sendMessage("You now have 5min. of Speed digging at the cost of 5min. of weakness");
                    player1.addPotionEffect(new PotionEffect(
                            PotionEffectType.FAST_DIGGING, 6000, 1));
                    player1.addPotionEffect(new PotionEffect(
                            PotionEffectType.WEAKNESS, 6000, 1));
     
                }
            }
     
            if (cmd.getName().equalsIgnoreCase("JumpBoost")) {
                if (player.hasPermission("Slash.JumpBoost")) {
                    player1.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,
                            6000, 1));
                    player1.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,
                            6000, 1));
                    sender.sendMessage("You now have 5min. of Jumpboost at the cost of 5min. of Slowness");
                }
            }
           
     
            if(cmd.getName().equalsIgnoreCase("Hello")){
                sender.sendMessage(plugin.getConfig().getString("Hello"));
                sender.sendMessage("It should send you a message!");
               
               
               
            }
           
           
            return false;
        }
    }



    plugin.yml
    Show Spoiler

    Code:
    name: SlashPotion
    main: com.gmail.yyamiyyugi.Main
    version: 0.1
    commands:
      haste:
          description:
          usage:
          permission: Slash.Haste
          permission-message: You are not strong enough to sacrafice strength for haste!
      JumpBoost:
          description:
          usage:
          permission: Slash.JumpBoost
          permission-message: You are slow enough as is!
      Hello:
          description:
          usage:
          permission: you can't say hello
          permission-message:
      



    Config.yml
    Show Spoiler

    Code:
    #Default config!
    Hello: Howdy there!
     
  2. Offline

    Jake0oo0

    You should cast your sender like this:
    Player player = (Player)sender;
    Then player.sendMessage("Hi");
     
  3. Offline

    xXShadowGuy3Xx

    That is not the problem, the problem is
    Show Spoiler

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("Hello")){
    2. sender.sendMessage(plugin.getConfig().getString("Hello"));
    3. sender.sendMessage("It should send you a message!");
    4.  
    5.  
    6.  
    7. }

    It should get the preset message from my config.yml and send the message to the player but when the command is typed nothing happens, it on;y says i used the command in console but i get no messages not even the sender.sendMessage("it should send you a message")

    I can make another one in the config and use it in the command jumpboost and it works fine

    Bump :3

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

    ProtoTempus

    xXShadowGuy3Xx Looks like your plugin.yml file's syntax is wrong for the Hello command's permission... This could be causing a problem:

    Code:
    Hello:
      description:
      usage:
      permission: you can't say hello
      permission-message:
     
  5. Offline

    xXShadowGuy3Xx

    ProtoTempus That doesn't seem to be the issue, I redid that line by copyand pasting the jumpboost command then changing the info to fit hello, also if that was the case wouldn't there be a console error?
     
  6. Offline

    Henzz

  7. Offline

    xXShadowGuy3Xx

    Henzz -.- *facepalm* I feel stupid, totally forgot about that XD thanks for pointing that out and saving me the time
     
Thread Status:
Not open for further replies.

Share This Page