Need help with ips!

Discussion in 'Plugin Development' started by JDJ, Jul 17, 2014.

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

    JDJ

    Hello! You may have recently seen another thread of mine. I am developing a rather large plugin. I am having trouble with recording the player's ips. Here is what I have.

    Code:java
    1. public void onEnable()
    2. {
    3. saveConfig();
    4. getConfig().options().copyDefaults(true);
    5. }
    6. public void onDisable()
    7. {
    8. saveConfig();
    9. }
    10.  
    11.  


    That is the Enable/Disable code.

    Here is what I have it set to do when a player joins:

    Code:java
    1. Player p = event.getPlayer();
    2.  
    3. getConfig().set(p.getName() + ".ip", p.getAddress().getAddress().getHostAddress());


    When I join though, the config.yml is completely empty and will not function at all. I have another question... how do u also only log one ip per player? I don't want the config to be spammed with ips everytime a player joins. Please help!

    Note: I know that the join event is not the problem, because I have used it before.
     
  2. Offline

    fireblast709

    JDJ it will be empty till you reload/restart, since you only seem to save onDisable
     
  3. Offline

    JDJ

    I am sorry, I didnt add the snippet in the player join event where it saves the config.
     
  4. Offline

    fireblast709

    JDJ post the full code
     
  5. Offline

    JDJ

    Code:java
    1. package me.hockey.IceyHubUtils;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class IceyHubUtils extends JavaPlugin
    15. {
    16. public void onEnable()
    17. {
    18. saveConfig();
    19. getConfig().options().copyDefaults(true);
    20. }
    21. public void onDisable()
    22. {
    23. saveConfig();
    24. }
    25.  
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String cL, String[] args)
    28. {
    29. if (cmd.getName().equalsIgnoreCase("pm"))
    30. {
    31. if (args.length == 2)
    32. {
    33. Player to = Bukkit.getServer().getPlayer(args[0]);
    34. if (to != null)
    35. {
    36. to.sendMessage(ChatColor.GREEN + "[" + sender.getName() + " to: you] " + args[1]);
    37. sender.sendMessage(ChatColor.GREEN + "[you to: " + to.getName() + "] " + args[1]);
    38. }
    39. else
    40. {
    41. sender.sendMessage(ChatColor.DARK_RED + "Could not find the specified player.");
    42. }
    43. }
    44. else
    45. {
    46. sender.sendMessage(ChatColor.DARK_RED + "Usage: /pm <player> <message>");
    47. }
    48. }
    49. if (cmd.getName().equalsIgnoreCase("iceysmite"))
    50. {
    51. Player target = Bukkit.getServer().getPlayer(args[0]);
    52. World world = target.getWorld();
    53. Location loc = target.getLocation();
    54.  
    55. if (sender.hasPermission("iceyutil.smite"))
    56. {
    57. if (args.length == 2)
    58. {
    59. Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " has casted a full blown storm over: " + target.getName() + ".");
    60. target.getInventory().clear();
    61. world.strikeLightningEffect(loc);
    62. world.strikeLightningEffect(loc);
    63. world.strikeLightningEffect(loc);
    64. world.strikeLightningEffect(loc);
    65. world.strikeLightningEffect(loc);
    66. world.strikeLightningEffect(loc);
    67. world.strikeLightningEffect(loc);
    68. world.strikeLightningEffect(loc);
    69. world.strikeLightningEffect(loc);
    70. world.strikeLightningEffect(loc);
    71. target.kickPlayer(ChatColor.RED + "You were smiten by: " + sender.getName() + " for commiting the following offense: " + args[1]);
    72. }
    73. else
    74. {
    75. sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceysmite <player> <reason>");
    76. }
    77. }
    78. else
    79. {
    80. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command.");
    81. }
    82. }
    83. if (cmd.getName().equalsIgnoreCase("iceyban"))
    84. {
    85. if (sender.hasPermission("icetutil.ban"))
    86. {
    87. if (args.length == 2)
    88. {
    89. Player target = Bukkit.getServer().getPlayer(args[0]);
    90. World world = target.getWorld();
    91. Location loc = target.getLocation();
    92. String ip = getConfig().getString(target.getName() + ".ip");
    93.  
    94. Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " Full oblivion will be casted upon: " + target.getName() + "!");
    95. Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " - Banning " + target.getName());
    96. world.strikeLightningEffect(loc);
    97. world.strikeLightningEffect(loc);
    98. world.strikeLightningEffect(loc);
    99. world.strikeLightningEffect(loc);
    100. world.strikeLightningEffect(loc);
    101. world.strikeLightningEffect(loc);
    102. world.strikeLightningEffect(loc);
    103. world.strikeLightningEffect(loc);
    104. world.strikeLightningEffect(loc);
    105. world.strikeLightningEffect(loc);
    106. world.strikeLightningEffect(loc);
    107. world.strikeLightningEffect(loc);
    108. world.strikeLightningEffect(loc);
    109. world.strikeLightningEffect(loc);
    110. world.strikeLightningEffect(loc);
    111. world.strikeLightningEffect(loc);
    112. world.strikeLightningEffect(loc);
    113. world.strikeLightningEffect(loc);
    114. target.getServer().banIP(ip);
    115. target.kickPlayer(ChatColor.RED + "You were banned by: " + sender.getName() + " for committing the following offense: " + args[1]);
    116. }
    117. else
    118. {
    119. sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceyban <player> <reason>");
    120. }
    121. }
    122. else
    123. {
    124. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command.");
    125. }
    126. }
    127. if (cmd.getName().equalsIgnoreCase("iceyunban"))
    128. {
    129. if (sender.hasPermission("iceyutil.unban"))
    130. {
    131. if (args.length == 1)
    132. {
    133. Player target = Bukkit.getServer().getPlayer(args[0]);
    134. String ip = getConfig().getString(target.getName() + ".ip");
    135.  
    136. Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.GREEN + sender.getName() + " - Unbanning: " + target.getName() + ".");
    137. target.getServer().unbanIP(ip);
    138. }
    139. else
    140. {
    141. sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceyunban <player> <reason>");
    142. }
    143. }
    144. else
    145. {
    146. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command.");
    147. }
    148. }
    149. if (cmd.getName().equalsIgnoreCase("findip"))
    150. {
    151. if (sender.hasPermission("iceyutil.findip"))
    152. {
    153. if (args.length == 1)
    154. {
    155. Player target = Bukkit.getServer().getPlayer(args[0]);
    156. String ip = getConfig().getString(target.getName() + ".ip");
    157.  
    158. sender.sendMessage(ChatColor.GREEN + "Player ips: " + ip);
    159. }
    160. else
    161. {
    162. sender.sendMessage(ChatColor.DARK_RED + "Usage: /findip <player>");
    163. }
    164. }
    165. else
    166. {
    167. sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command.");
    168. }
    169. }
    170. return true;
    171. }
    172. @EventHandler
    173. public void onPlayerJoin (PlayerJoinEvent event)
    174. {
    175. Player p = event.getPlayer();
    176.  
    177. getConfig().set(p.getName() + ".ip", p.getAddress().getAddress().getHostAddress());
    178.  
    179. p.sendMessage(ChatColor.BLUE + "Welcome to IceyCraft... the coolest server on the planet! I know... that pun was horrible.");
    180. p.sendMessage(ChatColor.DARK_PURPLE + "Click the compass to get started! If you need any help, contact a staff member!");
    181. p.sendMessage(ChatColor.RED + "Please note: If you are playing in Survival, if you do not use /sethome, your current location will be lost.");
    182.  
    183. if (p.hasPermission("iceyutil.lightning"))
    184. {
    185. Location lightning = p.getLocation();
    186. World world = p.getWorld();
    187. world.strikeLightning(lightning);
    188. }
    189. if (p.hasPermission("iceyutil.rank.owner"))
    190. {
    191. Bukkit.broadcastMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "OWNER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub.");
    192. }
    193. if (p.hasPermission("iceyutil.rank.co"))
    194. {
    195. Bukkit.broadcastMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "CO-OWNER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub.");
    196. }
    197. if (p.hasPermission("iceyutil.rank.admin"))
    198. {
    199. Bukkit.broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD + "ADMIN " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub.");
    200. }
    201. if (p.hasPermission("iceyutil.rank.mod"))
    202. {
    203. Bukkit.broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "MOD " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub.");
    204. }
    205. if (p.hasPermission("iceyutil.rank.helper"))
    206. {
    207. Bukkit.broadcastMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "HELPER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub.");
    208. }
    209. }
    210. }

    It is for a server called: iceycraft.

    Here it is:
     
  6. Offline

    moose517

    i only see where you do getConfig().set() in the playerJoinEvent. You need to do SaveConfig() there as well if you want it to save to file right then as well.
     
  7. Offline

    Garris0n

    Register your events.

    You should always ask that question first :p
     
  8. Offline

    JDJ

    Garris0n How would I register the events? And moose517 I have already done that, I just forgot to update the code.
     
  9. Offline

    Gater12

  10. Offline

    JDJ

    Gater12 Garris0n That helps... thank u! I will post my plugin.yml shortly, but the permissions arent working. The error in console says "Permission <permission> is not valid. I also get errors when I use /iceysmite if my args aren't correct. It will give errors in console, and send a message "An internal error occurred while performing this command"
     
  11. Offline

    GreySwordz

    Please post a new thread.
     
  12. Offline

    JDJ

    GreySwordz Why do I need to? Please tell me the rule I broke.
     
  13. Offline

    Garris0n

    He was just suggesting posting a new thread because it's a different issue.

    Regardless, if there's an error, POST THE CODE AND ERROR.
     
  14. Offline

    JDJ

    Code:
    name: IceyHubUtils
    main: me.hockey.IceyHubUtils.IceyHubUtils
    version: 1.7.9
    description: Hi.
     
    commands:
        iceysmite:
        iceyban:
        iceyunban:
        findip:
        pm:
     
    permissions:
      iceyutil.smite:
          description: Hi.
          default: op
      iceyutil.ban:
          description: Hi.
          default: op
      iceyutil.unban:
          description: Hi.
          default: op   
      iceyutil.lightning:
          description: Hi.
          default: op
      iceyutil.rank.owner:
          description: Hi.
          default: false
      iceyutil.rank.co:
          description: Hi.
          default: false
      iceyutil.rank.admin:
          description: Hi.
          default: false
      iceyutil.rank.mod:
          description: Hi.
          default: false
      iceyutil.rank.helper:
          description: Hi.
          default: false
      iceyutil.findip:
          description: Hi.
          default: op
    Garris0n Here is my plugin.yml. And I am sorry if that came off as rude. The error code says that it is an invalid plugin.yml.
     
  15. Offline

    _LB

    You need to use 2 spaces per indent because the Bukkit YAML parser is senselessly picky for no reason other than to punish you for forgetting.
     
  16. Offline

    Garris0n

    Obviously, if it's a YAML error, you might not need to post the code.

    Either way, always post the error if there is an error. "There is an error somewhere" is extremely unhelpful.
     
  17. Offline

    augustt198

    It's not just bukkit, it's in the official YAML specification. http://yaml.org/spec/current.html#id2519916
     
Thread Status:
Not open for further replies.

Share This Page