Well hello everybody and welcome back to Minecraft plugin tutorial Series in today’s episode I’m gonna teach you how to add custom commands so that we can actually spawn a custom cow and only make this cow explode if I spawn a normal cow and I right click it’s not Going to do anything but if I click this cow it’s going to give it a nice little blow so welcome to this tutorial and this is what we’re going to be covering I’m going to teach you how to create custom commands with something called command executor interface I’m also Going to show you how to enter how to use plugin.yml to register these commands in bucket and then finally we’re going to be doing some tap completion stuff because that’s also what you guys requested so please check out the blog post below this video for more in-depth explanations including the Link to the source code because I’m going to be posting the FourSquare full full source code completely for free for you guys in the blog post below now there’s a couple of useful links the first one being all bucket commands which you can see if you go to bucket That fandom.com I’m also going to be pasting this link in the blog video and if you open up this one you’re just going to see all these different commands uh from Minecraft and from bucket in case you didn’t know them also if you wonder what you can or cannot put Inside the plugin that yml which is this file right here by the way please check out the second video in this tutorial series to understand how we created this code right here because we’re going to be starting I think the second video deals with the code creation at the very Beginning so if you want to know what to put inside of the plugin file go to the other Link at the docs paper i o again the full link will be available at the blog post blog post command at the link in the description below to my website And then the blog post there and as you can see all the options are specified right here all you have to do today we deal with the command section so first of all if you want to create a new command you have to register it inside the bucket Section inside the plugin that yaml section so that the bucket or specular paper what have you can actually see that the plugin has a command so the way we’re going to do it we can just copy this code as it is and then we can just paste it right here There we go and now we can actually change this Command right here to the main label of the command which is just going to be Cal that means if I go into the game and I type slash cow this command will run the description of this command will be very simple this will Simply spawn an exploding cow and then the usage is going to be very simple it’s just the cow and then say I want to type if the cow is a baby or not if I type in just a cow it’s just going to spawn an adult or if I type in cow baby is going to spawn as a nice little baby and then the command Elias means means what other things and then how can I place can I put in the chat to run the same command so if I want to spawn the cow by not only Calling Cal but also calling cow canoon then this is the Elias for the main command that I can leave here and then the permission can be I don’t know how very simple and the permission message can be the default you don’t have the permission to oops to spawn To spawn a cow an exploding cow there we go very simple uh guys also make sure if you write text into these yml files it is a good practice to use brackets okay so put them into brackets right here because especially if you want to put Colors like this one or you want to put in a single bracket or stuff like that or even a columns it can break things a little bit so it is a good practice to put text in the in the double quotes or you can use either so you can use single quotes or Double quotes right here like that and it’s going to always load properly I’ve seen people sometimes be confused about it uh but that’s just how it works you you don’t have to use it in here in particular but if I would to make this this a colorful message which I can deal With in another another video I can show how to deal with these commands uh colors including you know hex codes then you definitely need to place uh double quotes around it good now we have that it’s time to actually come up with a custom class we can just give it a nice Name called cow command and as I mentioned we’re going to be implementing something called a command executor and I can also Implement tab executor although I think that the command executor should have the tab no it does not have it good so we just get we can Implement multiple interfaces by simply Separating them by comma first one being the command executor which is going to force us to implement the on command method and if you start typing all n and you pre press uh Control Plus space It should give you a hint in your IntelliJ and now if you just double click this One it should actually implement the whole command for you awesome that’s the first one and the other one being on no that one is actually called top complete there we go on tap complete again there we go now you have these commands don’t worry about these annotations right here you actually Don’t need to have them IntelliJ just places them because they are inherited from the uh from the interface as they are here so first one the first argument this is the sender this can be a console this can be a a player and this can be also I think An offline player I’m not sure how many things can this be but this can definitely be a console or a living player so we gotta check that so if the sender is not a player we’re just gonna say only players can use this command awesome and the AI here It works properly and it also completed roughly what I would want to say and then we simply return true what happens if we return false bucket will send us the usage message okay if you return true bucket is going to send us absolutely nothing because the command Was handled so that is how to implement this basic command uh moving on to the other thing Command right here is the same command basically if you type in command dot get here these things are the exact same as you’re supposed to be having here okay so this is just Informative purely for Cosmetics I personally never used this here then the label the label could be cow or I think the label closely calcul depends on what you type in a chat and then the argument simply means what comes after the command label so if I type in slash cow Hello world this is pretty then the cow is the label hello is the zero argument so if I want to get that I simply get arcs zero let me just space it out a little bit if I want to get the second argument I simply get RX1 And so on and so forth okay so that’s how it works it can be a bit confusing for beginners right but that’s how it works in Java uh if you don’t know Java Basics if the the syntax right here causes you you know your head to spin a little bit more Please note that we have a full Java Plus Minecraft plugin course where I give you personalized help device per week I’m actually doing live calls with you guys plus there’s seven weeks of Court content which is on demand it’s always available plus there is an entire Java course it’s called projectorian and You can get it in the link in the description of this video and I’ll be more than happy to show you guys this more in depth however for for now let’s just stick with this for now so if someone types in Cal we also have to see If they typed in baby right here so if so we can just say is baby and this can be false however if the Orcs length is at least one that means that someone typed the first argument and the orgs 0 equals to baby and we can also use equals ignore case so that Someone can also type baby right it’s gonna match then it’s going to be true and this is just the basic I may change the code later on and now it’s time to actually spawn the command so we can get the player because now we know that the player is not a Console so we can cast the player to uh the sender to the player like this one and then we can simply get the world and we can spawn uh a cow and the player location for example and then we can spawn a cow class right here that’s gonna return the Cal instance And then if is baby we can simply call cow said baby however we can simplify this so I can just just copy this right here I can place this right here and then I can delete the whole bunch of Code Black that is now not being used Awesome however I want to make sure that the command is high quality remember coding standard so what if someone types in cow baby world right this is not good so if the commands argument are actually greater than one we want to return false and then bucket should tell the player Uh this usage right here good so that one should work now the thing is that I promised you in the very beginning if we click the cow we have to mark the car with a custom metadata so the discount is different from all the other cows and only this cow explodes so We’re gonna set the metadata for the cow the name of the key of the metadata is just going to be calcanin and then the metadata value in bucket is actually something called a fixed metadata value which stores uh which takes in an instance of our plugin which we can go Into our main class to get so I can just type in public static get instance and then I can just reference the the buckets way of getting the plugin instance this will return this it’s going to return this however I have access to the get instance from the Entirety for all different classes of this plugin again this is basic Java stuff if you don’t know how static works please make sure to learn Java before and this will be then callable from anywhere so I can go and I can I can call Tau canon.get instance and then the Fixed metadata value has the object this value so think about metadata as a hash map right in Java so you can place anything it can be calculated as a key and then here can be anything this can be one uh this can be I don’t know a String a number a a float a Boolean but it does not really matter what we place here because we are only interested in checking if the cow has this method now the limitation for this is if you restart the server this method metadata will get lost if you don’t want this to Get lost look into persistent data container this has been added in Minecraft 1.14 I don’t have time to cover this in this video but I may make a lesson about the persistent data container later on so that you will always you can always spawn entities and they’re actually going to remain with The custom Uh custom data on the map even after the server has been reloaded for now this is enough good and also for fun you’ve noticed at the beginning of this video The Cow had a custom name so I can set a custom name to milk me And I can give it a nice chat color red by the way guys don’t worry about the fact that this is depreciated this is just depreciated because paper is essentially uh is essentially rewriting the system of bucket and they’re using a different library for custom components but I don’t want to Torture you guys with more stuff than necessary for this video we can cover the adventure API later on but for now you can just go with the default Alder API that puts that makes it possible for you to put in the strings right away like this one and that’s it we also need To make sure that the custom name is always visible otherwise we’re not going to see it unless we pointer our cursor directly on the cow okay that’s it now now the cow has been spawned also make sure to return true here and then the on tap complete so what we can do right Here we can actually just return a list an empty list to make sure that there’s no tab completion because if you return null visible return all player names for bucket however if if the arcs say are one I think then we can just return baby right here that’s it and I’m not Really sure if this is zero or one this always trips me up I do recommend you guys maybe print out the size of arguments if you struggle with this you can have a debug message right here right that always helps because I if you are as forgetful as I so Essentially if I type in say cow and then I press tab it should automatically offer the baby to be completed there we go awesome final thing before we hop off we have to register the command and we have to make some adjustments here in the entity listener so how do you actually register The command very simple you get the command this will then try to get the command based on the information from the file and then you set the executor of the command being a new instance of the cow command Okay a bit confusing here what is the executor well it’s Basically just a bunch of code that we just implemented it’s going to take care of actually running the command because bucket knows that there is a command but it does not know where to execute it so now it knows both okay you can also look into setting the tab completer you can have It in a different class but I don’t recommend it and you can also change a bunch of stuff here essentially you’re just overriding these options which you don’t have to good now let me make a final adjustment right here let me just get the energy the right click entity right away and Then I can just make a couple of couple of shorthands methods and then we have to check if the energy has the metadata there we go and I can also get the player and we can also check if the player get item in hand get type is a Bucket and you don’t you don’t have to use the depreciated method here you can just get the inventory and then get item in main hand but for me uh I know bucket is not gonna remove the depreciated method and it’s way quicker right and that’s fine too if you are coding for Minecraft 1.9 Plus what do you need to do you also need to check if the event get hand is a normal hand because this event is actually fired device one for your right hand the other times for your left hand in this code I only want to make sure That this code works for the main hand it does not work for the left hand which is called the off hand so I should have maybe probably covered this in the last video but I did not want it to be that long uh so now you have it and you have A full code everything works as it should let let’s pray and let’s compile together let’s see if that works okay guys if I spawn a normal cow I can click it and I can click it as much as I want to holding the bucket and it’s not going To explode thankfully but if I type in Cal you can also see now that the baby at argument is being tap completed and if I try typing something more you can send the console the size increases right since it’s really handy now it’s gonna Just tell us cow baby but if I type in cow baby actually it’s going to spawn a little cow and if I right click the little cow should blow however if I right click without holding a bucket it’ll just it will do also absolutely nothing also guys so I hope you’ve Enjoyed this video everything works I’m very happy again check out project Orient course if you want to learn how to build amazing plugins and we can actually go 10 times more deeply than we went in this quick video for commands that’s about it for commands I’ll see You guys in the next video thank you guys for watching take care see you next time Video Information
This video, titled ‘Ep4. Commands & Tab Complete – Minecraft Plugin Development’, was uploaded by Matej Pacan on 2023-06-22 15:45:01. It has garnered 589 views and 10 likes. The duration of the video is 00:16:08 or 968 seconds.
You’ll learn to make your own commands in Minecraft plugins by creating custom cows with glowing names above them that explode when right clicked with a bucket 😉
🧠 The best place to start learning Minecraft plugin development ➡ https://mineacademy.org/project-orion?st=yt&sc=tut_ep4
Welcome to Minecraft plugin development tutorial series! In this episode, we’ll cover:
– Commands — Making a custom command with CommandExecutor interface. – Registering commands — Using plugin.yml and the getCommand() method to register a command. – Tab completion — Making commands tab complete.
📖 Blog post link + resources: https://mineacademy.org/tutorial-4/?st=yt&sc=tut_ep4
🙋♂️ Need help? Ask in our Discord community: https://mineacademy.org/discord
👋🏼 About Me Hi! My name is Matej Pacan and since 2013 I’ve developed plugins like ChatControl, Boss, CoreArena and dozens of others attracting over 700,000+ downloads, scaled my own network to 30,000+ players and taught 2,000+ people to do the same in our MineAcademy.org training programs.
You’ve found my YouTube channel where I help other people wrap their heads around Java programming by teaching them coding using Minecraft and growing a lucrative skillset.
My only hope is that one day some of you will learn enough from my videos to see an exciting opportunity in the IT space and build a life you love.
🧠 The best place to start learning Minecraft plugin development ➡ https://mineacademy.org/project-orion?st=yt&sc=tut_ep4
#minecraft #spigot #minecraftplugin #java