add guildlist command

- add guildlist
- fix invite guild issue where it says "your invitation has expired" even if you accepted the invitation
This commit is contained in:
speedxx 2020-07-02 16:58:05 -04:00
parent 6e174a3f06
commit 7bd956e55b
8 changed files with 71 additions and 8 deletions

View file

@ -6,7 +6,7 @@
<groupId>me.totalfreedom</groupId>
<artifactId>TFGuilds</artifactId>
<version>0.1.7</version>
<version>0.1.8</version>
<packaging>jar</packaging>
<name>TFGuilds</name>

View file

@ -47,6 +47,7 @@ public final class TFGuilds extends JavaPlugin
this.getCommand("guildadmin").setExecutor(new GuildAdminCommand());
this.getCommand("guildsetmoderator").setExecutor(new GuildSetModeratorCommand());
this.getCommand("guildremovemoderator").setExecutor(new GuildRemoveModeratorCommand());
this.getCommand("guildlist").setExecutor(new GuildListCommand());
}
private void enableListeners()

View file

@ -11,6 +11,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import java.util.Objects;
public class CreateGuildCommand extends GBase implements CommandExecutor
{
@Override
@ -37,7 +39,7 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
{
for (String guild : guildMembers.getKeys(false))
{
if (plugin.guilds.getString("guilds." + guild + ".members").contains(player.getName()))
if (Objects.requireNonNull(plugin.guilds.getString("guilds." + guild + ".members")).contains(player.getName()))
{
player.sendMessage(GMessage.IN_GUILD);
return true;

View file

@ -45,7 +45,7 @@ public class DisbandGuildCommand implements CommandExecutor
if (args[0].equalsIgnoreCase("confirm"))
{
GUtil.deleteGuild(player);
GUtil.deleteGuild(player, guild);
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
GLog.info(player.getName() + " deleted guild " + guild);

View file

@ -0,0 +1,31 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.List;
public class GuildListCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
List<String> guilds = GUtil.getGuilds();
if (guilds.isEmpty())
{
sender.sendMessage(ChatColor.RED + "Nobody has made a guild yet.");
return true;
}
sender.sendMessage(GUtil.color("&2-=-=-=- &aGuild List (Total: " + guilds.size() + ") &2-=-=-=-"));
sender.sendMessage(GUtil.color("&2- &a" + StringUtils.join(guilds, ",\n&2- &a")));
sender.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
return true;
}
}

View file

@ -42,9 +42,9 @@ public class GuildTagCommand extends GBase implements CommandExecutor
String tag = StringUtils.join(args, " ", 1, args.length);
if (args[0].equalsIgnoreCase("set"))
{
if (!tag.contains(guild))
if (!tag.toLowerCase().contains(guild))
{
player.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name.");
player.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name in one word.");
return true;
}

View file

@ -28,30 +28,43 @@ public class GUtil
public static void createGuild(CommandSender owner, String guildName)
{
// Set guild name & owner
plugin.guilds.set("guilds." + guildName, guildName);
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
// Set guild moderator
List<String> moderators = plugin.guilds.getStringList("guilds." + guildName + ".moderators");
moderators.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".moderators", moderators);
// Set guild player
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
players.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".members", players);
plugin.guilds.set("guilds." + guildName + ".tag", GUtil.color("&8[&7" + guildName + "&8]&r "));
// Set time guild was created
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date = new Date();
plugin.guilds.set("guilds." + guildName + ".created", dateFormat.format(date));
// Add guild to guild list
List<String> guilds = plugin.guilds.getStringList("list");
guilds.add(guildName);
plugin.guilds.set("list", guilds);
// Save everything & log guild creation
plugin.guilds.save();
GLog.info(owner.getName() + " has created a new guild: " + guildName);
}
public static void deleteGuild(CommandSender owner)
public static void deleteGuild(CommandSender owner, String guildName)
{
GLog.info("Removing guilds.yml data for " + getGuild((Player) owner));
plugin.guilds.set("guilds." + getGuild((Player) owner), null);
GLog.info("Removing guilds.yml data for " + guildName);
plugin.guilds.set("guilds." + guildName, null);
List<String> guilds = plugin.guilds.getStringList("list");
guilds.remove(guildName);
plugin.guilds.set("list", guilds);
plugin.guilds.save();
}
@ -59,6 +72,9 @@ public class GUtil
{
GLog.info("Removing guilds.yml data for " + guildName);
plugin.guilds.set("guilds." + guildName, null);
List<String> guilds = plugin.guilds.getStringList("list");
guilds.remove(guildName);
plugin.guilds.set("list", guilds);
plugin.guilds.save();
}
@ -74,6 +90,10 @@ public class GUtil
{
public void run()
{
if (!invitedPlayers.containsKey(player.getName()))
{
return;
}
invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
}
@ -158,6 +178,11 @@ public class GUtil
return g;
}
public static List<String> getGuilds()
{
return plugin.guilds.getStringList("list");
}
public static String getOwner(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".owner");

View file

@ -55,3 +55,7 @@ commands:
description: Demotes a guild mod
usage: /<command> <player>
aliases: [gremovemod, removeguildmod, removeguildmoderator, guildremovemod, guilddemote, gdemote]
guildlist:
description: Lists all guilds
usage: /<command>
aliases: [listguilds]