mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Change /party kick to a subcommand
This commit is contained in:
parent
2be57414ad
commit
5da51e78cc
@ -30,6 +30,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
|
private CommandExecutor partyExpShareCommand = new PartyExpShareCommand();
|
||||||
private CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
|
private CommandExecutor partyItemShareCommand = new PartyItemShareCommand();
|
||||||
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
|
private CommandExecutor partyInviteCommand = new PartyInviteCommand();
|
||||||
|
private CommandExecutor partyKickCommand = new PartyKickCommand();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
@ -80,7 +81,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return partyInviteCommand.onCommand(sender, command, label, args);
|
return partyInviteCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("kick")) {
|
else if (args[0].equalsIgnoreCase("kick")) {
|
||||||
return kick(args);
|
return partyKickCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("disband")) {
|
else if (args[0].equalsIgnoreCase("disband")) {
|
||||||
return disband();
|
return disband();
|
||||||
@ -188,55 +189,6 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick a party member
|
|
||||||
*/
|
|
||||||
private boolean kick(String[] args) {
|
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.kick")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (args.length) {
|
|
||||||
case 2:
|
|
||||||
String playerName = player.getName();
|
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (party.getLeader().equals(playerName)) {
|
|
||||||
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(args[1]);
|
|
||||||
|
|
||||||
if (!party.getMembers().contains(member)) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (member.isOnline()) {
|
|
||||||
Player onlineMember = member.getPlayer();
|
|
||||||
String partyName = party.getName();
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(onlineMember, partyName, null, EventReason.KICKED_FROM_PARTY);
|
|
||||||
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
onlineMember.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.removeFromParty(member, party);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disband the current party, kicks out all party members.
|
* Disband the current party, kicks out all party members.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.gmail.nossr50.party.commands;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.commands.CommandHelper;
|
||||||
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||||
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.party.Party;
|
||||||
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
|
import com.gmail.nossr50.util.Permissions;
|
||||||
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
|
public class PartyKickCommand implements CommandExecutor {
|
||||||
|
private Player player;
|
||||||
|
private Party playerParty;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!Permissions.hasPermission(sender, "mcmmo.commands.party.kick")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args.length) {
|
||||||
|
case 2:
|
||||||
|
player = (Player) sender;
|
||||||
|
playerParty = Users.getPlayer(player).getParty();
|
||||||
|
|
||||||
|
if (!playerParty.getLeader().equals(player.getName())) {
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
McMMOPlayer mcMMOTarget = Users.getPlayer(args[1]);
|
||||||
|
|
||||||
|
// Would be nice to find a way to check if a player is valid here - this won't work directly because it'll also throw null for an offline player
|
||||||
|
// if (mcMMOTarget == null) {
|
||||||
|
// sender.sendMessage(LocaleLoader.getString("Party.Player.Invalid"));
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
Player target = mcMMOTarget.getPlayer();
|
||||||
|
|
||||||
|
if (!PartyManager.inSameParty(player, target)) {
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", args[1]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mcMMO.p.getServer().getOfflinePlayer(args[1]).isOnline()) {
|
||||||
|
String partyName = playerParty.getName();
|
||||||
|
|
||||||
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(target, partyName, null, EventReason.KICKED_FROM_PARTY);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.sendMessage(LocaleLoader.getString("Commands.Party.Kick", partyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.removeFromParty(target, playerParty);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user