Minecraft Blogs / Tutorial

How to Make a Java Plugin (Simple Plugin)

  • 1,753 views, 2 today
  • 2
  • 1
  • 1
ToxicCoder's Avatar ToxicCoder
Level 4 : Apprentice Explorer
4
Hello guy ima try my best to show you how to make a simple plugin (sorry for lack of screenshots). I am gonna assume you have eclipse and java JDK.

1.) Open Eclipse (Ez right?)
2.) click ALT + shift + n (ez)
3.) new java project
4.)Name it Test
5.) Download bukkit api dl.bukkit.org/downloads/bukkit/
click on Development build if its for 1.6.4
6.) click your project, go to properties, click on java build path, click on libraries on tabs above, and click add external jars and locate ur bukkit api.
7.) now to get on with the good stuff
8.)click on project, right click, new, package name it me.toxic.test
9.) click on project, right click, new, class, Test.
10.) here is where we start our code ( i may have a source code posted)
11.) you should see public class Test{
}
12.) this is what you need public class Test extends JavaPlugin implements Listener{
}
13.) put your mouse over them and export them with bukkit. JavaPlugin just means were making a minecraft plugin , listener means well to tell the plugin to pay attention to the player.
14.) add this @Override
public void onEnable(){
}
15.) this means that when the plugin turns on it will do what the code says that re inside these { }.
16.) so now your code looks like this
public class Test extends JavaPlugin implements Listener{
@Override
public void onEnable(){
}
p.s. you may need to export onEnable
17. Now were gonna add @Override
public void onDisable(){
}
18. that means that the plugin will be disabled when the server shuts down.
19. our code should now look like this
public class Test extends JavaPlugin implements Listener{
@Override
public void onEnable(){
}
@Override
public void onDisable(){
}
}

20. You guys may be getting confused if you need more details just post a comment.
21. ok now were gonna do an event Handler. That means we gonna do an event for example When a player dies, i can set a custom death message like King was slaughtered!
22. ok i know it may be hard just keep with me.
23. this is what were gonna do now
@EventHandler
this means well it handles events the code says it and this needs to be exported.
24. when you have added that do this
public void onPlayerJoin(PlayerJoinEvent e){
}

this is a player Join event means when a player joins the server.

25. our code should look like this.

public class Test extends JavaPlugin implements Listener{
@Override
public void onEnable(){
}
@Override
public void onDisable(){
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
}
}

26. WoW LOOK AT THAT CODE
27. were almost done with our first basic plugin.......
28. ok lets finish up this plugin shall we...

29. Now lets set a custom join Message
Player p = e.getPlayer();
im guessing you wanna know what that means well here we go e = Event has i stated above with PlayerJoinEvent e
so its just getting the player that is joining ok lets do this
30.) e.setJoinMessage("O look a new person!");
import everything on this line that needs to be if i mess up here i will fix it in a bit :D
you could of has said anything you wanted to in the "" marks..
31. ok lets see our code now shall we....
public class Test extends JavaPlugin implements Listener{
@Override
public void onEnable(){
}
@Override
public void onDisable(){
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player p = e.getPlayer();
e.setJoinMessage("O look a new person!");
}
}

32. WOW now before we finish up the code 1 more thing we need to do or nothing will work and i may add something ez in there tho :D.

33. We HAVE to add this for the plugin to work right below this code
@Override
public void onEnable(){
add this....
Bukkit.getServer().getPluginManager().registerEvents(this, this);

that registers the event for playerjoin which means it makes it say the new join message....

34. here is the whole new code....

public class Test extends JavaPlugin implements Listener{
@Override
public void onEnable(){
Bukkit.getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable(){
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player p = e.getPlayer();
e.setJoinMessage("O look a new person!");
}
}

WOW ikr not alot but may be tough for the new people.....

35.) lets add a plugin.yml cause WE HAVE to
so right click on your project click new File name it plugin.yml
now copy/paste this in there

name: JoinMessage
main: me.toxic.test.Test
version: 1.1

there

36. now lets add this so we can look in the console to see if it works below this code

@Override
public void onEnable(){
Bukkit.getServer().getPluginManager().registerEvents(this, this);
add this
getLogger().info("JoinMessage has been enabled!");

so we know it'll work now the code should look like this...

public class PMC extends JavaPlugin implements Listener{
@Override
public void onEnable(){
Bukkit.getServer().getPluginManager().registerEvents(this, this);
getLogger().info("JoinMessage has been enabled!");
}
@Override
public void onDisable(){
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
Player p = e.getPlayer();
e.setJoinMessage("O look a new person!");
}
}

WOW now the plugin should work let me try it........
Works Now click your project Export it as a Jar File and and THERE YOU GO and put it in your plugins folder and check it out..
I will do more Advanced Things later Thanks for reading bye and dont forget to subscribe to my profile for more blogs!
Tags

Create an account or sign in to comment.

1
11/17/2013 8:35 pm
Level 4 : Apprentice Explorer
ToxicCoder
ToxicCoder's Avatar
Was this helpful?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome