Weird Problem, PlayerInteract and SignChangeEvents

Discussion in 'Plugin Development' started by amazed2025, Oct 28, 2013.

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

    amazed2025

    Hey,
    So I'm trying to have it so when a player was to right-click a sign, it'd give them certain items. Also to have it so when someone were to make a sign with certain text, it'd send them a message.
    Code:java
    1. package net.theaura.AuraKits;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.block.Sign;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.block.Action;
    12. import org.bukkit.event.block.SignChangeEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.plugin.PluginDescriptionFile;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class AuraKits extends JavaPlugin {
    19.  
    20. public final Logger logger = Logger.getLogger("Minecraft");
    21. public static AuraKits plugin;
    22.  
    23. public void onEnable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[" + ChatColor.RED + pdfFile.getName() + ChatColor.GREEN + "]" + ChatColor.GOLD + " Has been enabled!");
    26. }
    27.  
    28. public void onDisable() {
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[" + ChatColor.RED + pdfFile.getName() + ChatColor.GREEN + "]" + ChatColor.DARK_RED + " Has been disabled!");
    31. }
    32. @EventHandler
    33. public void GAME1(SignChangeEvent sign){
    34. Player p = sign.getPlayer();
    35. if(sign.getLine(0).equalsIgnoreCase("[aurakits]")){
    36. if(sign.getLine(1).equalsIgnoreCase("tank")){
    37. p.sendMessage("Tank class has successfully been added");
    38. }
    39.  
    40. }
    41. }
    42. @EventHandler
    43. public void clicksign(PlayerInteractEvent e) {
    44. Player p = e.getPlayer();
    45. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    46. Block b = e.getClickedBlock();
    47. if (b.getType() == Material.SIGN_POST|| b.getType() == Material.WALL_SIGN) {
    48. Sign sign = (Sign) b.getState();
    49. if (sign.getLine(0).equalsIgnoreCase("[aurakits]")) {
    50. if (sign.getLine(1).equalsIgnoreCase("tank")) {
    51. p.getInventory().addItem(new ItemStack(Material.APPLE, 1));
    52. p.getInventory().addItem(new ItemStack(Material.RAW_CHICKEN, 1));
    53. p.sendMessage(ChatColor.GREEN + "You have been given the tank kit!");
    54. }
    55. }
    56. }
    57. }
    58. }
    59. }
    60.  
     
  2. You don't register your events, and you didn't implement listener.
    in onEnable() add this:
    Code:
    GetServer().getPluginManager().registerEvents(this, this);
    then, hover over the errors in this thingie and click "let (yourclass) implement Listener"
     
    amazed2025 likes this.
  3. Offline

    amazed2025

    Ohhh, Thank you! Now that you're here, how do I make it so you can add kits and items in those kits via a config.yml? Since I quit coding for a good 3 months and completely forgot everything. xD
     
  4. amazed2025 that's alot you ask me there, I am on my phone no, so I maybe could get to it tomorrow
     
  5. Offline

    amazed2025

    Alright, :)
    I was also wondering if by any chance you could help me make it so when they would right-click the same sign that gives them items, they'd be teleported to a coordinate in a different/same world.
     
Thread Status:
Not open for further replies.

Share This Page