.

Discussion in 'Plugin Development' started by elementalgodz11, Nov 19, 2013.

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

    elementalgodz11

  2. Offline

    jusjus112

    elementalgodz11
    You need an SignChangeEvent

    Because, if you will do some command/events with a sign,
    you must do a sign change event, other you can do a interactevent
    then you must put the sign in Material.SIGN and not in "sign"

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract (PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getClickedBlock == Material.SIGN) {
    5. If (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block block = e.getClickedBlock();
    7. String Line 3 = sign.getLine(2);
    8. String Line2 = sign.getLine(1);
    9. if (Line3.equals("Clear")
    10. p.getInventory.clear();
    11. p.getInventory.setArnourContents (null);
    12. }
    13.  


    elementalgodz11
    This should work

    Other you can do a signChangeEvent, you started with a new event and do some stuff with your event

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

    FatAussieFatBoy

    Here is what your Code should look like

    Code:text
    1. @EventHandler
    2. public void onPlayerInteract (PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getClickedBlock == Material.SIGN) {
    5. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block block = e.getClickedBlock();
    7. BlockState st = block.getState();
    8. if (st instanceof Sign) {
    9. String Line 3 = sign.getLine(2);
    10. if (Line3.equals("Clear") {
    11. p.getInventory.setContents(null);
    12. p.getInventory.setArmorContents(null);
    13. }
    14. }
    15. }
    16. }


    I did not rewrite this in Eclipse so the Spacing might be off.
     
  4. Offline

    jusjus112

  5. Offline

    FatAussieFatBoy

    jusjus112
    I posted him a Working code, so I think I do know what I'm doing... Maybe you should consider thinking before you type.

    EDIT: Sorry I meant to put "if(e.getClickedBlock == Material.SIGN)" in the code.
     
  6. Offline

    jusjus112

    FatAussieFatBoy
    If you set that in your code, i dont say nothing. but i say it
    because your code dont work. now its work.

    elementalgodz11
    1. p.getInventory.setContents(null);
    2. p.getInventory.setArmorContents(null);
    put that in your code and it should work
    and remove p.getInventory.clear

    FatAussieFatBoy
    it should work, but your now setting 1 item in air.
    if i get the point, he will remove all items

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

    FatAussieFatBoy

    jusjus112
    Never Mind, I will delete the Post, I wasn't thinking.
    It's like 11:00pm here so I'm kind of starting to drift to sleep.
    To many late nights I think :p
     
  8. Offline

    jusjus112

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract (PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getClickedBlock == Material.SIGN // Sign or Wall.Sign) {
    5. If (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block block = e.getClickedBlock();
    7. // Block State
    8. String Line 3 = sign.getLine(2);
    9. String Line2 = sign.getLine(1);
    10. if (Line3.equals("Clear")
    11. p.getInventory.clear();
    12. p.getInventory.setArnourContents (null);
    13. }

    elementalgodz11
     
  9. Offline

    FatAussieFatBoy

    elementalgodz11
    Here is a Working code :

    Code:java
    1. @EventHandler
    2. public void onSignClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Block b = e.getClickedBlock();
    5. if(b.getType() == Material.SIGN) {
    6. Sign s = (Sign) b;
    7. s.update();
    8. if(s.getLine(3).equals("Clear")) {
    9. p.getInventory().setContents(null);
    10. p.getInventory().setArmorContents(null);
    11. p.setItemInHand(null);
    12. }
    13. }
    14. }


    Note: Not tested but it should work...
     
  10. Offline

    jusjus112

  11. Offline

    FatAussieFatBoy

    elementalgodz11
    did you set the word "Clear" on the 3rd line of the Sign, In The Minecraft Game? If so then change the code where is says :

    if(s.getLine(3).equals("Clear")) {

    To :

    if(s.getLine(2).equals("Clear")) {

    If you did put the word "Clear" on the 4th Line of the Minecraft Sign then just msg me back and I will do a quick debug of my Code...

    elementalgodz11
    I did a quick De-Bug and this is what my New Code is :

    Code:java
    1. @EventHandler
    2. public void onSignClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Block b = e.getClickedBlock();
    5. if(b.equals(Material.SIGN)) {
    6. Sign s = (Sign) b;
    7. s.update();
    8. if(s.getLine(3).equals("Clear")) {
    9. p.getInventory().setContents(null);
    10. p.getInventory().setArmorContents(null);
    11. p.setItemInHand(null);
    12. }
    13. }
    14. }


    Note: Not Tested!

    elementalgodz11
    Give this a Try :

    Code:java
    1. @EventHandler
    2. public void onSignClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Block b = e.getClickedBlock();
    5. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. if(b.getType().equals(Material.SIGN)) {
    7. Sign s = (Sign) b;
    8. s.update();
    9. if(s.getLine(3).equals("Clear")) {
    10. p.getInventory().setContents(null);
    11. p.getInventory().setArmorContents(null);
    12. p.setItemInHand(null);
    13. }
    14. }
    15. }
    16. }


    Note: Not Tested!

    The Reason I believe the last 2 Codes haven't worked is simply because we haven't been checking what Action the Player has been using, so in theory this should work, and If not try changing the :

    if(b.getType().equals(Material.SIGN)) {

    to

    if(b.getType() == Material.SIGN) {

    EDIT: Change
    if(b.getType().equals(Material.SIGN)) {
    to
    if(b.getType().equals(Material.SIGN) || b.getType().equals(Material.WALL_SIGN) || b.getType().equals(Material.SIGN_POST)) {

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

    L33m4n123

    what about

    Code:text
    1. if (b.getType() == Material.SIGN)


    Since you check if a block == Material and that is not working. So you need to get the blocktype first (which is a Material) thus you can compare it if it is Material.SIGN
     
  13. Offline

    FatAussieFatBoy

  14. Offline

    desht

    Could everyone please stop suggesting the use of Material.SIGN here? Material.SIGN is the sign item (not a block), and will never be the result of event.getClickedBlock().

    Additionally, setContents(null) is not the way to clear an inventory's contents. There's a method for this: .clear().

    Try this code (untested):
    PHP:
    Block b event.getClickedBlock();
    if (
    != null && (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST)) {
      
    Sign sign = (Signb.getState();
      if (
    sign.getLine(3).equals("Clear")) {  // or whichever line you need
        
    event.getPlayer().getInventory().clear();
        
    // I can't remember offhand if the above will clear equipment too; if not, use this:
        
    event.getPlayer().getEquipment().clear();
      }
    }
    PHP:
    player.setItemInHand(null);
    // next method is deprecated but use it; it's
    // the only way currently to ensure the client
    // sees the change right away
    player.updateInventory();
    By the way, a quick google for "bukkit clear item in hand" found that solution pretty quickly.

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

Share This Page