Skip to content

Commit

Permalink
Add <context.inventory>, and 'DROPS item_list'/'NO_DROPS' determinati…
Browse files Browse the repository at this point in the history
…ons to on player dies.
  • Loading branch information
aufdemrand committed Oct 11, 2013
1 parent aa03f4b commit ae7f188
Showing 1 changed file with 21 additions and 4 deletions.
Expand Up @@ -140,8 +140,8 @@ public static String doEvents(List<String> eventNames, dNPC npc, Player player,
// If a list of events uses identifiers, also add those events to the list
// with their identifiers stripped
return doEvents(usesIdentifiers ? addAlternates(eventNames)
: eventNames,
npc, player, context);
: eventNames,
npc, player, context);
}

public static String doEvents(List<String> eventNames, dNPC npc, Player player, Map<String, dObject> context) {
Expand Down Expand Up @@ -3116,26 +3116,43 @@ public void playerCommandPreprocess(PlayerCommandPreprocessEvent event) {
// @Triggers when a player dies.
// @Context
// <context.message> returns an Element of the death message.
// <context.inventory> returns a copy of the Player's inventory before death.
//
// @Determine
// Element(String) to change the death message.
// "NO_DROPS" to specify the Player's drops should be removed.
// "DROPS <i@item|...>" to specify new items to be dropped.
//
// -->
@EventHandler
public void playerDeath(PlayerDeathEvent event) {

Map<String, dObject> context = new HashMap<String, dObject>();
context.put("message", new Element(event.getDeathMessage()));
context.put("inventory", new dInventory(event.getEntity().getInventory()));

String determination = doEvents(Arrays.asList
("player dies",
"player death"),
null, event.getEntity(), context);

// Handle message
if (!determination.equals("none")) {
if (determination.equalsIgnoreCase("NO_DROPS")) {
event.getDrops().clear();

} else if (determination.toUpperCase().startsWith("DROPS ")) {
dList drops = dList.valueOf(determination.substring(6));
drops.filter(dItem.class);
event.getDrops().clear();
for (String drop : drops) {
dItem item = dItem.valueOf(drop);
if (item != null)
event.getDrops().add(item.getItemStack());
}

} else if (!determination.equalsIgnoreCase("NONE"))
event.setDeathMessage(determination);
}

}

// <--[event]
Expand Down

0 comments on commit ae7f188

Please sign in to comment.