Skip to content

Commit

Permalink
Fixed Spawn Eggs being awful
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 13, 2018
1 parent 3189b1a commit 43ed630
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 18 deletions.
Expand Up @@ -19,6 +19,8 @@

package com.sk89q.worldguard.bukkit.listener;

import static com.sk89q.worldguard.bukkit.cause.Cause.create;

import com.google.common.collect.Lists;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
Expand Down Expand Up @@ -46,46 +48,94 @@
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.protection.flags.Flags;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Hopper;
import org.bukkit.entity.*;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockExpEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockMultiPlaceEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustByBlockEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.ExpBottleEvent;
import org.bukkit.event.entity.LingeringPotionSplashEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SpawnEggMeta;
import org.bukkit.material.Dispenser;
import org.bukkit.material.MaterialData;
import org.bukkit.material.PistonExtensionMaterial;
import org.bukkit.material.SpawnEgg;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

import static com.sk89q.worldguard.bukkit.cause.Cause.create;
import javax.annotation.Nullable;

public class EventAbstractionListener extends AbstractListener {

Expand Down Expand Up @@ -940,14 +990,7 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even

// Handle created spawn eggs
if (item != null && Materials.isSpawnEgg(item.getType())) {
ItemMeta data = item.getItemMeta();
if (data instanceof SpawnEggMeta) {
@Nullable EntityType type = ((SpawnEggMeta) data).getSpawnedType();
if (type == null) {
type = EntityType.SHEEP; // Haven't investigated why it's sometimes null
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), type));
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), Materials.getEntitySpawnEgg(item.getType())));
return;
}

Expand Down
Expand Up @@ -872,6 +872,115 @@ public static boolean isSpawnEgg(Material material) {
}
}

public static EntityType getEntitySpawnEgg(Material material) {
switch (material) {
case SPIDER_SPAWN_EGG:
return EntityType.SPIDER;
case BAT_SPAWN_EGG:
return EntityType.BAT;
case BLAZE_SPAWN_EGG:
return EntityType.BLAZE;
case CAVE_SPIDER_SPAWN_EGG:
return EntityType.CAVE_SPIDER;
case CHICKEN_SPAWN_EGG:
return EntityType.CHICKEN;
case COD_SPAWN_EGG:
return EntityType.COD;
case COW_SPAWN_EGG:
return EntityType.COW;
case CREEPER_SPAWN_EGG:
return EntityType.CREEPER;
case DOLPHIN_SPAWN_EGG:
return EntityType.DOLPHIN;
case DONKEY_SPAWN_EGG:
return EntityType.DONKEY;
case DROWNED_SPAWN_EGG:
return EntityType.DROWNED;
case ELDER_GUARDIAN_SPAWN_EGG:
return EntityType.ELDER_GUARDIAN;
case ENDERMAN_SPAWN_EGG:
return EntityType.ENDERMAN;
case ENDERMITE_SPAWN_EGG:
return EntityType.ENDERMITE;
case EVOKER_SPAWN_EGG:
return EntityType.EVOKER;
case GHAST_SPAWN_EGG:
return EntityType.GHAST;
case GUARDIAN_SPAWN_EGG:
return EntityType.GUARDIAN;
case HORSE_SPAWN_EGG:
return EntityType.HORSE;
case HUSK_SPAWN_EGG:
return EntityType.HUSK;
case LLAMA_SPAWN_EGG:
return EntityType.LLAMA;
case MAGMA_CUBE_SPAWN_EGG:
return EntityType.MAGMA_CUBE;
case MOOSHROOM_SPAWN_EGG:
return EntityType.MUSHROOM_COW;
case MULE_SPAWN_EGG:
return EntityType.MULE;
case OCELOT_SPAWN_EGG:
return EntityType.OCELOT;
case PARROT_SPAWN_EGG:
return EntityType.PARROT;
case PHANTOM_SPAWN_EGG:
return EntityType.PHANTOM;
case PIG_SPAWN_EGG:
return EntityType.PIG;
case POLAR_BEAR_SPAWN_EGG:
return EntityType.POLAR_BEAR;
case PUFFERFISH_SPAWN_EGG:
return EntityType.PUFFERFISH;
case RABBIT_SPAWN_EGG:
return EntityType.RABBIT;
case SALMON_SPAWN_EGG:
return EntityType.SALMON;
case SHEEP_SPAWN_EGG:
return EntityType.SHEEP;
case SHULKER_SPAWN_EGG:
return EntityType.SHULKER;
case SILVERFISH_SPAWN_EGG:
return EntityType.SILVERFISH;
case SKELETON_HORSE_SPAWN_EGG:
return EntityType.SKELETON_HORSE;
case SKELETON_SPAWN_EGG:
return EntityType.SKELETON;
case SLIME_SPAWN_EGG:
return EntityType.SLIME;
case SQUID_SPAWN_EGG:
return EntityType.SQUID;
case STRAY_SPAWN_EGG:
return EntityType.STRAY;
case TROPICAL_FISH_SPAWN_EGG:
return EntityType.TROPICAL_FISH;
case TURTLE_SPAWN_EGG:
return EntityType.TURTLE;
case VEX_SPAWN_EGG:
return EntityType.VEX;
case VILLAGER_SPAWN_EGG:
return EntityType.VILLAGER;
case VINDICATOR_SPAWN_EGG:
return EntityType.VINDICATOR;
case WITCH_SPAWN_EGG:
return EntityType.WITCH;
case WITHER_SKELETON_SPAWN_EGG:
return EntityType.WITHER_SKELETON;
case WOLF_SPAWN_EGG:
return EntityType.WOLF;
case ZOMBIE_HORSE_SPAWN_EGG:
return EntityType.ZOMBIE_HORSE;
case ZOMBIE_PIGMAN_SPAWN_EGG:
return EntityType.PIG_ZOMBIE;
case ZOMBIE_SPAWN_EGG:
return EntityType.ZOMBIE;
case ZOMBIE_VILLAGER_SPAWN_EGG:
return EntityType.ZOMBIE_VILLAGER;
default:
return EntityType.PIG; // Uhhh
}
}

public static boolean isBed(Material material) {
switch (material) {
case BLACK_BED:
Expand Down

0 comments on commit 43ed630

Please sign in to comment.