Messaging Plugin

Discussion in 'Plugin Development' started by Aarooncia, Oct 15, 2019.

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

    Aarooncia

    Hey there, I'm currently developing a Messaging plugin just for fun, and I'm looking for some help with a feature. Here is the current code I have for the /amsg command - It's basically the default /msg command but coded myself. Pointless, right? I know, I was just bored. But what I'd like to add is to add a little popping sound whenever the player receives a message. Here is my current code -
    https://pastebin.com/trUQWjXt

    In addition, I'd also like to know how I could make a Social Spy/Message Spy component, if anybody has any notable tutorials or suggestions, please comment, been searching the web for about 20 minutes now with nothing.
     
  2. Offline

    KarimAKL

    @Aarooncia
    1. Use this method to play a sound to the player.
    2. For the social spy; simply loop all the online players, and then send them the message if the condition (permission, toggled, etc.) is met.
    3. I'd recommend using StringBuilder instead of String+String. For an explanation you can look up "Java StringBuilder vs String Concatenation"
     
  3. Offline

    ThePandaPlayer

    This is certainly accurate. Here's a method I've used for years that has an added feature:
    Code:
    public static String buildMessage(String[] material, int start) {
            StringBuilder builder = new StringBuilder();
    
            for(int i = start; i<material.length; i++) {
    
                builder.append(material[i]);
                builder.append(" ");
    
            }
    
            return builder.toString().trim();
    
    
        }
    This takes two arguments, a String[] array of material, and an int for where to start. Basically, this allows you to parse messages from command syntax, without having to worry about knit-pickily cutting out specific elements from the array. Zero corresponds to the first part of the array, so if you want to include all elements, pass 0, etc.



    Playing a sound to a player is as simple as getting the player instance you want, and calling the playSound method.
     
  4. Offline

    Strahan

    Apache Commons is shaded in, so it's even easier to just do String message = StringUtils.join(args, " ", 1, args.length);
     
Thread Status:
Not open for further replies.

Share This Page