mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 00:30:07 +01:00
Convert /party quit to a subcommand
This commit is contained in:
parent
6d9db06305
commit
ae3a95dd34
@ -26,6 +26,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
|
private CommandExecutor partyJoinCommand = new PartyJoinCommand();
|
||||||
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
|
private CommandExecutor partyAcceptCommand = new PartyAcceptCommand();
|
||||||
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
|
private CommandExecutor partyCreateCommand = new PartyCreateCommand();
|
||||||
|
private CommandExecutor partyQuitCommand = new PartyQuitCommand();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
@ -59,7 +60,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
|
|
||||||
if (mcMMOPlayer.inParty()) {
|
if (mcMMOPlayer.inParty()) {
|
||||||
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase("q") || args[0].equalsIgnoreCase("leave")) {
|
||||||
return quit();
|
return partyQuitCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("expshare")) {
|
else if (args[0].equalsIgnoreCase("expshare")) {
|
||||||
return shareExp(args);
|
return shareExp(args);
|
||||||
@ -173,31 +174,6 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean quit() {
|
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playerName = player.getName();
|
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (party != null) {
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, party.getName(), null, EventReason.LEFT_PARTY);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PartyManager.removeFromParty(playerName, party);
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean shareExp(String[] args) {
|
private boolean shareExp(String[] args) {
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.expshare")) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.gmail.nossr50.party.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
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 PartyQuitCommand 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.quit")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args.length) {
|
||||||
|
case 1:
|
||||||
|
player = (Player) sender;
|
||||||
|
playerParty = Users.getPlayer(player).getParty();
|
||||||
|
|
||||||
|
if (playerParty == null) {
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.removeFromParty(player.getName(), playerParty);
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "[quit|q|leave]"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user