From abe01a84e5e397942b3d0bb235b1bc49c409e899 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 21 Mar 2012 23:48:55 -0400 Subject: [PATCH] Eggs no longer spawn chickens. :D --- .../nossr50/listeners/mcEntityListener.java | 36 +++++++++---------- src/main/java/com/gmail/nossr50/mcMMO.java | 4 +++ .../java/com/gmail/nossr50/skills/Staves.java | 6 ++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index 724ff0995..7f94d1060 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.listeners; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -164,13 +165,24 @@ public class mcEntityListener implements Listener { * * @param event The event to monitor */ - @EventHandler (priority = EventPriority.MONITOR) + @EventHandler (priority = EventPriority.LOW) public void onCreatureSpawn(CreatureSpawnEvent event) { SpawnReason reason = event.getSpawnReason(); if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !LoadProperties.xpGainsMobSpawners) { event.getEntity().setMetadata("mcmmoFromMobSpawner", new FixedMetadataValue(plugin, true)); } + else if (event.getSpawnReason().equals(SpawnReason.EGG)) { + Location eLoc = event.getLocation(); + + for (Entity projectile : plugin.projectileTracker) { + Location pLoc = projectile.getLocation(); + + if (pLoc.getX() == eLoc.getX() && pLoc.getY() == eLoc.getY() && pLoc.getZ() == eLoc.getZ()) { + event.setCancelled(true); + } + } + } } /** @@ -320,25 +332,13 @@ public class mcEntityListener implements Listener { /** * Monitor ProjectileHit events. * - * @param event The event to monitor + * @param event The event to watch */ + @EventHandler (priority = EventPriority.MONITOR) public void onProjectileHit(ProjectileHitEvent event) { - if (!event.getEntity().hasMetadata("mcmmoFiredFromStaff")) { - return; - } - - switch (event.getEntityType()) { - case EGG: - break; - - case FIREBALL: - break; - - case SNOWBALL: - break; - - default: - break; + Entity projectile = event.getEntity(); + if (plugin.projectileTracker.contains(projectile)) { + plugin.projectileTracker.remove(projectile); } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index f09d04075..0aa361ed3 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -23,6 +23,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; +import java.util.HashSet; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -48,8 +49,11 @@ public class mcMMO extends JavaPlugin { //Alias - Command public HashMap aliasMap = new HashMap(); + + //Various trackers public HashMap arrowTracker = new HashMap(); public HashMap tntTracker = new HashMap(); + public HashSet projectileTracker = new HashSet(); public static Database database = null; diff --git a/src/main/java/com/gmail/nossr50/skills/Staves.java b/src/main/java/com/gmail/nossr50/skills/Staves.java index 48160d052..f9b7a2aff 100644 --- a/src/main/java/com/gmail/nossr50/skills/Staves.java +++ b/src/main/java/com/gmail/nossr50/skills/Staves.java @@ -59,7 +59,7 @@ public class Staves { * @param plugin mcMMO plugin instance */ public static void altFire(Material type, Player attacker, mcMMO plugin) { - Projectile projectile = null; + Projectile projectile; switch (type) { case BLAZE_ROD: @@ -75,9 +75,10 @@ public class Staves { break; default: - break; + return; } + plugin.projectileTracker.add(projectile); projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true)); } @@ -119,6 +120,7 @@ public class Staves { duration = (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS); } + shooter.setLevel(shooter.getLevel() - 2); target.addPotionEffect(new PotionEffect(type, duration, amplifier)); if (type.equals(PotionEffectType.SLOW)) {