YouLosing

Untitled

Jul 26th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. package fr.youlosing.tempban;
  2.  
  3. import java.sql.Date;
  4. import java.text.SimpleDateFormat;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.concurrent.TimeUnit;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.player.PlayerLoginEvent;
  17.  
  18. public class Tempban implements CommandExecutor,Listener {
  19.  
  20. public static Map<String,String> TempBan = new HashMap<>();
  21. public static Map<String,Long> TempBan_now = new HashMap<>();
  22. public static Map<String,Long> TempBan_time = new HashMap<>();
  23. public static Map<String,String> TempBan_player = new HashMap<>();
  24.  
  25. @Override
  26. public boolean onCommand(CommandSender sender, Command command, String msg, String[] args) {
  27.  
  28. if(command.getName().equalsIgnoreCase("tempban")) {
  29. Long l = Long.valueOf(args[1]);
  30. Tempban.ban(Bukkit.getPlayer(sender.getName()), l, "sec");
  31. }
  32. return false;
  33. }
  34.  
  35. private static void ban(Player player, Long time, String unity) {
  36. TempBan.put("" + player.getName(),"Aucune raison");
  37. TempBan_now.put("" + player.getName(), System.currentTimeMillis());
  38. time = time * 1000;
  39. TempBan_time.put("" + player.getName(), time);
  40. TempBan_player.put("" + player.getName(),"CONSOLE");
  41. String t = "" + calculateTime(time);
  42. if(!t.equals("null")) {
  43. player.kickPlayer("§cVous avez été banni !" + "\n" + "§cInfraction : §c" + TempBan.get(player.getName()));
  44. }
  45. }
  46.  
  47. @EventHandler
  48. public void onJoin(PlayerLoginEvent e) {
  49. if(TempBan.containsKey(e.getPlayer().getName())) {
  50. Long b = System.currentTimeMillis()-TempBan_now.get(e.getPlayer().getName());
  51. if (b < TempBan_time.get(e.getPlayer().getName())) {
  52. Long timexd = TempBan_now.get(e.getPlayer().getName());
  53. timexd = timexd + TempBan_time.get(e.getPlayer().getName());
  54. Long l = timexd-System.currentTimeMillis();
  55. String t = "" + calculateTime(l);
  56. if(!t.equals("null")) {
  57. long yourmilliseconds = timexd;
  58. SimpleDateFormat sdf = new SimpleDateFormat("dd,MM,yyyy à HH:mm");
  59. Date resultdate = new Date(yourmilliseconds);
  60. String s2 = sdf.format(resultdate);
  61. e.getPlayer().kickPlayer("§cVous avez été banni jusqu'au " + s2.replaceAll(",", "/") + " !" + "\n" + "§c- " + TempBan_player.get(e.getPlayer().getName()) + "§c: Infraction : §c" + TempBan.get(e.getPlayer().getName()));
  62. }else {
  63. TempBan.remove(e.getPlayer().getName());
  64. TempBan_time.remove(e.getPlayer().getName());
  65. TempBan_now.remove(e.getPlayer().getName());
  66. TempBan_player.remove(e.getPlayer().getName());
  67. }
  68.  
  69.  
  70. }else {
  71. TempBan.remove(e.getPlayer().getName());
  72. TempBan_time.remove(e.getPlayer().getName());
  73. TempBan_now.remove(e.getPlayer().getName());
  74. TempBan_player.remove(e.getPlayer().getName());
  75. }
  76.  
  77.  
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90.  
  91. public static String calculateTime(Long timeIn){
  92. int day = (int) TimeUnit.MILLISECONDS.toDays(timeIn);
  93. long hours = TimeUnit.MILLISECONDS.toHours(timeIn) - (day * 24);
  94. long minutes = TimeUnit.MILLISECONDS.toMinutes(timeIn) - (TimeUnit.MILLISECONDS.toHours(timeIn) * 60);
  95. long seconds = TimeUnit.MILLISECONDS.toSeconds(timeIn) - (TimeUnit.MILLISECONDS.toMinutes(timeIn) * 60);
  96.  
  97. String time = String.valueOf(day) + " Days " + String.valueOf(hours) + " Hours " +
  98. String.valueOf(minutes) + " Minutes " + String.valueOf(seconds) + " Seconds.";
  99.  
  100. return time;
  101. }
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment