2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2018-07-31 07:05:28 +00:00
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2016-05-12 19:40:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.banning.Ban;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class AutoEject extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
private final Map<String, Integer> ejects = new HashMap<>(); // ip -> amount
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void autoEject(Player player, String kickMessage)
|
|
|
|
{
|
|
|
|
EjectMethod method = EjectMethod.STRIKE_ONE;
|
2020-07-01 01:51:06 +00:00
|
|
|
final String ip = FUtil.getIp(player);
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
if (!ejects.containsKey(ip))
|
|
|
|
{
|
|
|
|
ejects.put(ip, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kicks = ejects.get(ip);
|
|
|
|
kicks += 1;
|
|
|
|
|
|
|
|
ejects.put(ip, kicks);
|
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
if (kicks == 2)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
method = EjectMethod.STRIKE_TWO;
|
|
|
|
}
|
|
|
|
else if (kicks >= 3)
|
|
|
|
{
|
|
|
|
method = EjectMethod.STRIKE_THREE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLog.info("AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
|
|
|
|
|
|
|
|
player.setOp(false);
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
player.getInventory().clear();
|
|
|
|
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case STRIKE_ONE:
|
|
|
|
{
|
|
|
|
final Calendar cal = new GregorianCalendar();
|
|
|
|
cal.add(Calendar.MINUTE, 5);
|
|
|
|
final Date expires = cal.getTime();
|
|
|
|
|
|
|
|
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 5 minutes.");
|
|
|
|
|
|
|
|
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
|
|
|
player.kickPlayer(kickMessage);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRIKE_TWO:
|
|
|
|
{
|
|
|
|
final Calendar c = new GregorianCalendar();
|
|
|
|
c.add(Calendar.MINUTE, 10);
|
|
|
|
final Date expires = c.getTime();
|
|
|
|
|
|
|
|
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 10 minutes.");
|
|
|
|
|
|
|
|
plugin.bm.addBan(Ban.forPlayer(player, Bukkit.getConsoleSender(), expires, kickMessage));
|
|
|
|
player.kickPlayer(kickMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRIKE_THREE:
|
|
|
|
{
|
|
|
|
plugin.bm.addBan(Ban.forPlayerFuzzy(player, Bukkit.getConsoleSender(), null, kickMessage));
|
|
|
|
|
|
|
|
FUtil.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
|
|
|
|
|
|
|
|
player.kickPlayer(kickMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
public enum EjectMethod
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2020-12-25 19:46:43 +00:00
|
|
|
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|