Factions/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java

144 lines
4.2 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
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;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
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;
2017-03-24 13:05:58 +01:00
import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CmdFactionsInviteRemove extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsInviteRemove()
{
// Parameters
2015-11-06 02:10:29 +01:00
this.addParameter(TypeSet.get(TypeMPlayer.get()), "players/all", true);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
{
2017-03-24 14:03:29 +01:00
Set<MPlayer> mplayers = new HashSet<>();
boolean all = false;
// Args
2015-05-06 17:04:35 +02:00
if ("all".equalsIgnoreCase(this.argAt(0)))
{
List<MPlayer> invitedPlayers = msenderFaction.getInvitedMPlayers();
// Doesn't show up if list is empty. Test at home if it worked.
if (invitedPlayers == null || invitedPlayers.isEmpty())
{
msg("<b>Your faction has not invited anyone.");
return;
}
all = true;
mplayers.addAll(invitedPlayers);
}
else
{
2015-05-06 17:04:35 +02:00
mplayers = this.readArgAt(0);
}
// MPerm
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
for (MPlayer mplayer : mplayers)
{
// Already member?
if (mplayer.getFaction() == msenderFaction)
{
2015-09-08 19:18:45 +02:00
// Mson
2016-02-25 22:28:09 +01:00
String command = CmdFactions.get().cmdFactionsKick.getCommandLine(mplayer.getName());
2015-09-08 19:18:45 +02:00
String tooltip = Txt.parse("Click to <c>%s<i>.", command);
Mson kick = Mson.mson(
mson("You might want to kick him. ").color(ChatColor.YELLOW),
mson(ChatColor.RED.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command)
);
// Inform
msg("%s<i> is already a member of %s<i>.", mplayer.getName(), msenderFaction.getName());
2015-09-08 19:18:45 +02:00
message(kick);
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 Player
mplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer));
// Inform Faction
if ( ! all)
{
msenderFaction.msg("%s<i> revoked %s's<i> invitation.", msender.describeTo(msenderFaction), mplayer.describeTo(msenderFaction));
}
// Apply
msenderFaction.setInvited(mplayer, false);
2015-11-08 17:59:32 +01:00
// If all, we do this at last. So we only do it once.
if (! all) msenderFaction.changed();
}
else
{
2015-09-08 19:18:45 +02:00
// Mson
2016-02-25 22:28:09 +01:00
String command = CmdFactions.get().cmdFactionsInvite.cmdFactionsInviteAdd.getCommandLine(mplayer.getName());
2015-09-08 19:18:45 +02:00
String tooltip = Txt.parse("Click to <c>%s<i>.", command);
Mson invite = Mson.mson(
mson("You might want to invite him. ").color(ChatColor.YELLOW),
mson(ChatColor.GREEN.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command)
);
// Inform
msg("%s <i>is not invited to %s<i>.", mplayer.describeTo(msender, true), msenderFaction.describeTo(mplayer));
2015-09-08 19:18:45 +02:00
message(invite);
}
}
// Inform Faction if all
if (all)
{
2017-03-24 14:03:29 +01:00
List<String> names = new ArrayList<>();
2015-09-08 19:18:45 +02:00
for (MPlayer mplayer : mplayers)
{
names.add(mplayer.describeTo(msender, true));
}
Mson factionsRevokeAll = mson(
Mson.parse("%s<i> revoked ", msender.describeTo(msenderFaction)),
Mson.parse("<i>all <h>%s <i>pending invitations", mplayers.size()).tooltip(names),
mson(" from your faction.").color(ChatColor.YELLOW)
);
msenderFaction.sendMessage(factionsRevokeAll);
2015-11-08 17:59:32 +01:00
msenderFaction.changed();
}
}
}