Advertisement
mrmag518

NoLavaBucketListener

Oct 5th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. package me.mrmag518.plugins.nolava;
  2.  
  3. //author mrmag518
  4.  
  5. import org.bukkit.Material;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.player.PlayerBucketEmptyEvent;
  8. import org.bukkit.event.player.PlayerBucketFillEvent;
  9. import org.bukkit.event.player.PlayerListener;
  10. import org.bukkit.inventory.ItemStack;
  11.  
  12. public class NoLavaBucketListener extends PlayerListener {
  13. private Nolava plugin;
  14.  
  15. public NoLavaBucketListener(Nolava plugin) {
  16. this.plugin = plugin;
  17. }
  18.  
  19. @Override
  20. public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
  21. if ( !this.plugin.isEnabled() ) {
  22. return;
  23. }
  24. final Player player = event.getPlayer();
  25.  
  26. if (!player.hasPermission("NoLava.useLava")){
  27. return;
  28. }
  29.  
  30. if ( event.getBucket() == Material.LAVA_BUCKET ) {
  31. event.setCancelled(true);
  32.  
  33. player.setItemInHand(null);
  34. this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
  35. new Runnable() {public void run() {
  36. player.setItemInHand(new ItemStack(Material.BUCKET, 1));
  37. }}
  38. , 1);
  39. }
  40. }
  41.  
  42. @Override
  43. public void onPlayerBucketFill(PlayerBucketFillEvent event) {
  44. if ( !this.plugin.isEnabled() ) {
  45. return;
  46. }
  47.  
  48. final Player player = event.getPlayer();
  49.  
  50. if (!player.hasPermission("NoLava.useLava")){
  51. return;
  52. }
  53.  
  54. if ( event.getBlockClicked().getType() == Material.STATIONARY_LAVA ||
  55. event.getBlockClicked().getType() == Material.LAVA ) {
  56. event.setCancelled(true);
  57.  
  58. player.setItemInHand(null);
  59. this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
  60. new Runnable() {public void run() {
  61. player.setItemInHand(new ItemStack(Material.BUCKET, 1));
  62. }}
  63. , 1);
  64.  
  65. player.sendBlockChange(event.getBlockClicked().getLocation(),
  66. event.getBlockClicked().getType(),
  67. event.getBlockClicked().getData());
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement