fix disbandguild, inviteguild needs to be fixed

i uhoruihiuhaoui
This commit is contained in:
speedxx 2020-06-20 17:23:53 -04:00
parent 5afd9b1edc
commit c7acd5d062
5 changed files with 114 additions and 20 deletions

View file

@ -43,6 +43,7 @@ public final class TFGuilds extends JavaPlugin
this.getCommand("guildchat").setExecutor(new GuildChatCommand()); this.getCommand("guildchat").setExecutor(new GuildChatCommand());
this.getCommand("disbandguild").setExecutor(new DisbandGuildCommand()); this.getCommand("disbandguild").setExecutor(new DisbandGuildCommand());
this.getCommand("guildteleport").setExecutor(new GuildTeleportCommand()); this.getCommand("guildteleport").setExecutor(new GuildTeleportCommand());
this.getCommand("inviteguild").setExecutor(new InviteGuildCommand());
} }
private void enableListeners() private void enableListeners()

View file

@ -16,8 +16,6 @@ public class DisbandGuildCommand implements CommandExecutor
Player player = (Player) sender; Player player = (Player) sender;
String guild = GUtil.getGuild(player); String guild = GUtil.getGuild(player);
if (args.length == 0)
{
if (GUtil.isConsole(player)) if (GUtil.isConsole(player))
{ {
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command."); sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
@ -37,6 +35,8 @@ public class DisbandGuildCommand implements CommandExecutor
return true; return true;
} }
if (args.length == 0)
{
sender.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue."); sender.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue.");
return true; return true;
} }

View file

@ -0,0 +1,71 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class InviteGuildCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 1)
{
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
Player target = Bukkit.getPlayer(args[0]);
if (GUtil.isConsole(player))
{
player.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
return true;
}
GUtil.invitePlayer(target, 60);
if (!(target == null))
{
if (GUtil.invitedPlayers.containsKey(target.getName()))
{
if (GUtil.isGuildMember(target, GUtil.getGuild(target)))
{
player.sendMessage(ChatColor.RED + "That player is already in a guild.");
return true;
}
player.sendMessage(GUtil.color("&aSent an invitation to " + target.getName()));
if (args[0].equalsIgnoreCase("accept"))
{
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.add(target.getName());
GUtil.invitedPlayers.remove(target.getName());
target.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild);
}
if (args[0].equalsIgnoreCase("deny"))
{
GUtil.invitedPlayers.remove(target.getName());
target.sendMessage(ChatColor.GREEN + "You have declined to join " + guild);
}
}
else
{
sender.sendMessage(ChatColor.RED + "You haven't received any guild invitations.");
}
}
else
{
sender.sendMessage(ChatColor.RED + "Player not found.");
}
}
return false;
}
}

View file

@ -9,11 +9,13 @@ import org.bukkit.entity.Player;
import me.totalfreedom.tfguilds.TFGuilds; import me.totalfreedom.tfguilds.TFGuilds;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; 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 boolean isConsole(CommandSender sender) public static boolean isConsole(CommandSender sender)
{ {
@ -42,6 +44,22 @@ public class GUtil
plugin.guilds.save(); plugin.guilds.save();
} }
public static void invitePlayer(Player player, int seconds)
{
if (seconds > 0)
{
invitedPlayers.put(player.getName(), ((seconds * 1000) + System.currentTimeMillis()));
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.");
}
if (!(invitedPlayers.get(player.getName()) >= System.currentTimeMillis()))
{
invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
}
}
public static void setTag(String tag, String guildName) public static void setTag(String tag, String guildName)
{ {
plugin.guilds.set("guilds." + guildName + ".tag", tag); plugin.guilds.set("guilds." + guildName + ".tag", tag);

View file

@ -30,3 +30,7 @@ commands:
description: Teleport to other guild members description: Teleport to other guild members
usage: /<command> <player> usage: /<command> <player>
aliases: [guildtp, tpguild] aliases: [guildtp, tpguild]
inviteguild:
description: If invited, allows you to join a guild
usage: /<command> <player>
aliases: [guildinvite]