Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package Refez.Tempban;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.configuration.file.FileConfiguration;
  11. import org.bukkit.configuration.file.YamlConfiguration;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.player.PlayerJoinEvent;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17. public class Main extends JavaPlugin implements Listener {
  18. public static File bplayers = new File("plugins/BanManager", "bannedplayers.yml");
  19. public static FileConfiguration bcfg = YamlConfiguration.loadConfiguration(bplayers);
  20.  
  21. ArrayList<Player> cooldown = new ArrayList<Player>();
  22.  
  23. public void onEnable() {
  24. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  25. try {
  26. bcfg.save(bplayers);
  27. }
  28. catch (IOException e1) {
  29. e1.printStackTrace();
  30. }
  31.  
  32.  
  33. }
  34. @EventHandler
  35. public void onJoin(PlayerJoinEvent e) {
  36. int ban = bcfg.getInt("Banned.Players." + e.getPlayer().getName() + ".Ban");
  37. if (ban == 1) {
  38. e.getPlayer().kickPlayer("§aYou are already banned from server for 10 second.");
  39.  
  40. }
  41. }
  42.  
  43. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  44. final Player p = (Player) sender;
  45. if (cmd.getName().equalsIgnoreCase("tempban")) {
  46. if (args.length == 1) {
  47. Player target = Bukkit.getPlayerExact(args[0]);
  48. int ban = bcfg.getInt("Banned.Players." + target.getName() + ".Ban");
  49. if (cooldown.contains(target)) {
  50. p.sendMessage("§aSorry, This player already banned.");
  51. }
  52. if (!cooldown.contains(target)) {
  53. cooldown.add(target);
  54. bcfg.set("Banned.Players." + target.getName() + ".Ban", Integer.valueOf(1));
  55. p.sendMessage("§aPlayer successfuly banned !");
  56. p.sendMessage("§aBanned time: 10 seconds.");
  57. target.kickPlayer("§cYou are banned from server for 10 seconds.");
  58. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  59. public void run() {
  60. bcfg.set("Banned.Players." + target.getName() + ".Ban", Integer.valueOf(0));
  61. cooldown.remove(p);
  62. }
  63. }, 200);
  64. return true;
  65.  
  66. }
  67.  
  68. }
  69. }
  70. p.sendMessage("§aPlease to ban a player 10 seconds, /tempban [Name]");
  71.  
  72. return true;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement