Tested to be working, but made some minor changes.

This commit is contained in:
ZeroEpoch1969 2018-03-24 18:41:51 -07:00
parent 01223d44ef
commit 88f89d7e67
No known key found for this signature in database
GPG Key ID: E0AAB104FB9F8FDF
8 changed files with 201 additions and 100 deletions

View File

@ -9,33 +9,41 @@ 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 {
@CommandParameters(description = "Manage your verification", usage = "/<command> <enable | disable | clearips | status> <discord | forum>", aliases = "playerverification,pv")
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) {
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)) {
if (plugin.al.isAdmin(sender))
{
msg("This command is only for OP's.", ChatColor.RED);
return true;
}
switch (args[0].toLowerCase()) {
switch (args[0].toLowerCase())
{
case "enable":
switch (args[1].toLowerCase()) {
switch (args[1].toLowerCase())
{
case "discord":
if (!plugin.dc.enabled) {
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()) {
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);
msg("Enabled discord verification. Please type /linkdiscord to link a discord account.", ChatColor.GREEN);
return true;
case "forum":
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;
}
case "disable":
switch (args[1].toLowerCase()) {
switch (args[1].toLowerCase())
{
case "discord":
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
if (!data.isDiscordVerificationEnabled()) {
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);
msg("Disabled discord verification.", ChatColor.GREEN);
return true;
case "forum":
msg("TODO. Forum verification will be enabled in a later update.");
@ -62,13 +72,14 @@ public class Command_playerverify extends FreedomCommand {
return false;
}
case "status":
switch (args[1].toLowerCase()) {
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"));
msg(ChatColor.GRAY + "Discord Verification Enabled: " + (enabled ? ChatColor.GREEN + "true" : ChatColor.RED + "false"));
msg(ChatColor.GRAY + "Discord ID: " + (specified ? ChatColor.GREEN + data.getDiscordID() : ChatColor.RED + "not set"));
return true;
case "forum":
msg("TODO. Forum verification will be enabled in a later update.");
@ -79,8 +90,10 @@ public class Command_playerverify extends FreedomCommand {
case "clearips":
VPlayer data = plugin.pv.getVerificationPlayer(playerSender);
int cleared = 0;
for (String ip : data.getIPs()) {
if (!ip.equals(Ips.getIp(playerSender))) {
for (String ip : data.getIPs())
{
if (!ip.equals(Ips.getIp(playerSender)))
{
data.removeIp(ip);
cleared++;
}

View File

@ -11,39 +11,48 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Date;
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) {
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);
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);
return true;
}
String discordId = "";
if (plugin.al.isAdminImpostor(playerSender)) {
if (plugin.al.isAdminImpostor(playerSender))
{
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);
return true;
}
discordId = admin.getDiscordID();
} else {
if (plugin.pv.isPlayerImpostor(playerSender)) {
if (plugin.pv.getVerificationPlayer(playerSender).getDiscordID() == null) {
}
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;
}
@ -51,27 +60,36 @@ public class Command_verify extends FreedomCommand {
}
}
if (args.length < 1) {
if (args.length < 1)
{
String code = "";
Random random = new Random();
for (int i = 0; i < 10; i++) {
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 {
}
else
{
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);
return true;
} else {
if (plugin.al.isAdminImpostor(playerSender)) {
}
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) {
if (playerSender != null)
{
admin.setName(playerSender.getName());
admin.addIp(Ips.getIp(playerSender));
}
@ -80,14 +98,27 @@ public class Command_verify extends FreedomCommand {
plugin.al.save();
plugin.al.updateTables();
plugin.rm.updateDisplay(playerSender);
if (playerSender != null)
{
plugin.rm.updateDisplay(playerSender);
}
final FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
if (fPlayer.getFreezeData().isFrozen()) {
if (fPlayer.getFreezeData().isFrozen())
{
fPlayer.getFreezeData().setFrozen(false);
msg("You have been unfrozen.");
}
} else {
}
else
{
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);
msg("You have been unfrozen.");
}

View File

@ -27,6 +27,7 @@ public class Command_verifyplayer extends FreedomCommand {
}
FUtil.adminAction(sender.getName(), "Manually verifying player " + player.getName(), true);
plugin.pv.verifyPlayer(player);
plugin.rm.updateDisplay(player);
return true;
}

View File

@ -66,7 +66,7 @@ public class Discord extends FreedomService
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))
{
@ -76,9 +76,12 @@ public class Discord extends FreedomService
return null;
}
public static String getCodeForPlayer(VPlayer playerData) {
for (String code : PLAYER_LINK_CODES.keySet()) {
if (PLAYER_LINK_CODES.get(code).equals(playerData)) {
public static String getCodeForPlayer(VPlayer playerData)
{
for (String code : PLAYER_LINK_CODES.keySet())
{
if (PLAYER_LINK_CODES.get(code).equals(playerData))
{
return code;
}
}

View File

@ -17,14 +17,16 @@ public class MessageListener extends ListenerAdapter
if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]"))
{
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.setDiscordID(event.getMessage().getAuthor().getId());
Discord.LINK_CODES.remove(code);
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();
}
if (Discord.PLAYER_LINK_CODES.get(code) != null) {
if (Discord.PLAYER_LINK_CODES.get(code) != null)
{
VPlayer player = Discord.PLAYER_LINK_CODES.get(code);
player.setDiscordID(event.getMessage().getAuthor().getId());

View File

@ -16,43 +16,52 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.io.File;
import java.util.Map;
public class PlayerVerification extends FreedomService {
public class PlayerVerification extends FreedomService
{
@Getter
public final Map<String, VPlayer> dataMap = Maps.newHashMap(); // username, data
private File configFolder;
public PlayerVerification(TotalFreedomMod plugin) {
public PlayerVerification(TotalFreedomMod plugin)
{
super(plugin);
this.configFolder = new File(plugin.getDataFolder(), "playerverification");
}
@Override
protected void onStart() {
protected void onStart()
{
dataMap.clear();
}
public void save(VPlayer data) {
public void save(VPlayer data)
{
YamlConfig config = getConfig(data);
data.saveTo(config);
config.save();
}
@Override
protected void onStop() {
protected void onStop()
{
//save all (should be saved in theory but to be safe)
for (VPlayer player : dataMap.values()) {
for (VPlayer player : dataMap.values())
{
save(player);
}
}
public Boolean isPlayerImpostor(Player player) {
public Boolean isPlayerImpostor(Player player)
{
VPlayer vplayer = getVerificationPlayer(player.getName());
return !plugin.al.isAdmin(player) && vplayer != null && (vplayer.getForumVerificationEnabled() || vplayer.getDiscordVerificationEnabled()) && !vplayer.getIPs().contains(Ips.getIp(player));
}
public void verifyPlayer(Player player) {
if (!isPlayerImpostor(player)) {
public void verifyPlayer(Player player)
{
if (!isPlayerImpostor(player))
{
return;
}
VPlayer vplayer = getVerificationPlayer(player.getName());
@ -60,8 +69,10 @@ public class PlayerVerification extends FreedomService {
saveVerificationData(vplayer);
}
public void saveVerificationData(VPlayer player) {
if (dataMap.containsKey(player.getName())) {
public void saveVerificationData(VPlayer player)
{
if (dataMap.containsKey(player.getName()))
{
dataMap.remove(player.getName());
}
dataMap.put(player.getName(), player);
@ -69,9 +80,11 @@ public class PlayerVerification extends FreedomService {
}
//may not return null
public VPlayer getVerificationPlayer(Player player) {
public VPlayer getVerificationPlayer(Player player)
{
VPlayer data = getVerificationPlayer(player.getName());
if (data != null) {
if (data != null)
{
return data;
}
// Create new entry.
@ -85,28 +98,34 @@ public class PlayerVerification extends FreedomService {
}
//may return null
public VPlayer getVerificationPlayer(String username) {
if (dataMap.containsKey(username)) {
public VPlayer getVerificationPlayer(String username)
{
if (dataMap.containsKey(username))
{
return dataMap.get(username);
}
VPlayer player = loadData(username);
if (player != null) {
if (player != null)
{
return player;
}
return null;
}
public VPlayer loadData(String username) {
public VPlayer loadData(String username)
{
final File configFile = getConfigFile(username);
if (!configFile.exists()) {
if (!configFile.exists())
{
return null;
}
final VPlayer data = new VPlayer(username);
data.loadFrom(getConfig(data));
if (!data.isValid()) {
if (!data.isValid())
{
FLog.warning("Could not load player verification entry: " + username + ". Entry is not valid!");
configFile.delete();
return null;
@ -114,8 +133,10 @@ public class PlayerVerification extends FreedomService {
// Only store data in map if the player is online
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.getName().equals(username)) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
{
if (onlinePlayer.getName().equals(username))
{
dataMap.put(username, data);
return data;
}
@ -123,28 +144,35 @@ public class PlayerVerification extends FreedomService {
return data;
}
public void removeEntry(String username) {
if (getVerificationPlayer(username) != null) {
public void removeEntry(String username)
{
if (getVerificationPlayer(username) != null)
{
getConfigFile(username).delete();
if (dataMap.containsKey(username)) {
if (dataMap.containsKey(username))
{
dataMap.remove(username);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
if (dataMap.containsKey(event.getPlayer().getName())) {
public void onPlayerQuit(PlayerQuitEvent event)
{
if (dataMap.containsKey(event.getPlayer().getName()))
{
saveVerificationData(dataMap.get(event.getPlayer().getName()));
dataMap.remove(event.getPlayer().getName());
}
}
protected File getConfigFile(String name) {
protected File getConfigFile(String name)
{
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);
config.load();
return config;

View File

@ -13,7 +13,8 @@ import org.bukkit.entity.Player;
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();
@Getter
@ -33,18 +34,21 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
private Boolean forumVerificationEnabled = false;
public VPlayer(String username) {
public VPlayer(String username)
{
this.name = username;
}
public void loadFrom(Player player) {
public void loadFrom(Player player)
{
name = player.getName();
ips.clear();
ips.add(Ips.getIp(player));
}
@Override
public void loadFrom(ConfigurationSection cs) {
public void loadFrom(ConfigurationSection cs)
{
name = cs.getString("username", null);
ips.clear();
ips.addAll(cs.getStringList("ips"));
@ -55,7 +59,8 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
}
@Override
public void saveTo(ConfigurationSection cs) {
public void saveTo(ConfigurationSection cs)
{
Validate.isTrue(isValid(), "Could not save player veirfication entry: " + name + ". Entry not valid!");
cs.set("username", name);
cs.set("forum_username", forumUsername);
@ -66,68 +71,85 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable {
}
// Util IP methods
public void addIp(String ip) {
if (!ips.contains(ip)) {
public void addIp(String ip)
{
if (!ips.contains(ip))
{
ips.add(ip);
}
}
public void addIps(List<String> ips) {
for (String ip : ips) {
public void addIps(List<String> ips)
{
for (String ip : ips)
{
addIp(ip);
}
}
public void removeIp(String ip) {
if (ips.contains(ip)) {
public void removeIp(String ip)
{
if (ips.contains(ip))
{
ips.remove(ip);
}
}
public List<String> getIPs() {
public List<String> getIPs()
{
return ips;
}
public void clearIPs() {
public void clearIPs()
{
ips.clear();
}
public Boolean isDiscordVerificationEnabled() {
public Boolean isDiscordVerificationEnabled()
{
return discordVerificationEnabled;
}
public Boolean isForumVerificationEnabled() {
public Boolean isForumVerificationEnabled()
{
return forumVerificationEnabled;
}
public void setDiscordVerificationEnabled(boolean enabled) {
public void setDiscordVerificationEnabled(boolean enabled)
{
this.discordVerificationEnabled = enabled;
}
public void setForumVerificationEnabled(boolean enabled) {
public void setForumVerificationEnabled(boolean enabled)
{
this.forumVerificationEnabled = enabled;
}
public String getDiscordID() {
public String getDiscordID()
{
return discordID;
}
public void setDiscordID(String discordID) {
public void setDiscordID(String discordID)
{
this.discordID = discordID;
}
public String getForumUsername() {
public String getForumUsername()
{
return forumUsername;
}
public void setForumUsername(String forumUsername) {
public void setForumUsername(String forumUsername)
{
this.forumUsername = forumUsername;
}
@Override
public boolean isValid() {
public boolean isValid()
{
return name != null
&& !ips.isEmpty();
}

View File

@ -162,7 +162,8 @@ public class RankManager extends FreedomService
if (isImposter)
{
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);
}
String displayName = Rank.IMPOSTOR.getColor() + player.getName();