Add Variants for Rabbits and Guardians, add ability to Capture mobs by simply smacking them with the egg

This commit is contained in:
Nicolas Shreiner 2015-03-23 03:34:16 -04:00
parent 9d382bcf9b
commit 362040ac47
2 changed files with 116 additions and 31 deletions

View File

@ -11,11 +11,13 @@ import org.bukkit.ChatColor;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.PortalType;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Damageable; import org.bukkit.entity.Damageable;
import org.bukkit.entity.Egg; import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Guardian; import org.bukkit.entity.Guardian;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
@ -33,9 +35,11 @@ import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCreatePortalEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.HorseInventory; import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -457,9 +461,13 @@ public class EggCatcherEntityListener
{ {
lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + ((Ocelot)entity).getCatType().name()); lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + ((Ocelot)entity).getCatType().name());
} }
if ((entity instanceof Creeper) && ((Creeper) entity).isPowered()) if ((entity instanceof Creeper))
{ {
lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + "Charged"); Creeper c = (Creeper)entity;
if(c.isPowered()){
lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + "Charged");
entity = (Entity)c;
}
} }
if ((entity instanceof Ageable)) if ((entity instanceof Ageable))
{ {
@ -520,35 +528,41 @@ public class EggCatcherEntityListener
lore.add(ChatColor.BLUE + "Color: " + ChatColor.WHITE + ((Wolf)entity).getCollarColor().name()); lore.add(ChatColor.BLUE + "Color: " + ChatColor.WHITE + ((Wolf)entity).getCollarColor().name());
} }
if((entity instanceof Guardian && ((Guardian)entity).isElder())) { if(entity instanceof Guardian) {
meta = eggStack.getItemMeta(); Guardian g = (Guardian)entity;
meta.setDisplayName("Spawn Elder Guardian"); if(g.isElder()){
eggStack.setItemMeta(meta); meta = eggStack.getItemMeta();
lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + "Elder"); meta.setDisplayName("Spawn Elder Guardian");
eggStack.setItemMeta(meta);
lore.add(ChatColor.BLUE + "Variant: " + ChatColor.WHITE + "Elder");
entity = (Entity)g;
}
} }
if((entity instanceof Rabbit)){ if(entity instanceof Rabbit){
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.BLACK) { Rabbit r = (Rabbit)entity;
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); if (r.getRabbitType() == Rabbit.Type.BLACK) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.BLACK_AND_WHITE) { if (r.getRabbitType() == Rabbit.Type.BLACK_AND_WHITE) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.BROWN) { if (r.getRabbitType() == Rabbit.Type.BROWN) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.GOLD) { if (r.getRabbitType() == Rabbit.Type.GOLD) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.SALT_AND_PEPPER) { if (r.getRabbitType() == Rabbit.Type.SALT_AND_PEPPER) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.THE_KILLER_BUNNY) { if (r.getRabbitType() == Rabbit.Type.THE_KILLER_BUNNY) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
if (((Rabbit)entity).getRabbitType() == Rabbit.Type.WHITE) { if (r.getRabbitType() == Rabbit.Type.WHITE) {
lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + ((Rabbit)entity).getRabbitType().toString()); lore.add(ChatColor.BLUE + "Type: " + ChatColor.WHITE + r.getRabbitType().toString());
} }
entity = (Entity)r;
} }
if ((entity instanceof Horse)) if ((entity instanceof Horse))
{ {
@ -625,9 +639,77 @@ public class EggCatcherEntityListener
return entity; return entity;
} }
// ************* Stop Creatures killed by EggCatcher from Dropping Normal Drops ***************** //If Entity is an EnderDragon, Cancel the Explode Effect; This technically shouldn't happen, but just in case.
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event){
if(event.getEntity() instanceof EnderDragon){
Entity entity = event.getEntity();
EnderDragon d = (EnderDragon) entity;
if(d.getHealth() <= 0)
{
if((d.getKiller() instanceof Player || d.getKiller() instanceof Egg) && d.getKiller() != null)
{
if(d.getKiller() instanceof Egg)
{
event.setCancelled(true);
}
if(d.getKiller() instanceof Player)
{
Player p = d.getKiller();
ItemStack hand = null;
if(p.getItemInHand()!=null)
hand = p.getItemInHand();
if(hand.getType() == Material.EGG)
{
event.setCancelled(true);
}
}
}
}
}
}
//If Entity is an EnderDragon, Cancel the EnderPortal Drops; This technically shouldn't happen, but just in case.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCreatePortal(EntityCreatePortalEvent event){
if(event.getEntity() instanceof EnderDragon)
{
Entity entity = event.getEntity();
EnderDragon d = (EnderDragon) entity;
if(d.getHealth() <= 0)
{
if((d.getKiller() instanceof Player || d.getKiller() instanceof Egg) && d.getKiller() != null)
{
if(d.getKiller() instanceof Egg)
{
if(event.getPortalType() != null && event.getPortalType() == PortalType.ENDER)
{
event.setCancelled(true);
}
}
if(d.getKiller() instanceof Player)
{
Player p = d.getKiller();
ItemStack hand = null;
if(p.getItemInHand()!=null)
hand = p.getItemInHand();
if(hand.getType() == Material.EGG)
{
if(event.getPortalType() != null && event.getPortalType() == PortalType.ENDER)
{
event.setCancelled(true);
}
}
}
}
}
}
}
// ************* Stop Creatures killed by EggCatcher from Dropping Normal Drops *****************
@EventHandler
public void stopCaptureDrops(EntityDeathEvent event) public void stopCaptureDrops(EntityDeathEvent event)
{ {
Entity entity = event.getEntity(); Entity entity = event.getEntity();

View File

@ -39,13 +39,10 @@ public class EggCatcherPlayerClickListener implements org.bukkit.event.Listener
if (i.getItemMeta().getDisplayName() != null) if (i.getItemMeta().getDisplayName() != null)
{ {
String s = i.getItemMeta().getDisplayName(); String s = i.getItemMeta().getDisplayName();
if(s.contains("Spawn ")){ if(!(s.contains("Spawn "))){
String l = s.replace("§f", "");
l = l.replace("Spawn ", "");
s = l;
}
entity.setCustomName(s); entity.setCustomName(s);
entity.setCustomNameVisible(true); entity.setCustomNameVisible(true);
}
} }
for (String s : i.getItemMeta().getLore()) { for (String s : i.getItemMeta().getLore()) {
if (s.contains("Health:")) { if (s.contains("Health:")) {
@ -69,10 +66,14 @@ public class EggCatcherPlayerClickListener implements org.bukkit.event.Listener
((Skeleton)entity).setSkeletonType(Skeleton.SkeletonType.valueOf(l)); ((Skeleton)entity).setSkeletonType(Skeleton.SkeletonType.valueOf(l));
} }
if ((entity instanceof Guardian)){ if ((entity instanceof Guardian)){
((Guardian)entity).setElder(true); Guardian g = (Guardian)entity;
g.setElder(true);
entity = (LivingEntity)g;
} }
if ((entity instanceof Creeper)){ if ((entity instanceof Creeper)){
((Creeper)entity).setPowered(true); Creeper c = (Creeper)entity;
c.setPowered(true);
entity = (LivingEntity) c;
} }
} }
if (s.contains("Age:")) { if (s.contains("Age:")) {
@ -223,7 +224,9 @@ public class EggCatcherPlayerClickListener implements org.bukkit.event.Listener
l = l.replaceAll("§f", ""); l = l.replaceAll("§f", "");
l = l.replaceAll("Type: ", ""); l = l.replaceAll("Type: ", "");
if ((entity instanceof Rabbit)) { if ((entity instanceof Rabbit)) {
((Rabbit)entity).setRabbitType(Rabbit.Type.valueOf(l)); Rabbit r = (Rabbit)entity;
r.setRabbitType(Rabbit.Type.valueOf(l));
entity = (LivingEntity)r;
} }
} }
} }