Development Assistance Halp me pls, english pls

Discussion in 'Plugin Help/Development/Requests' started by Plexiscore, Jun 4, 2015.

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

    Plexiscore

    Hey guys, I've been trying to make an emotes plugin, and I first started coding java yesterday so I'm noob asf.
    I've been testing it with the single command '/hello (player name here)'
    I have got that part working, but I want it to work when you only type a part of the players name in.

    For example: (player name = plexiscore)
    Command typed in: /hello plexi
    Expected output: "(sender) says hello to Plexiscore!"
    Actual output: "player not found"

    It would also be great if someone told me how to make it so the players name gets capitalized appropriately.

    For example: (player name = ExoTic_RemiiXx)
    Command typed in: /hello exotic_remiixx
    Expected output: "(sender) says hello to ExoTic_RemiiXx"
    Actual output: "(sender) says hello exotic_remiixx"

    Here is my code so far below:
    Code:
    package me.plexiscore;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class NCEmotes extends JavaPlugin {
    
        @override
        public void onEnable () {
            getLogger().info("Hello Youtube! onEnable has been enabled!");
        }
       
        @override
        public void onDisable () {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("Hello") && sender instanceof Player) {
               
                Player player = (Player) sender;
               
                //Arg 0 = first word entered after command, Arg 1 = second word, etc
                int length = args.length;
               
                if (length == 1) {
                   
                    boolean playerFound = false;
                   
                   
                   
                    for (Player playerTarget : Bukkit.getServer().getOnlinePlayers()) {
                        if (playerTarget.getName().equalsIgnoreCase(args[0])) {
                            getServer().broadcastMessage(ChatColor.WHITE + player1.getName() + " says hello to " + args[0] + "!" );
                            playerFound = true;
                            break;
                        }
                    }
                   
                    if (playerFound == false) {
                        player1.sendMessage(ChatColor.RED + args[0] + " was not found!");
                    }
                   
                } else getServer().broadcastMessage(ChatColor.WHITE + player.getName() + " says hello!");
               
               
                return true;
            }
           
            return false;
        }
    
       
    }
    
    Thanks for your time! ^-^
     
  2. Offline

    pie_flavor

    @Plexiscore First of all, glaring noob mistake: Don't log that your plugin has been enabled. Or disabled, for that matter. Bukkit does this automatically.
    Second, not everything needs to be stored in a variable. You can just do
    Code:
    if (args.length == 1) {
    Third, answering your question: You don't need to iterate over Bukkit's players.
    Code:
    @SuppressWarnings("deprecation")
    Player target = getServer().getPlayer(args[0]);
    if (target == null) {
        player.sendMessage("§c"+args[0]+" was not found!");
        return true;
    }
    getServer().broadcastMessage("§f"+player.getName()+" says hello to "+target.getName()+"!");
    I think you have your variables mixed up. According to this, player1 does not exist. Also, you have reversed the order of who says hello to who. Remember, player is the sender, target is the recipient.
    Server#getPlayer(String) gets a 'fuzzy match' of the name, and since it returns a player object you can use the actual name of the player.
    Also, if you know your color codes, just use § instead of &. Alternatively, somewhere in your class put
    Code:
    String c(String s) { return ChatColor.translateAlternateColorCodes('& , s);}
    and then to use colors, just put c() around the string, and use the standard & codes.
     
  3. Offline

    Plexiscore

    Thanks for this dude ^-^
     
    Last edited: Jun 5, 2015
Thread Status:
Not open for further replies.

Share This Page