AlanGomes

Untitled

Feb 13th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public FileConfiguration cfg=getConfig();
  2.  
  3.  
  4. // Salvar arquivo
  5. public static void saveCfg() {
  6. saveConfig();
  7. }
  8.  
  9. // tempo em segundos
  10. public static void banir(Player p, int tempo, String motivo) {
  11. long timestamp = System.currentTimeMillis() / 1000;
  12. cfg.set("Bans."+p.getName()+".TempoAtual", timestamp);
  13. cfg.set("Bans."+p.getName()+".Tempo", tempo);
  14. cfg.set("Bans."+p.getName()+".Motivo", motivo);
  15. saveCfg();
  16. p.kickPlayer(motivo);
  17. }
  18.  
  19. public static boolean estaBanido(Player p) {
  20. for (String key:cfg.getConfigurationSection("Bans").getKeys(false)) {
  21. if (key.equalsIgnoreCase(p.getName())) {
  22. long timestamp = System.currentTimeMillis() / 1000;
  23. if ((timestamp-cfg.getLong("Bans."+key+".TempoAtual"))>cfg.getInt("Bans."+key+".Tempo")) {
  24. cfg.set("Bans."+key, null);
  25. saveCfg();
  26. return false;
  27. } else {
  28. return true;
  29. }
  30. }
  31. }
  32. return false;
  33. }
  34.  
  35. @EventHandler
  36. public void aoEntrar(PlayerJoinEvent e){
  37. File f = new File(getDataFolder, "bans.yml");
  38. cfg = Yamlconfiguration.loadFile(f);
  39. Player p = e.getPlayer();
  40. if (estaBanido(p)) {
  41. p.kickPlayer(cfg.getString("Bans."+p.getName()+".Motivo"));
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment