guild commands only for admins

This commit is contained in:
speedxx 2020-06-23 20:37:02 -04:00
parent 87e591abc1
commit 3166680e94
5 changed files with 97 additions and 2 deletions

View file

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

View file

@ -47,6 +47,7 @@ public final class TFGuilds extends JavaPlugin
this.getCommand("leaveguild").setExecutor(new LeaveGuildCommand()); this.getCommand("leaveguild").setExecutor(new LeaveGuildCommand());
this.getCommand("guildkick").setExecutor(new GuildKickCommand()); this.getCommand("guildkick").setExecutor(new GuildKickCommand());
this.getCommand("guildinfo").setExecutor(new GuildInfoCommand()); this.getCommand("guildinfo").setExecutor(new GuildInfoCommand());
this.getCommand("guildadmin").setExecutor(new GuildAdminCommand());
} }
private void enableListeners() private void enableListeners()

View file

@ -0,0 +1,84 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GLog;
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 GuildAdminCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
Player player = (Player) sender;
if (!plugin.tfmb.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "No permission.");
return true;
}
if (args.length != 2)
{
return false;
}
String guild = GUtil.getGuild(args[1]);
if (guild == null)
{
player.sendMessage(ChatColor.RED + "Guild not found.");
return true;
}
if (args[0].equalsIgnoreCase("cleartag"))
{
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r "), guild);
player.sendMessage(ChatColor.GREEN + "Successfully cleared tag for guild " + guild);
return true;
}
if (args[0].equalsIgnoreCase("disbandguild"))
{
GUtil.deleteGuild(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);
return true;
}
if (args[0].equalsIgnoreCase("join"))
{
if (GUtil.isConsole(sender))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
return true;
}
if (GUtil.isGuildMember(player, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "You are already in a guild.");
return true;
}
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.add(player.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
player.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.GREEN + player.getName() + " has joined the guild");
}
}
}
return true;
}
}

View file

@ -51,6 +51,13 @@ public class GUtil
plugin.guilds.save(); plugin.guilds.save();
} }
public static void deleteGuild(String guildName)
{
GLog.info("Removing guilds.yml data for " + guildName);
plugin.guilds.set("guilds." + guildName, null);
plugin.guilds.save();
}
public static void invitePlayer(Player player, String guild, int seconds) public static void invitePlayer(Player player, String guild, int seconds)
{ {
if (seconds > 0) if (seconds > 0)

View file

@ -43,4 +43,7 @@ commands:
usage: /<command> <player> usage: /<command> <player>
guildinfo: guildinfo:
description: Gives you information about any guild description: Gives you information about any guild
usage: /<command> usage: /<command> <guild>
guildadmin:
description: Guild commands only for admins
usage: /<command> <cleartag | disbandguild | join> <guild>