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 public void onEnable(){saveConfig();getConfig().options().copyDefaults(true);}public void onDisable(){saveConfig();} That is the Enable/Disable code. Here is what I have it set to do when a player joins: Code:java Player p = event.getPlayer(); 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.
Code:java package me.hockey.IceyHubUtils; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.World;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.plugin.java.JavaPlugin; public class IceyHubUtils extends JavaPlugin{ public void onEnable() { saveConfig(); getConfig().options().copyDefaults(true); } public void onDisable() { saveConfig(); } public boolean onCommand(CommandSender sender, Command cmd, String cL, String[] args) { if (cmd.getName().equalsIgnoreCase("pm")) { if (args.length == 2) { Player to = Bukkit.getServer().getPlayer(args[0]); if (to != null) { to.sendMessage(ChatColor.GREEN + "[" + sender.getName() + " to: you] " + args[1]); sender.sendMessage(ChatColor.GREEN + "[you to: " + to.getName() + "] " + args[1]); } else { sender.sendMessage(ChatColor.DARK_RED + "Could not find the specified player."); } } else { sender.sendMessage(ChatColor.DARK_RED + "Usage: /pm <player> <message>"); } } if (cmd.getName().equalsIgnoreCase("iceysmite")) { Player target = Bukkit.getServer().getPlayer(args[0]); World world = target.getWorld(); Location loc = target.getLocation(); if (sender.hasPermission("iceyutil.smite")) { if (args.length == 2) { Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " has casted a full blown storm over: " + target.getName() + "."); target.getInventory().clear(); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); target.kickPlayer(ChatColor.RED + "You were smiten by: " + sender.getName() + " for commiting the following offense: " + args[1]); } else { sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceysmite <player> <reason>"); } } else { sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command."); } } if (cmd.getName().equalsIgnoreCase("iceyban")) { if (sender.hasPermission("icetutil.ban")) { if (args.length == 2) { Player target = Bukkit.getServer().getPlayer(args[0]); World world = target.getWorld(); Location loc = target.getLocation(); String ip = getConfig().getString(target.getName() + ".ip"); Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " Full oblivion will be casted upon: " + target.getName() + "!"); Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.RED + sender.getName() + " - Banning " + target.getName()); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); world.strikeLightningEffect(loc); target.getServer().banIP(ip); target.kickPlayer(ChatColor.RED + "You were banned by: " + sender.getName() + " for committing the following offense: " + args[1]); } else { sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceyban <player> <reason>"); } } else { sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command."); } } if (cmd.getName().equalsIgnoreCase("iceyunban")) { if (sender.hasPermission("iceyutil.unban")) { if (args.length == 1) { Player target = Bukkit.getServer().getPlayer(args[0]); String ip = getConfig().getString(target.getName() + ".ip"); Bukkit.broadcastMessage(ChatColor.BLUE + "[IceyCraft] " + ChatColor.GREEN + sender.getName() + " - Unbanning: " + target.getName() + "."); target.getServer().unbanIP(ip); } else { sender.sendMessage(ChatColor.DARK_RED + "Usage: /iceyunban <player> <reason>"); } } else { sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command."); } } if (cmd.getName().equalsIgnoreCase("findip")) { if (sender.hasPermission("iceyutil.findip")) { if (args.length == 1) { Player target = Bukkit.getServer().getPlayer(args[0]); String ip = getConfig().getString(target.getName() + ".ip"); sender.sendMessage(ChatColor.GREEN + "Player ips: " + ip); } else { sender.sendMessage(ChatColor.DARK_RED + "Usage: /findip <player>"); } } else { sender.sendMessage(ChatColor.DARK_RED + "You do not have permission to perform this command."); } } return true; } @EventHandler public void onPlayerJoin (PlayerJoinEvent event) { Player p = event.getPlayer(); getConfig().set(p.getName() + ".ip", p.getAddress().getAddress().getHostAddress()); p.sendMessage(ChatColor.BLUE + "Welcome to IceyCraft... the coolest server on the planet! I know... that pun was horrible."); p.sendMessage(ChatColor.DARK_PURPLE + "Click the compass to get started! If you need any help, contact a staff member!"); p.sendMessage(ChatColor.RED + "Please note: If you are playing in Survival, if you do not use /sethome, your current location will be lost."); if (p.hasPermission("iceyutil.lightning")) { Location lightning = p.getLocation(); World world = p.getWorld(); world.strikeLightning(lightning); } if (p.hasPermission("iceyutil.rank.owner")) { Bukkit.broadcastMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "OWNER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub."); } if (p.hasPermission("iceyutil.rank.co")) { Bukkit.broadcastMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "CO-OWNER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub."); } if (p.hasPermission("iceyutil.rank.admin")) { Bukkit.broadcastMessage(ChatColor.RED + "" + ChatColor.BOLD + "ADMIN " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub."); } if (p.hasPermission("iceyutil.rank.mod")) { Bukkit.broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "MOD " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub."); } if (p.hasPermission("iceyutil.rank.helper")) { Bukkit.broadcastMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "HELPER " + ChatColor.RESET + p.getName() + ChatColor.YELLOW + "" + ChatColor.BOLD + " has joined the server hub."); } }} It is for a server called: iceycraft. Here it is:
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.
Garris0n How would I register the events? And moose517 I have already done that, I just forgot to update the code.
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"
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.
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.
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.
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.
It's not just bukkit, it's in the official YAML specification. http://yaml.org/spec/current.html#id2519916