guildkick

This commit is contained in:
speedxx 2020-06-21 12:00:01 -04:00
parent bbbb1afffb
commit 6479bbc76b
5 changed files with 73 additions and 3 deletions

View file

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

View file

@ -45,6 +45,7 @@ public final class TFGuilds extends JavaPlugin
this.getCommand("guildteleport").setExecutor(new GuildTeleportCommand());
this.getCommand("inviteguild").setExecutor(new InviteGuildCommand());
this.getCommand("leaveguild").setExecutor(new LeaveGuildCommand());
this.getCommand("guildkick").setExecutor(new GuildKickCommand());
}
private void enableListeners()

View file

@ -0,0 +1,66 @@
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 GuildKickCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
{
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
return true;
}
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!");
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null)
{
sender.sendMessage(ChatColor.RED + "Player not found");
return true;
}
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.remove(target.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.RED + target.getName() + " has been kicked from the guild");
}
}
sender.sendMessage(ChatColor.GREEN + "Successfully kicked " + target.getName() + " from the guild");
return true;
}
}

View file

@ -56,7 +56,7 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
player.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(player, guild))
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.GREEN + player.getName() + " has joined the guild");
}

View file

@ -37,4 +37,7 @@ commands:
leaveguild:
description: Leave your guild
usage: /<command>
aliases: [guildleave]
aliases: [guildleave]
guildkick:
description: Kicks a player from the guild
usage: /<command> <player>