Skip to content

Commit

Permalink
Include modifications to BucketFillScriptEvent that didnt get staged.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyAMC committed Feb 20, 2015
1 parent 12ec24b commit 2e584ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -11,6 +11,7 @@
import net.aufdemrand.denizen.events.scriptevents.EntityDespawnScriptEvent;
import net.aufdemrand.denizen.events.scriptevents.EntityTeleportScriptEvent;
import net.aufdemrand.denizen.events.scriptevents.LiquidSpreadScriptEvent;
import net.aufdemrand.denizen.events.scriptevents.BucketFillScriptEvent;
import net.aufdemrand.denizen.events.scriptevents.VehicleMoveScriptEvent;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitElementProperties;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitListProperties;
Expand Down Expand Up @@ -597,6 +598,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(new EntityTeleportScriptEvent());
ScriptEvent.registerScriptEvent(new LiquidSpreadScriptEvent());
ScriptEvent.registerScriptEvent(new EntityDespawnScriptEvent());
ScriptEvent.registerScriptEvent(new BucketFillScriptEvent());


ObjectFetcher.registerWithObjectFetcher(dItem.class); // i@
Expand Down
@@ -1,11 +1,11 @@
package net.aufdemrand.denizen.events.scriptevents;

import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
Expand All @@ -20,6 +20,7 @@ public class BucketFillScriptEvent extends ScriptEvent implements Listener {
// <--[event]
// @Events
// player fills bucket
// player fills bucket with <material>
//
// @Triggers when a player fills a bucket.
//
Expand All @@ -39,29 +40,28 @@ public BucketFillScriptEvent() {
}

public static BucketFillScriptEvent instance;
public dEntity entity;
public dItem item;
public dMaterial material;
public dLocation location;
public dLocation relative;
public PlayerBucketFillEvent event;
public PlayerBucketFillEvent pEvent;


@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
return CoreUtilities.xthArgEquals(1, lower, "fills")
&& (CoreUtilities.xthArgEquals(3, lower, "bucket")
|| CoreUtilities.xthArgEquals(2, lower, "bucket"));
return CoreUtilities.xthArgEquals(1, lower, "fills");
}

@Override
public boolean matches(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
String iName = event.getBucket().getData().getName().toLowerCase();
String iName2 = material.identifySimple().substring(2);
String matName = pEvent.getBlockClicked().getRelative(pEvent.getBlockFace()).getType().getData().getName().toLowerCase();
String matName2 = material.identifySimple().substring(2);
return (lower.startsWith("player fills bucket")
|| lower.startsWith("player fills" + iName + "bucket")
|| lower.startsWith("player fills" + iName2 + "bucket"));
|| lower.endsWith("with" + matName)
|| lower.endsWith("with" + matName2));
}

@Override
Expand All @@ -84,6 +84,12 @@ public boolean applyDetermination(ScriptContainer container, String determinatio
return super.applyDetermination(container, determination);
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(pEvent != null ? new dPlayer(pEvent.getPlayer()): null,
entity.isNPC() ? entity.getDenizenNPC(): null);
}

@Override
public HashMap<String, dObject> getContext() {
HashMap<String, dObject> context = super.getContext();
Expand All @@ -96,12 +102,13 @@ public HashMap<String, dObject> getContext() {

@EventHandler
public void onBucketFill(PlayerBucketFillEvent event) {
entity = new dEntity(event.getPlayer());
location = new dLocation(event.getBlockClicked().getLocation());
relative = new dLocation(event.getBlockClicked().getRelative(event.getBlockFace()).getLocation());
item = new dItem(event.getBucket());
material = dMaterial.getMaterialFrom(event.getBlockClicked().getRelative(event.getBlockFace()).getType(), event.getBlockClicked().getRelative(event.getBlockFace()).getData());
cancelled = event.isCancelled();
this.event = event;
pEvent = event;
fire();
event.setCancelled(cancelled);
}
Expand Down
Expand Up @@ -3035,40 +3035,6 @@ public void playerBucketEmpty(PlayerBucketEmptyEvent event) {

}

// <--[event]
// @Events
// player fills bucket
//
// @Triggers when a player fills a bucket.
// @Context
// <context.item> returns the dItem of the bucket.
// <context.location> returns the dLocation of the block clicked with the bucket.
//
// @Determine
// "CANCELLED" to stop the player from filling the bucket.
// dItem to set the item in the player's hand after the event.
//
// -->
@EventHandler
public void playerBucketFill(PlayerBucketFillEvent event) {

Map<String, dObject> context = new HashMap<String, dObject>();
context.put("item", new dItem(event.getBucket()));
context.put("location", new dLocation(event.getBlockClicked().getLocation()));

String determination = doEvents(Arrays.asList
("player fills bucket"),
null, new dPlayer(event.getPlayer()), context);

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

// <--[event]
// @Events
// player changes world
Expand Down

0 comments on commit 2e584ac

Please sign in to comment.