Plugin saying I'm not looking at sign but I am

Discussion in 'Plugin Development' started by dingus007, Sep 9, 2013.

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

    dingus007

    So I made a newer version of my personal plugin where you can change the line of a sign. I added color support and spacing, but now it doesn't find the sign I'm looking at. I can't figure out why it's not finding it and that's why I'm here. If you can help, please.

    Code:java
    1. package com.conectedpvp.signchanger;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.block.BlockState;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.block.Sign;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class SignChanger extends JavaPlugin {
    14. public void sendMessage(String text,CommandSender player) {
    15. player.sendMessage(ChatColor.GREEN + "[SignChanger] " + ChatColor.GOLD + text);
    16. }
    17.  
    18. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    19. if (cmd.getName().equalsIgnoreCase("changeline") && args.length >= 2) {
    20. if (sender instanceof Player) {
    21. Player player = (Player) sender;
    22. if (player.hasPermission("SignChanger.changeline")) {
    23. @SuppressWarnings("deprecation")
    24. Block block = player.getTargetBlock(null, 200);
    25. if (block.equals(Material.WALL_SIGN) || block.equals(Material.SIGN_POST)) {
    26. StringBuilder buffer = new StringBuilder();
    27. for (int i = 1; i < args.length; i++) {
    28. buffer.append(' ').append(args[i]);
    29. }
    30. String newb = buffer.toString().replaceAll("(&([a-f0-9]))", "\u00A7$2");
    31. if (newb.length() <= 15) {
    32. int num = Integer.parseInt(args[0])+1;
    33. if (num <= 5 || num > 0){
    34. BlockState state = block.getState();
    35. Sign sign = (Sign)state;
    36. sign.setLine(num, newb);
    37. sign.update(true);
    38. } else sendMessage("There are only 4 lines on one sign!",sender);
    39. } else sendMessage("There are only 15 character spots one line!",sender);
    40. } else sendMessage("Please look at a sign to run this command!",sender);
    41. } else return false;
    42. } else sendMessage("You must be a player to run this command!",sender);
    43. }
    44.  
    45. return true;
    46. }
    47. }
    48. [/i]
     
  2. Offline

    Musaddict

    Code:java
    1. if (block.equals(Material.WALL_SIGN) || block.equals(Material.SIGN_POST)) {


    this needs to be:

    Code:java
    1. if (block.getType(Material.WALL_SIGN) || block.getType(Material.SIGN_POST)) {
     
  3. Offline

    dingus007

    That doesn't have any arguments, but I did this, would it work?

    Code:java
    1. block.getType().equals(Material.WALL_SIGN)
     
  4. Offline

    Musaddict

    That's right, sorry, I'm used to block.getType() == Material.WALL_SIGN, so I forgot you need to input the equals() if you omit the"=".
     
Thread Status:
Not open for further replies.

Share This Page