Solved [Unsolved]Please help! onPlayerInteract and onSignChange

Discussion in 'Plugin Development' started by ClydetorkleGaming, Oct 31, 2013.

Thread Status:
Not open for further replies.
  1. Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16. public class MainListener implements Listener {
    17.  
    18. public static MainListener plugin;
    19. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    20.  
    21. @EventHandler
    22. public void onSignChange(SignChangeEvent event) {
    23. if(event.getLine(0).equalsIgnoreCase("[Warp]") && event.getLine(1).getString "warps")) {
    24. event.setLine(2, "Click to warp");
    25.  
    26. }
    27. }
    28.  
    29. @EventHandler
    30. public void onBlockBreak(BlockBreakEvent event) {
    31. Player player = event.getPlayer();
    32. if(signs.conatainsKey(event.getBlock().getLocation()) && !signs.containsValue(event.getPlayer().getName())) {
    33.  
    34. }
    35.  
    36.  
    37. @EventHandler
    38. public void onPlayerInteract(PlayerInteractEvent event) {
    39. if (!(event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    40. if (event.getClickedBlock().getState() instanceof Sign) {
    41. Sign s = (Sign) event.getClickedBlock().getState();
    42. if (s.getLine(0).equalsIgnoreCase("[Warp]")) {
    43. event.getPlayer().
    44. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    45. }
    46. }
    47. }
    48. }
    49.  

    I need help with onSignChange and onPlayerInteract I'm working on part of my plugin where a player will enter [Warp] on line 0 of the sign and the warp name on line 1 and it will create a warp sign. On right click it will warp them to the warp they listed on the first line. I also need help with how I would get the warp name string.
     
  2. Offline

    TheUpdater

    this means if you dont right click
    PHP:
    !(event.getAction() == Action.RIGHT_CLICK_BLOCK
    IGHT_CLICK_BLOCK
     
    JPG2000 likes this.
  3. Offline

    PatrickH123

    Change line 39 to:

    Code:java
    1. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){


    And add another } at the end of your code.
     
  4. Thanks for the help, but what about line line 23 where it is getting the string for the warp name.
     
  5. Offline

    Hugs

    Make a list of warps that are valid & try if (warpList.contains(e.getLine(1)){
     
  6. Offline

    The_Coder

    Code:
    if(event.getLine(0).equalsIgnoreCase("[Warps]") && event.getLine(1) != null) {
    // Do stuff here like saving to the config file the location
     
    }else {
    player.sendMessage("You need to name this warp");
    }
     
  7. Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16. public class MainListener implements Listener {
    17.  
    18. public static MainListener plugin;
    19. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    20.  
    21. @EventHandler
    22. public void onSignChange(SignChangeEvent event) {
    23. Player player = event.getPlayer();
    24. if(event.getLine(0).equalsIgnoreCase("[Warps]") && event.getLine(1) != null) {
    25. //saveConfig();
    26. }else {
    27. player.sendMessage("You need to name this warp");
    28.  
    29. }
    30. }
    31.  
    32. @EventHandler
    33. public void onBlockBreak(BlockBreakEvent event) {
    34. Player player = event.getPlayer();
    35. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    36.  
    37. }
    38. }
    39.  
    40. @EventHandler
    41. public void onPlayerInteract(PlayerInteractEvent event) {
    42. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    43. if (event.getClickedBlock().getState() instanceof Sign) {
    44. Sign s = (Sign) event.getClickedBlock().getState();
    45. if (s.getLine(0).equalsIgnoreCase("[Warp]")) {
    46. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    47. }
    48. }
    49. }
    50. }
    51. }
    52.  


    I fixed line 42 and the string part, but know Im stuck on onPlayerInteract, if you see anything that needs to be changed please comment.

    When I upload this to my server it doesn't do anything what could cause this. If you are new to the discussion refer to the first post.

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

    HyrulesLegend

  9. Did I mess some of the code up because it doesn't do what it is supposed to do. Refer to he first post to see what Im wanting it to do. For some reason the onSignChange and onPlayerInteract isn,t working.

    This is my current code did I mess anything up because when I upload it to my server and place a sign with [Warp] on the first line and "warp name" on the second line it doesn't do anything. Please comment if you see an error that would be great.
    Code:java
    1. package me.clydetorklegaming.warpandspawn;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.BlockBreakEvent;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15.  
    16. public class MainListener implements Listener {
    17.  
    18. public static MainListener plugin;
    19. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    20.  
    21. @EventHandler
    22. public void onSignChange(SignChangeEvent event) {
    23. Player player = event.getPlayer();
    24. if(event.getLine(0).equalsIgnoreCase("[Warp]") && event.getLine(1) != null) {
    25. //saveConfig();
    26. }else {
    27. player.sendMessage("You need to name this warp");
    28.  
    29. }
    30. }
    31.  
    32. @EventHandler
    33. public void onBlockBreak(BlockBreakEvent event) {
    34. Player player = event.getPlayer();
    35. if(signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    36.  
    37. }
    38. }
    39.  
    40. @EventHandler
    41. public void onPlayerInteract(PlayerInteractEvent event) {
    42. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    43. if (event.getClickedBlock().getState() instanceof Sign) {
    44. Sign s = (Sign) event.getClickedBlock().getState();
    45. if (s.getLine(0).equalsIgnoreCase("[Warp]")) {
    46. event.getPlayer().sendMessage(ChatColor.GREEN + "Sucessfuly warped!");
    47. }
    48. }
    49. }
    50. }
    51. }


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

Share This Page