First two hooks working, updated sample

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot
2010-12-26 02:20:05 +00:00
parent 42ef5c31b7
commit a3ff0f1177
8 changed files with 53 additions and 23 deletions

View File

@@ -0,0 +1,28 @@
package com.dinnerbone.bukkit.sample;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent;
/**
* Handle events for all Player related events
* @author Dinnerbone
*/
public class SamplePlayerListener extends PlayerListener {
private final SamplePlugin plugin;
public SamplePlayerListener(SamplePlugin instance) {
plugin = instance;
}
@Override
public void onPlayerJoin(PlayerEvent event) {
System.out.println(event.getPlayer().getName() + " joined the server! :D");
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
System.out.println(event.getPlayer().getName() + " left the server! :'(");
}
}

View File

@@ -3,6 +3,8 @@ package com.dinnerbone.bukkit.sample;
import java.io.File;
import org.bukkit.Server;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerEvent.EventType;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
@@ -13,9 +15,14 @@ import org.bukkit.plugin.java.JavaPlugin;
* @author Dinnerbone
*/
public class SamplePlugin extends JavaPlugin {
private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, plugin, cLoader);
System.out.println("Johnny five is alive!");
registerEvents();
}
public void onDisable() {
@@ -25,4 +32,9 @@ public class SamplePlugin extends JavaPlugin {
public void onEnable() {
System.out.println("Hello world!");
}
private void registerEvents() {
getServer().getPluginManager().registerEvent(EventType.Join, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(EventType.Quit, playerListener, Priority.Normal, this);
}
}