TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java
Jerom van der Sar aca3398d21 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 21:51:58 +02:00

189 lines
5.4 KiB
Java

package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.FreedomService;
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;
import net.pravian.aero.util.ChatUtils;
import org.apache.commons.lang3.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;
public class RankManager extends FreedomService
{
public RankManager(TotalFreedomMod plugin)
{
super(plugin);
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
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
if (plugin.al.isAdminImpostor(player))
{
return Rank.IMPOSTOR;
}
// Developers always show up
if (FUtil.DEVELOPERS.contains(player.getName()))
{
return Title.DEVELOPER;
}
final Rank rank = getRank(player);
// Non-admins don't have titles, display actual rank
if (!rank.isAdmin())
{
return rank;
}
// If the player's an owner, display that
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
{
return Title.OWNER;
}
return rank;
}
public Rank getRank(CommandSender sender)
{
if (sender instanceof Player)
{
return getRank((Player) sender);
}
// CONSOLE?
if (sender.getName().equals("CONSOLE"))
{
return ConfigEntry.ADMINLIST_CONSOLE_IS_SENIOR.getBoolean() ? Rank.SENIOR_CONSOLE : Rank.TELNET_CONSOLE;
}
// Console admin, get by name
Admin admin = plugin.al.getEntryByName(sender.getName());
// Unknown console: RCON?
if (admin == null)
{
return Rank.SENIOR_CONSOLE;
}
Rank rank = admin.getRank();
// Get console
if (rank.hasConsoleVariant())
{
rank = rank.getConsoleVariant();
}
return rank;
}
public Rank getRank(Player player)
{
if (plugin.al.isAdminImpostor(player))
{
return Rank.IMPOSTOR;
}
final Admin entry = plugin.al.getAdmin(player);
if (entry != null)
{
return entry.getRank();
}
return player.isOp() ? Rank.OP : Rank.NON_OP;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
final Player player = event.getPlayer();
//plugin.pl.getData(player);
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);
fPlayer.setSuperadminIdVerified(false);
}
else
{
fPlayer.setSuperadminIdVerified(true);
plugin.al.updateLastLogin(player);
}
}
// Handle impostors
if (plugin.al.isAdminImpostor(player))
{
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + Rank.IMPOSTOR.getColoredLoginMessage());
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as an impostor and has been frozen!", ChatColor.RED);
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;
}
// Set display
if (isAdmin || FUtil.DEVELOPERS.contains(player.getName()))
{
final Displayable display = getDisplay(player);
String loginMsg = display.getColoredLoginMessage();
if (isAdmin)
{
Admin admin = plugin.al.getAdmin(player);
if (admin.hasLoginMessage())
{
loginMsg = ChatUtils.colorize(admin.getLoginMessage());
}
}
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + loginMsg);
plugin.pl.getPlayer(player).setTag(display.getColoredTag());
String displayName = display.getColor() + player.getName();
try
{
player.setPlayerListName(StringUtils.substring(displayName, 0, 16));
}
catch (IllegalArgumentException ex)
{
}
}
}
}