mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Tested to be working, but made some minor changes.
This commit is contained in:
parent
01223d44ef
commit
88f89d7e67
@ -9,33 +9,41 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Manage your verification", usage = "/<command> <enable | disable | clearips | status> <discord | forum>", aliases = "playerverification, opverification, opverify, opv")
|
@CommandParameters(description = "Manage your verification", usage = "/<command> <enable | disable | clearips | status> <discord | forum>", aliases = "playerverification,pv")
|
||||||
public class Command_playerverify extends FreedomCommand {
|
public class Command_playerverify extends FreedomCommand
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
if (args.length < 2) {
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plugin.al.isAdmin(sender)) {
|
if (plugin.al.isAdmin(sender))
|
||||||
|
{
|
||||||
msg("This command is only for OP's.", ChatColor.RED);
|
msg("This command is only for OP's.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase())
|
||||||
|
{
|
||||||
case "enable":
|
case "enable":
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase())
|
||||||
|
{
|
||||||
case "discord":
|
case "discord":
|
||||||
if (!plugin.dc.enabled) {
|
if (!plugin.dc.enabled)
|
||||||
|
{
|
||||||
msg("The discord verification system is currently disabled.", ChatColor.RED);
|
msg("The discord verification system is currently disabled.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||||
if (data.isDiscordVerificationEnabled()) {
|
if (data.isDiscordVerificationEnabled())
|
||||||
|
{
|
||||||
msg("Discord verification is already enabled for you.", ChatColor.RED);
|
msg("Discord verification is already enabled for you.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
data.setDiscordVerificationEnabled(true);
|
data.setDiscordVerificationEnabled(true);
|
||||||
plugin.pv.saveVerificationData(data);
|
plugin.pv.saveVerificationData(data);
|
||||||
msg("Enabled discord verification. Please type /linkdiscord to link a discord account.", ChatColor.AQUA);
|
msg("Enabled discord verification. Please type /linkdiscord to link a discord account.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
||||||
case "forum":
|
case "forum":
|
||||||
msg("TODO. This will be enabled in a later update. Please use discord verification instead.");
|
msg("TODO. This will be enabled in a later update. Please use discord verification instead.");
|
||||||
@ -44,16 +52,18 @@ public class Command_playerverify extends FreedomCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case "disable":
|
case "disable":
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase())
|
||||||
|
{
|
||||||
case "discord":
|
case "discord":
|
||||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||||
if (!data.isDiscordVerificationEnabled()) {
|
if (!data.isDiscordVerificationEnabled())
|
||||||
|
{
|
||||||
msg("Discord verification is already disabled for you.", ChatColor.RED);
|
msg("Discord verification is already disabled for you.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
data.setDiscordVerificationEnabled(false);
|
data.setDiscordVerificationEnabled(false);
|
||||||
plugin.pv.saveVerificationData(data);
|
plugin.pv.saveVerificationData(data);
|
||||||
msg("Disabled discord verification.", ChatColor.AQUA);
|
msg("Disabled discord verification.", ChatColor.GREEN);
|
||||||
return true;
|
return true;
|
||||||
case "forum":
|
case "forum":
|
||||||
msg("TODO. Forum verification will be enabled in a later update.");
|
msg("TODO. Forum verification will be enabled in a later update.");
|
||||||
@ -62,13 +72,14 @@ public class Command_playerverify extends FreedomCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case "status":
|
case "status":
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase())
|
||||||
|
{
|
||||||
case "discord":
|
case "discord":
|
||||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||||
boolean enabled = data.isDiscordVerificationEnabled();
|
boolean enabled = data.isDiscordVerificationEnabled();
|
||||||
boolean specified = data.getDiscordID() != null;
|
boolean specified = data.getDiscordID() != null;
|
||||||
msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.AQUA + "true" : ChatColor.RED + "false"));
|
msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.GREEN + "true" : ChatColor.RED + "false"));
|
||||||
msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.AQUA + data.getDiscordID() : ChatColor.RED + "not set"));
|
msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.GREEN + data.getDiscordID() : ChatColor.RED + "not set"));
|
||||||
return true;
|
return true;
|
||||||
case "forum":
|
case "forum":
|
||||||
msg("TODO. Forum verification will be enabled in a later update.");
|
msg("TODO. Forum verification will be enabled in a later update.");
|
||||||
@ -79,8 +90,10 @@ public class Command_playerverify extends FreedomCommand {
|
|||||||
case "clearips":
|
case "clearips":
|
||||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||||
int cleared = 0;
|
int cleared = 0;
|
||||||
for (String ip : data.getIPs()) {
|
for (String ip : data.getIPs())
|
||||||
if (!ip.equals(Ips.getIp(playerSender))) {
|
{
|
||||||
|
if (!ip.equals(Ips.getIp(playerSender)))
|
||||||
|
{
|
||||||
data.removeIp(ip);
|
data.removeIp(ip);
|
||||||
cleared++;
|
cleared++;
|
||||||
}
|
}
|
||||||
|
@ -11,39 +11,48 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.ONLY_IN_GAME)
|
@CommandPermissions(level = Rank.IMPOSTOR, source = SourceType.ONLY_IN_GAME)
|
||||||
@CommandParameters(description = "Sends a verification code to the player, or the player can input the sent code.", usage = "/<command> [code]")
|
@CommandParameters(description = "Sends a verification code to the player, or the player can input the sent code.", usage = "/<command> [code]")
|
||||||
public class Command_verify extends FreedomCommand {
|
public class Command_verify extends FreedomCommand
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
|
||||||
if (!plugin.dc.enabled) {
|
if (!plugin.dc.enabled)
|
||||||
|
{
|
||||||
msg("The discord verification system is currently disabled", ChatColor.RED);
|
msg("The discord verification system is currently disabled", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.al.isAdminImpostor(playerSender) && !plugin.pv.isPlayerImpostor(playerSender)) {
|
if (!plugin.al.isAdminImpostor(playerSender) && !plugin.pv.isPlayerImpostor(playerSender))
|
||||||
|
{
|
||||||
msg("You are not an imposter, therefore you do not need to verify.", ChatColor.RED);
|
msg("You are not an imposter, therefore you do not need to verify.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String discordId = "";
|
String discordId = "";
|
||||||
|
|
||||||
if (plugin.al.isAdminImpostor(playerSender)) {
|
if (plugin.al.isAdminImpostor(playerSender))
|
||||||
|
{
|
||||||
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
||||||
if (admin.getDiscordID() == null) {
|
if (admin.getDiscordID() == null)
|
||||||
|
{
|
||||||
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
discordId = admin.getDiscordID();
|
discordId = admin.getDiscordID();
|
||||||
} else {
|
}
|
||||||
if (plugin.pv.isPlayerImpostor(playerSender)) {
|
else
|
||||||
if (plugin.pv.getVerificationPlayer(playerSender).getDiscordID() == null) {
|
{
|
||||||
|
if (plugin.pv.isPlayerImpostor(playerSender))
|
||||||
|
{
|
||||||
|
if (plugin.pv.getVerificationPlayer(playerSender).getDiscordID() == null)
|
||||||
|
{
|
||||||
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -51,27 +60,36 @@ public class Command_verify extends FreedomCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1)
|
||||||
|
{
|
||||||
String code = "";
|
String code = "";
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
code += random.nextInt(10);
|
code += random.nextInt(10);
|
||||||
}
|
}
|
||||||
Discord.VERIFY_CODES.add(code);
|
Discord.VERIFY_CODES.add(code);
|
||||||
Discord.bot.getUserById(discordId).openPrivateChannel().complete().sendMessage("A user with the ip `" + Ips.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete();
|
Discord.bot.getUserById(discordId).openPrivateChannel().complete().sendMessage("A user with the ip `" + Ips.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete();
|
||||||
msg("A verification code has been sent to your account, please copy the code and run /verify <code>", ChatColor.GREEN);
|
msg("A verification code has been sent to your account, please copy the code and run /verify <code>", ChatColor.GREEN);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
String code = args[0];
|
String code = args[0];
|
||||||
if (!Discord.VERIFY_CODES.contains(code)) {
|
if (!Discord.VERIFY_CODES.contains(code))
|
||||||
|
{
|
||||||
msg("You have entered an invalid verification code", ChatColor.RED);
|
msg("You have entered an invalid verification code", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
if (plugin.al.isAdminImpostor(playerSender)) {
|
else
|
||||||
|
{
|
||||||
|
if (plugin.al.isAdminImpostor(playerSender))
|
||||||
|
{
|
||||||
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
||||||
Discord.VERIFY_CODES.remove(code);
|
Discord.VERIFY_CODES.remove(code);
|
||||||
FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD);
|
FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD);
|
||||||
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the admin list", true);
|
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the admin list", true);
|
||||||
if (playerSender != null) {
|
if (playerSender != null)
|
||||||
|
{
|
||||||
admin.setName(playerSender.getName());
|
admin.setName(playerSender.getName());
|
||||||
admin.addIp(Ips.getIp(playerSender));
|
admin.addIp(Ips.getIp(playerSender));
|
||||||
}
|
}
|
||||||
@ -80,14 +98,27 @@ public class Command_verify extends FreedomCommand {
|
|||||||
plugin.al.save();
|
plugin.al.save();
|
||||||
plugin.al.updateTables();
|
plugin.al.updateTables();
|
||||||
plugin.rm.updateDisplay(playerSender);
|
plugin.rm.updateDisplay(playerSender);
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
plugin.rm.updateDisplay(playerSender);
|
||||||
|
}
|
||||||
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
||||||
if (fPlayer.getFreezeData().isFrozen()) {
|
if (fPlayer.getFreezeData().isFrozen())
|
||||||
|
{
|
||||||
fPlayer.getFreezeData().setFrozen(false);
|
fPlayer.getFreezeData().setFrozen(false);
|
||||||
msg("You have been unfrozen.");
|
msg("You have been unfrozen.");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
||||||
if (fPlayer.getFreezeData().isFrozen()) {
|
FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD);
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
plugin.rm.updateDisplay(playerSender);
|
||||||
|
}
|
||||||
|
if (fPlayer.getFreezeData().isFrozen())
|
||||||
|
{
|
||||||
fPlayer.getFreezeData().setFrozen(false);
|
fPlayer.getFreezeData().setFrozen(false);
|
||||||
msg("You have been unfrozen.");
|
msg("You have been unfrozen.");
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public class Command_verifyplayer extends FreedomCommand {
|
|||||||
}
|
}
|
||||||
FUtil.adminAction(sender.getName(), "Manually verifying player " + player.getName(), true);
|
FUtil.adminAction(sender.getName(), "Manually verifying player " + player.getName(), true);
|
||||||
plugin.pv.verifyPlayer(player);
|
plugin.pv.verifyPlayer(player);
|
||||||
|
plugin.rm.updateDisplay(player);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ public class Discord extends FreedomService
|
|||||||
super(plugin);
|
super(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startBot()
|
public void startBot()
|
||||||
{
|
{
|
||||||
enabled = !Strings.isNullOrEmpty(ConfigEntry.DISCORD_TOKEN.getString());
|
enabled = !Strings.isNullOrEmpty(ConfigEntry.DISCORD_TOKEN.getString());
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
{
|
{
|
||||||
@ -40,7 +40,7 @@ public class Discord extends FreedomService
|
|||||||
{
|
{
|
||||||
for (Object object : bot.getRegisteredListeners())
|
for (Object object : bot.getRegisteredListeners())
|
||||||
{
|
{
|
||||||
bot.removeEventListener(object);
|
bot.removeEventListener(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@ -63,10 +63,10 @@ public class Discord extends FreedomService
|
|||||||
{
|
{
|
||||||
startBot();
|
startBot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCodeForAdmin(Admin admin)
|
public static String getCodeForAdmin(Admin admin)
|
||||||
{
|
{
|
||||||
for (String code: LINK_CODES.keySet())
|
for (String code : LINK_CODES.keySet())
|
||||||
{
|
{
|
||||||
if (LINK_CODES.get(code).equals(admin))
|
if (LINK_CODES.get(code).equals(admin))
|
||||||
{
|
{
|
||||||
@ -76,9 +76,12 @@ public class Discord extends FreedomService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCodeForPlayer(VPlayer playerData) {
|
public static String getCodeForPlayer(VPlayer playerData)
|
||||||
for (String code : PLAYER_LINK_CODES.keySet()) {
|
{
|
||||||
if (PLAYER_LINK_CODES.get(code).equals(playerData)) {
|
for (String code : PLAYER_LINK_CODES.keySet())
|
||||||
|
{
|
||||||
|
if (PLAYER_LINK_CODES.get(code).equals(playerData))
|
||||||
|
{
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,19 +12,21 @@ public class MessageListener extends ListenerAdapter
|
|||||||
{
|
{
|
||||||
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()))
|
||||||
{
|
{
|
||||||
|
|
||||||
// Handle link code
|
// Handle link code
|
||||||
if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]"))
|
if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]"))
|
||||||
{
|
{
|
||||||
String code = event.getMessage().getContentRaw();
|
String code = event.getMessage().getContentRaw();
|
||||||
if (Discord.LINK_CODES.get(code) != null) {
|
if (Discord.LINK_CODES.get(code) != null)
|
||||||
|
{
|
||||||
Admin admin = Discord.LINK_CODES.get(code);
|
Admin admin = Discord.LINK_CODES.get(code);
|
||||||
admin.setDiscordID(event.getMessage().getAuthor().getId());
|
admin.setDiscordID(event.getMessage().getAuthor().getId());
|
||||||
Discord.LINK_CODES.remove(code);
|
Discord.LINK_CODES.remove(code);
|
||||||
event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + admin.getName() + "`.\n "
|
event.getChannel().sendMessage("Link successful. Now this Discord account is linked with the Minecraft account `" + admin.getName() + "`.\n "
|
||||||
+ "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();
|
+ "Now when you are an impostor on the server, you may use `/verify` to verify.").complete();
|
||||||
}
|
}
|
||||||
if (Discord.PLAYER_LINK_CODES.get(code) != null) {
|
if (Discord.PLAYER_LINK_CODES.get(code) != null)
|
||||||
|
{
|
||||||
VPlayer player = Discord.PLAYER_LINK_CODES.get(code);
|
VPlayer player = Discord.PLAYER_LINK_CODES.get(code);
|
||||||
player.setDiscordID(event.getMessage().getAuthor().getId());
|
player.setDiscordID(event.getMessage().getAuthor().getId());
|
||||||
|
|
||||||
|
@ -16,43 +16,52 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlayerVerification extends FreedomService {
|
public class PlayerVerification extends FreedomService
|
||||||
|
{
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public final Map<String, VPlayer> dataMap = Maps.newHashMap(); // username, data
|
public final Map<String, VPlayer> dataMap = Maps.newHashMap(); // username, data
|
||||||
private File configFolder;
|
private File configFolder;
|
||||||
|
|
||||||
public PlayerVerification(TotalFreedomMod plugin) {
|
public PlayerVerification(TotalFreedomMod plugin)
|
||||||
|
{
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.configFolder = new File(plugin.getDataFolder(), "playerverification");
|
this.configFolder = new File(plugin.getDataFolder(), "playerverification");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart()
|
||||||
|
{
|
||||||
dataMap.clear();
|
dataMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(VPlayer data) {
|
public void save(VPlayer data)
|
||||||
|
{
|
||||||
YamlConfig config = getConfig(data);
|
YamlConfig config = getConfig(data);
|
||||||
data.saveTo(config);
|
data.saveTo(config);
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop()
|
||||||
|
{
|
||||||
//save all (should be saved in theory but to be safe)
|
//save all (should be saved in theory but to be safe)
|
||||||
for (VPlayer player : dataMap.values()) {
|
for (VPlayer player : dataMap.values())
|
||||||
|
{
|
||||||
save(player);
|
save(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isPlayerImpostor(Player player) {
|
public Boolean isPlayerImpostor(Player player)
|
||||||
|
{
|
||||||
VPlayer vplayer = getVerificationPlayer(player.getName());
|
VPlayer vplayer = getVerificationPlayer(player.getName());
|
||||||
return !plugin.al.isAdmin(player) && vplayer != null && (vplayer.getForumVerificationEnabled() || vplayer.getDiscordVerificationEnabled()) && !vplayer.getIPs().contains(Ips.getIp(player));
|
return !plugin.al.isAdmin(player) && vplayer != null && (vplayer.getForumVerificationEnabled() || vplayer.getDiscordVerificationEnabled()) && !vplayer.getIPs().contains(Ips.getIp(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifyPlayer(Player player) {
|
public void verifyPlayer(Player player)
|
||||||
if (!isPlayerImpostor(player)) {
|
{
|
||||||
|
if (!isPlayerImpostor(player))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VPlayer vplayer = getVerificationPlayer(player.getName());
|
VPlayer vplayer = getVerificationPlayer(player.getName());
|
||||||
@ -60,8 +69,10 @@ public class PlayerVerification extends FreedomService {
|
|||||||
saveVerificationData(vplayer);
|
saveVerificationData(vplayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveVerificationData(VPlayer player) {
|
public void saveVerificationData(VPlayer player)
|
||||||
if (dataMap.containsKey(player.getName())) {
|
{
|
||||||
|
if (dataMap.containsKey(player.getName()))
|
||||||
|
{
|
||||||
dataMap.remove(player.getName());
|
dataMap.remove(player.getName());
|
||||||
}
|
}
|
||||||
dataMap.put(player.getName(), player);
|
dataMap.put(player.getName(), player);
|
||||||
@ -69,9 +80,11 @@ public class PlayerVerification extends FreedomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//may not return null
|
//may not return null
|
||||||
public VPlayer getVerificationPlayer(Player player) {
|
public VPlayer getVerificationPlayer(Player player)
|
||||||
|
{
|
||||||
VPlayer data = getVerificationPlayer(player.getName());
|
VPlayer data = getVerificationPlayer(player.getName());
|
||||||
if (data != null) {
|
if (data != null)
|
||||||
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
// Create new entry.
|
// Create new entry.
|
||||||
@ -85,28 +98,34 @@ public class PlayerVerification extends FreedomService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//may return null
|
//may return null
|
||||||
public VPlayer getVerificationPlayer(String username) {
|
public VPlayer getVerificationPlayer(String username)
|
||||||
if (dataMap.containsKey(username)) {
|
{
|
||||||
|
if (dataMap.containsKey(username))
|
||||||
|
{
|
||||||
return dataMap.get(username);
|
return dataMap.get(username);
|
||||||
}
|
}
|
||||||
VPlayer player = loadData(username);
|
VPlayer player = loadData(username);
|
||||||
if (player != null) {
|
if (player != null)
|
||||||
|
{
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VPlayer loadData(String username) {
|
public VPlayer loadData(String username)
|
||||||
|
{
|
||||||
final File configFile = getConfigFile(username);
|
final File configFile = getConfigFile(username);
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists())
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final VPlayer data = new VPlayer(username);
|
final VPlayer data = new VPlayer(username);
|
||||||
data.loadFrom(getConfig(data));
|
data.loadFrom(getConfig(data));
|
||||||
|
|
||||||
if (!data.isValid()) {
|
if (!data.isValid())
|
||||||
|
{
|
||||||
FLog.warning("Could not load player verification entry: " + username + ". Entry is not valid!");
|
FLog.warning("Could not load player verification entry: " + username + ". Entry is not valid!");
|
||||||
configFile.delete();
|
configFile.delete();
|
||||||
return null;
|
return null;
|
||||||
@ -114,8 +133,10 @@ public class PlayerVerification extends FreedomService {
|
|||||||
|
|
||||||
|
|
||||||
// Only store data in map if the player is online
|
// Only store data in map if the player is online
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||||
if (onlinePlayer.getName().equals(username)) {
|
{
|
||||||
|
if (onlinePlayer.getName().equals(username))
|
||||||
|
{
|
||||||
dataMap.put(username, data);
|
dataMap.put(username, data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -123,28 +144,35 @@ public class PlayerVerification extends FreedomService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeEntry(String username) {
|
public void removeEntry(String username)
|
||||||
if (getVerificationPlayer(username) != null) {
|
{
|
||||||
|
if (getVerificationPlayer(username) != null)
|
||||||
|
{
|
||||||
getConfigFile(username).delete();
|
getConfigFile(username).delete();
|
||||||
if (dataMap.containsKey(username)) {
|
if (dataMap.containsKey(username))
|
||||||
|
{
|
||||||
dataMap.remove(username);
|
dataMap.remove(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event)
|
||||||
if (dataMap.containsKey(event.getPlayer().getName())) {
|
{
|
||||||
|
if (dataMap.containsKey(event.getPlayer().getName()))
|
||||||
|
{
|
||||||
saveVerificationData(dataMap.get(event.getPlayer().getName()));
|
saveVerificationData(dataMap.get(event.getPlayer().getName()));
|
||||||
dataMap.remove(event.getPlayer().getName());
|
dataMap.remove(event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File getConfigFile(String name) {
|
protected File getConfigFile(String name)
|
||||||
|
{
|
||||||
return new File(configFolder, name + ".yml");
|
return new File(configFolder, name + ".yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected YamlConfig getConfig(VPlayer data) {
|
protected YamlConfig getConfig(VPlayer data)
|
||||||
|
{
|
||||||
final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getName().toLowerCase()), false);
|
final YamlConfig config = new YamlConfig(plugin, getConfigFile(data.getName().toLowerCase()), false);
|
||||||
config.load();
|
config.load();
|
||||||
return config;
|
return config;
|
||||||
|
@ -13,7 +13,8 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
|
public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
|
||||||
|
{
|
||||||
|
|
||||||
private final List<String> ips = Lists.newArrayList();
|
private final List<String> ips = Lists.newArrayList();
|
||||||
@Getter
|
@Getter
|
||||||
@ -33,18 +34,21 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
|
|||||||
private Boolean forumVerificationEnabled = false;
|
private Boolean forumVerificationEnabled = false;
|
||||||
|
|
||||||
|
|
||||||
public VPlayer(String username) {
|
public VPlayer(String username)
|
||||||
|
{
|
||||||
this.name = username;
|
this.name = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFrom(Player player) {
|
public void loadFrom(Player player)
|
||||||
|
{
|
||||||
name = player.getName();
|
name = player.getName();
|
||||||
ips.clear();
|
ips.clear();
|
||||||
ips.add(Ips.getIp(player));
|
ips.add(Ips.getIp(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFrom(ConfigurationSection cs) {
|
public void loadFrom(ConfigurationSection cs)
|
||||||
|
{
|
||||||
name = cs.getString("username", null);
|
name = cs.getString("username", null);
|
||||||
ips.clear();
|
ips.clear();
|
||||||
ips.addAll(cs.getStringList("ips"));
|
ips.addAll(cs.getStringList("ips"));
|
||||||
@ -55,7 +59,8 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveTo(ConfigurationSection cs) {
|
public void saveTo(ConfigurationSection cs)
|
||||||
|
{
|
||||||
Validate.isTrue(isValid(), "Could not save player veirfication entry: " + name + ". Entry not valid!");
|
Validate.isTrue(isValid(), "Could not save player veirfication entry: " + name + ". Entry not valid!");
|
||||||
cs.set("username", name);
|
cs.set("username", name);
|
||||||
cs.set("forum_username", forumUsername);
|
cs.set("forum_username", forumUsername);
|
||||||
@ -66,68 +71,85 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Util IP methods
|
// Util IP methods
|
||||||
public void addIp(String ip) {
|
public void addIp(String ip)
|
||||||
if (!ips.contains(ip)) {
|
{
|
||||||
|
if (!ips.contains(ip))
|
||||||
|
{
|
||||||
ips.add(ip);
|
ips.add(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIps(List<String> ips) {
|
public void addIps(List<String> ips)
|
||||||
for (String ip : ips) {
|
{
|
||||||
|
for (String ip : ips)
|
||||||
|
{
|
||||||
addIp(ip);
|
addIp(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeIp(String ip) {
|
public void removeIp(String ip)
|
||||||
if (ips.contains(ip)) {
|
{
|
||||||
|
if (ips.contains(ip))
|
||||||
|
{
|
||||||
ips.remove(ip);
|
ips.remove(ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getIPs() {
|
public List<String> getIPs()
|
||||||
|
{
|
||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearIPs() {
|
public void clearIPs()
|
||||||
|
{
|
||||||
ips.clear();
|
ips.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isDiscordVerificationEnabled() {
|
public Boolean isDiscordVerificationEnabled()
|
||||||
|
{
|
||||||
return discordVerificationEnabled;
|
return discordVerificationEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isForumVerificationEnabled() {
|
public Boolean isForumVerificationEnabled()
|
||||||
|
{
|
||||||
return forumVerificationEnabled;
|
return forumVerificationEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiscordVerificationEnabled(boolean enabled) {
|
public void setDiscordVerificationEnabled(boolean enabled)
|
||||||
|
{
|
||||||
this.discordVerificationEnabled = enabled;
|
this.discordVerificationEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForumVerificationEnabled(boolean enabled) {
|
public void setForumVerificationEnabled(boolean enabled)
|
||||||
|
{
|
||||||
this.forumVerificationEnabled = enabled;
|
this.forumVerificationEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDiscordID() {
|
public String getDiscordID()
|
||||||
|
{
|
||||||
return discordID;
|
return discordID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDiscordID(String discordID) {
|
public void setDiscordID(String discordID)
|
||||||
|
{
|
||||||
this.discordID = discordID;
|
this.discordID = discordID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getForumUsername() {
|
public String getForumUsername()
|
||||||
|
{
|
||||||
return forumUsername;
|
return forumUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForumUsername(String forumUsername) {
|
public void setForumUsername(String forumUsername)
|
||||||
|
{
|
||||||
this.forumUsername = forumUsername;
|
this.forumUsername = forumUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid() {
|
public boolean isValid()
|
||||||
|
{
|
||||||
return name != null
|
return name != null
|
||||||
&& !ips.isEmpty();
|
&& !ips.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,8 @@ public class RankManager extends FreedomService
|
|||||||
if (isImposter)
|
if (isImposter)
|
||||||
{
|
{
|
||||||
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + Rank.IMPOSTOR.getColoredLoginMessage());
|
FUtil.bcastMsg(ChatColor.AQUA + player.getName() + " is " + Rank.IMPOSTOR.getColoredLoginMessage());
|
||||||
if (plugin.al.isAdminImpostor(player)) {
|
if (plugin.al.isAdminImpostor(player))
|
||||||
|
{
|
||||||
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as an impostor and has been frozen!", ChatColor.RED);
|
FUtil.bcastMsg("Warning: " + player.getName() + " has been flagged as an impostor and has been frozen!", ChatColor.RED);
|
||||||
}
|
}
|
||||||
String displayName = Rank.IMPOSTOR.getColor() + player.getName();
|
String displayName = Rank.IMPOSTOR.getColor() + player.getName();
|
||||||
|
Loading…
Reference in New Issue
Block a user