mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 22:40:21 +01:00
First two hooks working, updated sample
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
42ef5c31b7
commit
a3ff0f1177
8 changed files with 53 additions and 23 deletions
|
@ -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! :'(");
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RegisteredListener>();
|
||||
playerListeners.put(type, listeners);
|
||||
}
|
||||
|
||||
listeners.add(position, new RegisteredListener(listener, priority, plugin));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue