package com.massivecraft.factions.cmd; import java.util.Collection; import org.bukkit.ChatColor; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.type.TypeMPlayer; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.type.TypeSet; import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsInviteAdd extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsInviteAdd() { // Aliases this.addAliases("a", "add"); // Parameters this.addParameter(TypeSet.get(TypeMPlayer.get(), true), "players", true); // Requirements this.addRequirements(ReqHasPerm.get(Perm.INVITE_ADD.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() throws MassiveException { // Args Collection mplayers = this.readArg(); // MPerm if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return; for (MPlayer mplayer : mplayers) { // Already member? if (mplayer.getFaction() == msenderFaction) { msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName()); continue; } // Already invited? boolean isInvited = msenderFaction.isInvited(mplayer); if ( ! isInvited) { // Event EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited); event.run(); if (event.isCancelled()) continue; isInvited = event.isNewInvited(); // Inform mplayer.msg("%s invited you to %s.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer)); msenderFaction.msg("%s invited %s to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction)); // Apply msenderFaction.setInvited(mplayer, true); } else { // Mson String command = Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteRemove.getCommandLine(mplayer.getName()); String tooltip = Txt.parse("Click to %s.", command); Mson remove = Mson.mson( mson("You might want to remove him. ").color(ChatColor.YELLOW), mson("Click to " + command).color(ChatColor.RED).tooltip(tooltip).suggest(command) ); // Inform msg("%s is already invited to %s.", mplayer.getName(), msenderFaction.getName()); message(remove); } } } }