Sunday, April 21, 2024
HomeHow To Make A Minecraft Plugin

How To Make A Minecraft Plugin

Introduction To Onenable And Ondisable

How to Make a Minecraft Plugin | First Plugin (Ep. 1)

Create the methods onEnable and onDisable inside the main class created in the previous section. It will look something like the following

The methods now exist, but they don’t do anything yet.Note: There is no reason to print a message such as ” has been enabled!” as bukkit will do this automatically.For more information about events, click here.

Learning How To Code Quickly Without Prior Experience

This option is suitable for 99% of people. Even if you need an extremely large solution like Mineplex or Hypixel, you still need to understand at least the basics so you wont need to ping your developer team each time you need to change a simple message in the code for you.

Coding is easier and faster than most people experience. The problem out there is a lack of quality resources, proven systems to follow and professional guidance to help you get unstuck. And as you probably know, if youre a beginner, youll get stuck a lot.

Getting Started With Coding For Free

Here are some great starting points for coding plugins. Minecraft updates rapidly and plugins break, so I really tried to write this article in an universal and future-proof way to avoid putting out a version-specific advice out there.

Understand This Before You Start

Minecraft is coded in Java. Everything we do will have to do with the Java programming language. If you never coded anything before, or you dont understand the Java programming language, you need to learn it before you can developer great Minecraft plugins. Yes, this tutorial is designed as a jumpstart right into production and we will not cover how Java works in general, but for most people you need to learn it simultaneously if you are serious about your progress.

How To Code Minecraft Plugins From Scratch

Ever wondered how to code your own Minecraft plugins and develop custom servers from the ground up? This article from the largest Minecraft education portal on Earth is designed to help you quickly.

A lot of Minecraft server owners are tired and frustrated of broken and limited plugins that cant do what they want them to do. The choice of existing plugins is large, however most of them are hard to configure, prone to bugs and errors, and their authors hard to reach or give up soon after the first version.

So is there a better alternative than to rely on the existing plugins?

There are two options to transform your ideas into reality:

#1 You find talented developers and build a great team#2 You learn how to code your own plugins fast and implement what you want, the way you want it

Warning: Theres a lot of psychology and principles oriented thinking in this article. To avoid failure, frustration, procrastination and overwhelm when coding, please read this article in full.

Recommended Reading: Brown Dye In Minecraft

How To Code A Minecraft Plugin

After many years of waiting, today I can officially announce that Minecraft Plugin Development has come to replit! With this tutorial you will understand all you need to know on how to create the basic boilerplate for a standard Java edition plugin for the Spigot API.

This guide is geared towards creating a plugin on but will also work for IDEs such as Intelij IDEA and Eclipse

For any assistance feel free to leave a reply or join my Discord server

How To Create A Minecraft Plugin

Minecraft 1.16.5 Plugins

After creating a Spigot server and installing all the appropriate programs, the “climax” arrived, that is, the creation of the plugin.

If you have followed the instructions I gave you in the previous chapter, you already have the IDE window available Intellij IDEA on your screen. Then press the button Skip the rest and set the default values and click on the New project. After that select the Java in the upper left corner and press the button twice Next.

At this point, give a project’s name and click the button Finalize. You can press on Close in case some “tutorial” windows appear on the screen.

After that, press the voice Archive in the upper left corner and click Project structure. Move, then, in the Libraries… click on the icon … + Click on the entry Java Select the server jar files and awards in OK.

Great, now you’ve successfully imported all the libraries out of the box. After that, close the library window, expand projects folder present left, do right-click in the folder src and select the items New menu that is proposed to you, and then assigning the name that you prefer .

After that you do right-click en package you just created, which is on the left, and select the elements Java class from the menu that is offered to you. So, hit the name you want and press OK.

Of course you have to end everything with support. In case JavaPlugin is not recognized, try reimporting the vase file from the server in the way I showed you before.

Don’t Miss: What Does Rotten Flesh Do In Minecraft

Das Pluginyml Anlegen Das Projekt Bauen Und Testen

Im plugin.yml schreiben wir alles das rein, das Minecraft braucht, um unser Plugin zu erkennen und im richtigen Moment auch aufrufen zu können. Dazu legen wir das File zuerst einmal an. Überraschenderweise klickst du wieder mit der rechten Maustaste auf das und wählst New und YAML File aus. Falls du diesen Eintrag nicht findest, wählst du im Menü ganz unten Other aus und wählst aus der Kategorie Other den Punkt YAML File aus.

Inzwischen kennst du den zweiten Schritt wahrscheinlich auch schon: Wir müssen das File benennen. Achte darauf, dass,

  • das File wirklich plugin heißt und
  • wie beim Java-File auch, du nicht die Dateierweiterung .yml dazuschreibst. Es reicht der Name plugin, im Feld siehst du, dass das yml automatisch angehängt wird:
  • Und wenn du jetzt in den Project Explorer schaust, dann entdeckst du, dass unser geliebtes < default package> wiederauferstanden ist. Das ist auch richtig so, da Minecraft das plugin.yml genau an dieser Stelle sucht.

    Jetzt haben wir wieder ein leeres File und dürfen hier die notwendigen Informationen eintragen:

    Bevor du beginnst, das abzuschreiben, lies dir die folgenden Punkte bitte durch: Als erstes achte bitte darauf, dass nach den Doppelpunkten immer unbedingt ein Leerzeichen kommen muss.

  • name ist eben der Name und kann beliebig gewählt werden. Sinnvollerweise nennen wir unser Plugin so, wie wir auch das Projekt genannt haben.
  • version ist eben die Verion. Das darfst du dir aussuchen.
  • What If I Want To Switch To Java In The Future

    Skript doesnt interfere with Java or any of your other plugins at all. Skript is essentially just another plugin, so creating additional plugins wont have any impact. If you decide youd like to make the switch to Java at any point, you can simply begin creating new Java plugins.

    Skript is a great introduction to programming because it follows the same concepts and logic as any other programming language. If you are an aspiring Java developer, it certainly is a good pathway to begin on.

    Also Check: Bad Omen Minecraft Cure

    Adding Your Command To The Pluginyml

    You will also need to add the command to your plugin.yml file. Add the following to the end of plugin.yml:

    name:Basicmain:< main package> .< main class> version:1.0author:< your IGN or name> commands:basic:description:This is a demo command.usage:/< command>  permission:< plugin name> .basicpermission-message:You don't have < permission> 
    • basic – the name of the command.
    • description – the description of the command .
    • usage – the help dialog that users will see when you return false in the onCommand method. Write clearly, so that others can discern what the command is and how to use it.
    • permission – This is used by some help plugins to work out which commands to show to the user.
    • permission-message – This is output when the player attempts but does not have permission to use the command.

    Note that yml files use 2 spaces for tabs, as the tab character will cause problems.

    Creating Spigot Plugin Workspace

    How to Make a Minecraft Plugin | Essentials Series – Fly Command (Ep.1)

    To create a Spigot workspace, open MCreator, and click the “+” button to create a new workspace.

    If the plugin is properly installed, you will see the “Spigot plugin” type on the left side of the workspace creation window. Click on this option and enter workspace details.

    After you create a new workspace, setup will be run and afterward, you can start making your mod.

    Keep in mind the plugin is still in the development so not all mod elements or functionalities will be supported.

    For more help, check the related pages listed below.

    Recommended Reading: Can You Ride A Zombie Horse In Minecraft

    Reference The Bukkit Api

    Before you begin developing your plugin you will need to add the Bukkit API library to your project as a dependency, you can also add any other API’s you may want to use.

    Double-click pom.xml, which is at the bottom of your project’s folder. Click the pom.xml tab at the bottom, and you should see something like this:

    If you wish to use Java 6+ language features, you must specify the Java version that the project should be built on. Copy and paste this before < /project> :

    < build> < plugins> < plugin> < groupId> org.apache.maven.plugins< /groupId> < artifactId> maven-compiler-plugin< /artifactId> < configuration> < source> 1.7< /source> < target> 1.7< /target> < /configuration> < /plugin> < /plugins> < /build> 

    You may use other levels, such as 1.8 for Java 8 or 11 for Java 11. Please note that according to BStats, a sizeable number of servers run Java 8 , so compiling for Java 11 will result in many server owners being unable to run your plugin. If you do use Java 1.8 or 11 features, Eclipse will suggest changing the language level when you hover over the code “error”. Do so.

    Before the < /project> at the bottom, copy and paste this block :

    < repositories> < repository> < id> spigot-repo< /id> < url> < /url> < /repository> < /repositories> 

    The spigot repository is the only working repository as the former repository “bukkit-repo” is down.

    Next, before the < /project> at the bottom, copy and paste this block :

    Creating Your First Project In Eclipse

    Create the project itself

  • Choose File -> New -> Java Project
  • Enter the name of your plugin
  • Choose Next
  • Click the Libraries tab.
  • Click Add External JARs
  • Choose the shaded version of the Spigot-API JAR file from the Spigot directory that you compiled above. Within the directory with BuildTools.jar the API file will be in Spigot/Spigot-API/target and will probably be named something like spigot-api-1.14.2-R0-SNAPSHOT-shaded.jar
  • Toggle the triangle to the left of spigot-api
  • Choose Javadoc Location
  • Click Edit
  • In Javadoc location path, enter: . This will allow the autocomplete in Eclipse to autocomplete Spigot API objects and methods.
  • Click OK
  • Create a package

  • Choose File -> New -> Package
  • Enter the name of your package. This is usually structured like a domain name, but in reverse. It should start with something that identifies you, and then have the name of the project at the end, and be all lower-case. Minecraft itself is net.minecraft.server for example, Spigot is org.spigotmc, and the Bukkit plugin API is org.bukkit.plugin. Ill use tld.example.myplugin in the examples.
  • Click Finish
  • Create the Main class

  • Choose File -> New -> Class
  • Enter the name of the class which will be loaded by Spigot when it loads the plugin. You can really name this anything you want , but for simplicity Ill call it Main in the examples.
  • Next to Superclass, click Browse
  • In the search box, type JavaPlugin, and choose what should be the only match
  • Click OK

    Also Check: How To Tp In Minecraft Xbox

    Using A Separate Commandexecutor Class

    The examples above just put the onCommand method into the plugin’s main class. For small plugins, this is fine, but if you’re writing something more extensive, it may make sense to put your onCommand method into its own class. Fortunately, this isn’t too hard:

    • Create a new class within your plugin’s package. Call it something like MyPluginCommandExecutor . That class must implement the Bukkit CommandExecutor interface.
    • In your plugin’s onEnable method, you need to create an instance of your new command executor class, and then make a call like getCommand.setExecutor , where “basic” is the command we want to handle, and myExecutor is the instance we created.

    Best explained by example: :

    Notice how we send a reference of the main plugin object to MyPluginCommandExecutor. This allows us easy access to the main plugin objects’s methods if we need to.

    By doing this, we can better organise our code – if the main onCommand method is large and complex, it can be split into submethods without cluttering up the plugin’s main class.

    Note that if your plugin has multiple commands, you will need set the command executor for each command individually.

    Ein Package Und Die Plugin

    Minecraft Plugin Tutorial

    Du speicherst Java-Dateien in Packages ab. Wenn du im Project Explorer den Ordner öffnest, siehst du das Package < default package> . Damit Package-Namen aber sicherlich eindeutig sind, legst du besser ein neues Package an, mit io.coderdojo-linz.< dein-name> .firstplugin . Wenn du eine eigene Domain über die du im Netz erreichbar bist hast, dann kannst du auch die verwenden.

    Also klickst du mit der rechten Maustaste auf und wählst aus dem Kontextmenü New und dann Java Package aus.

    Im nun folgenden Fenster gibst du den Namen deines Packages, wie wir oben beschrieben haben, ein und klickst auf den Button Finish.

    Jetzt ist das Package < default package> verschwunden. Das macht nichts, weil wir es derzeit echt nicht brauchen. Und nun musst du noch die Klasse anlegen, in der wir dieses Plugin programmieren. Dazu klickst du mit der rechten Maustaste auf das neu erstellte Package und wählst dann New und Java Class aus

    Im darauffolgenden Fenster gibst du der neuen Klasse einen Namen und klickst auf Finish.

    Jetzt solltest du in NetBeans ziemlich genau dieses Bild vor dir haben:

    Die grauen Zeilen am Anfang des Files sehen wahrscheinlich ein wenig anders aus. Das macht aber nix, weil das ist ein Kommentar und Kommentare werden vom Compiler ignoriert. Man verwendet Kommentare, um etwas in sein Programm reinzuschreiben, das für Menschen wichtig ist, aber nicht für Computer. Du kannst das ausprobieren und in einer Zeile außerhalb eines Kommentars folgende Zeilen dazuschreiben:

    Also Check: How To Make Cyan Clay

    Console Commands Vs Player Commands

    You may have noticed the CommandSender sender parameter above. CommandSender is a Bukkit interface which has two useful subclasses: Player and ConsoleCommandSender.

    When you’re writing your plugin, it’s a very good idea to ensure that commands that can be run from the console actually work, and that commands that should only be run as a logged-in player really are only run as a logged-in player. Some plugins simply return if the sender is not a player , even when those commands make perfect sense from the console .

    One way to do this is:

    In this example, the command basic can be run by anyone – a logged-in player, or the server operator on the console. But the command basic2 can only be run by logged-in players.

    In general, you should allow as many commands as possible to work on both the console and for players. Commands that need a logged-in player can use the mechanism in the example above to check that the CommandSender is actually a player before continuing. Such commands would generally depend on some attribute of the player, e.g. a teleportation command needs a player to teleport, an item giving command needs a player to give the item to…

    If you want to get more advanced, you could do some extra checks on your command arguments so that e.g. a teleportation command could be used from the console if and only if a player’s name is also supplied.

    Creating A Plugin From Scratch Gradle

    • Open IntelliJ IDEA.

    • Select Gradle in the popup.

    • If you want, select any additional libraries and frameworks you desire, for example Kotlin.

    • Make sure your Project SDK is set to some version of Java 8/1.8.

    • Enter your Group ID, Artifact ID, and Version.

    • Your Group ID should usually correspond to your Java package name. See Main Plugin Class for details.

    • Your Artifact ID should usually correspond to your plugin ID you chose earlier, e.g. myplugin.

    • Your Version is up to you. See Version Numbers for details.

  • The project will be created without a src directory. If you add java files to the incorrectlocation underneath the project, they will be ignored and not compiled, so it is a good idea toenable the checkbox âCreate directories for empty content rootsâ, found in:

  • Windows: File -> Settings -> Build,Execution,Deployment -> Gradle

  • Mac: IntellijIDEA -> Preferences -> Build,Execution,Deployment -> BuildTools -> Gradle

  • Enabling UseAuto-import in the same location will allow change to the gradle configuration toautomatically reload without IDEA prompting you each time.

  • Upon enabling those settings, a /src/main/java directory should be created, where you canstart creating your main plugin code files.

  • Don’t Miss: Can You Tame Pandas In Minecraft

    Writing A Safe Oncommand

    When writing an onCommand, it’s important that you don’t assume any information, such as the sender being a Player. Things to keep in mind:

    Make sure the sender is a Player before casting

    Using simple code like this makes it possible:

    Check the arguments length

    Don’t always assume the sender typed the correct amount of arguments.

    Check if a Player is online before getting them

    Sometimes you want to get another player by the name entered by the player. Always make sure the player is online!

    If you need to modify a Player currently not online, the OfflinePlayer class provides basic manipulation methods.

    Prepare Your Battle Plan And Mindset

    How to code a Minecraft plugin in 10 minutes

    No, the first step is, contrary to what most articles do, NOT downloading software and clicking a freaking button to create a new project right away. You can do this and give up, like most people after 1-4 weeks. Before you even touch something, you need to set your foundations right.

    Start by planning out the next 30 days what days will you be able to dedicate to this, and how many hours? Any important exams, doctor appointments, job or client work, or holidays? Once you get that handled, set a specific goal for the month. It can be I will easily code a double-jump plugin in the next 30 days. It should be attainable and realistic to your level of experience.

    Studies show that most people over-exaggerate their expectations so you should probably divide yours by 1/3 or more. Once you start seeing progress from something realistic it will give you a winners effect and a feeling of empowerment that will keep you motivated. If you set the bar too high you will crash and lose motivation once you get stuck, and then find yourself browsing Facebook or Youtube videos and soon give up on your plan. So really, keep this in mind !

    You May Like: How To Make Big Mushrooms In Minecraft


    Most Popular