mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-11 13:33:54 +00:00
[UNTESTED] implement player verification system
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.discord.Discord;
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Link your discord account to your minecraft account", usage = "/<command>")
|
||||
public class Command_linkdiscord extends FreedomCommand
|
||||
{
|
||||
@ -21,28 +24,45 @@ public class Command_linkdiscord extends FreedomCommand
|
||||
msg("The discord verification system is currently disabled.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
Admin admin = plugin.al.getAdmin(playerSender);
|
||||
if (admin.getDiscordID() != null)
|
||||
{
|
||||
msg("Your minecraft account is already linked to a discord account.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.dc.LINK_CODES.containsValue(admin))
|
||||
{
|
||||
msg("Your linking code is " + ChatColor.GREEN + plugin.dc.getCodeForAdmin(admin), ChatColor.AQUA);
|
||||
|
||||
if (plugin.al.isAdmin(playerSender)) {
|
||||
Admin admin = plugin.al.getAdmin(playerSender);
|
||||
if (admin.getDiscordID() != null) {
|
||||
msg("Your minecraft account is already linked to a discord account.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Discord.LINK_CODES.containsValue(admin)) {
|
||||
msg("Your linking code is " + ChatColor.GREEN + Discord.getCodeForAdmin(admin), ChatColor.AQUA);
|
||||
} else {
|
||||
String code = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
code += random.nextInt(10);
|
||||
}
|
||||
Discord.LINK_CODES.put(code, admin);
|
||||
msg("Your linking code is " + ChatColor.GREEN + code, ChatColor.AQUA);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String code = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
code += random.nextInt(10);
|
||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||
if (data.getDiscordID() != null) {
|
||||
msg("Your minecraft account is already linked to a discord account.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Discord.PLAYER_LINK_CODES.containsValue(data)) {
|
||||
msg("Your linking code is " + ChatColor.GREEN + Discord.getCodeForPlayer(data), ChatColor.AQUA);
|
||||
} else {
|
||||
String code = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
code += random.nextInt(10);
|
||||
}
|
||||
Discord.PLAYER_LINK_CODES.put(code, data);
|
||||
msg("Your linking code is " + ChatColor.GREEN + code, ChatColor.AQUA);
|
||||
}
|
||||
plugin.dc.LINK_CODES.put(code, admin);
|
||||
msg("Your linking code is " + ChatColor.GREEN + code, ChatColor.AQUA);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@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")
|
||||
public class Command_playerverify extends FreedomCommand {
|
||||
@Override
|
||||
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.al.isAdmin(sender)) {
|
||||
msg("This command is only for OP's.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "enable":
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "discord":
|
||||
if (!plugin.dc.enabled) {
|
||||
msg("The discord verification system is currently disabled.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||
if (data.isDiscordVerificationEnabled()) {
|
||||
msg("Discord verification is already enabled for you.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
data.setDiscordVerificationEnabled(true);
|
||||
plugin.pv.saveVerificationData(data);
|
||||
msg("Enabled discord verification. Please type /linkdiscord to link a discord account.", ChatColor.AQUA);
|
||||
return true;
|
||||
case "forum":
|
||||
msg("TODO. This will be enabled in a later update. Please use discord verification instead.");
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case "disable":
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "discord":
|
||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||
if (!data.isDiscordVerificationEnabled()) {
|
||||
msg("Discord verification is already disabled for you.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
data.setDiscordVerificationEnabled(false);
|
||||
plugin.pv.saveVerificationData(data);
|
||||
msg("Disabled discord verification.", ChatColor.AQUA);
|
||||
return true;
|
||||
case "forum":
|
||||
msg("TODO. Forum verification will be enabled in a later update.");
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case "status":
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "discord":
|
||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||
boolean enabled = data.isDiscordVerificationEnabled();
|
||||
boolean specified = data.getDiscordID() != null;
|
||||
msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.AQUA + "true" : ChatColor.RED + "false"));
|
||||
msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.AQUA + data.getDiscordID() : ChatColor.RED + "not set"));
|
||||
return true;
|
||||
case "forum":
|
||||
msg("TODO. Forum verification will be enabled in a later update.");
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case "clearips":
|
||||
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
|
||||
int cleared = 0;
|
||||
for (String ip : data.getIPs()) {
|
||||
if (!ip.equals(Ips.getIp(playerSender))) {
|
||||
data.removeIp(ip);
|
||||
cleared++;
|
||||
}
|
||||
}
|
||||
msg("Cleared all IP's except your current IP \"" + Ips.getIp(playerSender) + "\"");
|
||||
msg("Cleared " + cleared + " IP's.");
|
||||
plugin.pv.saveVerificationData(data);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Date;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
@ -12,6 +11,8 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manage admins.", usage = "/<command> <list | clean | reload | | setrank <username> <rank> | <add | remove | info> <username>>")
|
||||
public class Command_saconfig extends FreedomCommand
|
||||
@ -220,8 +221,8 @@ public class Command_saconfig extends FreedomCommand
|
||||
player.setOp(true);
|
||||
player.sendMessage(YOU_ARE_OP);
|
||||
}
|
||||
plugin.pv.removeEntry(player.getName()); // admins can't have player verification entries
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,88 +1,100 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.discord.Discord;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import java.util.Random;
|
||||
|
||||
import java.util.Date;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import java.util.Random;
|
||||
|
||||
@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]")
|
||||
public class Command_verify extends FreedomCommand
|
||||
{
|
||||
public class Command_verify extends FreedomCommand {
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (!plugin.dc.enabled)
|
||||
{
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
|
||||
if (!plugin.dc.enabled) {
|
||||
msg("The discord verification system is currently disabled", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdminImpostor(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);
|
||||
return true;
|
||||
}
|
||||
|
||||
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
||||
|
||||
if (admin.getDiscordID() == null)
|
||||
{
|
||||
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
String code = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
code += random.nextInt(10);
|
||||
}
|
||||
plugin.dc.VERIFY_CODES.add(code);
|
||||
plugin.dc.bot.getUserById(admin.getDiscordID()).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);
|
||||
}
|
||||
else
|
||||
{
|
||||
String code = args[0];
|
||||
if (!plugin.dc.VERIFY_CODES.contains(code))
|
||||
{
|
||||
msg("You have entered an invalid verification code", ChatColor.RED);
|
||||
|
||||
String discordId = "";
|
||||
|
||||
if (plugin.al.isAdminImpostor(playerSender)) {
|
||||
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
||||
if (admin.getDiscordID() == null) {
|
||||
msg("You do not have a discord account linked to your minecraft account, please verify the manual way.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.dc.VERIFY_CODES.remove(code);
|
||||
FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD);
|
||||
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the admin list", true);
|
||||
if (playerSender != null)
|
||||
{
|
||||
admin.setName(playerSender.getName());
|
||||
admin.addIp(Ips.getIp(playerSender));
|
||||
discordId = admin.getDiscordID();
|
||||
} else {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
admin.setActive(true);
|
||||
admin.setLastLogin(new Date());
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
plugin.rm.updateDisplay(playerSender);
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
||||
if (fPlayer.getFreezeData().isFrozen())
|
||||
{
|
||||
fPlayer.getFreezeData().setFrozen(false);
|
||||
msg("You have been unfrozen.");
|
||||
discordId = plugin.pv.getVerificationPlayer(playerSender).getDiscordID();
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
String code = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
code += random.nextInt(10);
|
||||
}
|
||||
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();
|
||||
msg("A verification code has been sent to your account, please copy the code and run /verify <code>", ChatColor.GREEN);
|
||||
} else {
|
||||
String code = args[0];
|
||||
if (!Discord.VERIFY_CODES.contains(code)) {
|
||||
msg("You have entered an invalid verification code", ChatColor.RED);
|
||||
return true;
|
||||
} else {
|
||||
if (plugin.al.isAdminImpostor(playerSender)) {
|
||||
Admin admin = plugin.al.getEntryByName(playerSender.getName());
|
||||
Discord.VERIFY_CODES.remove(code);
|
||||
FUtil.bcastMsg(playerSender.getName() + " has verified themself!", ChatColor.GOLD);
|
||||
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Readding " + admin.getName() + " to the admin list", true);
|
||||
if (playerSender != null) {
|
||||
admin.setName(playerSender.getName());
|
||||
admin.addIp(Ips.getIp(playerSender));
|
||||
}
|
||||
admin.setActive(true);
|
||||
admin.setLastLogin(new Date());
|
||||
plugin.al.save();
|
||||
plugin.al.updateTables();
|
||||
plugin.rm.updateDisplay(playerSender);
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
||||
if (fPlayer.getFreezeData().isFrozen()) {
|
||||
fPlayer.getFreezeData().setFrozen(false);
|
||||
msg("You have been unfrozen.");
|
||||
}
|
||||
} else {
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
|
||||
if (fPlayer.getFreezeData().isFrozen()) {
|
||||
fPlayer.getFreezeData().setFrozen(false);
|
||||
msg("You have been unfrozen.");
|
||||
}
|
||||
plugin.pv.verifyPlayer(playerSender);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Manually verifies a player", usage = "/<command> <partialname>")
|
||||
public class Command_verifyplayer extends FreedomCommand {
|
||||
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
final Player player = getPlayer(args[0]);
|
||||
if (player == null) {
|
||||
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
if (!plugin.pv.isPlayerImpostor(player)) {
|
||||
msg("That player is not an impostor.");
|
||||
return true;
|
||||
}
|
||||
FUtil.adminAction(sender.getName(), "Manually verifying player " + player.getName(), true);
|
||||
plugin.pv.verifyPlayer(player);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user