THIS TUTORIAL IS FOR PEOPLE WHO HAVE JAVA EXPERIENCEDon't have Java Experience? Here are a few links that could help you get some: Java Docs (Official): http://docs.oracle.com/javase/8/ Bukkit Wiki (Basic Setup): http://wiki.bukkit.org/Main_Page I will explain most things as we go along. After getting knowledge on Java, you should know what Strings, Integers, Booleans, and that kind of stuff is. You should also know how to import different imports, operate with the Java Build Path, and what YAML files are. If you don't know, and you can't understand it from the links above, feel free to comment below or look up a tutorial (on youtube or something). Also, if I am not specific enough, or you notice any problems with my work, please comment them below. AFTER SETTING UP YOUR WORKSPACELets begin! This tutorial is just going to show you how to get in it with commands! In This EpisodeIn this episode, we are going to add a command to our Minecraft Bukkit Server. The command that we are going to make is "/hello". You can make it whatever you want. Bukkit Development Skills (this episode): - Command Development - Getting a Player's name and placing it in a string - Sending a message to a player - Making the plugin.yml Step 1We need to add the Bukkit API into our Java Build Path of our project (src > Build Path > Configure Build Path > Libraries > Add External Jars). Go ahead and download that here. That link will take you to the Bukkit Repository, where you can get your Jar. You should already have a server, if you want to make a bukkit plugin. The file is basically the same one that you use for your server (craftbukkit.jar, spigot.jar, etc.). Once you are done with that. We will go ahead and add the extension to our class. public class Tutorial extends JavaPlugin { Step 2Now we are going to add our onEnable() method. Basically, this method is ran every time the server (or more specifically the plugin) starts. Since in this tutorial, we do not have anything that we need in our onEnable() method, we are just going to add a message to the logger saying that the plugin has loaded. This is optional, because Bukkit/Spigot already adds this. public void onEnable(){ You can do the same thing with "public void onDisable()", but we are not going to add that. Step 3We are now going to provide the listener for our command. When the player sends the command in-game, the onCommand() method that we are creating will listen for it, and then send an output to the player (what you set under the method). Technically, the command will go through the plugin.yml first, but that will be explained later. Let's create the onCommand() method. Step 4 will explain how to actually set the command in. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ We created the CommandSender called sender (whoever sent the command), the Command itself called cmd, the commandLabel String (what the command says), and the arguments (everything after the command). The return (as you might know from the Java tutorials) ends the process (stops . Step 4Now let's add the command to the method. The command should not contain the "/". If you do add the slash, it will think that you are saying "//hello". if (cmd.getName().equalsIgnoreCase("hello")){ Under the onCommand(...) method You could also have a false return at the end, which will spit out the usage from the plugin.yml (explained later), but it should never get to that point. Basically, what this is doing is saying that: if the command's name (or text) is equal to "hello", it will do the following. Step 5sender.sendMessage(ChatColor.YELLOW + "Hello, " + sender.getName()); Now let's send a message to the command sender, saying: "Hello, <sender name>". This should be in the cmd.getName(). We will also make it in the color YELLOW In-Game example: If my username was "Blockhead7360" (which it is), then it will say (in yellow): Hello, Blockhead7360 Step 6Now lets create the plugin.yml. This is the file that all plugins must have in order to run correctly. In here, we specify the plugin name, version, author, description, main path, commands, permissions (later episode), and more. To create your plugin.yml, add a new file into your src (under your Java Project). Name it "plugin.yml". Here is an example of the file: name: TutorialPlugin Usage: How the command is used. If you want your own usage messages, just leave the usage in the plugin.yml as "/<command>". If you do add a usage (ex. "/<command> <argument>"), it will not accept the command until you have the entire usage complete in-game. Description: This is the description of the command. It will be displayed under the server's "/help" command Aliases: This is optional (so is the description). It is basically a String list of other commands that will represent as the main one (basically an alias xD) Name: What the server sees as the name of your plugin. Version: Plugin version Author: Plugin author Main: The main class that the plugin refers to (where it all starts). This is your package, and then your main class. In this case, we only created 1 class. <package>.<main-class> (me.blockhead7360.tutorial + .Tutorial) Description: About your plugin (brief) An entire plugin.yml description is shown here: http://wiki.bukkit.org/Plugin_YAML Step 7Export your Java Project as a Jar File into your Server's plugins folder, and start up your server! It should work! The EndYou learned how to make a simple and basic plugin! Next Episode is coming soon! Did I make any problems? Comment below! (I hope I didn't) Have any suggestions for future episodes (want to learn something else)? Comment below! Wanna talk? Comment below! FINAL CODE (Tutorial.java): http://pastebin.com/MayA3aib
0 Comments
Leave a Reply. |
|