2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.rank;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
|
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2016-05-12 19:40:39 +00:00
|
|
|
import net.pravian.aero.util.ChatUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class RankManager extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public RankManager(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
public Displayable getDisplay(CommandSender sender)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
if (!(sender instanceof Player))
|
|
|
|
{
|
|
|
|
return getRank(sender); // Consoles don't have display ranks
|
|
|
|
}
|
|
|
|
|
|
|
|
final Player player = (Player) sender;
|
|
|
|
|
2016-02-29 20:48:17 +00:00
|
|
|
// Display impostors
|
|
|
|
if (plugin.al.isAdminImpostor(player))
|
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Rank.IMPOSTOR;
|
2016-02-29 20:48:17 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 03:09:23 +00:00
|
|
|
// Master builders show up if they are not admins
|
2018-05-13 19:49:13 +00:00
|
|
|
if (plugin.mbl.isMasterBuilder(player) && !plugin.al.isAdmin(player))
|
2018-05-12 03:09:23 +00:00
|
|
|
{
|
|
|
|
return Title.MASTER_BUILDER;
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
// Developers always show up
|
|
|
|
if (FUtil.DEVELOPERS.contains(player.getName()))
|
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Title.DEVELOPER;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 19:49:13 +00:00
|
|
|
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && plugin.al.isAdmin(player))
|
|
|
|
{
|
|
|
|
return Title.EXECUTIVE;
|
|
|
|
}
|
|
|
|
|
2016-02-29 20:48:17 +00:00
|
|
|
// If the player's an owner, display that
|
2016-05-12 19:40:39 +00:00
|
|
|
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Title.OWNER;
|
2016-02-29 20:48:17 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
return getRank(player);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
public Rank getRank(CommandSender sender)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
|
|
|
return getRank((Player) sender);
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
// CONSOLE?
|
2016-03-06 15:56:15 +00:00
|
|
|
if (sender.getName().equals("CONSOLE"))
|
|
|
|
{
|
|
|
|
return ConfigEntry.ADMINLIST_CONSOLE_IS_SENIOR.getBoolean() ? Rank.SENIOR_CONSOLE : Rank.TELNET_CONSOLE;
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 20:48:17 +00:00
|
|
|
// Console admin, get by name
|
2015-11-15 23:32:04 +00:00
|
|
|
Admin admin = plugin.al.getEntryByName(sender.getName());
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
// Unknown console: RCON?
|
2015-11-15 23:32:04 +00:00
|
|
|
if (admin == null)
|
2016-02-29 20:48:17 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Rank.SENIOR_CONSOLE;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
Rank rank = admin.getRank();
|
|
|
|
|
|
|
|
// Get console
|
|
|
|
if (rank.hasConsoleVariant())
|
|
|
|
{
|
|
|
|
rank = rank.getConsoleVariant();
|
|
|
|
}
|
|
|
|
return rank;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
public Rank getRank(Player player)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2018-05-13 19:49:13 +00:00
|
|
|
if (plugin.al.isAdminImpostor(player) || plugin.pv.isPlayerImpostor(player) || plugin.mbl.isMasterBuilderImpostor(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Rank.IMPOSTOR;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final Admin entry = plugin.al.getAdmin(player);
|
2016-03-02 19:28:01 +00:00
|
|
|
if (entry != null)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
return entry.getRank();
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
return player.isOp() ? Rank.OP : Rank.NON_OP;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 19:33:58 +00:00
|
|
|
public void updateDisplay(Player player)
|
|
|
|
{
|
2018-02-22 01:22:13 +00:00
|
|
|
if (!player.isOnline())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-01-07 19:33:58 +00:00
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
if (plugin.al.isAdmin(player))
|
|
|
|
{
|
|
|
|
Displayable display = getDisplay(player);
|
2018-03-03 04:29:08 +00:00
|
|
|
fPlayer.setTag(display.getColoredTag());
|
2018-01-07 19:33:58 +00:00
|
|
|
String displayName = display.getColor() + player.getName();
|
|
|
|
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fPlayer.setTag(null);
|
|
|
|
player.setPlayerListName(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
2016-02-29 20:48:17 +00:00
|
|
|
//plugin.pl.getData(player);
|
2015-11-15 23:32:04 +00:00
|
|
|
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
|
|
|
|
// Unban admins
|
|
|
|
boolean isAdmin = plugin.al.isAdmin(player);
|
|
|
|
if (isAdmin)
|
|
|
|
{
|
|
|
|
// Verify strict IP match
|
|
|
|
if (!plugin.al.isIdentityMatched(player))
|
|
|
|
{
|
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED);
|
2016-05-12 19:40:39 +00:00
|
|
|
fPlayer.setSuperadminIdVerified(false);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fPlayer.setSuperadminIdVerified(true);
|
|
|
|
plugin.al.updateLastLogin(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle impostors
|
2018-05-13 19:49:13 +00:00
|
|
|
Boolean isImposter = plugin.al.isAdminImpostor(player) || plugin.pv.isPlayerImpostor(player) || plugin.mbl.isMasterBuilderImpostor(player);
|
2018-01-07 19:33:58 +00:00
|
|
|
if (isImposter)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + Rank.IMPOSTOR.getColoredLoginMessage());
|
2018-03-25 01:41:51 +00:00
|
|
|
if (plugin.al.isAdminImpostor(player))
|
|
|
|
{
|
2018-07-26 05:22:19 +00:00
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as an admin impostor and has been frozen!", ChatColor.RED);
|
|
|
|
}
|
|
|
|
else if (plugin.mbl.isMasterBuilderImpostor(player))
|
|
|
|
{
|
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as a Master Builder impostor and has been frozen!", ChatColor.RED);
|
|
|
|
}
|
|
|
|
else if (plugin.pv.isPlayerImpostor(player))
|
|
|
|
{
|
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as a player impostor and has been frozen!", ChatColor.RED);
|
2018-03-24 15:41:45 +00:00
|
|
|
}
|
2018-01-07 19:33:58 +00:00
|
|
|
String displayName = Rank.IMPOSTOR.getColor() + player.getName();
|
|
|
|
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
|
2015-11-15 23:32:04 +00:00
|
|
|
player.getInventory().clear();
|
|
|
|
player.setOp(false);
|
|
|
|
player.setGameMode(GameMode.SURVIVAL);
|
|
|
|
plugin.pl.getPlayer(player).getFreezeData().setFrozen(true);
|
2016-03-06 15:56:15 +00:00
|
|
|
player.sendMessage(ChatColor.RED + "You are marked as an impostor, please verify yourself!");
|
2016-03-07 20:32:05 +00:00
|
|
|
return;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set display
|
2018-05-13 19:49:13 +00:00
|
|
|
if (isAdmin || FUtil.DEVELOPERS.contains(player.getName()) || plugin.mbl.isMasterBuilder(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
final Displayable display = getDisplay(player);
|
2016-03-06 15:56:15 +00:00
|
|
|
String loginMsg = display.getColoredLoginMessage();
|
|
|
|
|
|
|
|
if (isAdmin)
|
|
|
|
{
|
|
|
|
Admin admin = plugin.al.getAdmin(player);
|
|
|
|
if (admin.hasLoginMessage())
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
loginMsg = ChatUtils.colorize(admin.getLoginMessage());
|
2016-03-06 15:56:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 05:22:19 +00:00
|
|
|
FUtil.bcastMsg(loginMsg.replace("%name%", player.getName()));
|
2015-11-15 23:32:04 +00:00
|
|
|
plugin.pl.getPlayer(player).setTag(display.getColoredTag());
|
2016-03-06 15:56:15 +00:00
|
|
|
|
2018-02-22 01:22:13 +00:00
|
|
|
if (isAdmin)
|
|
|
|
{
|
|
|
|
Admin admin = plugin.al.getAdmin(player);
|
|
|
|
if (admin.getTag() != null)
|
|
|
|
{
|
|
|
|
plugin.pl.getPlayer(player).setTag(FUtil.colorize(admin.getTag()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
String displayName = display.getColor() + player.getName();
|
2015-11-15 23:32:04 +00:00
|
|
|
try
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|