Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Partykillen07, Jun 12, 2019.
I need help to code a /reply or /r command.
My code: https://pastebin.com/EyYb26VZ
Please put your code in code tags like so
this code here
without spaces before ]
You should use the code tag to make the code readable
So.. Remember this: When you don't know something, at least try to code it. You should start coding, and if you have an issue (like something is not working, or you don't know how to do something (small thing, e.g send message to sender)), then you should post here.
Problems I see:
Don't need equalsIgnoreCase. This name will ALWAYS be the string defined in your plugin.yml
Player targetPlayer = Bukkit.getPlayerExact(args);
This code should only be run if you have verified the length of args to be greater than 0.
It will throw an exception because it's outside the if block..
EDIT: I made these comments based on the messed up code from not putting it in code blocks. It looks different from it did then.
I dont know how to code HashMaps
Map<Player, String> prefixes = new HashMap<>();
String prefix = prefixes.get(player);
So if I put if (cmd.getName().equals("msg"))
and I execute /MsG it will still work? equals and equalsIgnoreCase are different things
Yes. Because "msg" is what you put in your plugin.yml. You're doing command.getName().
"MsG" would be the "label" argument in onCommand. cmd.getName() will always be exactly what you put in the plugin.yml, hence why it's a field on the command object.
So if you do this
then you can do this
It doesn’t really matter...
It's less efficient code run everytime the player runs a command for no reason. And I only explained further because he replied to it specifically. :\
As for the OP, look up how to store information in Maps. When a player /msg's another player, set their username with the sender as a key. (So like sender, lastSent). When a player does /r, see if they're in the map, if they do, send the message to the value in the map.
HashMaps are just like physical memory, they store files for the time the file is active, once it resets then the whole HashMap is cleared.
You will want to research HashMaps, I’m not going to spoon feed you because it never helps people.
@Trophonix gave you a really great piece of pseudo code, learn what it does and take that knowledge and adapt to it.
I also suggest learning by decompiling similar plugins and learning what they are doing, DO NOT just copy and paste because it’s illegal and considered copyright infringement, and that’s just not going to help you.
Learn about HashMaps, and similar conditions here!