Set Spawner's NBT Data Based on Data from a Mob

Discussion in 'Plugin Development' started by Axe2760, Sep 4, 2013.

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

    Axe2760

    I made several stabs at this earlier... I can't seem to figure it out.
    PHP:
    public class NBTEvents implements Listener{
    @
    EventHandler
    public void clickEntity(PlayerInteractEntityEvent event){
    Player player event.getPlayer();
     
    if (
    PlayerSession.getEnabled(player) == true){
    PlayerSession.setClickState(player, (byte)1);
    CraftEntity ce = (CraftEntity)event.getRightClicked();
    if (
    ce instanceof CraftLivingEntity){
    CraftLivingEntity ent = (CraftLivingEntity)ce;
    NBTTagCompound com = new NBTTagCompound();
    ent.getHandle().a(com);
     
    PlayerSession.setPlayerStored(playercom);
    player.sendMessage(ChatColor.BLUE "You have clicked on an entity. Now right-click a spawner!");
    }
    }
    }
    @
    EventHandler
    public void clickSpawner(PlayerInteractEvent event){
    Player player event.getPlayer();
    if (
    PlayerSession.getClickState(player) == 1){
    if (
    PlayerSession.getPlayerStored(player) != null){
    if (
    event.getClickedBlock() != null){
    if (
    event.getClickedBlock().getType().equals(Material.getMaterial(52))){
    Location loc event.getClickedBlock().getLocation();
    CraftWorld cw = ((CraftWorld)event.getClickedBlock().getWorld());
    TileEntity te cw.getHandle().getTileEntity(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ());
    NBTTagCompound tag = new NBTTagCompound();
    te.b(tag);
     
    tag.setCompound("SpawnData"PlayerSession.getPlayerStored(player));
     
    te.a(tag);
     
    player.sendMessage(ChatColor.YELLOW "Applied the stored nbt tag to the spawner!");
    PlayerSession.setEnabled(playerfalse);
    PlayerSession.setClickState(player, (byte)0);
    }
    }
    }
    }
    }
    }
    I believe this is what you should need.
    Basically, my problem is that everything fires, but then the spawner still spawns what it was before (in this case, pigs). When I restart the server, an error is thrown and the spawner removed from the map. (So I assume that the NBT data was corrupted).
    Any ideas? I can't seem to get it to work.
     
  2. Offline

    chasechocolate

  3. Offline

    Axe2760

    chasechocolate will test that out, thanks :) Not sure if the NBT will work though.
     
Thread Status:
Not open for further replies.

Share This Page