mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Refactored event calling so its front loading avoiding the lookup for each event call.
This now uses an annoymous class implementing IExecutor that facilitates direct event method handler calling Changed commands from being executed exclusively by a player to by a CommandSender to facilitate external command callers such as rcon Fixed CustomEventListener Merged in additional events Added getFullName to PluginDescriptionFile which returns the combination of Name and Version There's also a few bits of reformatting as it seems someones been editing with either tabs or dos eol :( By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
parent
9755073204
commit
df05c36540
18 changed files with 534 additions and 361 deletions
|
@ -3,7 +3,7 @@ package org.bukkit.command;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class Command {
|
||||
private final String name;
|
||||
|
@ -17,12 +17,12 @@ public abstract class Command {
|
|||
this.usageMessage = "/" + name;
|
||||
}
|
||||
|
||||
public abstract boolean execute(Player player, String currentAlias, String[] args);
|
||||
|
||||
public abstract boolean execute(CommandSender sender, String currentAlias, String[] args);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
@ -34,17 +34,17 @@ public abstract class Command {
|
|||
public String getUsage() {
|
||||
return usageMessage;
|
||||
}
|
||||
|
||||
|
||||
public Command setAliases(List<String> aliases) {
|
||||
this.aliases = aliases;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Command setTooltip(String tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Command setUsage(String usage) {
|
||||
this.usageMessage = usage;
|
||||
return this;
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public interface CommandMap {
|
||||
/**
|
||||
* Registers all the commands belonging to a certain plugin.
|
||||
* Registers all the commands belonging to a certain plugin.
|
||||
* @param plugin
|
||||
* @return
|
||||
*/
|
||||
|
@ -13,17 +13,17 @@ public interface CommandMap {
|
|||
|
||||
/**
|
||||
* Registers a command. Returns true on success; false if name is already taken and fallback had to be used.
|
||||
*
|
||||
*
|
||||
* @param a label for this command, without the '/'-prefix.
|
||||
* @return Returns true if command was registered; false if label was already in use.
|
||||
*/
|
||||
public boolean register(String label, String fallbackPrefix, Command command);
|
||||
|
||||
/** Looks for the requested command and executes it if found.
|
||||
*
|
||||
*
|
||||
* @param cmdLine command + arguments. Example: "/test abc 123"
|
||||
* @return targetFound returns false if no target is found.
|
||||
*/
|
||||
public boolean dispatch(Player sender, String cmdLine);
|
||||
public boolean dispatch(CommandSender sender, String cmdLine);
|
||||
|
||||
}
|
||||
|
|
|
@ -13,15 +13,15 @@ public final class PluginCommand extends Command {
|
|||
this.usageMessage = "";
|
||||
}
|
||||
|
||||
public boolean execute(Player player, String commandLabel, String[] args) {
|
||||
boolean cmdSuccess = owningPlugin.onCommand(player, this, commandLabel, args);
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
boolean cmdSuccess = owningPlugin.onCommand(sender, this, commandLabel, args);
|
||||
if (!cmdSuccess && !usageMessage.isEmpty()) {
|
||||
String tmpMsg = usageMessage.replace("<command>", commandLabel);
|
||||
String[] usageLines = tmpMsg.split("\\n");
|
||||
for(String line: usageLines) {
|
||||
while (line.length() > 0) {
|
||||
int stripChars = (line.length() > 53 ? 53:line.length());
|
||||
player.sendMessage(ChatColor.RED + line.substring(0, stripChars));
|
||||
sender.sendMessage(ChatColor.RED + line.substring(0, stripChars));
|
||||
line = line.substring(stripChars);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ public final class SimpleCommandMap implements CommandMap {
|
|||
|
||||
register("reload", "bukkit", new Command("reload") {
|
||||
@Override
|
||||
public boolean execute(Player player, String currentAlias, String[] args) {
|
||||
if (player.isOp()) {
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (sender.isOp()) {
|
||||
server.reload();
|
||||
player.sendMessage(ChatColor.GREEN + "Reload complete.");
|
||||
sender.sendMessage(ChatColor.GREEN + "Reload complete.");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "You do not have sufficient access"
|
||||
sender.sendMessage(ChatColor.RED + "You do not have sufficient access"
|
||||
+ " to reload this server.");
|
||||
}
|
||||
|
||||
|
@ -56,28 +56,28 @@ public final class SimpleCommandMap implements CommandMap {
|
|||
register(name, fallbackPrefix, command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean register(String name, String fallbackPrefix, Command command) {
|
||||
boolean nameInUse = (knownCommands.get(name) != null);
|
||||
if (nameInUse)
|
||||
name = fallbackPrefix + ":" + name;
|
||||
|
||||
|
||||
knownCommands.put(name, command);
|
||||
return !nameInUse;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean dispatch(Player sender, String commandLine) {
|
||||
public boolean dispatch(CommandSender sender, String commandLine) {
|
||||
String[] args = commandLine.split(" ");
|
||||
String sentCommandLabel = args[0].substring(1);
|
||||
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
|
||||
Command target = knownCommands.get(sentCommandLabel);
|
||||
boolean isRegisteredCommand = (target != null);
|
||||
if (isRegisteredCommand) {
|
||||
|
@ -98,12 +98,12 @@ public final class SimpleCommandMap implements CommandMap {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String currentAlias, String[] args) {
|
||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
player.sendMessage("This server is running " + ChatColor.GREEN
|
||||
sender.sendMessage("This server is running " + ChatColor.GREEN
|
||||
+ server.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + server.getVersion());
|
||||
player.sendMessage("This server is also sporting some funky dev build of Bukkit!");
|
||||
player.sendMessage("Plugins: " + getPluginList());
|
||||
sender.sendMessage("This server is also sporting some funky dev build of Bukkit!");
|
||||
sender.sendMessage("Plugins: " + getPluginList());
|
||||
} else {
|
||||
StringBuilder name = new StringBuilder();
|
||||
|
||||
|
@ -118,26 +118,26 @@ public final class SimpleCommandMap implements CommandMap {
|
|||
|
||||
if (plugin != null) {
|
||||
PluginDescriptionFile desc = plugin.getDescription();
|
||||
player.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
|
||||
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
|
||||
|
||||
if (desc.getDescription() != null) {
|
||||
player.sendMessage(desc.getDescription());
|
||||
sender.sendMessage(desc.getDescription());
|
||||
}
|
||||
|
||||
if (desc.getWebsite() != null) {
|
||||
player.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
|
||||
sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
|
||||
}
|
||||
|
||||
if (!desc.getAuthors().isEmpty()) {
|
||||
if (desc.getAuthors().size() == 1) {
|
||||
player.sendMessage("Author: " + getAuthors(desc));
|
||||
sender.sendMessage("Author: " + getAuthors(desc));
|
||||
} else {
|
||||
player.sendMessage("Authors: " + getAuthors(desc));
|
||||
sender.sendMessage("Authors: " + getAuthors(desc));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("This server is not running any plugin by that name.");
|
||||
player.sendMessage("Plugins: " + getPluginList());
|
||||
sender.sendMessage("This server is not running any plugin by that name.");
|
||||
sender.sendMessage("Plugins: " + getPluginList());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,13 @@ package org.bukkit.entity;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Represents a player, connected or not
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Player extends HumanEntity {
|
||||
public interface Player extends HumanEntity, CommandSender {
|
||||
/**
|
||||
* Checks if this player is currently online
|
||||
*
|
||||
|
@ -16,20 +17,6 @@ public interface Player extends HumanEntity {
|
|||
*/
|
||||
public boolean isOnline();
|
||||
|
||||
/**
|
||||
* Checks if this player is currently op
|
||||
*
|
||||
* @return true if they are online
|
||||
*/
|
||||
public boolean isOp();
|
||||
|
||||
/**
|
||||
* Sends this player a message, which will be displayed in their chat
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
*/
|
||||
public void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* Gets the "friendly" name to display of this player. This may include color.
|
||||
*
|
||||
|
@ -49,14 +36,14 @@ public interface Player extends HumanEntity {
|
|||
* @return String containing a color formatted name to display for this player
|
||||
*/
|
||||
public void setDisplayName(String name);
|
||||
|
||||
|
||||
/**
|
||||
* Set the target of the player's compass.
|
||||
*
|
||||
*
|
||||
* @param loc
|
||||
*/
|
||||
public void setCompassTarget(Location loc);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the socket address of this player
|
||||
* @return the player's address
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
package org.bukkit.event;
|
||||
|
||||
public interface CustomEventListener {
|
||||
public void onCustomEvent(Event event);
|
||||
}
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all custom events
|
||||
*/
|
||||
public class CustomEventListener implements Listener {
|
||||
public CustomEventListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player joins a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onCustomEvent(Event event) {
|
||||
}
|
||||
}
|
|
@ -38,8 +38,7 @@ public abstract class Event {
|
|||
* @return Name of this event
|
||||
*/
|
||||
public final String getEventName() {
|
||||
if(type!=Type.CUSTOM_EVENT) return type.toString();
|
||||
else return name;
|
||||
return ( type != Type.CUSTOM_EVENT) ? type.toString() : name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,6 +274,13 @@ public abstract class Event {
|
|||
*/
|
||||
BLOCK_INTERACT (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a block is destroyed from being burnt by fire
|
||||
*
|
||||
* @see org.bukkit.event.block.BlockBurnEvent
|
||||
*/
|
||||
BLOCK_BURN (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when leaves are decaying naturally
|
||||
*
|
||||
|
@ -356,6 +362,13 @@ public abstract class Event {
|
|||
*/
|
||||
PLUGIN_DISABLE (Category.SERVER),
|
||||
|
||||
/**
|
||||
* Called when a plugin is disabled
|
||||
*
|
||||
* @see org.bukkit.event.server.PluginEvent
|
||||
*/
|
||||
SERVER_COMMAND (Category.SERVER),
|
||||
|
||||
/**
|
||||
* WORLD EVENTS
|
||||
*/
|
||||
|
@ -417,7 +430,7 @@ public abstract class Event {
|
|||
* @see org.bukkit.event.entity.EntityDamageByEntityEvent
|
||||
*/
|
||||
ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY),
|
||||
|
||||
|
||||
/**
|
||||
* Called when a LivingEntity is damaged by a projectile Entity
|
||||
*
|
||||
|
@ -445,7 +458,7 @@ public abstract class Event {
|
|||
* @todo: add javadoc see comment
|
||||
*/
|
||||
ENTITY_COMBUST (Category.LIVING_ENTITY),
|
||||
|
||||
|
||||
/**
|
||||
* Called when an entity explodes, either TNT, Creeper, or Ghast Fireball
|
||||
*
|
||||
|
@ -453,6 +466,13 @@ public abstract class Event {
|
|||
*/
|
||||
ENTITY_EXPLODE (Category.LIVING_ENTITY),
|
||||
|
||||
/**
|
||||
* Called when an entity targets another entity
|
||||
*
|
||||
* @see org.bukkit.event.entity.EntityTargetEvent
|
||||
*/
|
||||
ENTITY_TARGET (Category.LIVING_ENTITY),
|
||||
|
||||
/**
|
||||
* VEHICLE EVENTS
|
||||
*/
|
||||
|
|
|
@ -1,97 +1,104 @@
|
|||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to Blocks
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockListener implements Listener {
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public BlockListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is damaged (or broken)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we try to place a block, to see if we can build it
|
||||
*/
|
||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block flows (water/lava)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is interacted with
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when leaves are decaying naturally
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to Blocks
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockListener implements Listener {
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public BlockListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is damaged (or broken)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we try to place a block, to see if we can build it
|
||||
*/
|
||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block flows (water/lava)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is interacted with
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRightClick(BlockRightClickEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when leaves are decaying naturally
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is destroyed from burning
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ public class EntityListener implements Listener {
|
|||
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
}
|
||||
|
||||
|
||||
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
|
||||
}
|
||||
|
||||
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
}
|
||||
|
||||
|
@ -26,4 +26,10 @@ public class EntityListener implements Listener {
|
|||
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
}
|
||||
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
}
|
||||
|
||||
public void onEntityTarget(EntityTargetEvent event) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,4 +22,12 @@ public class ServerListener implements Listener {
|
|||
*/
|
||||
public void onPluginDisabled(PluginEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a server command is used
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onServerCommand(PluginEvent event) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ package org.bukkit.plugin;
|
|||
import java.io.File;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
/**
|
||||
|
@ -14,21 +14,21 @@ public interface Plugin {
|
|||
/**
|
||||
* Returns the folder that the plugin data's files are located in. The
|
||||
* folder may not yet exist.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getDataFolder();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the plugin.yaml file containing the details for this plugin
|
||||
*
|
||||
* @return Contents of the plugin.yaml file
|
||||
*/
|
||||
public PluginDescriptionFile getDescription();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the main configuration file. It should be loaded.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Configuration getConfiguration();
|
||||
|
@ -63,11 +63,11 @@ public interface Plugin {
|
|||
* Called when this plugin is enabled
|
||||
*/
|
||||
public void onEnable();
|
||||
|
||||
|
||||
/**
|
||||
* Called when a command registered by this plugin is received.
|
||||
* @param commandLabel
|
||||
* @param commandLabel
|
||||
* @return TODO
|
||||
*/
|
||||
public boolean onCommand(Player player, Command command, String commandLabel, String[] args);
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,15 @@ public final class PluginDescriptionFile {
|
|||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a plugin including the version
|
||||
*
|
||||
* @return String name
|
||||
*/
|
||||
public String getFullName() {
|
||||
return name + " v" + version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main class for a plugin
|
||||
*
|
||||
|
@ -85,7 +94,7 @@ public final class PluginDescriptionFile {
|
|||
public String getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
|
||||
public Object getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Represents a plugin loader, which handles direct access to specific types
|
||||
|
@ -27,13 +28,12 @@ public interface PluginLoader {
|
|||
public Pattern[] getPluginFileFilters();
|
||||
|
||||
/**
|
||||
* Calls a player related event with the given details
|
||||
* Creates and returns an event executor
|
||||
*
|
||||
* @param registration Registered information on the plugin to call about this event
|
||||
* @param type Type of player related event to call
|
||||
* @param event Event details
|
||||
* @param type Type of the event executor to create
|
||||
* @param listener the object that will handle the eventual call back
|
||||
*/
|
||||
public void callEvent(RegisteredListener registration, Event event);
|
||||
public IExecutor createExecutor(Event.Type type, Listener listener);
|
||||
|
||||
/**
|
||||
* Enables the specified plugin
|
||||
|
|
|
@ -93,6 +93,17 @@ public interface PluginManager {
|
|||
*/
|
||||
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);
|
||||
|
||||
/**
|
||||
* Registers the given event to the specified executor
|
||||
*
|
||||
* @param type EventType to register
|
||||
* @param listener Listener to register
|
||||
* @param executor IExecutor to register
|
||||
* @param priority Priority of this event
|
||||
* @param plugin Plugin to register
|
||||
*/
|
||||
public void registerEvent(Event.Type type, Listener listener, IExecutor executor, Priority priority, Plugin plugin);
|
||||
|
||||
/**
|
||||
* Enables the specified plugin
|
||||
*
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.bukkit.plugin;
|
|||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.IExecutor;
|
||||
|
||||
/**
|
||||
* Stores relevant information for plugin listeners
|
||||
|
@ -11,11 +12,20 @@ public class RegisteredListener {
|
|||
private final Listener listener;
|
||||
private final Event.Priority priority;
|
||||
private final Plugin plugin;
|
||||
private final IExecutor executor;
|
||||
|
||||
public RegisteredListener(final Listener pluginListener, final Event.Priority eventPriority, final Plugin registeredPlugin) {
|
||||
public RegisteredListener(final Listener pluginListener, final IExecutor eventExecutor, final Event.Priority eventPriority, final Plugin registeredPlugin ) {
|
||||
listener = pluginListener;
|
||||
priority = eventPriority;
|
||||
plugin = registeredPlugin;
|
||||
executor = eventExecutor;
|
||||
}
|
||||
|
||||
public RegisteredListener(final Listener pluginListener, final Event.Priority eventPriority, final Plugin registeredPlugin, Event.Type type ) {
|
||||
listener = pluginListener;
|
||||
priority = eventPriority;
|
||||
plugin = registeredPlugin;
|
||||
executor = registeredPlugin.getPluginLoader().createExecutor( type, pluginListener );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,4 +51,12 @@ public class RegisteredListener {
|
|||
public Event.Priority getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the event executor
|
||||
* @return Registered Priority
|
||||
*/
|
||||
public void callEvent(Event event) {
|
||||
executor.execute( listener, event );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,15 +193,11 @@ public final class SimplePluginManager implements PluginManager {
|
|||
|
||||
if (eventListeners != null) {
|
||||
for (RegisteredListener registration : eventListeners) {
|
||||
Plugin plugin = registration.getPlugin();
|
||||
PluginLoader loader = plugin.getPluginLoader();
|
||||
|
||||
if (plugin.isEnabled()) {
|
||||
try {
|
||||
loader.callEvent(registration, event);
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(SimplePluginManager.class.getName()).log(Level.SEVERE, "Could not pass event " + event.getType() + " to " + plugin.getDescription().getName(), ex);
|
||||
}
|
||||
// NOTE: no need to check isEnabled as all disabled plugins have their listeners disabled
|
||||
try {
|
||||
registration.callEvent( event );
|
||||
} catch (Throwable ex) {
|
||||
Logger.getLogger(SimplePluginManager.class.getName()).log(Level.SEVERE, "Could not pass event " + event.getType() + " to " + registration.getPlugin().getDescription().getName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,19 +212,43 @@ public final class SimplePluginManager implements PluginManager {
|
|||
* @param plugin Plugin to register
|
||||
*/
|
||||
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin) {
|
||||
getEventListeners( type ).offer(new RegisteredListener(listener, priority, plugin, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given event to the specified listener
|
||||
*
|
||||
* @param type EventType to register
|
||||
* @param listener PlayerListener to register
|
||||
* @param priority Priority of this event
|
||||
* @param plugin Plugin to register
|
||||
*/
|
||||
public void registerEvent(Event.Type type, Listener listener, IExecutor executor, Priority priority, Plugin plugin) {
|
||||
getEventListeners( type ).offer(new RegisteredListener(listener, executor, priority, plugin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PriorityQueue of RegisteredListener for the specified event type creating a new queue if needed
|
||||
*
|
||||
* @param type EventType to lookup
|
||||
* @return PriorityQueue<RegisteredListener> the looked up or create queue matching the requested type
|
||||
*/
|
||||
private PriorityQueue<RegisteredListener> getEventListeners( Event.Type type )
|
||||
{
|
||||
PriorityQueue<RegisteredListener> eventListeners = listeners.get(type);
|
||||
|
||||
if (eventListeners == null) {
|
||||
eventListeners = new PriorityQueue<RegisteredListener>(11,
|
||||
new Comparator<RegisteredListener>( ) {
|
||||
public int compare(RegisteredListener i, RegisteredListener j) {
|
||||
return i.getPriority().compareTo(j.getPriority());
|
||||
}
|
||||
}
|
||||
);
|
||||
listeners.put(type, eventListeners);
|
||||
if (eventListeners != null) {
|
||||
return eventListeners;
|
||||
}
|
||||
|
||||
eventListeners.offer(new RegisteredListener(listener, priority, plugin));
|
||||
eventListeners = new PriorityQueue<RegisteredListener>(
|
||||
11, new Comparator<RegisteredListener>() {
|
||||
public int compare(RegisteredListener i, RegisteredListener j) {
|
||||
return i.getPriority().compareTo(j.getPriority());
|
||||
}
|
||||
}
|
||||
);
|
||||
listeners.put(type, eventListeners);
|
||||
return eventListeners;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ package org.bukkit.plugin.java;
|
|||
import java.io.File;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
|
@ -49,7 +49,7 @@ public abstract class JavaPlugin implements Plugin {
|
|||
/**
|
||||
* Returns the folder that the plugin data's files are located in. The
|
||||
* folder may not yet exist.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getDataFolder() {
|
||||
|
@ -100,13 +100,13 @@ public abstract class JavaPlugin implements Plugin {
|
|||
public PluginDescriptionFile getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the main configuration located at
|
||||
* <plugin name>/config.yml and loads the file. If the configuration file
|
||||
* does not exist and it cannot be loaded, no error will be emitted and
|
||||
* the configuration file will have no values.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Configuration getConfiguration() {
|
||||
|
@ -138,11 +138,11 @@ public abstract class JavaPlugin implements Plugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when a command registered by this plugin is received.
|
||||
*/
|
||||
public boolean onCommand(Player player, Command cmd, String commandLabel, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return false; // default implementation: do nothing!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,9 @@ import org.bukkit.event.CustomEventListener;
|
|||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.server.PluginEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.event.server.*;
|
||||
import org.bukkit.event.vehicle.*;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
@ -77,7 +70,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
Class<?> jarClass = Class.forName(description.getMain(), true, loader);
|
||||
Class<? extends JavaPlugin> plugin = jarClass.asSubclass(JavaPlugin.class);
|
||||
Constructor<? extends JavaPlugin> constructor = plugin.getConstructor(PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, File.class, ClassLoader.class);
|
||||
|
||||
|
||||
result = constructor.newInstance(this, server, description, dataFolder, file, loader);
|
||||
} catch (Throwable ex) {
|
||||
throw new InvalidPluginException(ex);
|
||||
|
@ -85,13 +78,13 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
|
||||
return (Plugin)result;
|
||||
}
|
||||
|
||||
|
||||
private File getDataFolder(File file) {
|
||||
File dataFolder = null;
|
||||
|
||||
|
||||
String filename = file.getName();
|
||||
int index = file.getName().lastIndexOf(".");
|
||||
|
||||
|
||||
if (index != -1) {
|
||||
String name = filename.substring(0, index);
|
||||
dataFolder = new File(file.getParentFile(), name);
|
||||
|
@ -100,9 +93,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
// Using _ to prevent name collision
|
||||
dataFolder = new File(file.getParentFile(), filename + "_");
|
||||
}
|
||||
|
||||
|
||||
//dataFolder.mkdirs();
|
||||
|
||||
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
|
@ -118,158 +111,238 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
classes.put(name, clazz);
|
||||
}
|
||||
|
||||
public void callEvent(RegisteredListener registration, Event event) {
|
||||
Listener listener = registration.getListener();
|
||||
public IExecutor createExecutor( Event.Type type, Listener listener ) {
|
||||
// TODO: remove multiple Listener type and hence casts
|
||||
switch (type) {
|
||||
// Player Events
|
||||
case PLAYER_JOIN:
|
||||
return new IExecutor() {
|
||||
public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerJoin( (PlayerEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_QUIT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerQuit( (PlayerEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_COMMAND:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerCommand( (PlayerChatEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_CHAT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerChat( (PlayerChatEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_MOVE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerMove( (PlayerMoveEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_TELEPORT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerTeleport( (PlayerMoveEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_ITEM:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerItem( (PlayerItemEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_LOGIN:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerLogin( (PlayerLoginEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_EGG_THROW:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerEggThrow( (PlayerEggThrowEvent)event );
|
||||
}
|
||||
};
|
||||
case PLAYER_ANIMATION:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((PlayerListener)listener).onPlayerAnimation( (PlayerAnimationEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
if (listener instanceof PlayerListener) {
|
||||
PlayerListener trueListener = (PlayerListener)listener;
|
||||
// Block Events
|
||||
case BLOCK_PHYSICS:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockPhysics( (BlockPhysicsEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_CANBUILD:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockCanBuild( (BlockCanBuildEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_RIGHTCLICKED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockRightClick( (BlockRightClickEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_PLACED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockPlace( (BlockPlaceEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_DAMAGED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockDamage( (BlockDamageEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_INTERACT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockInteract( (BlockInteractEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_FLOW:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockFlow( (BlockFromToEvent)event );
|
||||
}
|
||||
};
|
||||
case LEAVES_DECAY:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onLeavesDecay( (LeavesDecayEvent)event );
|
||||
}
|
||||
};
|
||||
case BLOCK_IGNITE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockIgnite( (BlockIgniteEvent)event );
|
||||
}
|
||||
};
|
||||
case REDSTONE_CHANGE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockRedstoneChange( (BlockFromToEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.getType()) {
|
||||
case PLAYER_JOIN:
|
||||
trueListener.onPlayerJoin((PlayerEvent)event);
|
||||
break;
|
||||
case PLAYER_QUIT:
|
||||
trueListener.onPlayerQuit((PlayerEvent)event);
|
||||
break;
|
||||
case PLAYER_COMMAND:
|
||||
trueListener.onPlayerCommand((PlayerChatEvent)event);
|
||||
break;
|
||||
case PLAYER_CHAT:
|
||||
trueListener.onPlayerChat((PlayerChatEvent)event);
|
||||
break;
|
||||
case PLAYER_MOVE:
|
||||
trueListener.onPlayerMove((PlayerMoveEvent)event);
|
||||
break;
|
||||
case PLAYER_TELEPORT:
|
||||
trueListener.onPlayerTeleport((PlayerMoveEvent)event);
|
||||
break;
|
||||
case PLAYER_ITEM:
|
||||
trueListener.onPlayerItem((PlayerItemEvent)event);
|
||||
break;
|
||||
case PLAYER_LOGIN:
|
||||
trueListener.onPlayerLogin((PlayerLoginEvent)event);
|
||||
break;
|
||||
case PLAYER_EGG_THROW:
|
||||
trueListener.onPlayerEggThrow((PlayerEggThrowEvent)event);
|
||||
break;
|
||||
case PLAYER_ANIMATION:
|
||||
trueListener.onPlayerAnimation((PlayerAnimationEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if (listener instanceof BlockListener) {
|
||||
BlockListener trueListener = (BlockListener)listener;
|
||||
case BLOCK_BURN:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((BlockListener)listener).onBlockBurn( (BlockBurnEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.getType()) {
|
||||
case BLOCK_PHYSICS:
|
||||
trueListener.onBlockPhysics((BlockPhysicsEvent)event);
|
||||
break;
|
||||
case BLOCK_CANBUILD:
|
||||
trueListener.onBlockCanBuild((BlockCanBuildEvent)event);
|
||||
break;
|
||||
case BLOCK_RIGHTCLICKED:
|
||||
trueListener.onBlockRightClick((BlockRightClickEvent) event);
|
||||
break;
|
||||
case BLOCK_PLACED:
|
||||
trueListener.onBlockPlace((BlockPlaceEvent)event);
|
||||
break;
|
||||
case BLOCK_DAMAGED:
|
||||
trueListener.onBlockDamage((BlockDamageEvent)event);
|
||||
break;
|
||||
case BLOCK_INTERACT:
|
||||
trueListener.onBlockInteract((BlockInteractEvent)event);
|
||||
break;
|
||||
case BLOCK_FLOW:
|
||||
trueListener.onBlockFlow((BlockFromToEvent)event);
|
||||
break;
|
||||
case LEAVES_DECAY:
|
||||
trueListener.onLeavesDecay((LeavesDecayEvent)event);
|
||||
break;
|
||||
case BLOCK_IGNITE:
|
||||
trueListener.onBlockIgnite((BlockIgniteEvent)event);
|
||||
break;
|
||||
case REDSTONE_CHANGE:
|
||||
trueListener.onBlockRedstoneChange((BlockFromToEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if(listener instanceof ServerListener) {
|
||||
ServerListener trueListener = (ServerListener)listener;
|
||||
// Server Events
|
||||
case PLUGIN_ENABLE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((ServerListener)listener).onPluginEnabled( (PluginEvent)event );
|
||||
}
|
||||
};
|
||||
case PLUGIN_DISABLE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((ServerListener)listener).onPluginDisabled( (PluginEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.getType()) {
|
||||
case PLUGIN_ENABLE:
|
||||
trueListener.onPluginEnabled((PluginEvent)event);
|
||||
break;
|
||||
case PLUGIN_DISABLE:
|
||||
trueListener.onPluginDisabled((PluginEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if(listener instanceof WorldListener) {
|
||||
WorldListener trueListener = (WorldListener)listener;
|
||||
case SERVER_COMMAND:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((ServerListener)listener).onServerCommand( (ServerCommandEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.getType()) {
|
||||
case CHUNK_LOADED:
|
||||
trueListener.onChunkLoaded((ChunkLoadEvent)event);
|
||||
break;
|
||||
case CHUNK_UNLOADED:
|
||||
trueListener.onChunkUnloaded((ChunkUnloadEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if(listener instanceof EntityListener) {
|
||||
EntityListener trueListener = (EntityListener) listener;
|
||||
switch(event.getType())
|
||||
{
|
||||
case ENTITY_DAMAGEDBY_BLOCK:
|
||||
trueListener.onEntityDamageByBlock((EntityDamageByBlockEvent)event);
|
||||
break;
|
||||
case ENTITY_DAMAGEDBY_ENTITY:
|
||||
trueListener.onEntityDamageByEntity((EntityDamageByEntityEvent)event);
|
||||
break;
|
||||
case ENTITY_DAMAGEDBY_PROJECTILE:
|
||||
trueListener.onEntityDamageByProjectile((EntityDamageByProjectileEvent)event);
|
||||
break;
|
||||
case ENTITY_DAMAGED:
|
||||
trueListener.onEntityDamage((EntityDamageEvent)event);
|
||||
break;
|
||||
case ENTITY_DEATH:
|
||||
// TODO: ENTITY_DEATH hook
|
||||
break;
|
||||
case ENTITY_COMBUST:
|
||||
trueListener.onEntityCombust((EntityCombustEvent)event);
|
||||
break;
|
||||
case ENTITY_EXPLODE:
|
||||
trueListener.onEntityExplode((EntityExplodeEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if (listener instanceof VehicleListener) {
|
||||
VehicleListener trueListener = (VehicleListener)listener;
|
||||
// World Events
|
||||
case CHUNK_LOADED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((WorldListener)listener).onChunkLoaded( (ChunkLoadEvent)event );
|
||||
}
|
||||
};
|
||||
case CHUNK_UNLOADED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((WorldListener)listener).onChunkUnloaded( (ChunkUnloadEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.getType()) {
|
||||
case VEHICLE_CREATE:
|
||||
trueListener.onVehicleCreate((VehicleCreateEvent)event);
|
||||
break;
|
||||
case VEHICLE_DAMAGE:
|
||||
trueListener.onVehicleDamage((VehicleDamageEvent)event);
|
||||
break;
|
||||
case VEHICLE_COLLISION_BLOCK:
|
||||
trueListener.onVehicleBlockCollision((VehicleBlockCollisionEvent)event);
|
||||
break;
|
||||
case VEHICLE_COLLISION_ENTITY:
|
||||
trueListener.onVehicleEntityCollision((VehicleEntityCollisionEvent)event);
|
||||
break;
|
||||
case VEHICLE_ENTER:
|
||||
trueListener.onVehicleEnter((VehicleEnterEvent)event);
|
||||
break;
|
||||
case VEHICLE_EXIT:
|
||||
trueListener.onVehicleExit((VehicleExitEvent)event);
|
||||
break;
|
||||
case VEHICLE_MOVE:
|
||||
trueListener.onVehicleMove((VehicleMoveEvent)event);
|
||||
break;
|
||||
}
|
||||
} else if(listener instanceof CustomEventListener) {
|
||||
if(event.getType()==Event.Type.CUSTOM_EVENT) {
|
||||
((CustomEventListener)listener).onCustomEvent(event);
|
||||
}
|
||||
// Entity Events
|
||||
case ENTITY_DAMAGEDBY_BLOCK:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityDamageByBlock( (EntityDamageByBlockEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_DAMAGEDBY_ENTITY:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityDamageByEntity( (EntityDamageByEntityEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_DAMAGEDBY_PROJECTILE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityDamageByProjectile( (EntityDamageByProjectileEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_DAMAGED:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityDamage( (EntityDamageEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_DEATH:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityDeath( (EntityDeathEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_COMBUST:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityCombust( (EntityCombustEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_EXPLODE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityExplode( (EntityExplodeEvent)event );
|
||||
}
|
||||
};
|
||||
case ENTITY_TARGET:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((EntityListener)listener).onEntityTarget( (EntityTargetEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
// Vehicle Events
|
||||
case VEHICLE_CREATE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleCreate( (VehicleCreateEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_DAMAGE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleDamage( (VehicleDamageEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_COLLISION_BLOCK:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleBlockCollision( (VehicleBlockCollisionEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_COLLISION_ENTITY:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleEntityCollision( (VehicleEntityCollisionEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_ENTER:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleEnter( (VehicleEnterEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_EXIT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleExit( (VehicleExitEvent)event );
|
||||
}
|
||||
};
|
||||
case VEHICLE_MOVE:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((VehicleListener)listener).onVehicleMove( (VehicleMoveEvent)event );
|
||||
}
|
||||
};
|
||||
|
||||
// Custom Events
|
||||
case CUSTOM_EVENT:
|
||||
return new IExecutor() { public void execute( Listener listener, Event event ) {
|
||||
((CustomEventListener)listener).onCustomEvent( event );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "Event " + type + " is not supported" );
|
||||
}
|
||||
|
||||
public void enablePlugin(final Plugin plugin) {
|
||||
|
@ -281,7 +354,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
JavaPlugin jPlugin = (JavaPlugin)plugin;
|
||||
|
||||
server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_ENABLE, plugin));
|
||||
|
||||
|
||||
jPlugin.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue