TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java
Video 62fe72d99b Code quality and consistency improvements
Here's all the changes I've made in this commit:
- Resolves FS-44 (AutoEject.java)
- Resolves FS-45 (BlockBlocker.java)
- Resolves FS-47 and FS-48 (InteractBlocker.java)
- Resolves FS-49 (Command_cage.java)
- Resolves FS-50 (Command_manageshop.java)
- Resolves FS-51 (Command_notes.java)
- Resolves FS-52 (Command_potion.java)
- Resolves FS-53 (Command_tag.java)
- Resolves FS-55 (ItemFun.java)
- Resolves FS-56 (Module_list.java)
- Resolves FS-57 (Module_players.java)
- Removes redundant code from InteractBlocker.java
- Misc. code consistency corrections (global)
2021-06-16 21:10:08 -06:00

110 lines
3.0 KiB
Java

package me.totalfreedom.totalfreedommod;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
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
public void onStart()
{
}
@Override
public void onStop()
{
}
public void autoEject(Player player, String kickMessage)
{
EjectMethod method = EjectMethod.STRIKE_ONE;
final String ip = FUtil.getIp(player);
if (!ejects.containsKey(ip))
{
ejects.put(ip, 0);
}
int kicks = ejects.get(ip);
kicks += 1;
ejects.put(ip, kicks);
if (kicks == 2)
{
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;
}
default:
{
FLog.warning("Unrecognized EjectMethod " + method.name() + " found, defaulting to STRIKE_THREE");
}
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;
}
}
}
public enum EjectMethod
{
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE
}
}