From a3ff0f1177e2409e21a53414569ab0cea82463df Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 26 Dec 2010 02:20:05 +0000 Subject: [PATCH] First two hooks working, updated sample By: Dinnerbone --- .../bukkit/sample/SamplePlayerListener.java | 28 +++++++++++++++++++ .../bukkit/sample/SamplePlugin.java | 12 ++++++++ .../org/bukkit/event/player/PlayerEvent.java | 4 +-- .../bukkit/event/player/PlayerJoinEvent.java | 14 ---------- .../bukkit/event/player/PlayerListener.java | 10 ++++--- .../bukkit/plugin/SimplePluginManager.java | 4 ++- .../org/bukkit/plugin/java/JavaPlugin.java | 2 +- .../bukkit/plugin/java/JavaPluginLoader.java | 2 +- 8 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java delete mode 100644 paper-api/src/org/bukkit/event/player/PlayerJoinEvent.java diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java new file mode 100644 index 0000000000..1fb5d7a473 --- /dev/null +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java @@ -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! :'("); + } +} diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java index 8f5445d445..2d435b7416 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java @@ -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); + } } diff --git a/paper-api/src/org/bukkit/event/player/PlayerEvent.java b/paper-api/src/org/bukkit/event/player/PlayerEvent.java index c5900be486..bce15f6a88 100644 --- a/paper-api/src/org/bukkit/event/player/PlayerEvent.java +++ b/paper-api/src/org/bukkit/event/player/PlayerEvent.java @@ -8,10 +8,10 @@ import org.bukkit.event.Event; /** * Represents a player related event */ -public abstract class PlayerEvent extends Event { +public class PlayerEvent extends Event { private final Player player; - protected PlayerEvent(final Server server, final Player who) { + public PlayerEvent(final Server server, final Player who) { super(server); player = who; } diff --git a/paper-api/src/org/bukkit/event/player/PlayerJoinEvent.java b/paper-api/src/org/bukkit/event/player/PlayerJoinEvent.java deleted file mode 100644 index 192abe204e..0000000000 --- a/paper-api/src/org/bukkit/event/player/PlayerJoinEvent.java +++ /dev/null @@ -1,14 +0,0 @@ - -package org.bukkit.event.player; - -import org.bukkit.Player; -import org.bukkit.Server; - -/** - * Handles all event arguments in relation to a player joining a server - */ -public class PlayerJoinEvent extends PlayerEvent { - public PlayerJoinEvent(final Server server, final Player player) { - super(server, player); - } -} diff --git a/paper-api/src/org/bukkit/event/player/PlayerListener.java b/paper-api/src/org/bukkit/event/player/PlayerListener.java index df10bbd821..99ffbedaf0 100644 --- a/paper-api/src/org/bukkit/event/player/PlayerListener.java +++ b/paper-api/src/org/bukkit/event/player/PlayerListener.java @@ -6,19 +6,21 @@ import org.bukkit.event.Listener; /** * Handles all events thrown in relation to a Player */ -public abstract class PlayerListener implements Listener { - private PlayerListener() { +public class PlayerListener implements Listener { + public PlayerListener() { } /** * Called when a player joins a server * @param event Relevant event details */ - public abstract void onPlayerJoin(PlayerJoinEvent event); + public void onPlayerJoin(PlayerEvent event) { + } /** * Called when a player leaves a server * @param event Relevant event details */ - public abstract void onPlayerQuit(PlayerQuitEvent event); + public void onPlayerQuit(PlayerQuitEvent event) { + } } diff --git a/paper-api/src/org/bukkit/plugin/SimplePluginManager.java b/paper-api/src/org/bukkit/plugin/SimplePluginManager.java index 9eaefe1fa8..201e8ed026 100644 --- a/paper-api/src/org/bukkit/plugin/SimplePluginManager.java +++ b/paper-api/src/org/bukkit/plugin/SimplePluginManager.java @@ -15,7 +15,6 @@ import java.util.regex.Matcher; import org.bukkit.Server; import java.util.regex.Pattern; import org.bukkit.event.Event.Priority; -import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; @@ -202,6 +201,9 @@ public final class SimplePluginManager implements PluginManager { position++; } + } else { + listeners = new ArrayList(); + playerListeners.put(type, listeners); } listeners.add(position, new RegisteredListener(listener, priority, plugin)); diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPlugin.java b/paper-api/src/org/bukkit/plugin/java/JavaPlugin.java index e2fa61c14e..7692e3d5d6 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPlugin.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPlugin.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.PluginLoader; * Represents a Java plugin */ public abstract class JavaPlugin implements Plugin { - private boolean isEnabled = false; + private boolean isEnabled = true; private final PluginLoader loader; private final Server server; private final File file; diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index 26e0ac2618..0e273167db 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -82,7 +82,7 @@ public final class JavaPluginLoader implements PluginLoader { switch (type) { case Join: - trueListener.onPlayerJoin((PlayerJoinEvent)event); + trueListener.onPlayerJoin((PlayerEvent)event); break; case Quit: trueListener.onPlayerQuit((PlayerQuitEvent)event);