/src/com/dthielke/nocreep/NoCreep.java

https://bitbucket.org/DThielke/nocreep · Java · 43 lines · 36 code · 7 blank · 0 comment · 4 complexity · 9ba308690de628e4461fee7a1e334116 MD5 · raw file

  1. package com.dthielke.nocreep;
  2. import java.util.logging.Logger;
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.entity.Creeper;
  7. import org.bukkit.entity.Entity;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.entity.EntityExplodeEvent;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12. public class NoCreep extends JavaPlugin
  13. {
  14. private static final Logger logger = Logger.getLogger("Minecraft");
  15. public void onDisable() {
  16. logger.info("NoCreep disabled");
  17. }
  18. public void onEnable() {
  19. logger.info("NoCreep enabled");
  20. Bukkit.getServer().getPluginManager().registerEvents(new Listener() {
  21. @EventHandler(ignoreCancelled = true)
  22. public void onEntityExplode(EntityExplodeEvent event) {
  23. Entity entity = event.getEntity();
  24. if (entity == null) {
  25. return;
  26. }
  27. Location location = entity.getLocation();
  28. World world = entity.getWorld();
  29. if (((entity instanceof Creeper)) && (location.getY() >= world.getSeaLevel() - 5)) {
  30. event.setCancelled(true);
  31. world.createExplosion(location, 0.0F, false);
  32. }
  33. }
  34. }, this);
  35. }
  36. }