Code not working :/

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

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

    linkrock4

    Hello, im making this christmas plugin and umm well im trying to rename Command Blocks to pressents and its not working, heres the code: (theres no error in the console/in eclipse)
    Code:
    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.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);
            getConfig().options().copyDefaults(true);
            saveConfig();
            {
     
                getLogger().info("Checking already loaded chunks for snowy areas...");
     
                for(final World world : getServer().getWorlds())
                {
                    for(final Chunk chunk : world.getLoadedChunks())
                    {
                        checkChunk(chunk);
                    }
                }
            }
        }
     
        public void onDisable() { // Server Stops
            getLogger().info("Christmas Plugin has been disabled!");
     
        }
        //Message
        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
        @EventHandler
        @SuppressWarnings("deprecation")
            public void onBlockPlace(BlockPlaceEvent e) {
                if (e.getBlockPlaced().getTypeId() == 137) {
                    int id = rand.nextInt(400);
                    while(Material.getMaterial(id) == null)
                      id = rand.nextInt(400);
                        e.getPlayer().sendMessage(
                                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++) { // Loop over all, remove() will only remove if the amount matches with the one in the slot...
                            is = inv.getItem(i);
                            if(is.getTypeId() == 137)
                            {
                                if(is.getAmount() > 1)
                                    is.setAmount(is.getAmount() - 1);
                                else
                                    is = null;
                                inv.setItem(i, is);
                                break;
                            }
                        }
     
                        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);
                          e.getPlayer().updateInventory();
                      e.setCancelled(true);
     
            }
            // Weather
     
        }
        // Snow under blocks
        @EventHandler(ignoreCancelled = true)
        public void chunkLoad(final ChunkLoadEvent event)
        {
            checkChunk(event.getChunk());
        }
     
        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)
                return;
     
            placeSnow(event.getBlock());
        }
     
        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)
                return;
     
            int type = chunkSnap.getBlockTypeId(x, --y, z);
     
            if(type != Material.LEAVES.getId())
                return;
     
            int lastType = type;
     
            while(true)
            {
                type = chunkSnap.getBlockTypeId(x, --y, z);
     
                switch(Material.getMaterial(type))
                {
                    case AIR:
                    case SNOW:
                        break;
     
                    case LEAVES:
                    {
                        if(lastType == 0)
                            chunk.getBlock(x, y + 1, z).setType(Material.SNOW);
     
                        break;
                    }
     
                    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);
     
                        return;
                    }
     
                    default:
                        return;
                }
     
                lastType = type;
            }
            // Color names
     
        }
        // Snowman spawning
     
    }
    Any ideas why?

    Anyone?

    Any help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    Dpasi314

    Did you forget to initialize it in your plugin.yml?
     
  3. Offline

    linkrock4

    its not a command but i did do the plugin.yml :p
     
  4. You may wanna not bump so much. its annoying for people that need help right at that moment.
     
  5. Offline

    linkrock4

    It doesnt work
     
Thread Status:
Not open for further replies.

Share This Page