TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java

317 lines
9.6 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.FreedomService;
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;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
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;
public class RankManager extends FreedomService
{
@Override
2020-07-01 01:51:06 +00:00
public void onStart()
{
}
@Override
2020-07-01 01:51:06 +00:00
public void onStop()
{
}
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
public Displayable getDisplay(CommandSender sender)
{
if (!(sender instanceof Player))
{
return getRank(sender); // Consoles don't have display ranks
}
final Player player = (Player)sender;
// Display impostors
2020-08-15 16:35:48 +00:00
if (plugin.sl.isStaffImpostor(player))
{
return Rank.IMPOSTOR;
}
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
}
// Developers always show up
2020-08-20 01:19:15 +00:00
if (FUtil.isDeveloper(player))
{
return Title.DEVELOPER;
}
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))
{
2019-01-28 01:49:07 +00:00
return Title.MASTER_BUILDER;
}
2018-01-07 19:33:58 +00:00
return getRank(player);
}
2020-08-15 22:42:46 +00:00
public Displayable getDisplay(StaffMember staffMember)
{
// If the player's an owner, display that
2020-08-15 22:42:46 +00:00
if (ConfigEntry.SERVER_OWNERS.getList().contains(staffMember.getName()))
{
return Title.OWNER;
}
// Developers always show up
2020-08-20 01:19:15 +00:00
if (FUtil.isDeveloper((Player)staffMember))
{
return Title.DEVELOPER;
}
2020-08-15 22:42:46 +00:00
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(staffMember.getName()))
{
return Title.EXECUTIVE;
}
2020-08-15 22:42:46 +00:00
return staffMember.getRank();
}
public Rank getRank(CommandSender sender)
{
if (sender instanceof Player)
{
return getRank((Player)sender);
}
// CONSOLE?
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;
}
// Console admin, get by name
2020-08-15 22:42:46 +00:00
StaffMember staffMember = plugin.sl.getEntryByName(sender.getName());
// Unknown console: RCON?
2020-08-15 22:42:46 +00:00
if (staffMember == null)
{
return Rank.SENIOR_CONSOLE;
}
2020-08-15 22:42:46 +00:00
Rank rank = staffMember.getRank();
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
// Get console
if (rank.hasConsoleVariant())
{
rank = rank.getConsoleVariant();
}
return rank;
}
public Rank getRank(Player player)
{
2020-08-15 16:35:48 +00:00
if (plugin.sl.isStaffImpostor(player) || plugin.pl.isPlayerImpostor(player))
{
return Rank.IMPOSTOR;
}
2020-08-15 22:42:46 +00:00
final StaffMember entry = plugin.sl.getAdmin(player);
if (entry != null)
{
return entry.getRank();
}
return player.isOp() ? Rank.OP : Rank.NON_OP;
}
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);
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);
plugin.rd.updateFlair(player);
2018-01-07 19:33:58 +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);
2020-08-15 16:35:48 +00:00
// Unban staff
boolean isStaff = plugin.sl.isStaff(player);
if (isStaff)
{
// Verify strict IP match
2020-08-15 22:42:46 +00:00
if (!plugin.sl.isIdentityMatched(player))
{
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);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
fPlayer.setSuperadminIdVerified(false);
}
else
{
fPlayer.setSuperadminIdVerified(true);
2020-08-15 22:42:46 +00:00
plugin.sl.updateLastLogin(player);
}
}
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
}
// Handle impostors
2020-08-15 16:35:48 +00:00
boolean isImpostor = plugin.sl.isStaffImpostor(player) || plugin.pl.isPlayerImpostor(player);
if (isImpostor)
{
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + Rank.IMPOSTOR.getColoredLoginMessage());
2020-08-15 16:35:48 +00:00
if (plugin.sl.isStaffImpostor(player))
{
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-01-07 19:33:58 +00:00
String displayName = Rank.IMPOSTOR.getColor() + player.getName();
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
player.getInventory().clear();
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
plugin.pl.getPlayer(player).getFreezeData().setFrozen(true);
player.sendMessage(ChatColor.RED + "You are marked as an impostor, please verify yourself!");
return;
}
// Broadcast login message
if (isStaff || FUtil.isDeveloper(player) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).hasLoginMessage())
{
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));
}
}
// Set display
updateDisplay(player);
2020-06-30 07:25:38 +00:00
if (!plugin.pl.isPlayerImpostor(player) && target.hasVerification())
{
if (target.getTag() != null)
{
2020-06-30 07:25:38 +00:00
plugin.pl.getData(player).setTag(FUtil.colorize(target.getTag()));
}
}
}
2020-04-23 11:18:03 +00:00
public String craftLoginMessage(Player player, String message)
{
Displayable display = plugin.rm.getDisplay(player);
PlayerData playerData = plugin.pl.getData(player);
if (message == null)
2020-04-23 11:18:03 +00:00
{
if (playerData.hasLoginMessage())
{
message = playerData.getLoginMessage();
}
else
2020-04-23 11:18:03 +00:00
{
if (display.hasDefaultLoginMessage())
2020-04-23 11:18:03 +00:00
{
message = "%name% is %art% %coloredrank%";
2020-04-23 11:18:03 +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()));
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
}