Custom Creeper Help

Discussion in 'Plugin Development' started by ZomBlade_Shadow, Feb 16, 2015.

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

    ZomBlade_Shadow

    Hai!

    So basically i've been making a custom creeper egg plugin.
    But I have problems :c

    I haven't seen any tutorials or anything and my coding level is low,i've tried so many ways and EventHandlers:

    Code:
    package me.ZomBlade.BreakSidian;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Main extends JavaPlugin implements Listener{
      
      
        File f = new File("BreakSidian/BreakSidian", "Entity.yml");
        FileConfiguration cfg = YamlConfiguration.loadConfiguration(f);
        HashMap<Integer, ItemStack> creephash = new HashMap<Integer, ItemStack>();
        public void onEnable(){
            ItemStack creep = new ItemStack(Material.MONSTER_EGG,1,(short)50);
            ItemMeta creepmeta = creep.getItemMeta();
            creepmeta.setDisplayName(ChatColor.GOLD + "Super Creeper");
            ArrayList<String>lore = new ArrayList<String>();
            lore.add("Super Saiyan");
            creepmeta.setLore(lore);
            creep.setItemMeta(creepmeta);
            creephash.put(1, creep);
            getServer().getPluginManager().registerEvents(this, this);
        }
      
      
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player p = (Player) sender;
            Location loc = p.getLocation();
            // Just getting the Creeper egg.
            if(cmd.getName().equalsIgnoreCase("supercreeper")){
                if(sender instanceof Player){
                    if(args.length == 0){
                        p.getInventory().addItem(creephash.get(1));
                        p.sendMessage(ChatColor.GOLD + "SuperCreeper donné");
                        return true;
                    }
                }
            }
    // Tried to save the entity in a cfg to use later on.. Nooby stuff
            if(cmd.getName().equalsIgnoreCase("supersave")){
                Creeper c = (Creeper) loc.getWorld().spawn(loc, Creeper.class);
                c.setCustomName(ChatColor.GOLD + "Super Creeper");
                c.setCustomNameVisible(true);
                c.addPotionEffect(new PotionEffect (PotionEffectType.SPEED, 9999, 1));
                cfg.set("Entity." + ".creeper", c.getEntityId());
                try{
                    cfg.save(f);
                } catch (IOException e){
                    e.printStackTrace();
                }
                return true;
            }
          
            return false;
          
        }
         //I really need help here,I want it so that when I use the custom creeper egg,it spawns a custom creeper (like with a uniqueID or something)
    
    // This works,but it's really unefficient, It only works when I have 1 creeper egg :(
        @EventHandler
        public void onOpenEgg(PlayerInteractEvent e){
            Player p = e.getPlayer();
            ItemStack creep = creephash.get(1);
            Block b = e.getClickedBlock();
            Creeper c = (Creeper) cfg.get("Entity." + ".creeper");
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
                if(p.getInventory().getItemInHand().equals(creep)){
                    b.getLocation().getWorld().playEffect(b.getLocation(),Effect.BLAZE_SHOOT, 1);
                    b.getLocation().getWorld().playEffect(b.getLocation(),Effect.ENDER_SIGNAL, 1);
                    b.getLocation().getWorld().strikeLightningEffect(b.getLocation());
                }
            }
        }
      
    }
    

    So basically my plugin is that there's a custom creeper egg (Super Creeper) that only his explosion will be able to break Enchantment Tables and obsidian (didn't code the explosion part yet cause i'm blocked)

    I really need help to make a custom creeper egg that spawns a unique creeper;

    Bare with me please and thanks! :)
     
  2. Offline

    ESSHD

    It's not possible to make a creeper that only destroys certain blocks (as far as I've seen.)
     
  3. Offline

    ZomBlade_Shadow

    I'm pretty sure that I can,there are plugins that allow creepers to blow them,i'll make my custom creepers blow them
     
  4. Offline

    sn1cko

    Don't know if this helps but there are 2 different Materials of Monster Eggs
    Code:
    Material.MONSTER_EGG;
    Material.MONSTER_EGGS
    
    and it's possible to only destroy only specific blocks i think
    try it with the EntityExplodeEvent to check for the blocks type
     
  5. Offline

    ZomBlade_Shadow

    Thanks but it didn't work x)
    Monster_eggs = stone block where the silverfish spawns when you break it
    monster_egg = Spawn egg
    and thanks for the eventhandler i'll test it out,but once i get the Super Creeper part done ;)

    Please somebody :) haalp
     
  6. Offline

    sn1cko

    Haha ouh ok got that ^^
    havn't worked with that ever
    but what exactly do you need help with the super creeper i didn't really got your question
     
  7. Offline

    ZomBlade_Shadow

    I made a super creeper egg.
    when I do /supercreeper it gives me 1 super creeper egg
    when I "open the egg" by right clicking on the ground and I only have 1 egg it works (the playsounds and stuff)
    but when I have 2 or more creeper eggs it doesn't work

    What i want is to get the creeper that spawns out of the "Super Creeper Egg" and give it a unique ID or something,so that i can play around with it for the future
     
  8. Offline

    sn1cko

    i think i got what you ment
    Code:
        @EventHandler
        public void onExplode(EntityExplodeEvent e){
            if(e.getEntity() instanceof Creeper){
                Creeper c = (Creeper) e.getEntity();
                if(c.getCustomName() != null){
                  if(c.getCustomName().equalsIgnoreCase(ChatColor.GOLD + "Super Creeper")){
                      //DO STUFF
                  }
                }
            }
        }
    
    that would be the explode event for that specific creeper
    and the 2 egg spawn is working on my server :O

    EDIT: forgot the null execption
     
  9. Offline

    ZomBlade_Shadow

    Thanks!
    But when you do /supercreeper and then middle click it to do a stack in creative and spawn it,the effects work?
    doesn't work for me lol
     
  10. Offline

    sn1cko

    just set the itemstack to 64 ?
    Code:
    ItemStack creep = new ItemStack(Material.MONSTER_EGG,64,(short)50);
    
    cause that does work for me
     
  11. Offline

    Konato_K

    @ZomBlade_Shadow Try using ItemStack#isSimilar instead of ItemStack#equals

    For the explosion thing, attach metadata to the creeper, then when it explodes check if it has the metadata and react properly to it.
     
Thread Status:
Not open for further replies.

Share This Page