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.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2020-06-30 07:25:38 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
2020-08-15 22:58:48 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.staff.StaffMember;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.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;
|
2020-05-29 10:14:21 +00:00
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
import org.bukkit.scoreboard.Team;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class RankManager extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
final Player player = (Player)sender;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2016-02-29 20:48:17 +00:00
|
|
|
// Display impostors
|
2020-08-15 16:35:48 +00:00
|
|
|
if (plugin.sl.isStaffImpostor(player))
|
2016-02-29 20:48:17 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Rank.IMPOSTOR;
|
2016-02-29 20:48:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 01:49:07 +00:00
|
|
|
// If the player's an owner, display that
|
|
|
|
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
2018-05-12 03:09:23 +00:00
|
|
|
{
|
2019-01-28 01:49:07 +00:00
|
|
|
return Title.OWNER;
|
2018-05-12 03:09:23 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
// Developers always show up
|
2020-08-20 01:19:15 +00:00
|
|
|
if (FUtil.isDeveloper(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-03-06 15:56:15 +00:00
|
|
|
return Title.DEVELOPER;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && plugin.sl.isStaff(player))
|
2018-05-13 19:49:13 +00:00
|
|
|
{
|
|
|
|
return Title.EXECUTIVE;
|
|
|
|
}
|
|
|
|
|
2020-08-15 16:35:48 +00:00
|
|
|
if (plugin.sl.isVerifiedStaff(player))
|
2019-08-04 02:50:31 +00:00
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
return Title.VERIFIED_STAFF;
|
2019-08-04 02:50:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 16:35:48 +00:00
|
|
|
// Master builders show up if they are not staff
|
2020-08-15 22:42:46 +00:00
|
|
|
if (plugin.pl.getData(player).isMasterBuilder() && !plugin.sl.isStaff(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2019-01-28 01:49:07 +00:00
|
|
|
return Title.MASTER_BUILDER;
|
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
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
public Displayable getDisplay(StaffMember staffMember)
|
2019-08-11 21:12:53 +00:00
|
|
|
{
|
|
|
|
// If the player's an owner, display that
|
2020-08-15 22:42:46 +00:00
|
|
|
if (ConfigEntry.SERVER_OWNERS.getList().contains(staffMember.getName()))
|
2019-08-11 21:12:53 +00:00
|
|
|
{
|
|
|
|
return Title.OWNER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Developers always show up
|
2020-08-20 01:19:15 +00:00
|
|
|
if (FUtil.isDeveloper((Player)staffMember))
|
2019-08-11 21:12:53 +00:00
|
|
|
{
|
|
|
|
return Title.DEVELOPER;
|
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(staffMember.getName()))
|
2019-08-11 21:12:53 +00:00
|
|
|
{
|
|
|
|
return Title.EXECUTIVE;
|
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
return staffMember.getRank();
|
2019-08-11 21:12:53 +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)
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
return getRank((Player)sender);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
// CONSOLE?
|
2016-03-06 15:56:15 +00:00
|
|
|
if (sender.getName().equals("CONSOLE"))
|
|
|
|
{
|
2020-09-28 03:17:01 +00:00
|
|
|
return ConfigEntry.STAFFLIST_CONSOLE_IS_ADMIN.getBoolean() ? Rank.SENIOR_CONSOLE : Rank.ADMIN_CONSOLE;
|
2016-03-02 19:28:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 20:48:17 +00:00
|
|
|
// Console admin, get by name
|
2020-08-15 22:42:46 +00:00
|
|
|
StaffMember staffMember = plugin.sl.getEntryByName(sender.getName());
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
// Unknown console: RCON?
|
2020-08-15 22:42:46 +00:00
|
|
|
if (staffMember == null)
|
2016-02-29 20:48:17 +00:00
|
|
|
{
|
2020-09-28 02:51:15 +00:00
|
|
|
return Rank.SENIOR_CONSOLE;
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
Rank rank = staffMember.getRank();
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
if (plugin.sl.isStaffImpostor(player) || plugin.pl.isPlayerImpostor(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
|
|
|
}
|
|
|
|
|
2020-08-15 22:42:46 +00:00
|
|
|
final StaffMember entry = plugin.sl.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
|
|
|
}
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
public String getTag(Player player, String defaultTag)
|
|
|
|
{
|
|
|
|
String tag = defaultTag;
|
|
|
|
|
|
|
|
PlayerData playerData = plugin.pl.getData(player);
|
|
|
|
String t = playerData.getTag();
|
|
|
|
if (t != null && !t.isEmpty())
|
|
|
|
{
|
|
|
|
tag = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
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);
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData data = plugin.pl.getData(player);
|
|
|
|
Displayable display = getDisplay(player);
|
2020-10-02 09:27:06 +00:00
|
|
|
if (plugin.sl.isStaff(player) || data.isMasterBuilder() || FUtil.isDeveloper(player))
|
2018-01-07 19:33:58 +00:00
|
|
|
{
|
|
|
|
String displayName = display.getColor() + player.getName();
|
2020-06-30 07:25:38 +00:00
|
|
|
player.setPlayerListName(displayName);
|
2018-01-07 19:33:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fPlayer.setTag(null);
|
|
|
|
player.setPlayerListName(null);
|
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
fPlayer.setTag(getTag(player, display.getColoredTag()));
|
2020-05-29 10:14:21 +00:00
|
|
|
updatePlayerTeam(player);
|
2020-04-14 06:40:22 +00:00
|
|
|
plugin.pem.setPermissions(player);
|
2020-08-04 22:16:11 +00:00
|
|
|
plugin.rd.updateFlair(player);
|
2018-01-07 19:33:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
final Player player = event.getPlayer();
|
|
|
|
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
2020-06-30 07:25:38 +00:00
|
|
|
PlayerData target = plugin.pl.getData(player);
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2020-08-15 16:35:48 +00:00
|
|
|
// Unban staff
|
|
|
|
boolean isStaff = plugin.sl.isStaff(player);
|
|
|
|
if (isStaff)
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
// Verify strict IP match
|
2020-08-15 22:42:46 +00:00
|
|
|
if (!plugin.sl.isIdentityMatched(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " is a staff member, 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);
|
2020-08-15 22:42:46 +00:00
|
|
|
plugin.sl.updateLastLogin(player);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 16:35:48 +00:00
|
|
|
if (plugin.sl.isVerifiedStaff(player))
|
2019-08-04 02:50:31 +00:00
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " is a staff member, but does not have any staff permissions.", ChatColor.RED);
|
2019-08-04 02:50:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
// Handle impostors
|
2020-08-15 16:35:48 +00:00
|
|
|
boolean isImpostor = plugin.sl.isStaffImpostor(player) || plugin.pl.isPlayerImpostor(player);
|
2018-07-30 07:23:01 +00:00
|
|
|
if (isImpostor)
|
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());
|
2020-08-15 16:35:48 +00:00
|
|
|
if (plugin.sl.isStaffImpostor(player))
|
2018-03-25 01:41:51 +00:00
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as a staff impostor and has been frozen!", ChatColor.RED);
|
2018-07-26 05:22:19 +00:00
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
else if (plugin.pl.isPlayerImpostor(player))
|
2018-07-26 05:22:19 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-09 23:22:12 +00:00
|
|
|
// Broadcast login message
|
2020-10-02 09:27:06 +00:00
|
|
|
if (isStaff || FUtil.isDeveloper(player) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).hasLoginMessage())
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2020-08-15 22:58:48 +00:00
|
|
|
if (!plugin.sl.isVanished(player.getName()))
|
2020-07-22 21:40:58 +00:00
|
|
|
{
|
|
|
|
FUtil.bcastMsg(craftLoginMessage(player, null));
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2018-07-30 07:23:01 +00:00
|
|
|
|
2020-07-09 23:22:12 +00:00
|
|
|
// Set display
|
|
|
|
updateDisplay(player);
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
if (!plugin.pl.isPlayerImpostor(player) && target.hasVerification())
|
2018-07-30 07:23:01 +00:00
|
|
|
{
|
|
|
|
if (target.getTag() != null)
|
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
plugin.pl.getData(player).setTag(FUtil.colorize(target.getTag()));
|
2018-07-30 07:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
2020-04-23 11:18:03 +00:00
|
|
|
|
|
|
|
public String craftLoginMessage(Player player, String message)
|
|
|
|
{
|
|
|
|
Displayable display = plugin.rm.getDisplay(player);
|
2020-10-02 09:27:06 +00:00
|
|
|
PlayerData playerData = plugin.pl.getData(player);
|
|
|
|
if (message == null)
|
2020-04-23 11:18:03 +00:00
|
|
|
{
|
2020-10-02 09:27:06 +00:00
|
|
|
if (playerData.hasLoginMessage())
|
|
|
|
{
|
|
|
|
message = playerData.getLoginMessage();
|
|
|
|
}
|
|
|
|
else
|
2020-04-23 11:18:03 +00:00
|
|
|
{
|
2020-10-02 09:27:06 +00:00
|
|
|
if (display.hasDefaultLoginMessage())
|
2020-04-23 11:18:03 +00:00
|
|
|
{
|
2020-10-25 16:27:56 +00:00
|
|
|
message = "%name% is %art% %coloredrank%";
|
2020-04-23 11:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 09:27:06 +00:00
|
|
|
if (message != null)
|
|
|
|
{
|
|
|
|
String loginMessage = FUtil.colorize(ChatColor.AQUA + (message.contains("%name%") ? "" : player.getName() + " is ")
|
|
|
|
+ FUtil.colorize(message).replace("%name%", player.getName())
|
|
|
|
.replace("%rank%", display.getName())
|
|
|
|
.replace("%coloredrank%", display.getColoredName())
|
2020-10-25 17:24:41 +00:00
|
|
|
.replace("%art%", display.getArticle()));
|
2020-10-02 09:27:06 +00:00
|
|
|
return loginMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-04-23 11:18:03 +00:00
|
|
|
}
|
2020-05-29 10:14:21 +00:00
|
|
|
|
|
|
|
public void updatePlayerTeam(Player player)
|
|
|
|
{
|
|
|
|
Displayable display = getDisplay(player);
|
|
|
|
Scoreboard scoreboard = server.getScoreboardManager().getMainScoreboard();
|
|
|
|
Team team = scoreboard.getPlayerTeam(player);
|
2020-06-30 07:25:38 +00:00
|
|
|
if (!display.hasTeam())
|
2020-05-29 10:14:21 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
if (team != null)
|
|
|
|
{
|
|
|
|
team.removePlayer(player);
|
|
|
|
}
|
2020-05-29 10:14:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-30 07:25:38 +00:00
|
|
|
String name = StringUtils.substring(display.toString(), 0, 16);
|
|
|
|
team = scoreboard.getTeam(name);
|
2020-05-29 10:14:21 +00:00
|
|
|
if (team == null)
|
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
team = scoreboard.registerNewTeam(name);
|
|
|
|
team.setColor(display.getTeamColor());
|
|
|
|
}
|
|
|
|
if (!team.hasPlayer(player))
|
|
|
|
{
|
|
|
|
team.addPlayer(player);
|
2020-05-29 10:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-25 17:24:41 +00:00
|
|
|
}
|