Can't set Flower Pot contents

Discussion in 'Plugin Development' started by xMakerx, Oct 27, 2013.

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

    xMakerx

    I am trying to make it that if you right-click a flower pot with seeds or a water bottle potion it'll set the contents to something. I want it that if you right-click the Flower Pot with seeds it'll set the contents to a dead bush and if you right-click it with a Water Bottle it'll set the contents to a Fern if the contents are already a dead bush. The seeds side works, it'll take my seeds in my hand but nothing shows up in the pot. There is no errors. Thanks in advance!

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler(priority=EventPriority.HIGH)
    3. public void onPlayerInteract(PlayerInteractEvent e) {
    4. Player p = e.getPlayer();
    5.  
    6. if(e.getClickedBlock() != null) {
    7.  
    8. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    9. if(e.getClickedBlock().getType().equals(Material.FLOWER_POT)) {
    10. Potion waterPotion = new Potion(PotionType.WATER);
    11. if(p.getItemInHand().equals(waterPotion)) {
    12. if(e.getClickedBlock().getState().getData() instanceof FlowerPot) {
    13. FlowerPot wpot = (FlowerPot)e.getClickedBlock().getState().getData();
    14. if(wpot.getData() == (byte)10) {
    15. wpot.setData((byte) 11);
    16. p.getInventory().remove(p.getItemInHand());
    17. }
    18. }
    19. }else if(p.getItemInHand().getType().equals(Material.SEEDS)) {
    20. if(e.getClickedBlock().getState().getData() instanceof FlowerPot) {
    21. FlowerPot wpot = (FlowerPot)e.getClickedBlock().getState().getData();
    22. if(wpot.getContents() == null) {
    23. wpot.setData((byte) 10);
    24. p.getInventory().remove(p.getItemInHand());
    25. }
    26. }
    27. }
    28. }
    29. }
    30. }
    31. }
     
  2. Offline

    Conarnar

    I think I had this problem once. Try canceling the event.
     
  3. Offline

    xMakerx

    Conarnar
    Thanks, I'll attempt to try to cancel the event. I was thinking that it wasn't updating correctly, I'll try it when I get home from work.
     
  4. Offline

    Garris0n

  5. Offline

    xMakerx


    I've tried SetContents() it doesn't work at all. I switched to setData() because a previous issue with flower pots was fixed using this method.
     
Thread Status:
Not open for further replies.

Share This Page