Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. plugin.yml
  2.  
  3. name: DDPomocConf
  4. version: 0.1
  5. main: me.ddziekan.ddpomocconfig
  6. author: DDziekan
  7.  
  8. main
  9.  
  10. package me.ddziekan.ddpomocconfig;
  11.  
  12. import java.io.File;
  13. import java.io.IOException;
  14.  
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.ChatColor;
  17. import org.bukkit.configuration.file.YamlConfiguration;
  18. import org.bukkit.event.EventHandler;
  19. import org.bukkit.event.Listener;
  20. import org.bukkit.event.player.PlayerJoinEvent;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. public class Main extends JavaPlugin implements Listener{
  24.  
  25. private static Main inst;
  26.  
  27. public Main(){
  28. inst = this;
  29. }
  30.  
  31. public void onEnable() {
  32. FileManager.checkFiles();
  33. Bukkit.getPluginManager().registerEvents(this, this);
  34. }
  35.  
  36. public void onDisable(){}
  37.  
  38. public static Main getInst() {
  39. return inst;
  40. }
  41.  
  42. @EventHandler
  43. public void onJoin(PlayerJoinEvent e) throws IOException{
  44. File f;
  45. if(FileManager.getPFile(e.getPlayer()) == null){
  46. f = new File(FileManager.getUsersFolder(), e.getPlayer().getName() + ".yml");
  47. f.createNewFile();
  48. } else{
  49. f = FileManager.getPFile(e.getPlayer());
  50. }
  51. YamlConfiguration fYml = YamlConfiguration.loadConfiguration(f);
  52. fYml.set("name", e.getPlayer().getName());
  53. fYml.set("uuid", e.getPlayer().getUniqueId().toString());
  54. fYml.set("ip", e.getPlayer().getAddress().getAddress().toString().replace("/", ""));
  55. fYml.save(f);
  56. e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', FileManager.getMsg().getString("helloMsg")));
  57. }
  58. }
  59.  
  60. filemanager
  61.  
  62. package me.ddziekan.ddpomocconfig;
  63.  
  64. import java.io.File;
  65.  
  66. import org.bukkit.configuration.file.YamlConfiguration;
  67. import org.bukkit.entity.Player;
  68.  
  69. public class FileManager {
  70.  
  71. private static YamlConfiguration msg;
  72. private static File users = new File(Main.getInst().getDataFolder(), "users");
  73.  
  74. public static void checkFiles(){
  75. if(!Main.getInst().getDataFolder().exists()){
  76. Main.getInst().getDataFolder().mkdir();
  77. }
  78. if(!new File(Main.getInst().getDataFolder(), "config.yml").exists()){
  79. Main.getInst().saveDefaultConfig();
  80. }
  81. File m = new File(Main.getInst().getDataFolder(), "messages.yml");
  82. if(!m.exists()){
  83. Main.getInst().saveResource("messages.yml", true);
  84. }
  85. if(!users.exists()){
  86. users.mkdir();
  87. }
  88. msg = YamlConfiguration.loadConfiguration(m);
  89. }
  90.  
  91. public static YamlConfiguration getMsg(){
  92. return msg;
  93. }
  94.  
  95. public static File getPFile(Player p){
  96. File f = new File(users, p.getName() + ".yml");
  97. if(!f.exists()) return null;
  98. return f;
  99. }
  100.  
  101. public static File getUsersFolder(){
  102. return users;
  103. }
  104. }
  105.  
  106. messages.yml
  107.  
  108. #==========<Configuracja wiadomosci>==========
  109. helloMsg: '&4Witamy na ProHC.PL'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement