mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Cleaner way to cancel egg events.
This commit is contained in:
parent
b9b91403dd
commit
b1c2616b0e
@ -1,6 +1,5 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -21,7 +20,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
|||||||
import org.bukkit.event.entity.EntityTameEvent;
|
import org.bukkit.event.entity.EntityTameEvent;
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
import com.gmail.nossr50.Combat;
|
import com.gmail.nossr50.Combat;
|
||||||
@ -165,24 +163,13 @@ public class mcEntityListener implements Listener {
|
|||||||
*
|
*
|
||||||
* @param event The event to monitor
|
* @param event The event to monitor
|
||||||
*/
|
*/
|
||||||
@EventHandler (priority = EventPriority.LOW)
|
@EventHandler (priority = EventPriority.MONITOR)
|
||||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||||
SpawnReason reason = event.getSpawnReason();
|
SpawnReason reason = event.getSpawnReason();
|
||||||
|
|
||||||
if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !LoadProperties.xpGainsMobSpawners) {
|
if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !LoadProperties.xpGainsMobSpawners) {
|
||||||
event.getEntity().setMetadata("mcmmoFromMobSpawner", new FixedMetadataValue(plugin, true));
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -328,17 +315,4 @@ public class mcEntityListener implements Listener {
|
|||||||
Skills.XpCheckSkill(SkillType.TAMING, player);
|
Skills.XpCheckSkill(SkillType.TAMING, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Monitor ProjectileHit events.
|
|
||||||
*
|
|
||||||
* @param event The event to watch
|
|
||||||
*/
|
|
||||||
@EventHandler (priority = EventPriority.MONITOR)
|
|
||||||
public void onProjectileHit(ProjectileHitEvent event) {
|
|
||||||
Entity projectile = event.getEntity();
|
|
||||||
if (plugin.projectileTracker.contains(projectile)) {
|
|
||||||
plugin.projectileTracker.remove(projectile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||||
import org.bukkit.event.player.PlayerFishEvent;
|
import org.bukkit.event.player.PlayerFishEvent;
|
||||||
import org.bukkit.event.player.PlayerFishEvent.State;
|
import org.bukkit.event.player.PlayerFishEvent.State;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
@ -381,4 +382,11 @@ public class mcPlayerListener implements Listener {
|
|||||||
event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command)));
|
event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
|
||||||
|
if (event.getEgg().hasMetadata("mcmmoFiredFromStaff") && event.isHatching()) {
|
||||||
|
event.setHatching(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -53,7 +52,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
//Various trackers
|
//Various trackers
|
||||||
public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
|
public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
|
||||||
public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();
|
public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();
|
||||||
public HashSet<Entity> projectileTracker = new HashSet<Entity>();
|
|
||||||
|
|
||||||
public static Database database = null;
|
public static Database database = null;
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ public class Staves {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.projectileTracker.add(projectile);
|
|
||||||
projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true));
|
projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user