So I'm writing a plugin meant to simulate temperature effects on fluids at various altitudes. Currently, it works fine, but only if the blocks are hacked in to the inventory and then placed. Now, I've tried both the regular and STATIONARY_ values for both water and lava, but neither seems to work in terms of pouring a bucket of the stuff out, only if the block is directly placed from the inventory. This is unfortunate, as I really only want the plugin to affect fluids that players move with buckets, and not any natural fluids generated by the map. Is there something other than the blockplace event I should hook in to to catch fluid blocks generated via buckets? Here's my block listener. Code: package com.bukkit.PopeUrban.FluidTemp; import org.bukkit.block.*; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.*; import org.bukkit.inventory.Inventory; /** * FluidTemp block listener * @author PopeUrban */ public class FluidTempBlockListener extends BlockListener { private final FluidTemp plugin; public String stuff =""; //When blocks are placed public void onBlockPlace(BlockPlaceEvent event) { //if The blaced block is lava if (event.getBlock().getType() == Material.LAVA) { //if the block's position is above 63 world height if (event.getBlock().getY()>63) //replace with COBBLESTONE event.getBlock().setType(Material.COBBLESTONE); } //if The blaced block is WATER if (event.getBlock().getType() == Material.WATER) { //if the block's position is above 89 world height if (event.getBlock().getY()>89) //replace with ICE event.getBlock().setType(Material.ICE); } } public FluidTempBlockListener(final FluidTemp plugin) { this.plugin = plugin; } }
Hrm, I was thinking the syntax for that was public void onBucketPlace(PlayerItemEvent.onPlayerItem event){ //stuff } in the player listener, but I think I've got the call wrong as it doesn't resolve. darknesschaos, you handle a similar event in signtrader right?
So here's what I've got thusfar. I think I'm calling these wrong though, as the lava bucket event isn't cancelling, and its not firing my test confirmation message at me. The listener itself is registered in FluidTemp just like my blocklistener, but it seems to be ignoring the code here. Code: package com.bukkit.PopeUrban.FluidTemp; import java.io.*; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.*; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.*; import org.bukkit.material.MaterialData; import org.bukkit.*; /** * Handle events for all Player related events * @author PopeUrban */ public class FluidTempPlayerListener extends PlayerListener { private final FluidTemp plugin; public void onPlayerItem(PlayerItemEvent event) { //If using a lava bucket if (event.getPlayer().getItemInHand().getTypeId() == 327){ //Cancel the normal event event.setCancelled(true); //Change the lava bucket to an empty one event.getPlayer().getItemInHand().setTypeId(325); //***PSUEDOCODE*** //Test altitude of player // If player's target block is above 63 //Generate a COBBLESTONE block // Else //Generate a LAVA block //****END PSEUDOCODE**** //send the player a message event.getPlayer().sendMessage("Test code executed successfully"); } } public FluidTempPlayerListener(FluidTemp instance) { plugin = instance; } } --- merged: Feb 20, 2011 12:52 AM --- Edited above post for clarity *Edited Again to reflect onPlayerEvent function change
Changing onBucketPlace to onPlayerItem gives me the same results, and from everything I've looked over that should be the proper way to implement this, overwriting the call? I've actually edited to above post to reflect this change. If it isn't, then I'm happy to keep looking. If it is, I'd appreciate any insight in to why the listener doesn't seem to be executing its code. I'm not asking anyone to write the whole thing for me, just trying to get a bit of insight is all Edward.