I need help with making my config support color codes (the same as essentials use's) And 2 variables that translates %s% To: sender.getName() and %r% to targetPlayer.getName(), but it just getting error and still not working. here is the part of my code that i need help with: Code:java @Override public void onEnable() { getLogger().info("EmotionCraft has been enabled!"); File file = new File(getDataFolder() + File.separator + "config.yml"); if (!file.exists()) { this.getLogger().info("Generating Config.yml..."); this.getConfig().addDefault("Link For Variables:", "dev.bukkit.org/bukkit-plugins/EmotionCraft/"); ChatColor.translateAlternateColorCodes('&', message); String Sender = (String) getConfig().get("HugReciever"); Sender = Sender.replaceAll("%s", sender.getName()); String Reciever = (String) getConfig().get("HugSender"); Reciever = Reciever.replaceAll("%r", targetPlayer.getName()); this.getConfig().addDefault("HugReciever", "&cYou have been huged by %s%"); this.getConfig().addDefault("HugSender", "%r% &chuged"); this.getConfig().addDefault("KissReciever", "&cYou have been kissed by %s%"); this.getConfig().addDefault("KissSender", "%r% &ckissed"); this.getConfig().addDefault("SorryReciever", "%s% &cis sorry!"); this.getConfig().addDefault("SorrySender", "%r% &capologized!"); this.getConfig().addDefault("MakeOutReciever", "%s% &ctried to make out with you!"); this.getConfig().addDefault("MakeOutSender", "&cYou made out with %r%"); this.getConfig().addDefault("ComfortReciever", "%s% &ctrying to comfort you!"); this.getConfig().addDefault("ComfortSender", "%r% &cmust be happy now :)"); this.getConfig().addDefault("SlapReciever", "%s% &cslaped you!"); this.getConfig().addDefault("SlapSender", "%r% &cslaped!"); this.getConfig().options().copyDefaults(true); this.saveConfig(); this.getLogger().info("Generated Config.yml complete!"); } } bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I recommend for the senders and receivers, to just use %s% and %r%. This is how you would replace %s% with the sender: Code:java String Sender = (String) getConfig().get("HugReciever");Sender = Sender.replaceAll("%s", sender.getName()); This is how you would replace %r% with the receiver: Code:java String Reciever = (String) getConfig().get("HugSender");Receiver = Reciever.replaceAll("%r", targetPlayer.getName()); As for color codes, try this: Code:java String message = "&aPretend I got this from the &cconfig."message = message.replace('&', '§');
HMM the pretend i got this from the config should i remove the old color thing and paste this in on enable only? And the other (%s% and that, do i need to do as that on every config string (EX: ComfortReciever?)
Wherever you want to get color codes from the config, just use my replaceAll method. The %s% goes on every sender, and %r% goes to all receivers.
StaticJava i dont understand, have i done right?: Code:java @Override public void onEnable() { getLogger().info("EmotionCraft has been enabled!"); File file = new File(getDataFolder() + File.separator + "config.yml"); if (!file.exists()) { this.getLogger().info("Generating Config.yml..."); this.getConfig().addDefault("Link For Variables:", "dev.bukkit.org/bukkit-plugins/EmotionCraft/"); String Sender = (String) getConfig().get("HugReciever"); Sender = Sender.replaceAll("%s", sender.getName()); Sender = Sender.replace('&', '§'); String Reciever = (String) getConfig().get("HugSender"); Reciever = Reciever.replaceAll("%r", targetPlayer.getName()); Reciever = Reciever.replace('&', '§'); this.getConfig().addDefault("HugReciever", "&cYou have been huged by _Sender_"); this.getConfig().addDefault("HugSender", "_Reciever_ &chuged"); this.getConfig().addDefault("KissReciever", "&cYou have been kissed by _Sender_"); this.getConfig().addDefault("KissSender", "_Reciever_ &ckissed"); this.getConfig().addDefault("SorryReciever", "_Sender_ &cis sorry!"); this.getConfig().addDefault("SorrySender", "_Reciever_ &capologized!"); this.getConfig().addDefault("MakeOutReciever", "_Sender_ &ctried to make out with you!"); this.getConfig().addDefault("MakeOutSender", "&cYou made out with _Reciever_"); this.getConfig().addDefault("ComfortReciever", "_Sender_ &ctrying to comfort you!"); this.getConfig().addDefault("ComfortSender", "_Reciever_ &cmust be happy now :)"); this.getConfig().addDefault("SlapReciever", "_Sender_ &cslaped you!"); this.getConfig().addDefault("SlapSender", "_Reciever_ &cslaped!"); this.getConfig().options().copyDefaults(true); this.saveConfig(); this.getLogger().info("Generated Config.yml complete!"); } }
Almost. First off, you don't need to cast String to the config. Use getString for that. Why not use Bukkit's config methods? Instead of making a file, just make the config.yml in your IDE, and all these defaults manually?
1. thanks, 2. config.yml, saaay what? i think i should do as this, well how do you think i should solve this problem? can you make me a TuT?
BUMP, still needs help, and for the new code, i have updated the desc for this topic, so yeah! Someone that can help EDIT by Moderator: merged posts, please use the edit button instead of double posting.
glassbillen message = message.replaceAll('&', '§'); Don't use this, use message = ChatColor.translateAlternateColorCodes('&', message);
What is the error, if there is an error? What are you having trouble with? Also, iPoke111, you can use my way as well. It is much shorter and easier.
Really its Is (plugin name) Up to top? thing. and when i use the command the line is empty empty row, and no config create's