Solved Signs is not working properly?

Discussion in 'Plugin Development' started by Senexor, Mar 18, 2014.

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

    Senexor

    For some reason I have no errors however when I try to make the sign in game it won't even work or even show the correct colour codes or even getInventory etc...

    Code:java
    1.  
    2. package me.Senexor.VortexPvP;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.GameMode;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.block.SignChangeEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.ItemStack;
    14.  
    15. public class KitPvPSign implements Listener {
    16.  
    17. @EventHandler
    18. public void onSignChange(SignChangeEvent e) {
    19. if (e.getLine(0).equalsIgnoreCase("[Vortex]")) {
    20. e.setLine(0, "§8[§bVortex§aMC§8]");
    21. e.setLine(1, "§bKit PvP");
    22. }
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerInteract(PlayerInteractEvent e) {
    27. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    28. if (e.getClickedBlock().getState() instanceof Sign) {
    29. Sign s = (Sign) e.getClickedBlock().getState();
    30. if (s.getLine(0).equalsIgnoreCase("[Vortex]")) {
    31. e.getPlayer().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + "Vortex" + ChatColor.DARK_GRAY + "] " + ChatColor.RED + "You have recived your kit!");
    32. e.getPlayer().getInventory().clear();
    33. e.getPlayer().setGameMode(GameMode.SURVIVAL);
    34. e.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    35. e.getPlayer().getInventory().addItem(new ItemStack(Material.FISHING_ROD));
    36. e.getPlayer().getInventory().addItem(new ItemStack(Material.BOW));
    37. ItemStack arrow = new ItemStack(Material.ARROW, 16);
    38. e.getPlayer().getInventory().setItem(8, arrow);
    39. e.getPlayer().getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    40. e.getPlayer().getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    41. e.getPlayer().getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    42. e.getPlayer().getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    43.  
    44. }
    45. }
    46.  
    47. }
    48. }
    49.  


    Problem is that when I go in game to and make a sign with the first line being [Vortex] it doesn't work.
     
  2. Offline

    StealerSlain

    1. Color codes will not shows properly until you install specific plugin for that. Or create your own method.
    2. Use sign.update(); ...maybe.
    3. Line 30... You compares 2 strings "§8[§bVortex§aMC§8]" and "[Vortex]". How could these will be same?
     
  3. Offline

    Senexor

    StealerSlain I was watching PogoStick29Dev's tutorial while doing this... Do I have to register events?
     
  4. Offline

    Barnyard_Owl

    StealerSlain
    1. Color codes WILL show up properly, so long as you use the section sign (§) and not the ampersand.
    2. Yes, a sign.update(); would be required in most cases, but not in this case since this is within the actual sign changing event.
    3. If the user creates a new sign with [Vortex] on the first line, then the following code will execute, giving the sign colors and such. Makes sense to me.

    As for the OP...
    Senexor
    Yes, you need to register your events in onEnable.
    Code:java
    1. getServer( ).getPluginManager( ).registerEvents( new KitPvPSign( ), this );


    Another error within your code is that you are comparing the sign's text against something without colors.
    Code:java
    1. s.getLine(0).equalsIgnoreCase("[Vortex]")

    It needs to compare it against the actual text that will be there AFTER the event is triggered and the sign is created.
    Code:java
    1. s.getLine(0).equalsIgnoreCase("§8[§bVortex§aMC§8]")


    Everything else you posted in your KitPvPSign class looks fine to me. :)
     
  5. Offline

    Senexor

    Barnyard_Owl
    Still does'nt work :(

    Main class:
    Code:java
    1.  
    2. package me.Senexor.VortexPvP;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.GameMode;
    7. import org.bukkit.Material;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. public void onEnable() {
    18. getLogger().info("Plugin is enabled");
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. getServer( ).getPluginManager( ).registerEvents( new KitPvPSign( ), this );
    21.  
    22. }
    23.  
    24.  
    25. }
    26.  
    27.  



    AND
    MY KitPvPSign
    Code:java
    1.  
    2. package me.Senexor.VortexPvP;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.GameMode;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Sign;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.block.SignChangeEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class KitPvPSign extends JavaPlugin implements Listener {
    17.  
    18.  
    19.  
    20. @EventHandler
    21. public void onSignChange(SignChangeEvent e) {
    22. if (e.getLine(0).equalsIgnoreCase("§8[§bVortex§aMC§8]")) {
    23. e.setLine(0, "§8[§bVortex§aMC§8]");
    24. e.setLine(1, "§bKit PvP");
    25. }
    26. }
    27.  
    28. @EventHandler
    29. public void onPlayerInteract(PlayerInteractEvent e) {
    30. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    31. if (e.getClickedBlock().getState() instanceof Sign) {
    32. Sign s = (Sign) e.getClickedBlock().getState();
    33. if (s.getLine(0).equalsIgnoreCase("§8[§bVortex§aMC§8]")) {
    34. e.getPlayer().sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "Vortex" + ChatColor.YELLOW + "MC" + ChatColor.DARK_GRAY + "] " + ChatColor.RED + "You have recived your kit!");
    35. e.getPlayer().getInventory().clear();
    36. e.getPlayer().setGameMode(GameMode.SURVIVAL);
    37. e.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    38. e.getPlayer().getInventory().addItem(new ItemStack(Material.FISHING_ROD));
    39. e.getPlayer().getInventory().addItem(new ItemStack(Material.BOW));
    40. ItemStack arrow = new ItemStack(Material.ARROW, 16);
    41. e.getPlayer().getInventory().setItem(8, arrow);
    42. e.getPlayer().getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
    43. e.getPlayer().getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    44. e.getPlayer().getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    45. e.getPlayer().getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    46.  
    47. }
    48. }
    49.  
    50. }
    51. }
    52.  
     
  6. Offline

    Barnyard_Owl

    Senexor
    Sorry for the late response. :/

    I should have clarified about the 'if' statement. The if statement in onSignChange was correct, (and is now incorrect) and it should be
    Code:java
    1. e.getLine(0).equalsIgnoreCase("[Vortex]")

    The incorrect part was in playerinteract, which you have now fixed.

    Also, it is unnecessary to have the main class either implement listener or register events to itself, since you don't have any events in that class. (Main.class)
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
Thread Status:
Not open for further replies.

Share This Page