2015-01-13 13:50:38 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2015-05-06 17:04:35 +02:00
|
|
|
import java.util.Collection;
|
2015-01-13 13:50:38 +01:00
|
|
|
|
2015-09-08 19:18:45 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
2015-01-13 13:50:38 +01:00
|
|
|
import com.massivecraft.factions.Perm;
|
2015-10-21 19:35:41 +02:00
|
|
|
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
2015-01-13 13:50:38 +01:00
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
|
|
|
import com.massivecraft.factions.event.EventFactionsInvitedChange;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2015-11-06 02:10:29 +01:00
|
|
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
2016-02-03 05:06:49 +01:00
|
|
|
import com.massivecraft.massivecore.command.type.container.TypeSet;
|
2015-09-08 19:18:45 +02:00
|
|
|
import com.massivecraft.massivecore.mson.Mson;
|
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
2015-01-13 13:50:38 +01:00
|
|
|
|
|
|
|
public class CmdFactionsInviteAdd extends FactionsCommand
|
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
public CmdFactionsInviteAdd()
|
|
|
|
{
|
|
|
|
// Aliases
|
2015-10-21 21:18:00 +02:00
|
|
|
this.addAliases("add");
|
2015-01-13 13:50:38 +01:00
|
|
|
|
2015-10-21 19:35:41 +02:00
|
|
|
// Parameters
|
2015-11-06 02:10:29 +01:00
|
|
|
this.addParameter(TypeSet.get(TypeMPlayer.get()), "players", true);
|
2015-01-13 13:50:38 +01:00
|
|
|
|
|
|
|
// Requirements
|
2016-05-26 10:17:44 +02:00
|
|
|
this.addRequirements(RequirementHasPerm.get(Perm.INVITE_ADD));
|
2015-01-13 13:50:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2015-01-13 13:50:38 +01:00
|
|
|
{
|
|
|
|
// Args
|
2015-05-06 17:04:35 +02:00
|
|
|
Collection<MPlayer> mplayers = this.readArg();
|
2015-01-13 13:50:38 +01:00
|
|
|
|
|
|
|
// MPerm
|
|
|
|
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
|
|
|
|
|
|
|
|
for (MPlayer mplayer : mplayers)
|
|
|
|
{
|
|
|
|
// Already member?
|
|
|
|
if (mplayer.getFaction() == msenderFaction)
|
|
|
|
{
|
|
|
|
msg("%s<i> is already a member of %s<i>.", 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<i> invited you to %s<i>.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer));
|
|
|
|
msenderFaction.msg("%s<i> invited %s<i> to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction));
|
|
|
|
|
|
|
|
// Apply
|
|
|
|
msenderFaction.setInvited(mplayer, true);
|
2015-11-08 17:59:32 +01:00
|
|
|
msenderFaction.changed();
|
2015-01-13 13:50:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-08 19:18:45 +02:00
|
|
|
// Mson
|
2016-02-25 22:28:09 +01:00
|
|
|
String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteRemove.getCommandLine(mplayer.getName());
|
2015-09-08 19:18:45 +02:00
|
|
|
String tooltip = Txt.parse("<i>Click to <c>%s<i>.", 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)
|
|
|
|
);
|
|
|
|
|
2015-01-13 13:50:38 +01:00
|
|
|
// Inform
|
|
|
|
msg("%s <i>is already invited to %s<i>.", mplayer.getName(), msenderFaction.getName());
|
2015-09-08 19:18:45 +02:00
|
|
|
message(remove);
|
2015-01-13 13:50:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|