Player events not working !!!

Discussion in 'Plugin Development' started by CookieAssassin, Jan 14, 2014.

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

    CookieAssassin

    here is the start of the code:
    Code:java
    1. package me.FlameBlazer.ACC;
    2.  
    3.  
    4. import java.util.logging.Logger;
    5. import java.io.File;
    6. import java.io.IOException;
    7. import java.io.InputStream;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.configuration.file.FileConfiguration;
    14. import org.bukkit.configuration.file.YamlConfiguration;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.EventHandler;
    17. import org.bukkit.event.EventPriority;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.event.player.AsyncPlayerChatEvent;
    20. import org.bukkit.plugin.PluginDescriptionFile;
    21. import org.bukkit.plugin.PluginManager;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24. import ru.tehkode.permissions.bukkit.PermissionsEx;
    25.  
    26. public final class Main extends JavaPlugin implements Listener{
    27. public final Logger logger= Logger.getLogger("Minecraft");
    28. File file = new File(getDataFolder(), "config.yml");
    29.  
    30.  
    31.  
    32. public void changeColor(String colorcode, Player player){
    33.  
    34. String playerName = getConfig().getString(player.getName());
    35. getConfig().addDefault(player.getName(), colorcode);
    36. player.sendMessage(ChatColor.GREEN + "Your chat color has been successfully changed");
    37.  
    38.  
    39. }
    40. public void OnEnable(){
    41. PluginManager pm = this.getServer().getPluginManager();
    42. PluginDescriptionFile pdfFile = this.getDescription();
    43.  
    44.  
    45. FileConfiguration configFile = YamlConfiguration.loadConfiguration(this.file);
    46.  
    47. InputStream defaultStream = this.getResource("config.yml");
    48. if (defaultStream != null) {
    49.  
    50. getConfig().setDefaults(configFile);
    51. }
    52. getServer().getPluginManager().registerEvents(this, this);
    53. this.logger.info(pdfFile.getName() + " V." + pdfFile.getVersion() + " Has Been Enabled");
    54. }
    55. public void OnDisable(){
    56. PluginDescriptionFile pdfFile = this.getDescription();
    57. if(!file.exists()){
    58.  
    59. try {
    60. saveDefaultConfig();
    61. this.logger.info(pdfFile.getName() + " V." + pdfFile.getVersion() + " Has successfully saved the config");
    62. } catch (Exception e) {
    63. this.logger.info(pdfFile.getName() + " V." + pdfFile.getVersion() + " CANNOT SAVE THE CONFIG");
    64. }
    65. }
    66. this.logger.info(pdfFile.getName() + " V." + pdfFile.getVersion() + " Has Been Disabled");
    67. }

    Then there is my onCommand() ect... (which is working fine)
    And then there is my non working Listener:
    Code:java
    1. @EventHandler (priority = EventPriority.HIGH)
    2. public void onPlayerChat(AsyncPlayerChatEvent event){
    3.  
    4. Player player = event.getPlayer();
    5. player.sendMessage("0"); // i did this so i could Debug it to see if the listener was working at all
    6. if(event.getMessage().contains("&")||event.getMessage().contains("ยง")){
    7. player.sendMessage("1"); // i did this so i could Debug it to see if the listener was working at all
    8. }else{
    9. if(player.hasPermission("ACC.chat")){
    10. if(getConfig().getString(player.getName()) != null){
    11. event.setMessage(getConfig().getDefaults().getString(player.getName()) + event.getMessage());
    12. player.sendMessage("2");// i did this so i could Debug it to see if the listener was working at all
    13. }
    14. player.sendMessage("3");// i did this so i could Debug it to see if the listener was working at all
    15. }
    16. player.sendMessage("4");// i did this so i could Debug it to see if the listener was working at all
    17. }
    18.  
    19. }
    20. }

    I have no idea what the problem is, everything but the listener is working, it
    will not send the player the messages or do anything.
    Can someone help me please? This is really getting on my nerves :p

    view the whole version here: http://pastebin.com/saZhTbv6
     
  2. Offline

    Bionicrm

    I don't believe you actually created the listener's class.
     
  3. Offline

    SacredWaste

  4. Offline

    CookieAssassin

    I have registered the listener in OnEnable() haven't i?

    You do not need a listeners class, it can go in the same class.

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

    Bionicrm

    CookieAssassin Of course... but your code does not make clear that they are in fact in the same class.
     
  6. Offline

    SacredWaste

    Very true. I understood that the main class was registered, but you removed the handler from that class (if it is in there). When you provide code, you should not take out snippets of it.
     
  7. Offline

    CookieAssassin

    ok, view the whole version here: http://pastebin.com/saZhTbv6
     
  8. Offline

    Bionicrm

    No wonder: your onEnable() and onDisable() methods start with capital "o"'s.
     
  9. Offline

    CookieAssassin

    omg thank you so much. im such an idiot -.-
     
Thread Status:
Not open for further replies.

Share This Page