[Not Solved] Spawning ItemFrame (IllegalArgumentException)

Discussion in 'Plugin Development' started by Door Knob, Aug 16, 2013.

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

    Door Knob

    Hi there! I'm trying to spawn an ItemFrame. I have this system where it logs every broken ItemFrame, then places them all back upon use of a command. Logging it is not the problem, but the location is. I know IllegalArgumentException with ItemFrames means that it's not a valid location for the block. Since it's a hanging block, it needs to be spawned IN a block, technically. The problem is, I can't seem to be able to get that block. This is the code where it logs the block break events.
    Code:java
    1. @EventHandler
    2. public void onPlayerDestroyFrame(HangingBreakByEntityEvent e){
    3. Hanging block = e.getEntity();
    4. System.out.println("broke a hanging thingy (" + block.getType().getName() + ")");
    5. if(block instanceof ItemFrame){
    6. System.out.println("actually, broke an item frame.");
    7. Hanging item = e.getEntity();
    8. if(matchStarted){
    9. System.out.println("Match is already started when breaking the frame");
    10. brokenIF.add(item);
    11. System.out.println("LOGGED ITEM FRAME");
    12. locIF.add(item.getLocation());
    13. System.out.println("LOGGED LOCATION");
    14. }
    15. }
    16. }

    All of the debug text comes up. So this piece of code runs fine. But here is where I get the error:
    Code:java
    1. //yes, I created the variables at the top of my code and initiated the variables in my onEnable.
    2. for(Hanging IF: brokenIF){
    3. for(Location l: locIF){
    4. System.out.println(l);
    5. Bukkit.getWorld("server-world").spawnEntity(l, IF.getType());
    6. }
    7. }
    8. //this code is run when the command is executed.
    9.  


    The stacktrace's error is on 860. which is the line where I spawn an itemframe entity.

    So, does anyone know what's wrong?

    -bump-

    Can anyone help?

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

    xTrollxDudex

    Door Knob
    I think you should use an ItemFrame.class and spawn it with the spawn() method instead of spawnEntity(). You can use setRotation on the ItemFrame and set the item too. Also, don't bump within 24 hours
     
  3. Offline

    Door Knob

    No, I've tried that. It still doesn't work. Gives the exact same error.

    EDIT: Also, if I spawn an ItemFrame.class, how will I be able to set what's inside? I kinda need it to be the same as what it used to be.
    I can figure that part out, but it still gives me the same error.

    This is the error

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    xTrollxDudex

    Door Knob
    I think you many need to spawn the ItemFrame in the block's location not next to it.
     
  5. Offline

    Door Knob

    That's exactly what I'm asking. How do I get the ItemFrame's block location? It needs to be HUNG on the block.

    Can anyone help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  6. Offline

    xTrollxDudex

    Door Knob
    I think there should be a method to get the block behind it
     
  7. Offline

    Door Knob

    xTrollxDudex
    Is there? I've been checking everywhere...

    EDIT: There's getAttachedFace? I think that'd be the blockface though..
     
  8. Offline

    xTrollxDudex

    Door Knob
    From that you can clone the location of the ItemFrame and edit it with add() and subtract() methods to get the block it I s attached to and get the blocks location.
     
  9. Offline

    Door Knob

    I see that's the only way, thanks for your help
     
Thread Status:
Not open for further replies.

Share This Page