mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-02 00:30:07 +01:00
Update /party create to be a subcommand
This commit is contained in:
parent
3cc5cd4a04
commit
291393d45d
@ -25,6 +25,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();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
@ -50,7 +51,7 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return partyAcceptCommand.onCommand(sender, command, label, args);
|
return partyAcceptCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("create")) {
|
else if (args[0].equalsIgnoreCase("create")) {
|
||||||
return create(args);
|
return partyCreateCommand.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
else if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
|
||||||
return printHelp();
|
return printHelp();
|
||||||
@ -172,60 +173,6 @@ public class PartyCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean create(String[] args) {
|
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.create")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playerName = player.getName();
|
|
||||||
Party party = mcMMOPlayer.getParty();
|
|
||||||
|
|
||||||
if (args.length < 2) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Party.Help.1"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String partyname = args[1];
|
|
||||||
String password = null;
|
|
||||||
|
|
||||||
if (args.length > 2) {
|
|
||||||
password = args[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
Party newParty = PartyManager.getParty(partyname);
|
|
||||||
// Check to see if the party exists, and if it does cancel creating a new party
|
|
||||||
if (newParty != null) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", partyname));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mcMMOPlayer.inParty()) {
|
|
||||||
String oldPartyName = party.getName();
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, partyname, EventReason.CHANGED_PARTIES);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.removeFromParty(playerName, party);
|
|
||||||
PartyManager.createParty(player, mcMMOPlayer, partyname, password);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, null, partyname, EventReason.JOINED_PARTY);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartyManager.createParty(player, mcMMOPlayer, partyname, password);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean quit() {
|
private boolean quit() {
|
||||||
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) {
|
if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.party.quit")) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
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.datatypes.McMMOPlayer;
|
||||||
|
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 PartyCreateCommand implements CommandExecutor {
|
||||||
|
private McMMOPlayer mcMMOPlayer;
|
||||||
|
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.create")) {
|
||||||
|
sender.sendMessage(command.getPermissionMessage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args.length) {
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
Party newParty = PartyManager.getParty(args[1]);
|
||||||
|
|
||||||
|
// Check to see if the party exists, and if it does cancel creating a new party
|
||||||
|
if (newParty != null) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", args[1]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = (Player) sender;
|
||||||
|
mcMMOPlayer = Users.getPlayer(player);
|
||||||
|
|
||||||
|
// Changing parties
|
||||||
|
if (mcMMOPlayer.inParty()) {
|
||||||
|
playerParty = mcMMOPlayer.getParty();
|
||||||
|
if (!PartyManager.handlePartyChangeEvent(player, playerParty.getName(), args[1], EventReason.CHANGED_PARTIES)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.removeFromParty(player.getName(), playerParty);
|
||||||
|
}
|
||||||
|
else if (!PartyManager.handlePartyChangeEvent(player, null, args[1], EventReason.JOINED_PARTY)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartyManager.createParty(player, mcMMOPlayer, args[1], getPassword(args));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "create", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPassword(String[] args) {
|
||||||
|
if (args.length == 3) {
|
||||||
|
return args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user