SHOW:
|
|
- or go back to the newest paste.
| 1 | - | //Vai ficar assim: |
| 1 | + | public FileConfiguration cfg=getConfig(); |
| 2 | ||
| 3 | ||
| 4 | - | FileConfiguration fc = Yamlconfiguration.loadFile(f); |
| 4 | + | // Salvar arquivo |
| 5 | public static void saveCfg() {
| |
| 6 | - | if(fc.getString("Banidos." + p.getName()) != null){
|
| 6 | + | saveConfig(); |
| 7 | - | p.setKickMsg("Voce ainda esta banido!");
|
| 7 | + | |
| 8 | ||
| 9 | // tempo em segundos | |
| 10 | public static void banir(Player p, int tempo, String motivo) {
| |
| 11 | - | //Poderia adicionar mais ou menos, aquele código ai pra eu ver como ficaria, e vê ai, se é assim mesmo que tem que ser feito. |
| 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 | } |