Updating Plugin CraftItem Stack

Discussion in 'Plugin Development' started by linkrock4, Dec 20, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    So as all of you know the CraftItem Stack changed because of fireworks but i cant seem to update it because i dont understand why its not working.

    package net.skydevs.src;
    import java.util.Random;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Chunk;
    import org.bukkit.ChunkSnapshot;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.inventory.CraftItemStack;
    import org.bukkit.craftbukkit.v1_4_6.block.CraftBlock;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFormEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.world.ChunkLoadEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Christmas extends JavaPlugin implements Listener {
        Random rand = new Random();
        public String ChristmasMessage;
        public void onEnable() { // Server Starts
            getLogger().info("Christmas Plugin has been enabled!");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
                getLogger().info("Checking already loaded chunks for snowy areas...");
                for(final World world : getServer().getWorlds())
                    for(final Chunk chunk : world.getLoadedChunks())
        public void onDisable() { // Server Stops
            getLogger().info("Christmas Plugin has been disabled!");
        public boolean onCommand(CommandSender sender, Command cmd, String Label,
                String[] args) {
            if (cmd.getName().equalsIgnoreCase("Christmas")) {
                Bukkit.broadcastMessage(ChatColor.BLACK + "[" + ChatColor.RED
                        + "Christmas" + ChatColor.BLACK + "] " + ChatColor.GREEN
                        + "Happy " + ChatColor.RED
                        + "Christmas! We hope you enjoy the new features we have for you!");
            return false;
        // Presents
            public void onBlockPlace(BlockPlaceEvent e) {
                if (e.getBlockPlaced().getTypeId() == 19) {
                    int id = rand.nextInt(400);
                    while(Material.getMaterial(id) == null)
                      id = rand.nextInt(400);
                                ChatColor.BLACK + "[" + ChatColor.RED + "Christmas"
                                        + ChatColor.BLACK + "] " + ChatColor.GREEN
                                        + "Ho! Ho! Ho! " + ChatColor.RED
                                        + "Merry Christmas! Enjoy your gift!");
                        Inventory inv = e.getPlayer().getInventory();
                        ItemStack is;
                        for(int i = 0; i < inv.getSize(); i++) {
                            is = inv.getItem(i);
                            if(is.getTypeId() == 19)
                                if(is.getAmount() > 1)
                                    is.setAmount(is.getAmount() - 1);
                                    is = null;
                                inv.setItem(i, is);
                        is = new ItemStack(id, 1);
                        if(id == 137)
                            CraftItemStack cis = new CraftItemStack(is);
                            cis.getHandle().c(ChatColor.RED + "Present");
                            is = cis;
                        for(ItemStack item: inv.addItem(is).values())
                            e.getPlayer().getWorld().dropItemNaturally(e.getPlayer().getLocation(), item);
            // Weather
        // Snow under blocks
        @EventHandler(ignoreCancelled = true)
        public void chunkLoad(final ChunkLoadEvent event)
        private void checkChunk(final Chunk chunk)
            final ChunkSnapshot chunkSnap = chunk.getChunkSnapshot(true, false, false);
            for(int x = 0; x < 16; x++)
                for(int z = 0; z < 16; z++)
                    final int y = chunkSnap.getHighestBlockYAt(x, z);
                    if(chunkSnap.getBlockTypeId(x, y, z) == Material.SNOW.getId())
                        placeSnow(chunk, chunkSnap, x, y, z);
        @EventHandler(ignoreCancelled = true)
        public void snowForm(final BlockFormEvent event)
            if(event.getNewState().getType() != Material.SNOW)
        private void placeSnow(final Block block)
            final Location loc = block.getLocation();
            final Chunk chunk = block.getChunk();
            placeSnow(chunk, chunk.getChunkSnapshot(true, false, false), Math.abs((chunk.getX() * 16) - loc.getBlockX()), loc.getBlockY(), Math.abs((chunk.getZ() * 16) - loc.getBlockZ()));
        private void placeSnow(final Chunk chunk, final ChunkSnapshot chunkSnap, final int x, int y, final int z)
            if(y <= 1)
            int type = chunkSnap.getBlockTypeId(x, --y, z);
            if(type != Material.LEAVES.getId())
            int lastType = type;
                type = chunkSnap.getBlockTypeId(x, --y, z);
                    case AIR:
                    case SNOW:
                    case LEAVES:
                        if(lastType == 0)
                            chunk.getBlock(x, y + 1, z).setType(Material.SNOW);
                    case STONE:
                    case GRASS:
                    case DIRT:
                    case COBBLESTONE:
                    case WOOD:
                    case BEDROCK:
                    case SAND:
                    case GRAVEL:
                    case GOLD_ORE:
                    case IRON_ORE:
                    case COAL_ORE:
                    case LOG:
                    case SPONGE:
                    case GLASS:
                    case LAPIS_ORE:
                    case LAPIS_BLOCK:
                    case DISPENSER:
                    case SANDSTONE:
                    case NOTE_BLOCK:
    //                case PISTON_BASE:
    //                case PISTON_STICKY_BASE:
    //                case PISTON_MOVING_PIECE:
    //                case PISTON_EXTENSION:
                    case WOOL:
                    case GOLD_BLOCK:
                    case IRON_BLOCK:
                    case DOUBLE_STEP:
                    case BRICK:
                    case TNT:
                    case BOOKSHELF:
                    case MOSSY_COBBLESTONE:
                    case OBSIDIAN:
                    case MOB_SPAWNER:
                    case DIAMOND_ORE:
                    case DIAMOND_BLOCK:
                    case WORKBENCH:
                    case FURNACE:
    //                case BURNING_FURNACE:
                    case REDSTONE_ORE:
    //                case ICE:
                    case SNOW_BLOCK:
                    case CLAY:
                    case JUKEBOX:
                    case PUMPKIN:
                    case NETHERRACK:
                    case SOUL_SAND:
                    case GLOWSTONE:
    //                case JACK_O_LANTERN:
                    case SMOOTH_BRICK:
                    case MELON_BLOCK:
                    case NETHER_BRICK:
                    case ENDER_STONE:
                    case REDSTONE_LAMP_OFF:
    //                case REDSTONE_LAMP_ON:
                    case WOOD_DOUBLE_STEP:
                    case EMERALD_BLOCK:
                    case EMERALD_ORE:
                        if(lastType == 0)
                            chunk.getBlock(x, y + 1, z).setType(Material.SNOW);
                lastType = type;
            // Color names
        // Snowman spawning
  2. Offline


    Ok before I posted that I thought they had gotten rid of the Craft in front of the classes, this was misguided. What happened is they moved it one folder deeper. Where it was
    import org.bukkit.craftbukkit.entity.CraftHumanEntity;
    It now needs to be
    import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;

    You can also take the original development patch and move all of the filed from the v1_4_6 folder into the craftbukkit folder. (Note:More Code will have to be changed in this case)
  3. Offline


    I came on here to ask the exact question :L
  4. Offline


    You sir are a genius, but now i seem to have a problem with the:
    * new CraftItemStack();
    * blablabla...getHandle()...blablabla
  5. Offline


    Take a look at the new feature called ItemMeta
  6. Offline


    So basicly gethandle doesnt exsist in craftitemstack anymore, what can it be replaced by?

    EDIT: Fixed ;D
  7. Offline


    the newly added ItemMeta and CraftItemStack.asNMSCopy(original). Also you could use reflection to get the handle (though I do not recommend this method)
Thread Status:
Not open for further replies.

Share This Page