Invitations as inner entities
This commit is contained in:
@@ -6,13 +6,14 @@ import com.massivecraft.factions.entity.Board;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.Invitation;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.EntityInternalMap;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -70,11 +71,11 @@ public class CmdFactionsClean extends FactionsCommand
|
||||
|
||||
for (Faction faction : FactionColl.get().getAll())
|
||||
{
|
||||
Collection<String> invitedPlayerIds = faction.getInvitedPlayerIds();
|
||||
if (invitedPlayerIds.isEmpty()) continue;
|
||||
EntityInternalMap<Invitation> invitations = faction.getInvitations();
|
||||
if (invitations.isEmpty()) continue;
|
||||
|
||||
ret += invitedPlayerIds.size();
|
||||
invitedPlayerIds.clear();
|
||||
ret += invitations.size();
|
||||
invitations.clear();
|
||||
faction.changed();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.entity.Invitation;
|
||||
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.command.type.container.TypeSet;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -34,6 +36,9 @@ public class CmdFactionsInviteAdd extends FactionsCommand
|
||||
// Args
|
||||
Collection<MPlayer> mplayers = this.readArg();
|
||||
|
||||
String senderId = IdUtil.getId(sender);
|
||||
long creationMillis = System.currentTimeMillis();
|
||||
|
||||
// MPerm
|
||||
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
|
||||
|
||||
@@ -62,7 +67,8 @@ public class CmdFactionsInviteAdd extends FactionsCommand
|
||||
msenderFaction.msg("%s<i> invited %s<i> to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction));
|
||||
|
||||
// Apply
|
||||
msenderFaction.setInvited(mplayer, true);
|
||||
Invitation invitation = new Invitation(senderId, creationMillis);
|
||||
msenderFaction.invite(mplayer.getId(), invitation);
|
||||
msenderFaction.changed();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.Invitation;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.mixin.MixinDisplayName;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class CmdFactionsInviteList extends FactionsCommand
|
||||
{
|
||||
@@ -45,25 +53,39 @@ public class CmdFactionsInviteList extends FactionsCommand
|
||||
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
|
||||
|
||||
// Pager Create
|
||||
final List<MPlayer> mplayers = faction.getInvitedMPlayers();
|
||||
final Pager<MPlayer> pager = new Pager<>(this, "Invited Players List", page, mplayers, new Stringifier<MPlayer>()
|
||||
final List<Entry<String, Invitation>> invitations = new MassiveList<>(faction.getInvitations().entrySet());
|
||||
|
||||
Collections.sort(invitations, new Comparator<Entry<String, Invitation>>()
|
||||
{
|
||||
public String toString(MPlayer target, int index)
|
||||
@Override
|
||||
public int compare(Entry<String, Invitation> i1, Entry<String, Invitation> i2)
|
||||
{
|
||||
// TODO: Madus would like to implement this in MPlayer
|
||||
String targetName = target.getDisplayName(msender);
|
||||
String isAre = target == msender ? "are" : "is";
|
||||
Rel targetRank = target.getRole();
|
||||
Faction targetFaction = target.getFaction();
|
||||
String theAan = targetRank == Rel.LEADER ? "the" : Txt.aan(targetRank.name());
|
||||
String rankName = Txt.getNicedEnum(targetRank).toLowerCase();
|
||||
String ofIn = targetRank == Rel.LEADER ? "of" : "in";
|
||||
String factionName = targetFaction.describeTo(msender, true);
|
||||
if (targetFaction == msenderFaction)
|
||||
return ComparatorSmart.get().compare(i2.getValue().getCreationMillis(), i1.getValue().getCreationMillis());
|
||||
}
|
||||
});
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
final Pager<Entry<String, Invitation>> pager = new Pager<>(this, "Invited Players List", page, invitations, new Stringifier<Entry<String, Invitation>>()
|
||||
{
|
||||
public String toString(Entry<String, Invitation> entry, int index)
|
||||
{
|
||||
String inviteeId = entry.getKey();
|
||||
String inviterId = entry.getValue().getInviterId();
|
||||
|
||||
String inviteeDisplayName = MixinDisplayName.get().getDisplayName(inviteeId, sender);
|
||||
String inviterDisplayName = inviterId != null ? MixinDisplayName.get().getDisplayName(inviterId, sender) : Txt.parse("<silver>unknown");
|
||||
|
||||
String ageDesc = "";
|
||||
if (entry.getValue().getCreationMillis() != null)
|
||||
{
|
||||
factionName = factionName.toLowerCase();
|
||||
long millis = now - entry.getValue().getCreationMillis();
|
||||
LinkedHashMap<TimeUnit, Long> ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(millis, TimeUnit.getAllButMillis()), 2);
|
||||
ageDesc = TimeDiffUtil.formatedMinimal(ageUnitcounts, "<i>");
|
||||
ageDesc = " " + ageDesc + Txt.parse(" ago");
|
||||
}
|
||||
return Txt.parse("%s <i>%s %s <h>%s <i>%s %s<i>.", targetName, isAre, theAan, rankName, ofIn, factionName);
|
||||
|
||||
return Txt.parse("%s<i> was invited by %s<reset>%s<i>.", inviteeDisplayName, inviterDisplayName, ageDesc);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -39,15 +39,18 @@ public class CmdFactionsInviteRemove extends FactionsCommand
|
||||
// Args
|
||||
if ("all".equalsIgnoreCase(this.argAt(0)))
|
||||
{
|
||||
List<MPlayer> invitedPlayers = msenderFaction.getInvitedMPlayers();
|
||||
Set<String> ids = msenderFaction.getInvitations().keySet();
|
||||
// Doesn't show up if list is empty. Test at home if it worked.
|
||||
if (invitedPlayers == null || invitedPlayers.isEmpty())
|
||||
if (ids == null || ids.isEmpty())
|
||||
{
|
||||
msg("<b>Your faction has not invited anyone.");
|
||||
return;
|
||||
throw new MassiveException().addMsg("<b>No one is invited to your faction.");
|
||||
}
|
||||
all = true;
|
||||
mplayers.addAll(invitedPlayers);
|
||||
|
||||
for (String id : ids)
|
||||
{
|
||||
mplayers.add(MPlayer.get(id));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -98,7 +101,7 @@ public class CmdFactionsInviteRemove extends FactionsCommand
|
||||
}
|
||||
|
||||
// Apply
|
||||
msenderFaction.setInvited(mplayer, false);
|
||||
msenderFaction.uninvite(msender);
|
||||
|
||||
// If all, we do this at last. So we only do it once.
|
||||
if (! all) msenderFaction.changed();
|
||||
|
||||
@@ -117,7 +117,7 @@ public class CmdFactionsJoin extends FactionsCommand
|
||||
mplayer.resetFactionData();
|
||||
mplayer.setFaction(faction);
|
||||
|
||||
faction.setInvited(mplayer, false);
|
||||
faction.uninvite(mplayer);
|
||||
|
||||
// Derplog
|
||||
if (MConf.get().logFactionJoin)
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CmdFactionsKick extends FactionsCommand
|
||||
{
|
||||
mplayerFaction.promoteNewLeader();
|
||||
}
|
||||
mplayerFaction.setInvited(mplayer, false);
|
||||
mplayerFaction.uninvite(mplayer);
|
||||
mplayer.resetFactionData();
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ public class CmdFactionsRank extends FactionsCommand
|
||||
target.setFaction(endFaction);
|
||||
|
||||
// No longer invited.
|
||||
endFaction.setInvited(target, false);
|
||||
endFaction.uninvite(target);
|
||||
|
||||
// Create recipients
|
||||
Set<MPlayer> recipients = new HashSet<>();
|
||||
|
||||
Reference in New Issue
Block a user