mirror of
https://github.com/TotalFreedomMC/TFGuilds.git
synced 2025-01-03 13:38:19 +00:00
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:
parent
6e174a3f06
commit
7bd956e55b
8 changed files with 71 additions and 8 deletions
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>me.totalfreedom</groupId>
|
<groupId>me.totalfreedom</groupId>
|
||||||
<artifactId>TFGuilds</artifactId>
|
<artifactId>TFGuilds</artifactId>
|
||||||
<version>0.1.7</version>
|
<version>0.1.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>TFGuilds</name>
|
<name>TFGuilds</name>
|
||||||
|
|
|
@ -47,6 +47,7 @@ public final class TFGuilds extends JavaPlugin
|
||||||
this.getCommand("guildadmin").setExecutor(new GuildAdminCommand());
|
this.getCommand("guildadmin").setExecutor(new GuildAdminCommand());
|
||||||
this.getCommand("guildsetmoderator").setExecutor(new GuildSetModeratorCommand());
|
this.getCommand("guildsetmoderator").setExecutor(new GuildSetModeratorCommand());
|
||||||
this.getCommand("guildremovemoderator").setExecutor(new GuildRemoveModeratorCommand());
|
this.getCommand("guildremovemoderator").setExecutor(new GuildRemoveModeratorCommand());
|
||||||
|
this.getCommand("guildlist").setExecutor(new GuildListCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableListeners()
|
private void enableListeners()
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CreateGuildCommand extends GBase implements CommandExecutor
|
public class CreateGuildCommand extends GBase implements CommandExecutor
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +39,7 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
|
||||||
{
|
{
|
||||||
for (String guild : guildMembers.getKeys(false))
|
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);
|
player.sendMessage(GMessage.IN_GUILD);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class DisbandGuildCommand implements CommandExecutor
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("confirm"))
|
if (args[0].equalsIgnoreCase("confirm"))
|
||||||
{
|
{
|
||||||
GUtil.deleteGuild(player);
|
GUtil.deleteGuild(player, guild);
|
||||||
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
|
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
|
||||||
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
|
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
|
||||||
GLog.info(player.getName() + " deleted guild " + guild);
|
GLog.info(player.getName() + " deleted guild " + guild);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,9 +42,9 @@ public class GuildTagCommand extends GBase implements CommandExecutor
|
||||||
String tag = StringUtils.join(args, " ", 1, args.length);
|
String tag = StringUtils.join(args, " ", 1, args.length);
|
||||||
if (args[0].equalsIgnoreCase("set"))
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,30 +28,43 @@ public class GUtil
|
||||||
|
|
||||||
public static void createGuild(CommandSender owner, String guildName)
|
public static void createGuild(CommandSender owner, String guildName)
|
||||||
{
|
{
|
||||||
|
// Set guild name & owner
|
||||||
plugin.guilds.set("guilds." + guildName, guildName);
|
plugin.guilds.set("guilds." + guildName, guildName);
|
||||||
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
|
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
|
||||||
|
|
||||||
|
// Set guild moderator
|
||||||
List<String> moderators = plugin.guilds.getStringList("guilds." + guildName + ".moderators");
|
List<String> moderators = plugin.guilds.getStringList("guilds." + guildName + ".moderators");
|
||||||
moderators.add(owner.getName());
|
moderators.add(owner.getName());
|
||||||
plugin.guilds.set("guilds." + guildName + ".moderators", moderators);
|
plugin.guilds.set("guilds." + guildName + ".moderators", moderators);
|
||||||
|
|
||||||
|
// Set guild player
|
||||||
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
|
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
|
||||||
players.add(owner.getName());
|
players.add(owner.getName());
|
||||||
plugin.guilds.set("guilds." + guildName + ".members", players);
|
plugin.guilds.set("guilds." + guildName + ".members", players);
|
||||||
plugin.guilds.set("guilds." + guildName + ".tag", GUtil.color("&8[&7" + guildName + "&8]&r "));
|
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");
|
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
plugin.guilds.set("guilds." + guildName + ".created", dateFormat.format(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();
|
plugin.guilds.save();
|
||||||
GLog.info(owner.getName() + " has created a new guild: " + guildName);
|
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));
|
GLog.info("Removing guilds.yml data for " + guildName);
|
||||||
plugin.guilds.set("guilds." + getGuild((Player) owner), null);
|
plugin.guilds.set("guilds." + guildName, null);
|
||||||
|
List<String> guilds = plugin.guilds.getStringList("list");
|
||||||
|
guilds.remove(guildName);
|
||||||
|
plugin.guilds.set("list", guilds);
|
||||||
plugin.guilds.save();
|
plugin.guilds.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +72,9 @@ public class GUtil
|
||||||
{
|
{
|
||||||
GLog.info("Removing guilds.yml data for " + guildName);
|
GLog.info("Removing guilds.yml data for " + guildName);
|
||||||
plugin.guilds.set("guilds." + guildName, null);
|
plugin.guilds.set("guilds." + guildName, null);
|
||||||
|
List<String> guilds = plugin.guilds.getStringList("list");
|
||||||
|
guilds.remove(guildName);
|
||||||
|
plugin.guilds.set("list", guilds);
|
||||||
plugin.guilds.save();
|
plugin.guilds.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +90,10 @@ public class GUtil
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
if (!invitedPlayers.containsKey(player.getName()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
invitedPlayers.remove(player.getName());
|
invitedPlayers.remove(player.getName());
|
||||||
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
|
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
|
||||||
}
|
}
|
||||||
|
@ -158,6 +178,11 @@ public class GUtil
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getGuilds()
|
||||||
|
{
|
||||||
|
return plugin.guilds.getStringList("list");
|
||||||
|
}
|
||||||
|
|
||||||
public static String getOwner(String guildName)
|
public static String getOwner(String guildName)
|
||||||
{
|
{
|
||||||
return plugin.guilds.getString("guilds." + guildName + ".owner");
|
return plugin.guilds.getString("guilds." + guildName + ".owner");
|
||||||
|
|
|
@ -55,3 +55,7 @@ commands:
|
||||||
description: Demotes a guild mod
|
description: Demotes a guild mod
|
||||||
usage: /<command> <player>
|
usage: /<command> <player>
|
||||||
aliases: [gremovemod, removeguildmod, removeguildmoderator, guildremovemod, guilddemote, gdemote]
|
aliases: [gremovemod, removeguildmod, removeguildmoderator, guildremovemod, guilddemote, gdemote]
|
||||||
|
guildlist:
|
||||||
|
description: Lists all guilds
|
||||||
|
usage: /<command>
|
||||||
|
aliases: [listguilds]
|
||||||
|
|
Loading…
Reference in a new issue