Search in sources :

Example 1 with Rabbit

use of org.bukkit.entity.Rabbit in project MagicPlugin by elBukkit.

the class EntityData method modifyPreSpawn.

private boolean modifyPreSpawn(MageController controller, Entity entity) {
    if (entity == null || entity.getType() != type)
        return false;
    boolean isPlayer = (entity instanceof Player);
    if (extraData != null) {
        extraData.apply(entity);
    }
    CompatibilityUtils.setSilent(entity, isSilent);
    entity.setFireTicks(fireTicks);
    if (entity instanceof Ageable) {
        Ageable ageable = (Ageable) entity;
        if (isBaby) {
            ageable.setBaby();
        } else {
            ageable.setAdult();
        }
    }
    if (entity instanceof Tameable) {
        ((Tameable) entity).setTamed(isTamed);
    }
    if (entity instanceof Colorable && dyeColor != null) {
        Colorable colorable = (Colorable) entity;
        colorable.setColor(dyeColor);
    }
    if (tags != null && !tags.isEmpty()) {
        Set<String> entityTags = CompatibilityUtils.getTags(entity);
        entityTags.addAll(tags);
    }
    if (entity instanceof Creature) {
        Creature creature = (Creature) entity;
        creature.setCanPickupItems(canPickupItems);
    }
    if (entity instanceof Painting) {
        Painting painting = (Painting) entity;
        if (art != null) {
            painting.setArt(art, true);
        }
        if (facing != null) {
            painting.setFacingDirection(facing, true);
        }
    } else if (entity instanceof ItemFrame) {
        ItemFrame itemFrame = (ItemFrame) entity;
        itemFrame.setItem(item);
        if (facing != null) {
            itemFrame.setFacingDirection(facing, true);
        }
    } else if (entity instanceof Item) {
        Item droppedItem = (Item) entity;
        droppedItem.setItemStack(item);
    } else if (entity instanceof Wolf && dyeColor != null) {
        Wolf wolf = (Wolf) entity;
        wolf.setCollarColor(dyeColor);
    } else if (entity instanceof Ocelot && ocelotType != null) {
        Ocelot ocelot = (Ocelot) entity;
        ocelot.setCatType(ocelotType);
    } else if (entity instanceof Rabbit && rabbitType != null) {
        Rabbit rabbit = (Rabbit) entity;
        rabbit.setRabbitType(rabbitType);
    } else if (entity instanceof ExperienceOrb && xp != null) {
        ((ExperienceOrb) entity).setExperience(xp);
    }
    if (entity instanceof LivingEntity) {
        LivingEntity li = (LivingEntity) entity;
        if (hasPotionEffects) {
            Collection<PotionEffect> currentEffects = li.getActivePotionEffects();
            for (PotionEffect effect : currentEffects) {
                li.removePotionEffect(effect.getType());
            }
            if (potionEffects != null) {
                for (PotionEffect effect : potionEffects) {
                    li.addPotionEffect(effect);
                }
            }
        }
        try {
            if (!isPlayer) {
                applyAttributes(li);
                copyEquipmentTo(li);
                if (maxHealth != null) {
                    li.setMaxHealth(maxHealth);
                }
            }
            if (health != null) {
                li.setHealth(Math.min(health, li.getMaxHealth()));
            }
            if (airLevel != null) {
                li.setRemainingAir(Math.min(airLevel, li.getRemainingAir()));
            }
            if (!hasAI) {
                li.setAI(hasAI);
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
    if (!isPlayer && name != null && name.length() > 0) {
        entity.setCustomName(name);
    }
    boolean needsMage = controller != null && mageData != null;
    if (needsMage) {
        Mage apiMage = controller.getMage(entity);
        if (apiMage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) apiMage).setEntityData(this);
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) PotionEffect(org.bukkit.potion.PotionEffect) Rabbit(org.bukkit.entity.Rabbit) ExperienceOrb(org.bukkit.entity.ExperienceOrb) ItemFrame(org.bukkit.entity.ItemFrame) Ageable(org.bukkit.entity.Ageable) Painting(org.bukkit.entity.Painting) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Ocelot(org.bukkit.entity.Ocelot) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Colorable(org.bukkit.material.Colorable) Wolf(org.bukkit.entity.Wolf)

Example 2 with Rabbit

use of org.bukkit.entity.Rabbit in project askyblock by tastybento.

the class Schematic method pasteSchematic.

/*
     * This function pastes using World Edit - problem is that because it reads a file, it's slow.
    @SuppressWarnings("deprecation")
     */
/*
     * 
    public void pasteSchematic(final Location loc, final Player player, boolean teleport)  {
	plugin.getLogger().info("WE Pasting");
	com.sk89q.worldedit.Vector WEorigin = new com.sk89q.worldedit.Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
        EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), 999999999);
        try {
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, WEorigin, false);
        cc.pasteEntities(WEorigin);
        } catch (Exception e) {
            e.printStackTrace();
        }

    	if (teleport) {
    		World world = loc.getWorld();

    	    player.teleport(world.getSpawnLocation());
    	    plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

    		@Override
    		public void run() {
    		    plugin.getGrid().homeTeleport(player);

    		}}, 10L);

    	}
    }   
     */
/**
 * This method pastes a schematic.
 * @param loc - where to paste it
 * @param player - who for
 * @param teleport - should the player be teleported after pasting?
 * @param reason - why this was pasted
 */
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason) {
    // If this is not a file schematic, paste the default island
    if (this.file == null) {
        if (Settings.GAMETYPE == GameType.ACIDISLAND) {
            generateIslandBlocks(loc, player, reason);
        } else {
            loc.getBlock().setType(Material.BEDROCK);
            ASkyBlock.getPlugin().getLogger().severe("Missing schematic - using bedrock block only");
        }
        return;
    }
    World world = loc.getWorld();
    Location blockLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
    // Location blockLoc = new Location(world, loc.getX(), Settings.island_level, loc.getZ());
    blockLoc.subtract(bedrock);
    // plugin.getLogger().info("DEBUG: islandBlock size (paste) = " + islandBlocks.size());
    for (IslandBlock b : islandBlocks) {
        b.paste(nms, blockLoc, this.usePhysics, biome);
    }
    // Bukkit.getLogger().info("Block loc = " + blockLoc);
    if (pasteEntities) {
        for (EntityObject ent : entitiesList) {
            // If TileX/Y/Z id defined, we have to use it (for Item Frame & Painting)
            if (ent.getTileX() != null && ent.getTileY() != null && ent.getTileZ() != null) {
                ent.setLocation(new BlockVector(ent.getTileX(), ent.getTileY(), ent.getTileZ()));
            }
            Location entitySpot = ent.getLocation().toLocation(blockLoc.getWorld()).add(blockLoc.toVector());
            entitySpot.setPitch(ent.getPitch());
            entitySpot.setYaw(ent.getYaw());
            // Bukkit.getLogger().info("DEBUG: Entity type = " + ent.getType());
            if (ent.getType() == EntityType.PAINTING) {
                // Bukkit.getLogger().info("DEBUG: spawning " + ent.getType().toString() + " at " + entitySpot);
                try {
                    Painting painting = blockLoc.getWorld().spawn(entitySpot, Painting.class);
                    if (painting != null) {
                        if (paintingList.containsKey(ent.getMotive())) {
                            // painting.setArt(Art.GRAHAM);
                            painting.setArt(paintingList.get(ent.getMotive()), true);
                        } else {
                            // Set default
                            painting.setArt(Art.ALBAN, true);
                        }
                        // http://minecraft.gamepedia.com/Painting#Data_values
                        if (facingList.containsKey(ent.getFacing())) {
                            painting.setFacingDirection(facingList.get(ent.getFacing()), true);
                        } else {
                            // set default direction
                            painting.setFacingDirection(BlockFace.NORTH, true);
                        }
                    // Bukkit.getLogger().info("DEBUG: Painting setFacingDirection: " + painting.getLocation().toString() + "; facing: " + painting.getFacing() + "; ent facing: " + ent.getFacing());
                    // Bukkit.getLogger().info("DEBUG: Painting setArt: " + painting.getLocation().toString() + "; art: " + painting.getArt() + "; ent motive: " + ent.getMotive());
                    }
                } catch (IllegalArgumentException e) {
                // plugin.getLogger().warning("Cannot paste painting from schematic");
                }
            } else if (ent.getType() == EntityType.ITEM_FRAME) {
                // Bukkit.getLogger().info("DEBUG: spawning itemframe at" + entitySpot.toString());
                // Bukkit.getLogger().info("DEBUG: tileX: " + ent.getTileX() + ", tileY: " + ent.getTileY() + ", tileZ: " + ent.getTileZ());
                ItemFrame itemFrame = (ItemFrame) blockLoc.getWorld().spawnEntity(entitySpot, EntityType.ITEM_FRAME);
                if (itemFrame != null) {
                    // Need to improve this shity fix ...
                    Material material = Material.matchMaterial(ent.getId().substring(10).toUpperCase());
                    ;
                    if (material == null && IslandBlock.WEtoM.containsKey(ent.getId().substring(10).toUpperCase())) {
                        material = IslandBlock.WEtoM.get(ent.getId().substring(10).toUpperCase());
                    }
                    ItemStack item;
                    if (material != null) {
                        // Bukkit.getLogger().info("DEBUG: id: " + ent.getId() + ", material match: " + material.toString());
                        if (ent.getCount() != null) {
                            if (ent.getDamage() != null) {
                                item = new ItemStack(material, ent.getCount(), ent.getDamage());
                            } else {
                                item = new ItemStack(material, ent.getCount(), (short) 0);
                            }
                        } else {
                            if (ent.getDamage() != null) {
                                item = new ItemStack(material, 1, ent.getDamage());
                            } else {
                                item = new ItemStack(material, 1, (short) 0);
                            }
                        }
                    } else {
                        // Bukkit.getLogger().info("DEBUG: material can't be found for: " + ent.getId() + " (" + ent.getId().substring(10).toUpperCase() + ")");
                        // Set to default content
                        item = new ItemStack(Material.STONE, 0, (short) 4);
                    }
                    ItemMeta itemMeta = item.getItemMeta();
                    // TODO: Implement methods to get enchantement, names, lore etc.
                    item.setItemMeta(itemMeta);
                    itemFrame.setItem(item);
                    if (facingList.containsKey(ent.getFacing())) {
                        itemFrame.setFacingDirection(facingList.get(ent.getFacing()), true);
                    } else {
                        // set default direction
                        itemFrame.setFacingDirection(BlockFace.NORTH, true);
                    }
                    // TODO: Implements code to handle the rotation of the item in the itemframe
                    if (rotationList.containsKey(ent.getItemRotation())) {
                        itemFrame.setRotation(rotationList.get(ent.getItemRotation()));
                    } else {
                        // Set default direction
                        itemFrame.setRotation(Rotation.NONE);
                    }
                }
            } else {
                // Bukkit.getLogger().info("Spawning " + ent.getType().toString() + " at " + entitySpot);
                Entity spawned = blockLoc.getWorld().spawnEntity(entitySpot, ent.getType());
                if (spawned != null) {
                    spawned.setVelocity(ent.getMotion());
                    if (ent.getType() == EntityType.SHEEP) {
                        Sheep sheep = (Sheep) spawned;
                        if (ent.isSheared()) {
                            sheep.setSheared(true);
                        }
                        DyeColor[] set = DyeColor.values();
                        sheep.setColor(set[ent.getColor()]);
                        sheep.setAge(ent.getAge());
                    } else if (ent.getType() == EntityType.HORSE) {
                        Horse horse = (Horse) spawned;
                        Horse.Color[] set = Horse.Color.values();
                        horse.setColor(set[ent.getColor()]);
                        horse.setAge(ent.getAge());
                        horse.setCarryingChest(ent.isCarryingChest());
                    } else if (ent.getType() == EntityType.VILLAGER) {
                        Villager villager = (Villager) spawned;
                        villager.setAge(ent.getAge());
                        Profession[] proffs = Profession.values();
                        villager.setProfession(proffs[ent.getProfession()]);
                    } else if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && ent.getType() == EntityType.RABBIT) {
                        Rabbit rabbit = (Rabbit) spawned;
                        Rabbit.Type[] set = Rabbit.Type.values();
                        rabbit.setRabbitType(set[ent.getRabbitType()]);
                        rabbit.setAge(ent.getAge());
                    } else if (ent.getType() == EntityType.OCELOT) {
                        Ocelot cat = (Ocelot) spawned;
                        if (ent.isOwned()) {
                            cat.setTamed(true);
                            cat.setOwner(player);
                        }
                        Ocelot.Type[] set = Ocelot.Type.values();
                        cat.setCatType(set[ent.getCatType()]);
                        cat.setAge(ent.getAge());
                        cat.setSitting(ent.isSitting());
                    } else if (ent.getType() == EntityType.WOLF) {
                        Wolf wolf = (Wolf) spawned;
                        if (ent.isOwned()) {
                            wolf.setTamed(true);
                            wolf.setOwner(player);
                        }
                        wolf.setAge(ent.getAge());
                        wolf.setSitting(ent.isSitting());
                        DyeColor[] color = DyeColor.values();
                        wolf.setCollarColor(color[ent.getCollarColor()]);
                    }
                }
            }
        }
    }
    // Find the grass spot
    final Location grass;
    if (topGrass != null) {
        Location gr = topGrass.clone().toLocation(loc.getWorld()).subtract(bedrock);
        gr.add(loc.toVector());
        // Center of block and a bit up so the animal drops a bit
        gr.add(new Vector(0.5D, 1.1D, 0.5D));
        grass = gr;
    } else {
        grass = null;
    }
    // Bukkit.getLogger().info("DEBUG cow location " + grass);
    Block blockToChange = null;
    // Place a helpful sign in front of player
    if (welcomeSign != null) {
        // Bukkit.getLogger().info("DEBUG welcome sign schematic relative is:"
        // + welcomeSign.toString());
        Vector ws = welcomeSign.clone().subtract(bedrock);
        // Bukkit.getLogger().info("DEBUG welcome sign relative to bedrock is:"
        // + welcomeSign.toString());
        ws.add(loc.toVector());
        // Bukkit.getLogger().info("DEBUG welcome sign actual position is:"
        // + welcomeSign.toString());
        blockToChange = ws.toLocation(world).getBlock();
        BlockState signState = blockToChange.getState();
        if (signState instanceof Sign) {
            Sign sign = (Sign) signState;
            if (sign.getLine(0).isEmpty()) {
                sign.setLine(0, plugin.myLocale(player.getUniqueId()).signLine1.replace("[player]", player.getName()));
            }
            if (sign.getLine(1).isEmpty()) {
                sign.setLine(1, plugin.myLocale(player.getUniqueId()).signLine2.replace("[player]", player.getName()));
            }
            if (sign.getLine(2).isEmpty()) {
                sign.setLine(2, plugin.myLocale(player.getUniqueId()).signLine3.replace("[player]", player.getName()));
            }
            if (sign.getLine(3).isEmpty()) {
                sign.setLine(3, plugin.myLocale(player.getUniqueId()).signLine4.replace("[player]", player.getName()));
            }
            // BlockFace direction = ((org.bukkit.material.Sign)
            // sign.getData()).getFacing();
            // ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
            sign.update(true, false);
        }
    }
    if (chest != null) {
        Vector ch = chest.clone().subtract(bedrock);
        ch.add(loc.toVector());
        // Place the chest - no need to use the safe spawn function because we
        // know what this island looks like
        blockToChange = ch.toLocation(world).getBlock();
        // Settings.chestItems.length);
        if (useDefaultChest) {
            // Fill the chest
            if (blockToChange.getType() == Material.CHEST) {
                final Chest islandChest = (Chest) blockToChange.getState();
                DoubleChest doubleChest = null;
                InventoryHolder iH = islandChest.getInventory().getHolder();
                if (iH instanceof DoubleChest) {
                    // Bukkit.getLogger().info("DEBUG: double chest");
                    doubleChest = (DoubleChest) iH;
                }
                if (doubleChest != null) {
                    Inventory inventory = doubleChest.getInventory();
                    inventory.clear();
                    inventory.setContents(defaultChestItems);
                } else {
                    Inventory inventory = islandChest.getInventory();
                    inventory.clear();
                    inventory.setContents(defaultChestItems);
                }
            }
        }
    }
    if (teleport) {
        plugin.getPlayers().setInTeleport(player.getUniqueId(), true);
        // plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
        if (player.getWorld().equals(world)) {
            // plugin.getLogger().info("DEBUG: same world");
            int distSq = (int) ((player.getLocation().distanceSquared(loc) - ((double) Settings.islandDistance * Settings.islandDistance) / 16));
            // plugin.getLogger().info("DEBUG:  distsq = " + distSq);
            if (plugin.getServer().getViewDistance() * plugin.getServer().getViewDistance() < distSq) {
                // plugin.getLogger().info("DEBUG: teleporting");
                player.teleport(world.getSpawnLocation());
            }
        }
        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

            @Override
            public void run() {
                plugin.getGrid().homeTeleport(player);
                plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
                // Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world
                plugin.resetPlayer(player);
                // Reset money if required
                if (Settings.resetMoney) {
                    resetMoney(player);
                }
                // Show fancy titles!
                if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
                    if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
                    }
                    if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
                    }
                    if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""
                        // + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
                    }
                }
                if (reason.equals(PasteReason.NEW_ISLAND)) {
                    // plugin.getLogger().info("DEBUG: First time");
                    if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) {
                        // plugin.getLogger().info("DEBUG: Executing new island commands");
                        IslandCmd.runCommands(Settings.startCommands, player);
                    }
                } else if (reason.equals(PasteReason.RESET)) {
                    // plugin.getLogger().info("DEBUG: Reset");
                    if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) {
                        // plugin.getLogger().info("DEBUG: Executing reset island commands");
                        IslandCmd.runCommands(Settings.resetCommands, player);
                    }
                }
            }
        }, 10L);
    }
    if (!islandCompanion.isEmpty() && grass != null) {
        Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(), new Runnable() {

            @Override
            public void run() {
                spawnCompanion(player, grass);
            }
        }, 40L);
    }
// Set the bedrock block meta data to the original spawn location
// Doesn't survive a server restart. TODO: change to add this info elsewhere.
/*
        if (playerSpawn != null) {
            blockToChange = loc.getBlock();
            if (blockToChange.getType().equals(Material.BEDROCK)) {
                String spawnLoc = Util.getStringLocation(loc.clone().add(playerSpawn).add(new Vector(0.5D,0D,0.5D)));
                blockToChange.setMetadata("playerSpawn", new FixedMetadataValue(plugin, spawnLoc));
            }
        }
         */
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) DoubleChest(org.bukkit.block.DoubleChest) Chest(org.bukkit.block.Chest) Rabbit(org.bukkit.entity.Rabbit) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) Wolf(org.bukkit.entity.Wolf) BlockVector(org.bukkit.util.BlockVector) Vector(org.bukkit.util.Vector) InventoryHolder(org.bukkit.inventory.InventoryHolder) ItemMeta(org.bukkit.inventory.meta.ItemMeta) DyeColor(org.bukkit.DyeColor) Material(org.bukkit.Material) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) Ocelot(org.bukkit.entity.Ocelot) TreeType(org.bukkit.TreeType) EntityType(org.bukkit.entity.EntityType) GameType(com.wasteofplastic.askyblock.Settings.GameType) BlockState(org.bukkit.block.BlockState) Sheep(org.bukkit.entity.Sheep) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.askyblock.ASkyBlock) Sign(org.bukkit.block.Sign) BlockVector(org.bukkit.util.BlockVector) ItemStack(org.bukkit.inventory.ItemStack) DoubleChest(org.bukkit.block.DoubleChest) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location)

Example 3 with Rabbit

use of org.bukkit.entity.Rabbit in project acidisland by tastybento.

the class Schematic method pasteSchematic.

/*
     * This function pastes using World Edit - problem is that because it reads a file, it's slow.
    @SuppressWarnings("deprecation")
     */
/*
     * 
    public void pasteSchematic(final Location loc, final Player player, boolean teleport)  {
	plugin.getLogger().info("WE Pasting");
	com.sk89q.worldedit.Vector WEorigin = new com.sk89q.worldedit.Vector(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
        EditSession es = new EditSession(new BukkitWorld(loc.getWorld()), 999999999);
        try {
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, WEorigin, false);
        cc.pasteEntities(WEorigin);
        } catch (Exception e) {
            e.printStackTrace();
        }

    	if (teleport) {
    		World world = loc.getWorld();

    	    player.teleport(world.getSpawnLocation());
    	    plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

    		@Override
    		public void run() {
    		    plugin.getGrid().homeTeleport(player);

    		}}, 10L);

    	}
    }   
     */
/**
 * This method pastes a schematic.
 * @param loc - where to paste it
 * @param player - who for
 * @param teleport - should the player be teleported after pasting?
 * @param reason - why this was pasted
 */
public void pasteSchematic(final Location loc, final Player player, boolean teleport, final PasteReason reason) {
    // If this is not a file schematic, paste the default island
    if (this.file == null) {
        if (Settings.GAMETYPE == GameType.ACIDISLAND) {
            generateIslandBlocks(loc, player, reason);
        } else {
            loc.getBlock().setType(Material.BEDROCK);
            ASkyBlock.getPlugin().getLogger().severe("Missing schematic - using bedrock block only");
        }
        return;
    }
    World world = loc.getWorld();
    Location blockLoc = new Location(world, loc.getX(), loc.getY(), loc.getZ());
    // Location blockLoc = new Location(world, loc.getX(), Settings.island_level, loc.getZ());
    blockLoc.subtract(bedrock);
    // plugin.getLogger().info("DEBUG: islandBlock size (paste) = " + islandBlocks.size());
    for (IslandBlock b : islandBlocks) {
        b.paste(nms, blockLoc, this.usePhysics, biome);
    }
    // Bukkit.getLogger().info("Block loc = " + blockLoc);
    if (pasteEntities) {
        for (EntityObject ent : entitiesList) {
            // If TileX/Y/Z id defined, we have to use it (for Item Frame & Painting)
            if (ent.getTileX() != null && ent.getTileY() != null && ent.getTileZ() != null) {
                ent.setLocation(new BlockVector(ent.getTileX(), ent.getTileY(), ent.getTileZ()));
            }
            Location entitySpot = ent.getLocation().toLocation(blockLoc.getWorld()).add(blockLoc.toVector());
            entitySpot.setPitch(ent.getPitch());
            entitySpot.setYaw(ent.getYaw());
            // Bukkit.getLogger().info("DEBUG: Entity type = " + ent.getType());
            if (ent.getType() == EntityType.PAINTING) {
                // Bukkit.getLogger().info("DEBUG: spawning " + ent.getType().toString() + " at " + entitySpot);
                try {
                    Painting painting = blockLoc.getWorld().spawn(entitySpot, Painting.class);
                    if (painting != null) {
                        if (paintingList.containsKey(ent.getMotive())) {
                            // painting.setArt(Art.GRAHAM);
                            painting.setArt(paintingList.get(ent.getMotive()), true);
                        } else {
                            // Set default
                            painting.setArt(Art.ALBAN, true);
                        }
                        // http://minecraft.gamepedia.com/Painting#Data_values
                        if (facingList.containsKey(ent.getFacing())) {
                            painting.setFacingDirection(facingList.get(ent.getFacing()), true);
                        } else {
                            // set default direction
                            painting.setFacingDirection(BlockFace.NORTH, true);
                        }
                    // Bukkit.getLogger().info("DEBUG: Painting setFacingDirection: " + painting.getLocation().toString() + "; facing: " + painting.getFacing() + "; ent facing: " + ent.getFacing());
                    // Bukkit.getLogger().info("DEBUG: Painting setArt: " + painting.getLocation().toString() + "; art: " + painting.getArt() + "; ent motive: " + ent.getMotive());
                    }
                } catch (IllegalArgumentException e) {
                // plugin.getLogger().warning("Cannot paste painting from schematic");
                }
            } else if (ent.getType() == EntityType.ITEM_FRAME) {
                // Bukkit.getLogger().info("DEBUG: spawning itemframe at" + entitySpot.toString());
                // Bukkit.getLogger().info("DEBUG: tileX: " + ent.getTileX() + ", tileY: " + ent.getTileY() + ", tileZ: " + ent.getTileZ());
                ItemFrame itemFrame = (ItemFrame) blockLoc.getWorld().spawnEntity(entitySpot, EntityType.ITEM_FRAME);
                if (itemFrame != null) {
                    // Need to improve this shity fix ...
                    Material material = Material.matchMaterial(ent.getId().substring(10).toUpperCase());
                    ;
                    if (material == null && IslandBlock.WEtoM.containsKey(ent.getId().substring(10).toUpperCase())) {
                        material = IslandBlock.WEtoM.get(ent.getId().substring(10).toUpperCase());
                    }
                    ItemStack item;
                    if (material != null) {
                        // Bukkit.getLogger().info("DEBUG: id: " + ent.getId() + ", material match: " + material.toString());
                        if (ent.getCount() != null) {
                            if (ent.getDamage() != null) {
                                item = new ItemStack(material, ent.getCount(), ent.getDamage());
                            } else {
                                item = new ItemStack(material, ent.getCount(), (short) 0);
                            }
                        } else {
                            if (ent.getDamage() != null) {
                                item = new ItemStack(material, 1, ent.getDamage());
                            } else {
                                item = new ItemStack(material, 1, (short) 0);
                            }
                        }
                    } else {
                        // Bukkit.getLogger().info("DEBUG: material can't be found for: " + ent.getId() + " (" + ent.getId().substring(10).toUpperCase() + ")");
                        // Set to default content
                        item = new ItemStack(Material.STONE, 0, (short) 4);
                    }
                    ItemMeta itemMeta = item.getItemMeta();
                    // TODO: Implement methods to get enchantement, names, lore etc.
                    item.setItemMeta(itemMeta);
                    itemFrame.setItem(item);
                    if (facingList.containsKey(ent.getFacing())) {
                        itemFrame.setFacingDirection(facingList.get(ent.getFacing()), true);
                    } else {
                        // set default direction
                        itemFrame.setFacingDirection(BlockFace.NORTH, true);
                    }
                    // TODO: Implements code to handle the rotation of the item in the itemframe
                    if (rotationList.containsKey(ent.getItemRotation())) {
                        itemFrame.setRotation(rotationList.get(ent.getItemRotation()));
                    } else {
                        // Set default direction
                        itemFrame.setRotation(Rotation.NONE);
                    }
                }
            } else {
                // Bukkit.getLogger().info("Spawning " + ent.getType().toString() + " at " + entitySpot);
                Entity spawned = blockLoc.getWorld().spawnEntity(entitySpot, ent.getType());
                if (spawned != null) {
                    spawned.setVelocity(ent.getMotion());
                    if (ent.getType() == EntityType.SHEEP) {
                        Sheep sheep = (Sheep) spawned;
                        if (ent.isSheared()) {
                            sheep.setSheared(true);
                        }
                        DyeColor[] set = DyeColor.values();
                        sheep.setColor(set[ent.getColor()]);
                        sheep.setAge(ent.getAge());
                    } else if (ent.getType() == EntityType.HORSE) {
                        Horse horse = (Horse) spawned;
                        Horse.Color[] set = Horse.Color.values();
                        horse.setColor(set[ent.getColor()]);
                        horse.setAge(ent.getAge());
                        horse.setCarryingChest(ent.isCarryingChest());
                    } else if (ent.getType() == EntityType.VILLAGER) {
                        Villager villager = (Villager) spawned;
                        villager.setAge(ent.getAge());
                        Profession[] proffs = Profession.values();
                        villager.setProfession(proffs[ent.getProfession()]);
                    } else if (!Bukkit.getServer().getVersion().contains("(MC: 1.7") && ent.getType() == EntityType.RABBIT) {
                        Rabbit rabbit = (Rabbit) spawned;
                        Rabbit.Type[] set = Rabbit.Type.values();
                        rabbit.setRabbitType(set[ent.getRabbitType()]);
                        rabbit.setAge(ent.getAge());
                    } else if (ent.getType() == EntityType.OCELOT) {
                        Ocelot cat = (Ocelot) spawned;
                        if (ent.isOwned()) {
                            cat.setTamed(true);
                            cat.setOwner(player);
                        }
                        Ocelot.Type[] set = Ocelot.Type.values();
                        cat.setCatType(set[ent.getCatType()]);
                        cat.setAge(ent.getAge());
                        cat.setSitting(ent.isSitting());
                    } else if (ent.getType() == EntityType.WOLF) {
                        Wolf wolf = (Wolf) spawned;
                        if (ent.isOwned()) {
                            wolf.setTamed(true);
                            wolf.setOwner(player);
                        }
                        wolf.setAge(ent.getAge());
                        wolf.setSitting(ent.isSitting());
                        DyeColor[] color = DyeColor.values();
                        wolf.setCollarColor(color[ent.getCollarColor()]);
                    }
                }
            }
        }
    }
    // Find the grass spot
    final Location grass;
    if (topGrass != null) {
        Location gr = topGrass.clone().toLocation(loc.getWorld()).subtract(bedrock);
        gr.add(loc.toVector());
        // Center of block and a bit up so the animal drops a bit
        gr.add(new Vector(0.5D, 1.1D, 0.5D));
        grass = gr;
    } else {
        grass = null;
    }
    // Bukkit.getLogger().info("DEBUG cow location " + grass);
    Block blockToChange = null;
    // Place a helpful sign in front of player
    if (welcomeSign != null) {
        // Bukkit.getLogger().info("DEBUG welcome sign schematic relative is:"
        // + welcomeSign.toString());
        Vector ws = welcomeSign.clone().subtract(bedrock);
        // Bukkit.getLogger().info("DEBUG welcome sign relative to bedrock is:"
        // + welcomeSign.toString());
        ws.add(loc.toVector());
        // Bukkit.getLogger().info("DEBUG welcome sign actual position is:"
        // + welcomeSign.toString());
        blockToChange = ws.toLocation(world).getBlock();
        BlockState signState = blockToChange.getState();
        if (signState instanceof Sign) {
            Sign sign = (Sign) signState;
            if (sign.getLine(0).isEmpty()) {
                sign.setLine(0, plugin.myLocale(player.getUniqueId()).signLine1.replace("[player]", player.getName()));
            }
            if (sign.getLine(1).isEmpty()) {
                sign.setLine(1, plugin.myLocale(player.getUniqueId()).signLine2.replace("[player]", player.getName()));
            }
            if (sign.getLine(2).isEmpty()) {
                sign.setLine(2, plugin.myLocale(player.getUniqueId()).signLine3.replace("[player]", player.getName()));
            }
            if (sign.getLine(3).isEmpty()) {
                sign.setLine(3, plugin.myLocale(player.getUniqueId()).signLine4.replace("[player]", player.getName()));
            }
            // BlockFace direction = ((org.bukkit.material.Sign)
            // sign.getData()).getFacing();
            // ((org.bukkit.material.Sign) sign.getData()).setFacingDirection(BlockFace.NORTH);
            sign.update(true, false);
        }
    }
    if (chest != null) {
        Vector ch = chest.clone().subtract(bedrock);
        ch.add(loc.toVector());
        // Place the chest - no need to use the safe spawn function because we
        // know what this island looks like
        blockToChange = ch.toLocation(world).getBlock();
        // Settings.chestItems.length);
        if (useDefaultChest) {
            // Fill the chest
            if (blockToChange.getType() == Material.CHEST) {
                final Chest islandChest = (Chest) blockToChange.getState();
                DoubleChest doubleChest = null;
                InventoryHolder iH = islandChest.getInventory().getHolder();
                if (iH instanceof DoubleChest) {
                    // Bukkit.getLogger().info("DEBUG: double chest");
                    doubleChest = (DoubleChest) iH;
                }
                if (doubleChest != null) {
                    Inventory inventory = doubleChest.getInventory();
                    inventory.clear();
                    inventory.setContents(defaultChestItems);
                } else {
                    Inventory inventory = islandChest.getInventory();
                    inventory.clear();
                    inventory.setContents(defaultChestItems);
                }
            }
        }
    }
    if (teleport) {
        plugin.getPlayers().setInTeleport(player.getUniqueId(), true);
        // plugin.getLogger().info("DEBUG: view dist = " + plugin.getServer().getViewDistance());
        if (player.getWorld().equals(world)) {
            // plugin.getLogger().info("DEBUG: same world");
            int distSq = (int) ((player.getLocation().distanceSquared(loc) - ((double) Settings.islandDistance * Settings.islandDistance) / 16));
            // plugin.getLogger().info("DEBUG:  distsq = " + distSq);
            if (plugin.getServer().getViewDistance() * plugin.getServer().getViewDistance() < distSq) {
                // plugin.getLogger().info("DEBUG: teleporting");
                player.teleport(world.getSpawnLocation());
            }
        }
        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

            @Override
            public void run() {
                plugin.getGrid().homeTeleport(player);
                plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
                // Reset any inventory, etc. This is done AFTER the teleport because other plugins may switch out inventory based on world
                plugin.resetPlayer(player);
                // Reset money if required
                if (Settings.resetMoney) {
                    resetMoney(player);
                }
                // Show fancy titles!
                if (!Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
                    if (!plugin.myLocale(player.getUniqueId()).islandSubTitle.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " subtitle {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandSubTitleColor + "\"}");
                    }
                    if (!plugin.myLocale(player.getUniqueId()).islandTitle.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:title " + player.getName() + " title {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandTitle.replace("[player]", player.getName()) + "\", \"color\":\"" + plugin.myLocale(player.getUniqueId()).islandTitleColor + "\"}");
                    }
                    if (!plugin.myLocale(player.getUniqueId()).islandDonate.isEmpty() && !plugin.myLocale(player.getUniqueId()).islandURL.isEmpty()) {
                        // plugin.getLogger().info("DEBUG: tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\""
                        // + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
                        plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "minecraft:tellraw " + player.getName() + " {\"text\":\"" + plugin.myLocale(player.getUniqueId()).islandDonate.replace("[player]", player.getName()) + "\",\"color\":\"" + plugin.myLocale(player.getUniqueId()).islandDonateColor + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + plugin.myLocale(player.getUniqueId()).islandURL + "\"}}");
                    }
                }
                if (reason.equals(PasteReason.NEW_ISLAND)) {
                    // plugin.getLogger().info("DEBUG: First time");
                    if (!player.hasPermission(Settings.PERMPREFIX + "command.newexempt")) {
                        // plugin.getLogger().info("DEBUG: Executing new island commands");
                        IslandCmd.runCommands(Settings.startCommands, player);
                    }
                } else if (reason.equals(PasteReason.RESET)) {
                    // plugin.getLogger().info("DEBUG: Reset");
                    if (!player.hasPermission(Settings.PERMPREFIX + "command.resetexempt")) {
                        // plugin.getLogger().info("DEBUG: Executing reset island commands");
                        IslandCmd.runCommands(Settings.resetCommands, player);
                    }
                }
            }
        }, 10L);
    }
    if (!islandCompanion.isEmpty() && grass != null) {
        Bukkit.getServer().getScheduler().runTaskLater(ASkyBlock.getPlugin(), new Runnable() {

            @Override
            public void run() {
                spawnCompanion(player, grass);
            }
        }, 40L);
    }
// Set the bedrock block meta data to the original spawn location
// Doesn't survive a server restart. TODO: change to add this info elsewhere.
/*
        if (playerSpawn != null) {
            blockToChange = loc.getBlock();
            if (blockToChange.getType().equals(Material.BEDROCK)) {
                String spawnLoc = Util.getStringLocation(loc.clone().add(playerSpawn).add(new Vector(0.5D,0D,0.5D)));
                blockToChange.setMetadata("playerSpawn", new FixedMetadataValue(plugin, spawnLoc));
            }
        }
         */
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) DoubleChest(org.bukkit.block.DoubleChest) Chest(org.bukkit.block.Chest) Rabbit(org.bukkit.entity.Rabbit) ItemFrame(org.bukkit.entity.ItemFrame) World(org.bukkit.World) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) Wolf(org.bukkit.entity.Wolf) BlockVector(org.bukkit.util.BlockVector) Vector(org.bukkit.util.Vector) InventoryHolder(org.bukkit.inventory.InventoryHolder) ItemMeta(org.bukkit.inventory.meta.ItemMeta) DyeColor(org.bukkit.DyeColor) Material(org.bukkit.Material) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) Ocelot(org.bukkit.entity.Ocelot) TreeType(org.bukkit.TreeType) EntityType(org.bukkit.entity.EntityType) GameType(com.wasteofplastic.acidisland.Settings.GameType) BlockState(org.bukkit.block.BlockState) Sheep(org.bukkit.entity.Sheep) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) Sign(org.bukkit.block.Sign) BlockVector(org.bukkit.util.BlockVector) ItemStack(org.bukkit.inventory.ItemStack) DoubleChest(org.bukkit.block.DoubleChest) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location)

Example 4 with Rabbit

use of org.bukkit.entity.Rabbit in project Citizens2 by CitizensDev.

the class NPCCommands method rabbitType.

@Command(aliases = { "npc" }, usage = "rabbittype [type]", desc = "Set the Type of a Rabbit NPC", modifiers = { "rabbittype", "rbtype" }, min = 2, permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
    Rabbit.Type type;
    try {
        type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
    } catch (IllegalArgumentException ex) {
        throw new CommandException(Messages.INVALID_RABBIT_TYPE, StringUtils.join(Rabbit.Type.values(), ","));
    }
    npc.getTrait(RabbitType.class).setType(type);
    Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
}
Also used : RabbitType(net.citizensnpcs.trait.RabbitType) Rabbit(org.bukkit.entity.Rabbit) ServerCommandException(net.citizensnpcs.api.command.exception.ServerCommandException) CommandException(net.citizensnpcs.api.command.exception.CommandException) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 5 with Rabbit

use of org.bukkit.entity.Rabbit in project MyPet by xXKeyleXx.

the class EntityConverterService method convertEntity.

@Override
public void convertEntity(MyPet myPet, LivingEntity normalEntity) {
    if (myPet instanceof MyCreeper) {
        if (((MyCreeper) myPet).isPowered()) {
            ((Creeper) normalEntity).setPowered(true);
        }
    } else if (myPet instanceof MyGoat) {
        if (((MyGoat) myPet).isScreaming()) {
            ((Goat) normalEntity).setScreaming(true);
        }
    } else if (myPet instanceof MyEnderman) {
        if (((MyEnderman) myPet).hasBlock()) {
            ((Enderman) normalEntity).setCarriedMaterial(((MyEnderman) myPet).getBlock().getData());
        }
    } else if (myPet instanceof MyIronGolem) {
        ((IronGolem) normalEntity).setPlayerCreated(true);
    } else if (myPet instanceof MyMagmaCube) {
        ((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
    } else if (myPet instanceof MyPig) {
        ((Pig) normalEntity).setSaddle(((MyPig) myPet).hasSaddle());
    } else if (myPet instanceof MySheep) {
        ((Sheep) normalEntity).setSheared(((MySheep) myPet).isSheared());
        ((Sheep) normalEntity).setColor(((MySheep) myPet).getColor());
    } else if (myPet instanceof MyVillager) {
        MyVillager villagerPet = (MyVillager) myPet;
        Villager villagerEntity = ((Villager) normalEntity);
        Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
        Villager.Type type = Villager.Type.values()[villagerPet.getType().ordinal()];
        villagerEntity.setVillagerType(type);
        villagerEntity.setProfession(profession);
        villagerEntity.setVillagerLevel(villagerPet.getVillagerLevel());
        if (villagerPet.hasOriginalData()) {
            TagCompound villagerTag = villagerPet.getOriginalData();
            net.minecraft.world.entity.npc.Villager entityVillager = ((CraftVillager) villagerEntity).getHandle();
            try {
                if (villagerTag.containsKey("Offers")) {
                    TagCompound offersTag = villagerTag.get("Offers");
                    CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(offersTag);
                    entityVillager.setOffers(new MerchantOffers(vanillaNBT));
                }
                if (villagerTag.containsKey("Inventory")) {
                    TagList inventoryTag = villagerTag.get("Inventory");
                    ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
                    for (int i = 0; i < vanillaNBT.size(); ++i) {
                        net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.of(vanillaNBT.getCompound(i));
                        ItemStack item = CraftItemStack.asCraftMirror(itemstack);
                        if (!itemstack.isEmpty()) {
                            Villager vill = ((Villager) Bukkit.getServer().getEntity(normalEntity.getUniqueId()));
                            vill.getInventory().addItem(item);
                        }
                    }
                }
                if (villagerTag.containsKey("FoodLevel")) {
                    byte foodLevel = villagerTag.getAs("FoodLevel", TagByte.class).getByteData();
                    // Field: foodLevel
                    ReflectionUtil.setFieldValue("cq", entityVillager, foodLevel);
                }
                if (villagerTag.containsKey("Gossips")) {
                    TagList inventoryTag = villagerTag.get("Gossips");
                    ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
                    // This might be useful for later/following versions
                    // ((GossipContainer) ReflectionUtil.getFieldValue(net.minecraft.world.entity.npc.Villager.class, entityVillager, "cr")) //Field: gossips
                    entityVillager.getGossips().update(new Dynamic<>(NbtOps.INSTANCE, vanillaNBT));
                }
                if (villagerTag.containsKey("LastRestock")) {
                    long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
                    // Field: lastRestockGameTime
                    ReflectionUtil.setFieldValue("cv", entityVillager, lastRestock);
                }
                if (villagerTag.containsKey("LastGossipDecay")) {
                    long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
                    // Field: lastGossipDecayTime
                    ReflectionUtil.setFieldValue("ct", entityVillager, lastGossipDecay);
                }
                if (villagerTag.containsKey("RestocksToday")) {
                    int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
                    // Field: numberOfRestocksToday
                    ReflectionUtil.setFieldValue("cw", entityVillager, restocksToday);
                }
                // Field: AssignProfessionWhenSpawned
                ReflectionUtil.setFieldValue("cy", entityVillager, true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (villagerTag.containsKey("Xp")) {
                int xp = villagerTag.getAs("Xp", TagInt.class).getIntData();
                entityVillager.setVillagerXp(xp);
            }
        }
    } else if (myPet instanceof MySlime) {
        ((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
    } else if (myPet instanceof MyZombieVillager) {
        Villager.Profession profession = Villager.Profession.values()[((MyZombieVillager) myPet).getProfession()];
        net.minecraft.world.entity.monster.ZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle();
        nmsEntity.setVillagerData(nmsEntity.getVillagerData().setType(Registry.VILLAGER_TYPE.get(new ResourceLocation(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))).setLevel(((MyZombieVillager) myPet).getTradingLevel()).setProfession(Registry.VILLAGER_PROFESSION.get(new ResourceLocation(profession.name().toLowerCase(Locale.ROOT)))));
    } else if (myPet instanceof MyWitherSkeleton) {
        normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD));
    } else if (myPet instanceof MySkeleton) {
        normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
    } else if (myPet instanceof MyHorse) {
        Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
        Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
        ((Horse) normalEntity).setColor(color);
        ((Horse) normalEntity).setStyle(style);
        if (((MyHorse) myPet).hasSaddle()) {
            ((Horse) normalEntity).getInventory().setSaddle(((MyHorse) myPet).getSaddle().clone());
        }
        if (((MyHorse) myPet).hasArmor()) {
            ((Horse) normalEntity).getInventory().setArmor(((MyHorse) myPet).getArmor().clone());
        }
        ((Horse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MySkeletonHorse) {
        ((SkeletonHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyZombieHorse) {
        ((ZombieHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyLlama) {
        ((Llama) normalEntity).setColor(Llama.Color.values()[Math.max(0, Math.min(3, ((MyLlama) myPet).getVariant()))]);
        ((Llama) normalEntity).setCarryingChest(((MyLlama) myPet).hasChest());
        if (((MyLlama) myPet).hasDecor()) {
            ((Llama) normalEntity).getInventory().setDecor(((MyLlama) myPet).getDecor());
        }
        ((Llama) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyRabbit) {
        ((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
    } else if (myPet instanceof MyParrot) {
        ((Parrot) normalEntity).setVariant(Parrot.Variant.values()[((MyParrot) myPet).getVariant()]);
    } else if (myPet instanceof MyAxolotl) {
        ((Axolotl) normalEntity).setVariant(Axolotl.Variant.values()[((MyAxolotl) myPet).getVariant()]);
    } else if (myPet instanceof MyTropicalFish) {
        ((CraftTropicalFish) normalEntity).getHandle().setVariant(((MyTropicalFish) myPet).getVariant());
    } else if (myPet instanceof MyPufferfish) {
        ((PufferFish) normalEntity).setPuffState(((MyPufferfish) myPet).getPuffState().ordinal());
    } else if (myPet instanceof MyPhantom) {
        ((Phantom) normalEntity).setSize(((MyPhantom) myPet).getSize());
    } else if (myPet instanceof MyCat) {
        ((Cat) normalEntity).setCatType(((MyCat) myPet).getCatType());
        ((Cat) normalEntity).setCollarColor(((MyCat) myPet).getCollarColor());
    } else if (myPet instanceof MyMooshroom) {
        ((MushroomCow) normalEntity).setVariant(MushroomCow.Variant.values()[((MyMooshroom) myPet).getType().ordinal()]);
    } else if (myPet instanceof MyPanda) {
        ((Panda) normalEntity).setMainGene(((MyPanda) myPet).getMainGene());
        ((Panda) normalEntity).setHiddenGene(((MyPanda) myPet).getHiddenGene());
    } else if (myPet instanceof WanderingTrader) {
        MyWanderingTrader traderPet = (MyWanderingTrader) myPet;
        if (traderPet.hasOriginalData()) {
            TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
            for (String key : traderPet.getOriginalData().getCompoundData().keySet()) {
                villagerTag.put(key, traderPet.getOriginalData().get(key));
            }
            MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
        }
    } else if (myPet instanceof MyBee) {
        ((Bee) normalEntity).setHasNectar(((MyBee) myPet).hasNectar());
        ((Bee) normalEntity).setHasStung(((MyBee) myPet).hasStung());
    }
    if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
        if (((MyPetBaby) myPet).isBaby()) {
            ((Ageable) normalEntity).setBaby();
        } else {
            ((Ageable) normalEntity).setAdult();
        }
    }
}
Also used : MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) MyTropicalFish(de.Keyle.MyPet.api.entity.types.MyTropicalFish) MyWitherSkeleton(de.Keyle.MyPet.api.entity.types.MyWitherSkeleton) MyEnderman(de.Keyle.MyPet.api.entity.types.MyEnderman) MyCreeper(de.Keyle.MyPet.api.entity.types.MyCreeper) CraftTropicalFish(org.bukkit.craftbukkit.v1_18_R1.entity.CraftTropicalFish) MyMagmaCube(de.Keyle.MyPet.api.entity.types.MyMagmaCube) MySheep(de.Keyle.MyPet.api.entity.types.MySheep) MyWanderingTrader(de.Keyle.MyPet.api.entity.types.MyWanderingTrader) MyHorse(de.Keyle.MyPet.api.entity.types.MyHorse) AbstractHorse(org.bukkit.entity.AbstractHorse) MyHorse(de.Keyle.MyPet.api.entity.types.MyHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) MySkeletonHorse(de.Keyle.MyPet.api.entity.types.MySkeletonHorse) ZombieHorse(org.bukkit.entity.ZombieHorse) MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) SkeletonHorse(org.bukkit.entity.SkeletonHorse) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) MyVillager(de.Keyle.MyPet.api.entity.types.MyVillager) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) CraftVillager(org.bukkit.craftbukkit.v1_18_R1.entity.CraftVillager) WanderingTrader(org.bukkit.entity.WanderingTrader) MyWanderingTrader(de.Keyle.MyPet.api.entity.types.MyWanderingTrader) MyParrot(de.Keyle.MyPet.api.entity.types.MyParrot) MySkeleton(de.Keyle.MyPet.api.entity.types.MySkeleton) MyCat(de.Keyle.MyPet.api.entity.types.MyCat) MyPanda(de.Keyle.MyPet.api.entity.types.MyPanda) MySlime(de.Keyle.MyPet.api.entity.types.MySlime) MySkeletonHorse(de.Keyle.MyPet.api.entity.types.MySkeletonHorse) MyMooshroom(de.Keyle.MyPet.api.entity.types.MyMooshroom) Panda(org.bukkit.entity.Panda) MyPanda(de.Keyle.MyPet.api.entity.types.MyPanda) ZombieHorse(org.bukkit.entity.ZombieHorse) MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) MyPufferfish(de.Keyle.MyPet.api.entity.types.MyPufferfish) Enderman(org.bukkit.entity.Enderman) MyEnderman(de.Keyle.MyPet.api.entity.types.MyEnderman) MyGoat(de.Keyle.MyPet.api.entity.types.MyGoat) MyIronGolem(de.Keyle.MyPet.api.entity.types.MyIronGolem) Cat(org.bukkit.entity.Cat) MyCat(de.Keyle.MyPet.api.entity.types.MyCat) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) ZombieVillager(org.bukkit.entity.ZombieVillager) MyAxolotl(de.Keyle.MyPet.api.entity.types.MyAxolotl) Axolotl(org.bukkit.entity.Axolotl) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Dynamic(com.mojang.serialization.Dynamic) MyCreeper(de.Keyle.MyPet.api.entity.types.MyCreeper) Creeper(org.bukkit.entity.Creeper) MyRabbit(de.Keyle.MyPet.api.entity.types.MyRabbit) Rabbit(org.bukkit.entity.Rabbit) Ageable(org.bukkit.entity.Ageable) TagCompound(de.keyle.knbt.TagCompound) MyLlama(de.Keyle.MyPet.api.entity.types.MyLlama) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) MyPig(de.Keyle.MyPet.api.entity.types.MyPig) ResourceLocation(net.minecraft.resources.ResourceLocation) TagList(de.keyle.knbt.TagList) MyPhantom(de.Keyle.MyPet.api.entity.types.MyPhantom) MagmaCube(org.bukkit.entity.MagmaCube) MyMagmaCube(de.Keyle.MyPet.api.entity.types.MyMagmaCube) CompoundTag(net.minecraft.nbt.CompoundTag) MyVillager(de.Keyle.MyPet.api.entity.types.MyVillager) MyBee(de.Keyle.MyPet.api.entity.types.MyBee) MyBee(de.Keyle.MyPet.api.entity.types.MyBee) Bee(org.bukkit.entity.Bee) PufferFish(org.bukkit.entity.PufferFish) MyAxolotl(de.Keyle.MyPet.api.entity.types.MyAxolotl) Slime(org.bukkit.entity.Slime) MySlime(de.Keyle.MyPet.api.entity.types.MySlime) ListTag(net.minecraft.nbt.ListTag) MyLlama(de.Keyle.MyPet.api.entity.types.MyLlama) Llama(org.bukkit.entity.Llama) MerchantOffers(net.minecraft.world.item.trading.MerchantOffers) MyRabbit(de.Keyle.MyPet.api.entity.types.MyRabbit) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby) MySheep(de.Keyle.MyPet.api.entity.types.MySheep) Sheep(org.bukkit.entity.Sheep)

Aggregations

Rabbit (org.bukkit.entity.Rabbit)6 Horse (org.bukkit.entity.Horse)4 Sheep (org.bukkit.entity.Sheep)4 Villager (org.bukkit.entity.Villager)4 ItemStack (org.bukkit.inventory.ItemStack)4 Ageable (org.bukkit.entity.Ageable)3 ItemFrame (org.bukkit.entity.ItemFrame)3 LivingEntity (org.bukkit.entity.LivingEntity)3 Ocelot (org.bukkit.entity.Ocelot)3 Painting (org.bukkit.entity.Painting)3 Wolf (org.bukkit.entity.Wolf)3 Dynamic (com.mojang.serialization.Dynamic)2 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)2 MyAxolotl (de.Keyle.MyPet.api.entity.types.MyAxolotl)2 MyBee (de.Keyle.MyPet.api.entity.types.MyBee)2 MyCat (de.Keyle.MyPet.api.entity.types.MyCat)2 MyCreeper (de.Keyle.MyPet.api.entity.types.MyCreeper)2 MyEnderman (de.Keyle.MyPet.api.entity.types.MyEnderman)2 MyGoat (de.Keyle.MyPet.api.entity.types.MyGoat)2 MyHorse (de.Keyle.MyPet.api.entity.types.MyHorse)2