This commit is contained in:
Super_ 2020-06-20 17:55:33 -04:00
parent a10542f3eb
commit 58993e4ddb
2 changed files with 14 additions and 11 deletions

View file

@ -28,23 +28,23 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
} }
Player player = (Player) sender; Player player = (Player) sender;
String guild = GUtil.getGuild(player);
Player target = Bukkit.getPlayer(args[0]); Player target = Bukkit.getPlayer(args[0]);
if (target != null) if (target != null)
{ {
if (GUtil.isGuildMember(player, GUtil.getGuild(target))) if (GUtil.isGuildMember(target, GUtil.getGuild(player)))
{ {
player.sendMessage(ChatColor.RED + "That player is already in a guild."); player.sendMessage(ChatColor.RED + "That player is already in a guild.");
return true; return true;
} }
GUtil.invitePlayer(target, 60); GUtil.invitePlayer(target, GUtil.getGuild(player), 60);
player.sendMessage(GUtil.color("&aSent an invitation to " + target.getName())); player.sendMessage(GUtil.color("&aSent an invitation to " + target.getName()));
return true; return true;
} }
if (GUtil.invitedPlayers.containsKey(player.getName())) if (GUtil.invitedPlayers.containsKey(player.getName()))
{ {
String guild = GUtil.invitedPlayers.get(player.getName());
if (args[0].equalsIgnoreCase("accept")) if (args[0].equalsIgnoreCase("accept"))
{ {
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members"); List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");

View file

@ -7,6 +7,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.totalfreedom.tfguilds.TFGuilds; import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -15,7 +16,7 @@ import java.util.List;
public class GUtil public class GUtil
{ {
public static TFGuilds plugin = TFGuilds.plugin; public static TFGuilds plugin = TFGuilds.plugin;
public static HashMap<String, Long> invitedPlayers = new HashMap<>(); public static HashMap<String, String> invitedPlayers = new HashMap<>();
public static boolean isConsole(CommandSender sender) public static boolean isConsole(CommandSender sender)
{ {
@ -44,20 +45,22 @@ public class GUtil
plugin.guilds.save(); plugin.guilds.save();
} }
public static void invitePlayer(Player player, int seconds) public static void invitePlayer(Player player, String guild, int seconds)
{ {
if (seconds > 0) if (seconds > 0)
{ {
invitedPlayers.put(player.getName(), ((seconds * 1000) + System.currentTimeMillis())); invitedPlayers.put(player.getName(), guild);
player.sendMessage(ChatColor.GREEN + "To accept or decline, type /inviteguild accept or /inviteguild deny"); player.sendMessage(ChatColor.GREEN + "To accept or decline, type /inviteguild accept or /inviteguild deny");
player.sendMessage(ChatColor.GREEN + "You have " + seconds + " seconds to accept the request before it gets declined automatically."); player.sendMessage(ChatColor.GREEN + "You have " + seconds + " seconds to accept the request before it gets declined automatically.");
} }
new BukkitRunnable()
if (!(invitedPlayers.get(player.getName()) >= System.currentTimeMillis())) {
public void run()
{ {
invitedPlayers.remove(player.getName()); invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.RED + "Your invitation has expired."); player.sendMessage(ChatColor.RED + "Your invitation has expired.");
} }
}.runTaskLater(plugin, seconds * 20);
} }
public static void setTag(String tag, String guildName) public static void setTag(String tag, String guildName)