Skip to content

Instantly share code, notes, and snippets.

@vemacs
Created April 11, 2013 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vemacs/5367775 to your computer and use it in GitHub Desktop.
Save vemacs/5367775 to your computer and use it in GitHub Desktop.
A simple tutorial Bukkit plugin
package com.reddit.admincraft.Tutorial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
// This defines our Tutorial class as a Bukkit Plugin, and also adds the listener methods
public class Tutorial extends JavaPlugin implements Listener {
// onEnable() is run when Bukkit loads the plugin
public void onEnable() {
// we register the listener, which is located in the same class
getServer().getPluginManager().registerEvents(this, this);
}
// JavaPlugins have to have onDisable(), and since we don't need it, it's going to be empty
public void onDisable() {
}
// we set the priority to highest, so our plugin has the final say
@EventHandler(priority = EventPriority.HIGHEST)
// this is triggered when a player joins the game
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// we set the message that is shown here
event.setJoinMessage(ChatColor.YELLOW + "Hello, " + player.getName() + "!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment