Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.youlosing.tempban;
- import java.sql.Date;
- import java.text.SimpleDateFormat;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.concurrent.TimeUnit;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerLoginEvent;
- public class Tempban implements CommandExecutor,Listener {
- public static Map<String,String> TempBan = new HashMap<>();
- public static Map<String,Long> TempBan_now = new HashMap<>();
- public static Map<String,Long> TempBan_time = new HashMap<>();
- public static Map<String,String> TempBan_player = new HashMap<>();
- @Override
- public boolean onCommand(CommandSender sender, Command command, String msg, String[] args) {
- if(command.getName().equalsIgnoreCase("tempban")) {
- Long l = Long.valueOf(args[1]);
- Tempban.ban(Bukkit.getPlayer(sender.getName()), l, "sec");
- }
- return false;
- }
- private static void ban(Player player, Long time, String unity) {
- TempBan.put("" + player.getName(),"Aucune raison");
- TempBan_now.put("" + player.getName(), System.currentTimeMillis());
- time = time * 1000;
- TempBan_time.put("" + player.getName(), time);
- TempBan_player.put("" + player.getName(),"CONSOLE");
- String t = "" + calculateTime(time);
- if(!t.equals("null")) {
- player.kickPlayer("§cVous avez été banni !" + "\n" + "§cInfraction : §c" + TempBan.get(player.getName()));
- }
- }
- @EventHandler
- public void onJoin(PlayerLoginEvent e) {
- if(TempBan.containsKey(e.getPlayer().getName())) {
- Long b = System.currentTimeMillis()-TempBan_now.get(e.getPlayer().getName());
- if (b < TempBan_time.get(e.getPlayer().getName())) {
- Long timexd = TempBan_now.get(e.getPlayer().getName());
- timexd = timexd + TempBan_time.get(e.getPlayer().getName());
- Long l = timexd-System.currentTimeMillis();
- String t = "" + calculateTime(l);
- if(!t.equals("null")) {
- long yourmilliseconds = timexd;
- SimpleDateFormat sdf = new SimpleDateFormat("dd,MM,yyyy à HH:mm");
- Date resultdate = new Date(yourmilliseconds);
- String s2 = sdf.format(resultdate);
- 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()));
- }else {
- TempBan.remove(e.getPlayer().getName());
- TempBan_time.remove(e.getPlayer().getName());
- TempBan_now.remove(e.getPlayer().getName());
- TempBan_player.remove(e.getPlayer().getName());
- }
- }else {
- TempBan.remove(e.getPlayer().getName());
- TempBan_time.remove(e.getPlayer().getName());
- TempBan_now.remove(e.getPlayer().getName());
- TempBan_player.remove(e.getPlayer().getName());
- }
- }
- }
- public static String calculateTime(Long timeIn){
- int day = (int) TimeUnit.MILLISECONDS.toDays(timeIn);
- long hours = TimeUnit.MILLISECONDS.toHours(timeIn) - (day * 24);
- long minutes = TimeUnit.MILLISECONDS.toMinutes(timeIn) - (TimeUnit.MILLISECONDS.toHours(timeIn) * 60);
- long seconds = TimeUnit.MILLISECONDS.toSeconds(timeIn) - (TimeUnit.MILLISECONDS.toMinutes(timeIn) * 60);
- String time = String.valueOf(day) + " Days " + String.valueOf(hours) + " Hours " +
- String.valueOf(minutes) + " Minutes " + String.valueOf(seconds) + " Seconds.";
- return time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment