Need help with my code.

Discussion in 'Plugin Development' started by Rockindavies21, May 9, 2014.

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

    Rockindavies21

    Hi, i am creating an anvil repair system using serversigns. How it works is I set the command tcrepair to the anvil and when players right click the anvil with a damaged item it repairs the item with the particle effect. The code below works just fine. But, i want the particles to be on the anvil that the players are clicking. Currently the particles are showing around the player. Any help would be appreciated! :)





    Code:
    if(commandLabel.equalsIgnoreCase("tcrepair")){
          if(player.hasPermission("tc.repair")) {
          player.getItemInHand().setDurability((short) 0);
          player.sendMessage(ChatColor.GREEN + "Your item has been repaired!");
          Location loc = player.getLocation();
     
          try {
          ParticleEffects.spawnParticles(loc, player, "iconcrack_311", 1);
          } catch (IllegalArgumentException e) {
          e.printStackTrace();
          } catch (ClassNotFoundException e) {
          e.printStackTrace();
          } catch (IllegalAccessException e) {
          e.printStackTrace();
          } catch (InstantiationException e) {
          e.printStackTrace();
          } catch (NoSuchMethodException e) {
          e.printStackTrace();
          } catch (NoSuchFieldException e) {
          e.printStackTrace();
          } catch (InvocationTargetException e) {
          e.printStackTrace();
    }
     
     
    }
    }
     
    return false;
     
     
     
    }
     
  2. Offline

    ChunkMe

    Well, can you send me the event you use to click the anvil?
    Or are you not working so? Edit the code to the full class(es)
     
  3. Offline

    Rockindavies21

  4. Offline

    ChunkMe

    Try to use your own code.
    Because otherwise you don't going to make it
    Give me a second, ill update this message. Iam going to code it for ya ;D

    And i make it.
    I want to say that this is UNTESTED.
    So if you have any errors, send them to me.
    This is the event
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. //A simple event to get the clicked sign!
    4. public void interact1(PlayerInteractEvent e){
    5. if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    6. if(e.getClickedBlock().getState() instanceof Sign){
    7. Sign s = (Sign) e.getClickedBlock().getState();
    8. //Check the sign args
    9. if(s.getLine(0).equalsIgnoreCase("[Repairme!}")){
    10. if(s.getLine(1).equalsIgnoreCase("Repair")){
    11. if(s.getLine(2).equalsIgnoreCase("Repair")){
    12. //Get the blocks location
    13. Block clicked = e.getClickedBlock();
    14. Location block = clicked.getLocation();
    15. //Get the players location
    16. Player p = e.getPlayer();
    17. //Set the durability
    18. p.getItemInHand().setDurability((short)0);
    19. //Play the effect
    20. p.playEffect(block, Effect.EXPLOSION, 1);
    21. }
    22.  
    23. }
    24. }
    25. }
    26. }


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

    Rockindavies21

    ChunkMe I see how the block location works now. Thanks man! :) I was just about to write the event myself :p.

    ChunkMe Your code is for signs so i wrote one using anvils. But, it's not working can you point out what's wrong?

    EDIT: I got it working i forgot pluginmanager :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page