Solved command won't bring args[0] to broadcast message

Discussion in 'Plugin Development' started by Sivert2246, Nov 29, 2015.

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

    Sivert2246

    Yeah I use Eclipse

    OMG THANKS !
    IT WORKED!!!! current code:
    Code:
    
    [B]package[/B] mc.sivert2246.plugin.serverbroadcast;
    
    
    
    [B]import[/B] org.bukkit.Bukkit;
    
    [B]import[/B] org.bukkit.ChatColor;
    
    [B]import[/B] org.bukkit.command.Command;
    
    [B]import[/B] org.bukkit.command.CommandSender;
    
    [B]import[/B] org.bukkit.entity.Player;
    
    [B]import[/B] org.bukkit.plugin.java.JavaPlugin;
    
    
    
    [B]public class [/B]Main [B]extends [/B]JavaPlugin
    
    {
    
    @Override
    
    [B]public void onEnable[/B]()
    
    {
    
    getConfig().options().copyDefaults([B]true[/B]);
    
    saveConfig();
    
    reloadConfig();
    
    }
    
    [B]public boolean onCommand[/B](CommandSender sender,Command cmd,String label,String[] args)
    
    {
    
    [B]if[/B](cmd.getName().equalsIgnoreCase("bc")){
    
    [B]if[/B](sender [B]instanceof [/B]Player){
    
    Player [B]theSender[/B] =(Player) sender;{
    
    [B]if[/B](theSender.hasPermission("server.broadcast")){
    
    Bukkit.[I]broadcastMessage[/I](ChatColor.[I]translateAlternateColorCodes[/I]('&', getConfig().getString("Plugin-TAG")+ args[0]));
    
    }
    
    [B]else[/B]{
    
    Bukkit.[I]broadcastMessage[/I](ChatColor.[I]translateAlternateColorCodes[/I]('&', getConfig().getString("Plugin-TAG")+ args[0]));
    
    }
    
    }
    
    }
    
    }
    
    [B]return false[/B];
    
    }
    
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 29, 2015
  2. Offline

    mcdorli

    I'M HAPPY TO BE HELPFUL!!!!! Mark the thread solved please.
     
  3. Offline

    Chloe-chan

    Just remember to add a @Override above the onCommand in the future, it makes sure you're overriding the method instead of creating a new one.
     
  4. Offline

    mcdorli

    That's a another thing a lot of youtube tutorials get wrong. They always remove it, because "You don't need it".
     
  5. Offline

    Scimiguy

    The internet is an unfortunate minefield of people who think they know how to teach.

    Students don't learn by teachers doing the work for them.
    Students also don't learn by teachers telling them the answer.
    Students learn when a teacher explains how the answer works

    Many online tutorials forget this.
     
  6. Offline

    Chloe-chan

    Technically you don't need it for the application to run. It's only useful as a guarantee you are indeed overriding the method.
     
  7. Offline

    Sivert2246

    Ok, thanks everyone <3
     
Thread Status:
Not open for further replies.

Share This Page