Skip to content

Commit

Permalink
Add 'on fill bucket' and 'on empty bucket' world events. Available co…
Browse files Browse the repository at this point in the history
…ntext: bucket_type, bucket, clicked_location
  • Loading branch information
aufdemrand committed Apr 12, 2013
1 parent 4fdae8a commit 5618578
Showing 1 changed file with 34 additions and 1 deletion.
Expand Up @@ -15,6 +15,7 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.CitizensAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -26,6 +27,7 @@
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;

import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -294,6 +296,7 @@ public void playerHit(EntityDamageEvent event) {
&& !CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) {
Map<String, String> context = new HashMap<String, String>();
context.put("cause", event.getCause().toString());
context.put("amount", String.valueOf(event.getDamage()));

String determination;

Expand Down Expand Up @@ -396,9 +399,39 @@ public void playerEat(EntityRegainHealthEvent event) {
}

@EventHandler
public void bucketFill(PlayerBucketEvent event) {
public void bucketFill(PlayerBucketFillEvent event) {
Map<String, String> context = new HashMap<String, String>();
context.put("bucket_type", event.getBucket().name());
context.put("bucket", new dItem(event.getItemStack()).dScriptArgValue());
context.put("clicked_location", new dLocation(event.getBlockClicked().getLocation()).dScriptArgValue());

String determination = doEvent("fill bucket", null, event.getPlayer(), context);

// Handle message
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
if (determination.toUpperCase().startsWith("ITEM_IN_HAND")) {
ItemStack is = dItem.valueOf(aH.getStringFrom(determination)).getItemStack();
event.setItemStack( is != null ? is : new ItemStack(Material.AIR));
}
}

@EventHandler
public void bucketEmpty(PlayerBucketEmptyEvent event) {
Map<String, String> context = new HashMap<String, String>();
context.put("bucket_type", event.getBucket().name());
context.put("bucket", new dItem(event.getItemStack()).dScriptArgValue());
context.put("clicked_location", new dLocation(event.getBlockClicked().getLocation()).dScriptArgValue());

String determination = doEvent("empty bucket", null, event.getPlayer(), context);

// Handle message
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
if (determination.toUpperCase().startsWith("ITEM_IN_HAND")) {
ItemStack is = dItem.valueOf(aH.getStringFrom(determination)).getItemStack();
event.setItemStack( is != null ? is : new ItemStack(Material.AIR));
}

}

Expand Down

0 comments on commit 5618578

Please sign in to comment.