Events not doing anything

Discussion in 'Plugin Development' started by Gopaintman, Sep 7, 2013.

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

    Gopaintman

    Hi,
    So I have this test event here in my main class that when a player joins it tells them "yo". I've registered the events in the onEnable and I have the @EventHandler.

    Code:java
    1. package com.katsaroucraft.gopaintman;
    2.  
    3.  
    4.  
    5.  
    6. import java.io.File;
    7. import java.io.IOException;
    8. import java.io.InputStream;
    9. import java.util.logging.Level;
    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.PlayerJoinEvent;
    20. import org.bukkit.plugin.PluginManager;
    21. import org.bukkit.plugin.java.JavaPlugin;
    22.  
    23.  
    24.  
    25.  
    26.  
    27. public class Main extends JavaPlugin implements Listener{
    28. static File statsFile = null;
    29. static FileConfiguration statsFileConfig = null;
    30.  
    31. String[] help = {"help: Displays help info", "setsign <stat>: removes a selected leaderboard", "delsign"};
    32. String prefix;
    33.  
    34. @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
    35. public void onPlayerLogin(PlayerJoinEvent e){
    36. e.getPlayer().sendMessage("Yo");
    37.  
    38. }
    39. @Override
    40. public void onEnable() {
    41. PluginManager pm = this.getServer().getPluginManager();
    42. pm.registerEvents(this, this);
    43. this.getConfig().options().copyDefaults(true);
    44. reloadStatsFile();
    45. this.saveDefaultConfig();
    46. this.saveDefaultStatsFile();
    47. this.prefix = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("prefix"));
    48. getServer().getLogger();
    49.  
    50.  
    51. }
    52.  
    53. @Override
    54. public void onDisable() {
    55. getServer().getLogger();
    56. this.saveDefaultConfig();
    57.  
    58. }
    59. public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
    60. if(cmd.getName().equalsIgnoreCase("lb")){
    61. if(args.length>0){
    62. if(args[0].equalsIgnoreCase("help")){
    63. sender.sendMessage("");
    64. return false;
    65. }else if(args[0].equalsIgnoreCase("setsign")){
    66. //get WE API
    67. //sadface
    68. }else if(args[0].equalsIgnoreCase("delsign")){
    69. //get WE API
    70. //sadface
    71. }else if(args[0].equalsIgnoreCase("reset")){
    72. //reset dem stats you
    73. }else if(args[0].equalsIgnoreCase("kills")){
    74. if(args.length > 1 && statsFileConfig.contains(args[1])){
    75. statsFileConfig.set("players.kills." + args[1], 0);
    76.  
    77. }else{
    78. sender.sendMessage(prefix + "Player not found in the config");
    79.  
    80. }
    81. }else if(args[0].equalsIgnoreCase("deaths")){
    82.  
    83. }else if(args[0].equalsIgnoreCase("kdr")){
    84. if(sender instanceof Player){
    85. final Player player = (Player) sender;
    86. String name = player.getName();
    87. int kills = statsFileConfig.getInt("players.kills." + name);
    88. int deaths = statsFileConfig.getInt(prefix + ChatColor.AQUA + "players.kills." + name);
    89. if(deaths != 0){
    90. double kdr = kills/deaths;
    91. sender.sendMessage(prefix + "Your Kill to Death ratio is " + kdr);
    92. }else{
    93. sender.sendMessage(prefix + "You have no deaths!");
    94. }
    95.  
    96. }else{
    97. sender.sendMessage("This command can only be sent by a player");
    98. }
    99. }else if(args[0].equalsIgnoreCase("reload")){
    100. try {
    101. this.reloadConfig();
    102. this.reloadStatsFile();
    103. sender.sendMessage("InGameLeaderboard files have reloaded succesfully!");
    104. getLogger().info("InGameLeaderboard files have reloaded succesfully!");
    105. }catch(Exception e){
    106. getLogger().log(Level.SEVERE, "InGameLeaderboard files failed to reload!");
    107. sender.sendMessage("InGameLeaderboard files failed to reload!");
    108. e.printStackTrace();
    109. }
    110. }else{
    111. //put help in here
    112. }
    113.  
    114. }else{
    115. sender.sendMessage("");
    116. return false;
    117. }
    118. }
    119. return true;
    120.  
    121.  
    122.  
    123. }
    124. public void reloadStatsFile(){
    125. if(statsFile == null){
    126. statsFile = new File(getDataFolder(), "stats.yml");
    127. }
    128. statsFileConfig = YamlConfiguration.loadConfiguration(statsFile);
    129. //Look for defaults in the jar
    130. InputStream defConfigStream = this.getResource("stats.yml");
    131. if(defConfigStream != null){
    132. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    133. statsFileConfig.setDefaults(defConfig);
    134. }
    135. }
    136. public FileConfiguration getStatsFile(){
    137. if(statsFileConfig == null){
    138. reloadStatsFile();
    139. }
    140. return statsFileConfig;
    141. }
    142. public void saveStatsFile(){
    143. if(statsFile == null || statsFileConfig == null){
    144. return;
    145. }
    146. try{
    147. getStatsFile().save(statsFile);
    148. }catch(IOException ex){
    149. getLogger().log(Level.SEVERE, "Could not save config " + statsFile, ex);
    150. }
    151.  
    152. }
    153. public void saveDefaultStatsFile() {
    154. if (statsFile == null) {
    155. statsFile = new File(getDataFolder(), "stats.yml");
    156. }
    157. if (!statsFile.exists()) {
    158. this.saveResource("stats.yml", false);
    159. }
    160. }
    161.  
    162.  
    163.  
    164.  
    165.  
    166. /*public void createPlayerPaths(){
    167. for(int i = 0; i <= Bukkit.getOnlinePlayers().length;i++ ){
    168. Player[] players = Bukkit.getOnlinePlayers();
    169. String x = "Players." + players[0];
    170. StatsFileConfig.ad
    171.  
    172. }
    173.  
    174. }*/
    175.  
    176.  
    177. }
    178.  
     
  2. Offline

    Deleted user

    Gopaintman
    Seems fine
    See if there are other problems
     
  3. Offline

    Gopaintman

    Yea, I just found out what I did. I ran the wrong server :mad:
     
  4. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page