use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class BlockIgnitesScriptEvent method onBlockIgnites.
@EventHandler
public void onBlockIgnites(BlockIgniteEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
entity = null;
if (event.getIgnitingEntity() != null) {
entity = new dEntity(event.getIgnitingEntity());
}
origin_location = null;
if (event.getIgnitingBlock() != null) {
// TODO: Why would this be null?
origin_location = new dLocation(event.getIgnitingBlock().getLocation());
}
cause = new Element(event.getCause().toString());
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class CommandSmartEvent method playerCommandPreprocess.
// <--[event]
// @Events
// command
// <command_name>|... command (in <area>)
//
// @Regex ^on( [^\s]+)? command( in ((notable (cuboid|ellipsoid))|([^\s]+)))?$
//
// @Triggers when a player or console runs a Bukkit command. This happens before
// any code of established commands allowing scripters to 'override' existing commands.
// @Context
// <context.command> returns the command name as an Element.
// <context.raw_args> returns any args used as an Element.
// <context.args> returns a dList of the arguments.
// <context.server> returns true if the command was run from the console.
// <context.cuboids> DEPRECATED.
//
// @Determine
// "FULFILLED" to tell Bukkit the command was handled.
//
// -->
@EventHandler
public void playerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
String message = event.getMessage();
String command = message.split(" ")[0].replace("/", "").toUpperCase();
List<String> events = new ArrayList<String>();
events.add("command");
events.add(command + " command");
events.addAll(getAll(command));
// Look for cuboids that contain the block's location
List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(event.getPlayer().getLocation());
dList cuboid_context = new dList();
List<String> cuboidEvents = new ArrayList<String>();
for (dCuboid cuboid : cuboids) {
for (String str : events) {
cuboidEvents.add(str + " in " + cuboid.identifySimple());
}
cuboid_context.add(cuboid.identifySimple());
}
events.addAll(cuboidEvents);
// Add in cuboids context, with either the cuboids or an empty list
context.put("cuboids", cuboid_context);
List<String> args = Arrays.asList(aH.buildArgs(message.split(" ").length > 1 ? message.split(" ", 2)[1] : ""));
// Fill context
context.put("args", new dList(args));
context.put("parsed_args", new dList(args));
context.put("command", new Element(command));
context.put("raw_args", new Element((message.split(" ").length > 1 ? message.split(" ", 2)[1] : "")));
context.put("server", Element.FALSE);
String determination;
// Run any event scripts and get the determination.
determination = BukkitWorldScriptHelper.doEvents(events, null, dEntity.getPlayerFrom(event.getPlayer()), context).toUpperCase();
// receive the default 'Invalid command' gibberish from bukkit.
if (determination.equals("FULFILLED") || determination.equals("CANCELLED")) {
event.setCancelled(true);
}
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class CreeperPoweredScriptEvent method onCreeperPowered.
@EventHandler
public void onCreeperPowered(CreeperPowerEvent event) {
lightning = new dEntity(event.getLightning());
entity = new dEntity(event.getEntity());
cause = new Element(event.getCause().name());
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class EntityChangesBlockScriptEvent method onEntityChangesBlock.
@EventHandler
public void onEntityChangesBlock(EntityChangeBlockEvent event) {
entity = new dEntity(event.getEntity());
location = new dLocation(event.getBlock().getLocation());
old_material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
new_material = dMaterial.getMaterialFrom(event.getTo());
cuboids = new dList();
for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
}
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class EntityCreatePortalScriptEvent method onEntityCreatesPortal.
@EventHandler
public void onEntityCreatesPortal(EntityCreatePortalEvent event) {
entity = new dEntity(event.getEntity());
portal_type = new Element(event.getPortalType().toString());
/*
blocks = new dList();
for (int i=0; i < event.getBlocks().size(); i++) {
dLocation tempLoc = new dLocation(event.getBlocks().get(i).getBlock().getLocation());
blocks.add(tempLoc.identifySimple());
}
*/
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
Aggregations