Skip to content

Commit

Permalink
Add "player takes item from furnace" and "entity exits portal" world …
Browse files Browse the repository at this point in the history
…events.
  • Loading branch information
davidcernat committed Sep 15, 2013
1 parent abacb23 commit a7cc331
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dItem.java
Expand Up @@ -215,6 +215,10 @@ public dItem(int itemId) {
public dItem(Material material, int qty) {
item = new ItemStack(material, qty);
}

public dItem(dMaterial material, int qty) {
item = new ItemStack(material.getMaterial(), qty);
}

public dItem(int type, int qty) {
item = new ItemStack(type, qty);
Expand Down
Expand Up @@ -797,7 +797,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Fly
// @Usage fly (cancel) [<entity>|...] (origin:<location>) (destinations:<location>|...) (speed:<#.#>)
// @Usage fly (cancel) [<entity>|...] (controller:<player>) (origin:<location>) (destinations:<location>|...) (speed:<#.#>) (rotationthreshold:<#.#>)
// @Required 1
// @Stable Todo
// @Short Make an entity fly where its controller is looking or fly to waypoints.
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand Down Expand Up @@ -746,6 +747,43 @@ else if (Argument.valueOf(determination)
}
}

// <--[event]
// @Events
// player takes item from furnace
// player takes <item> from furnace
// player takes <material> from furnace
//
// @Triggers when a player takes an item from a furnace.
// @Context
// <context.location> returns the dLocation of the furnace.
// <context.item> returns the dItem taken out of the furnace.
//
// @Determine
// Element(Integer) to set the amount of experience the player will get.
//
// -->
@EventHandler
public void furnaceExtract(FurnaceExtractEvent event) {

Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial itemMaterial = new dMaterial(event.getItemType());
dItem item = new dItem(itemMaterial, event.getItemAmount());

context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("item", item);

String determination = doEvents(Arrays.asList
("player takes item from furnace",
"player takes " + item.identify() + " from furnace",
"player takes " + itemMaterial.identify() + " from furnace"),
null, event.getPlayer(), context);

if (Argument.valueOf(determination)
.matchesPrimitive(aH.PrimitiveType.Integer)) {
event.setExpToDrop(aH.getIntegerFrom(determination));
}
}

// <--[event]
// @Events
// furnace smelts item (into <item>)
Expand Down Expand Up @@ -1516,6 +1554,33 @@ public void entityPortalEnter(EntityPortalEnterEvent event) {
entityType + " enters portal"),
null, null, context);
}

// <--[event]
// @Events
// entity exits portal
// <entity> exits portal
//
// @Triggers when an entity exits a portal.
// @Context
// <context.entity> returns the dEntity.
// <context.location> returns the dLocation of the portal block touched by the entity.
//
// -->
@EventHandler
public void entityPortalExit(EntityPortalExitEvent event) {

Map<String, dObject> context = new HashMap<String, dObject>();
dEntity entity = new dEntity(event.getEntity());
String entityType = entity.getEntityType().name();

context.put("entity", entity);
context.put("location", new dLocation(event.getTo()));

doEvents(Arrays.asList
("entity exits portal",
entityType + " exits portal"),
null, null, context);
}

// <--[event]
// @Events
Expand Down

0 comments on commit a7cc331

Please sign in to comment.