Waiting between ItemFrame Rotations

Discussion in 'Plugin Development' started by BadReuben, Nov 19, 2012.

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

    BadReuben

    I am making a plugin that will cause item frames to rotate over a period of time; I am having issues trying to get them to wait or pause in-between rotations.

    Code:
    package me.blakkdock.meatspin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Meatspin extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Meatspin plugin;
        public static MeatSpinListener MeatspinListener = new MeatSpinListener();
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Disabled!!");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "V." + pdfFile.getVersion() + " Enabled!!");
            getServer().getPluginManager().registerEvents(MeatspinListener, this);
        }
    }
    

    Code:
    public class MeatSpinListener implements Listener {
        ItemFrame itemframe;
       
        @EventHandler
        public void PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent e) throws InterruptedException {
           
          if(e.getRightClicked().getType() == EntityType.ITEM_FRAME){
              itemframe = (ItemFrame) e.getRightClicked();
        //      e.getPlayer().sendMessage("1");
        //      if (itemframe.getItem().equals(Material.GRILLED_PORK) || itemframe.getItem().equals(Material.COOKED_BEEF) ||
        //              itemframe.getItem().equals(Material.COOKED_CHICKEN)){
        //                      e.getPlayer().sendMessage("2");
              for(int x=0; x<100000; x++){
                          itemframe.setRotation(Rotation.NONE);
                    //        itemframe.wait(10000);     
                          itemframe.setRotation(Rotation.CLOCKWISE);
                          itemframe.setRotation(Rotation.FLIPPED);
                          itemframe.setRotation(Rotation.COUNTER_CLOCKWISE);
                  }
          }
           return;
        }
    }
        
     
  2. Offline

    fireblast709

  3. Offline

    BadReuben

    I can't seem to get this working, without getting errors when a user right clicks an Itemframe.

    Code:
    package me.blakkdock.meatspin;
     
     
    import org.bukkit.Rotation;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.ItemFrame;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
     
    public class MeatSpinListener implements Listener {
        ItemFrame itemframe;
     
        @EventHandler
        public void PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent e) {
          if(e.getRightClicked().getType() == EntityType.ITEM_FRAME){
              itemframe = (ItemFrame) e.getRightClicked();
                          Meatspin.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Meatspin.plugin, new Runnable()
                          {
                              public void run(){
                                  itemframe.setRotation(Rotation.NONE);
                              }
                                }, 30L, 240L);
                          Meatspin.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Meatspin.plugin, new Runnable()
                          {
                              public void run(){
                                  itemframe.setRotation(Rotation.CLOCKWISE);
                              }
                                }, 60L, 240L);
                          Meatspin.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Meatspin.plugin, new Runnable()
                          {
                              public void run(){
                                  itemframe.setRotation(Rotation.FLIPPED);
                              }
                                }, 90L, 240L);
                          Meatspin.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Meatspin.plugin, new Runnable()
                          {
                              public void run(){
                                  itemframe.setRotation(Rotation.COUNTER_CLOCKWISE);
                              }
                                }, 120L, 240L);
                          }
        return;
        }
    }
        
     
  4. "Meatspin plugin;"
    LOL
     
  5. Offline

    ZeusAllMighty11

    I'm back from puking my guts out after the name reminded me of bad times with friends...xD

    I'd also check if action was right click, otherwise you can't break frames
     
  6. Offline

    fireblast709

    ZeusAllMighty11 PlayerInteractEntity is always rightclick
    BlakkDock you might want to try something like this
    Code:java
    1. package me.blakkdock.meatspin;
    2.  
    3.  
    4. import org.bukkit.Rotation;
    5. import org.bukkit.entity.EntityType;
    6. import org.bukkit.entity.ItemFrame;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9.  
    10. public class MeatSpinListener implements Listener
    11. {
    12. @EventHandler
    13. public void PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent e)
    14. {
    15. if(e.getRightClicked().getType() == EntityType.ITEM_FRAME)
    16. {
    17. final ItemFrame itemframe = (ItemFrame) e.getRightClicked();
    18.  
    19. Meatspin.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Meatspin.plugin, new Runnable()
    20. {
    21. public void run()
    22. {
    23. Rotation r = itemframe.getRotation();
    24. if(r == Rotation.NONE)
    25. {
    26. itemframe.setRotation(Rotation.CLOCKWISE);
    27. }
    28. else if(r == Rotation.CLOCKWISE)
    29. {
    30. itemframe.setRotation(Rotation.FLIPPED);
    31. }
    32. else if(r == Rotation.FLIPPED)
    33. {
    34. itemframe.setRotation(Rotation.COUNTER_CLOCKWISE);
    35. }
    36. else
    37. {
    38. itemframe.setRotation(Rotation.NONE);
    39. }
    40. }
    41. }, 30L, 30L);
    42. }
    43. return;
    44. }
    45. }
     
Thread Status:
Not open for further replies.

Share This Page