Require confirmation for significant actions

- Users will now be required to repeat the command when disbanding, leaving, kicking a player from, or transferring ownership within a guild.
This commit is contained in:
FTTT 2021-11-07 01:50:13 -07:00
parent 3a8691b18b
commit 196689db62
6 changed files with 122 additions and 20 deletions

View file

@ -13,8 +13,9 @@ public class Common
public static final String IN_GUILD = PREFIX + "You are already in a guild."; public static final String IN_GUILD = PREFIX + "You are already in a guild.";
public static final String PLAYER_NOT_FOUND = PREFIX + "That player is not online."; public static final String PLAYER_NOT_FOUND = PREFIX + "That player is not online.";
public static final String PLAYER_NOT_IN_GUILD = PREFIX + "That player is not in your guild."; public static final String PLAYER_NOT_IN_GUILD = PREFIX + "That player is not in your guild.";
public static final String IN_GAME_ONLY = PREFIX + "You must be in-game to interact with guilds"; public static final String IN_GAME_ONLY = PREFIX + "You must be in-game to interact with guilds.";
public static final String USAGE = PREFIX + "Correct usage: " + ChatColor.GOLD; public static final String USAGE = PREFIX + "Usage: " + ChatColor.GOLD;
public static final String WARN = PREFIX + ChatColor.RED + "Warning: " + ChatColor.GRAY;
public static final TFMBridge tfmBridge = TFGuilds.getPlugin().getTfmBridge(); public static final TFMBridge tfmBridge = TFGuilds.getPlugin().getTfmBridge();

View file

@ -22,7 +22,7 @@ public class TFGuilds extends JavaPlugin
private Config config; private Config config;
private SQLDatabase sqlDatabase; private SQLDatabase sqlDatabase;
private TFMBridge tfmBridge; private TFMBridge tfmBridge;
private Map<String, SubCommand> subCommands = new HashMap<>(); private final Map<String, SubCommand> subCommands = new HashMap<>();
public static TFGuilds getPlugin() public static TFGuilds getPlugin()
{ {
@ -32,7 +32,7 @@ public class TFGuilds extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
this.plugin = this; plugin = this;
config = new Config("config.yml"); config = new Config("config.yml");
sqlDatabase = new SQLDatabase(this); sqlDatabase = new SQLDatabase(this);
User.loadAll(); User.loadAll();

View file

@ -1,16 +1,21 @@
package me.totalfreedom.tfguilds.command; package me.totalfreedom.tfguilds.command;
import java.util.HashMap;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class DisbandSubCommand extends Common implements SubCommand public class DisbandSubCommand extends Common implements SubCommand
{ {
private final HashMap<CommandSender, Boolean> confirm = new HashMap<>();
@Override @Override
public void execute(CommandSender sender, Player playerSender, String[] args) public void execute(CommandSender sender, Player playerSender, String[] args)
{ {
@ -35,9 +40,7 @@ public class DisbandSubCommand extends Common implements SubCommand
return; return;
} }
guild.disband(); disband(sender, guild);
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
return; return;
} }
@ -54,8 +57,31 @@ public class DisbandSubCommand extends Common implements SubCommand
return; return;
} }
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded."); disband(sender, guild);
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName()); }
guild.disband(); private void disband(CommandSender sender, Guild guild)
{
if (!confirm.containsKey(sender))
{
sender.sendMessage(WARN + "Are you sure you want to disband the guild "
+ ChatColor.GOLD + guild.getName() + ChatColor.GRAY + "? Type "
+ ChatColor.GOLD + "/g disband" + ChatColor.GRAY + " again within 10 seconds to confirm.");
confirm.put(sender, true);
new BukkitRunnable()
{
@Override
public void run()
{
confirm.remove(sender);
}
}.runTaskLater(TFGuilds.getPlugin(), 10 * 20);
}
else
{
confirm.remove(sender);
guild.disband();
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
}
} }
} }

View file

@ -1,15 +1,20 @@
package me.totalfreedom.tfguilds.command; package me.totalfreedom.tfguilds.command;
import java.util.HashMap;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class KickSubCommand extends Common implements SubCommand public class KickSubCommand extends Common implements SubCommand
{ {
private final HashMap<CommandSender, Player> confirm = new HashMap<>();
@Override @Override
public void execute(CommandSender sender, Player playerSender, String[] args) public void execute(CommandSender sender, Player playerSender, String[] args)
{ {
@ -63,8 +68,28 @@ public class KickSubCommand extends Common implements SubCommand
return; return;
} }
guild.removeMember(player); if (!confirm.containsKey(sender) || !confirm.containsValue(player))
sender.sendMessage(PREFIX + "Successfully kicked " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " from your guild."); {
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has kicked you from " + ChatColor.GOLD + guild.getName()); sender.sendMessage(WARN + "Are you sure you want to kick "
+ ChatColor.GOLD + player.getName() + ChatColor.GRAY + " from the guild? Type "
+ ChatColor.GOLD + "/g kick " + player.getName()
+ ChatColor.GRAY + " again within 10 seconds to confirm.");
confirm.put(sender, player);
new BukkitRunnable()
{
@Override
public void run()
{
confirm.remove(player);
}
}.runTaskLater(TFGuilds.getPlugin(), 10 * 20);
}
else
{
confirm.remove(sender);
guild.removeMember(player);
sender.sendMessage(PREFIX + "Successfully kicked " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " from the guild.");
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has kicked you from " + ChatColor.GOLD + guild.getName());
}
} }
} }

View file

@ -1,14 +1,19 @@
package me.totalfreedom.tfguilds.command; package me.totalfreedom.tfguilds.command;
import java.util.HashMap;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class LeaveSubCommand extends Common implements SubCommand public class LeaveSubCommand extends Common implements SubCommand
{ {
private final HashMap<CommandSender, Boolean> confirm = new HashMap<>();
@Override @Override
public void execute(CommandSender sender, Player playerSender, String[] args) public void execute(CommandSender sender, Player playerSender, String[] args)
{ {
@ -31,8 +36,28 @@ public class LeaveSubCommand extends Common implements SubCommand
return; return;
} }
guild.removeMember(playerSender); if (!confirm.containsKey(sender))
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has left the guild."); {
sender.sendMessage(PREFIX + "You have left the guild."); sender.sendMessage(WARN + "Are you sure you want to leave "
+ ChatColor.GOLD + guild.getName() + ChatColor.GRAY + "? Type "
+ ChatColor.GOLD + "/g leave"
+ ChatColor.GRAY + " again within 10 seconds to confirm.");
confirm.put(sender, true);
new BukkitRunnable()
{
@Override
public void run()
{
confirm.remove(sender);
}
}.runTaskLater(TFGuilds.getPlugin(), 10 * 20);
}
else
{
confirm.remove(sender);
guild.removeMember(playerSender);
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has left the guild.");
sender.sendMessage(PREFIX + "You have left the guild.");
}
} }
} }

View file

@ -1,14 +1,18 @@
package me.totalfreedom.tfguilds.command; package me.totalfreedom.tfguilds.command;
import java.util.HashMap;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class SetOwnerSubCommand extends Common implements SubCommand public class SetOwnerSubCommand extends Common implements SubCommand
{ {
private final HashMap<CommandSender, Player> confirm = new HashMap<>();
@Override @Override
public void execute(CommandSender sender, Player playerSender, String[] args) public void execute(CommandSender sender, Player playerSender, String[] args)
@ -57,9 +61,30 @@ public class SetOwnerSubCommand extends Common implements SubCommand
return; return;
} }
guild.setOwner(player); if (!confirm.containsKey(sender) || !confirm.containsValue(player))
sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild."); {
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild."); sender.sendMessage(WARN + "Are you sure you want to transfer ownership of "
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set you as the owner of " + ChatColor.GOLD + guild.getName()); + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " to "
+ ChatColor.GOLD + player.getName() + ChatColor.GRAY + "? Type "
+ ChatColor.GOLD + "/g setowner " + player.getName()
+ ChatColor.GRAY + " again within 10 seconds to confirm.");
confirm.put(sender, player);
new BukkitRunnable()
{
@Override
public void run()
{
confirm.remove(sender);
}
}.runTaskLater(TFGuilds.getPlugin(), 10 * 20);
}
else
{
confirm.remove(sender);
guild.setOwner(player);
sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set you as the owner of " + ChatColor.GOLD + guild.getName());
}
} }
} }