mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-09-27 13:32:38 +02:00
Implement creatable ranks.
This commit is contained in:
parent
19a1d7fab4
commit
6b459391ef
@ -1,5 +1,7 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.adapter.BoardAdapter;
|
||||
import com.massivecraft.factions.adapter.BoardMapAdapter;
|
||||
import com.massivecraft.factions.adapter.RelAdapter;
|
||||
@ -14,8 +16,6 @@ import com.massivecraft.factions.chat.tag.ChatTagName;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagNameforce;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRelcolor;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRole;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRoleprefix;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagRoleprefixforce;
|
||||
import com.massivecraft.factions.chat.tag.ChatTagTitle;
|
||||
import com.massivecraft.factions.cmd.CmdFactions;
|
||||
import com.massivecraft.factions.cmd.type.TypeFactionChunkChangeType;
|
||||
@ -65,7 +65,6 @@ import com.massivecraft.massivecore.MassivePlugin;
|
||||
import com.massivecraft.massivecore.command.type.RegistryType;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.GsonBuilder;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Factions extends MassivePlugin
|
||||
{
|
||||
@ -188,8 +187,6 @@ public class Factions extends MassivePlugin
|
||||
// ChatTags,
|
||||
ChatTagRelcolor.class,
|
||||
ChatTagRole.class,
|
||||
ChatTagRoleprefix.class,
|
||||
ChatTagRoleprefixforce.class,
|
||||
ChatTagName.class,
|
||||
ChatTagNameforce.class,
|
||||
ChatTagTitle.class
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.massivecore.Identified;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.util.PermissionUtil;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
@ -115,6 +116,12 @@ public enum Perm implements Identified
|
||||
// HAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void hasThrow(Permissible permissible, boolean verboose) throws MassiveException
|
||||
{
|
||||
boolean has = this.has(permissible, verboose);
|
||||
if (!has) throw new MassiveException();
|
||||
}
|
||||
|
||||
public boolean has(Permissible permissible, boolean verboose)
|
||||
{
|
||||
return PermissionUtil.hasPermission(permissible, this, verboose);
|
||||
|
20
src/com/massivecraft/factions/PermissibleId.java
Normal file
20
src/com/massivecraft/factions/PermissibleId.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
|
||||
public class PermissibleId
|
||||
{
|
||||
// "Default" ranks
|
||||
public static final String LEADER = "leader";
|
||||
public static final String OFFICER = "officer";
|
||||
public static final String MEMBER = "member";
|
||||
public static final String RECRUIT = "recruit";
|
||||
|
||||
// Relations
|
||||
public static final String NEUTRAL = "neutral";
|
||||
public static final String TRUCE = "truce";
|
||||
public static final String ALLY = "ally";
|
||||
public static final String ENEMY = "enemy";
|
||||
|
||||
public static final String[] ALL = new String[] {LEADER, OFFICER, MEMBER, RECRUIT, NEUTRAL, TRUCE, ALLY, ENEMY};
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
public interface PermissionIdentifiable
|
||||
{
|
||||
String getPermissibleId();
|
||||
}
|
@ -1,26 +1,25 @@
|
||||
package com.massivecraft.factions.predicate;
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.predicate.Predicate;
|
||||
|
||||
public class PredicateMPlayerRole implements Predicate<MPlayer>
|
||||
public class PredicateRank implements Predicate<MPlayer>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Rel role;
|
||||
public Rel getRole() { return this.role; }
|
||||
private final Rank rank;
|
||||
public Rank getRank() { return this.rank; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE AND CONTRUCT
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static PredicateMPlayerRole get(Rel role) { return new PredicateMPlayerRole(role); }
|
||||
public PredicateMPlayerRole(Rel role)
|
||||
public static PredicateRank get(Rank role) { return new PredicateRank(role); }
|
||||
public PredicateRank(Rank rank)
|
||||
{
|
||||
this.role = role;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -31,6 +30,7 @@ public class PredicateMPlayerRole implements Predicate<MPlayer>
|
||||
public boolean apply(MPlayer mplayer)
|
||||
{
|
||||
if (mplayer == null) return false;
|
||||
return mplayer.getRole() == this.role;
|
||||
return mplayer.getRank().equals(this.getRank());
|
||||
}
|
||||
|
||||
}
|
158
src/com/massivecraft/factions/Rank.java
Normal file
158
src/com/massivecraft/factions/Rank.java
Normal file
@ -0,0 +1,158 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Prioritized;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public class Rank implements Named, Comparable<Rank>, Prioritized, PermissionIdentifiable
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static Rank LEADER = new Rank(1, "Leader");
|
||||
private static Rank OFFICER = new Rank(2, "Officer");
|
||||
private static Rank MEMBER = new Rank(3, "Member");
|
||||
private static Rank RECRUIT = new Rank(4, "Recruit");
|
||||
public static Rank DEFAULT = new Rank(null, null);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private transient String id;
|
||||
public String getId() { return this.id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
private transient Integer order;
|
||||
public Integer getOrder() { return this.order; }
|
||||
@Override public int getPriority() { return this.getOrder(); }
|
||||
public void setOrder(Integer order) { this.order = order; }
|
||||
|
||||
private String name;
|
||||
@Override public String getName() { return this.name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Rank(Integer order, String name)
|
||||
{
|
||||
this.id = MStore.createId();
|
||||
this.order = order;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVENIENCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Rank copy()
|
||||
{
|
||||
return new Rank(order, name);
|
||||
}
|
||||
|
||||
public boolean isLeader()
|
||||
{
|
||||
return this.getOrder() == 1;
|
||||
}
|
||||
|
||||
public boolean isHigherThan(Rank rank)
|
||||
{
|
||||
return this.getOrder() < rank.getOrder();
|
||||
}
|
||||
|
||||
public boolean isLessThan(Rank rank)
|
||||
{
|
||||
return this.getOrder() > rank.getOrder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissibleId()
|
||||
{
|
||||
return "rank" + this.getOrder();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE DEFAULT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Set<Rank> createDefaultRanks()
|
||||
{
|
||||
// Create
|
||||
Set<Rank> ret = new MassiveSet<>(4);
|
||||
|
||||
// Fill
|
||||
ret.add(LEADER.copy());
|
||||
ret.add(OFFICER.copy());
|
||||
ret.add(MEMBER.copy());
|
||||
ret.add(RECRUIT.copy());
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// VISUALIZE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Mson visualize()
|
||||
{
|
||||
return Mson.mson(
|
||||
String.valueOf(this.getOrder()),
|
||||
Mson.DOT,
|
||||
Mson.SPACE,
|
||||
this.getName()
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EQUALS & HASHCODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
if (this == object) return true;
|
||||
if (!(object instanceof Rank)) return false;
|
||||
Rank that = (Rank) object;
|
||||
|
||||
return MUtil.equals(
|
||||
this.order, that.order,
|
||||
this.name, that.name
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(order, name);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// COMPARE TO
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public int compareTo(Rank that)
|
||||
{
|
||||
if (that == null) return +1;
|
||||
|
||||
int orderOne = this.getOrder();
|
||||
int orderTwo = that.getOrder();
|
||||
|
||||
if (orderOne == orderTwo) return 0;
|
||||
if (orderOne > orderTwo) return +1;
|
||||
if (orderOne < orderTwo) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ import org.bukkit.ChatColor;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public enum Rel implements Colorized, Named
|
||||
public enum Rel implements Colorized, Named, PermissionIdentifiable
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
@ -35,25 +35,10 @@ public enum Rel implements Colorized, Named
|
||||
"Ally"
|
||||
) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } },
|
||||
|
||||
RECRUIT(
|
||||
"a recruit in your faction", "recruits in your faction", "", "",
|
||||
"Recruit"
|
||||
) { @Override public String getPrefix() { return MConf.get().prefixRecruit; } },
|
||||
|
||||
MEMBER(
|
||||
"a member in your faction", "members in your faction", "your faction", "your factions",
|
||||
"Member"
|
||||
) { @Override public String getPrefix() { return MConf.get().prefixMember; } },
|
||||
|
||||
OFFICER(
|
||||
"an officer in your faction", "officers in your faction", "", "",
|
||||
"Officer", "Moderator"
|
||||
) { @Override public String getPrefix() { return MConf.get().prefixOfficer; } },
|
||||
|
||||
LEADER(
|
||||
"your faction leader", "your faction leader", "", "",
|
||||
"Leader", "Admin", "Owner"
|
||||
) { @Override public String getPrefix() { return MConf.get().prefixLeader; } },
|
||||
FACTION(
|
||||
"someone in your faction", "a faction member", "faction members",
|
||||
"Faction"
|
||||
) { @Override public ChatColor getColor() { return MConf.get().colorMember; } },
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
@ -93,16 +78,6 @@ public enum Rel implements Colorized, Named
|
||||
this.names = Collections.unmodifiableSet(new MassiveSet<>(names));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ChatColor getColor()
|
||||
{
|
||||
return MConf.get().colorMember;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
@ -127,20 +102,16 @@ public enum Rel implements Colorized, Named
|
||||
return this.getValue() > rel.getValue();
|
||||
}
|
||||
|
||||
public boolean isRank()
|
||||
{
|
||||
return this.isAtLeast(Rel.RECRUIT);
|
||||
}
|
||||
|
||||
// Used for friendly fire.
|
||||
public boolean isFriend()
|
||||
{
|
||||
return this.isAtLeast(TRUCE);
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
@Override
|
||||
public String getPermissibleId()
|
||||
{
|
||||
return "";
|
||||
return this.getName().toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class ChatTagRole extends ChatTag
|
||||
// Get entities
|
||||
MPlayer usender = MPlayer.get(sender);
|
||||
|
||||
return Txt.upperCaseFirst(usender.getRole().toString().toLowerCase());
|
||||
return Txt.upperCaseFirst(usender.getRank().toString().toLowerCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTag;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ChatTagRoleprefix extends ChatTag
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRoleprefix() { super("factions_roleprefix"); }
|
||||
private static ChatTagRoleprefix i = new ChatTagRoleprefix();
|
||||
public static ChatTagRoleprefix get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Get entities
|
||||
MPlayer usender = MPlayer.get(sender);
|
||||
|
||||
// No "force"
|
||||
Faction faction = usender.getFaction();
|
||||
if (faction.isNone()) return "";
|
||||
|
||||
return usender.getRole().getPrefix();
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.massivecraft.factions.chat.tag;
|
||||
|
||||
import com.massivecraft.factions.chat.ChatTag;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ChatTagRoleprefixforce extends ChatTag
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); }
|
||||
private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce();
|
||||
public static ChatTagRoleprefixforce get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getReplacement(CommandSender sender, CommandSender recipient)
|
||||
{
|
||||
// Get entities
|
||||
MPlayer usender = MPlayer.get(sender);
|
||||
|
||||
return usender.getRole().getPrefix();
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasntFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
@ -70,8 +70,10 @@ public class CmdFactionsCreate extends FactionsCommand
|
||||
// Apply
|
||||
Faction faction = FactionColl.get().create(factionId);
|
||||
faction.setName(newName);
|
||||
faction.setRanks(Rank.createDefaultRanks());
|
||||
faction.setRankManager(faction.getRankLeader());
|
||||
|
||||
msender.setRole(Rel.LEADER);
|
||||
msender.setRank(faction.getRankLeader());
|
||||
msender.setFaction(faction);
|
||||
|
||||
EventFactionsMembershipChange joinEvent = new EventFactionsMembershipChange(sender, msender, faction, MembershipChangeReason.CREATE);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
@ -50,19 +50,23 @@ public class CmdFactionsInviteList extends FactionsCommand
|
||||
{
|
||||
public String toString(MPlayer target, int index)
|
||||
{
|
||||
// TODO: Madus would like to implement this in MPlayer
|
||||
|
||||
String targetName = target.getDisplayName(msender);
|
||||
String isAre = target == msender ? "are" : "is";
|
||||
Rel targetRank = target.getRole();
|
||||
Rank targetRank = target.getRank();
|
||||
boolean isLeader = targetRank.isLeader();
|
||||
|
||||
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 rankName = targetRank.getName();
|
||||
String theAan = isLeader ? "the" : Txt.aan(rankName);
|
||||
String ofIn = isLeader ? "of" : "in";
|
||||
|
||||
String factionName = targetFaction.describeTo(msender, true);
|
||||
if (targetFaction == msenderFaction)
|
||||
{
|
||||
factionName = factionName.toLowerCase();
|
||||
}
|
||||
|
||||
return Txt.parse("%s <i>%s %s <h>%s <i>%s %s<i>.", targetName, isAre, theAan, rankName, ofIn, factionName);
|
||||
}
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
@ -44,17 +43,17 @@ public class CmdFactionsKick extends FactionsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (mplayer.getRole() == Rel.LEADER && !msender.isOverriding())
|
||||
if (mplayer.getRank().isLeader() && !msender.isOverriding())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>The leader cannot be kicked.");
|
||||
}
|
||||
|
||||
if (mplayer.getRole().isMoreThan(msender.getRole()) && ! msender.isOverriding())
|
||||
if (mplayer.getRank().isHigherThan(msender.getRank()) && ! msender.isOverriding())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You can't kick people of higher rank than yourself.");
|
||||
}
|
||||
|
||||
if (mplayer.getRole() == msender.getRole() && ! msender.isOverriding())
|
||||
if (mplayer.getRank().equals(msender.getRank())&& ! msender.isOverriding())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You can't kick people of the same rank as yourself.");
|
||||
}
|
||||
@ -88,7 +87,7 @@ public class CmdFactionsKick extends FactionsCommand
|
||||
}
|
||||
|
||||
// Apply
|
||||
if (mplayer.getRole() == Rel.LEADER)
|
||||
if (mplayer.getRank().isLeader())
|
||||
{
|
||||
mplayerFaction.promoteNewLeader();
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.PermissibleId;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
@ -59,20 +63,23 @@ public class CmdFactionsPermSet extends FactionsCommand
|
||||
if (event.isCancelled()) return;
|
||||
value = event.getNewValue();
|
||||
|
||||
// TODO: Change and use a TypePermissibleID or something like it
|
||||
String permissibleId = rel.getName().toLowerCase();
|
||||
|
||||
// No change
|
||||
if (faction.getPermitted(perm).contains(rel) == value)
|
||||
if (faction.getPermitted(perm).contains(permissibleId) == value)
|
||||
{
|
||||
msg("%s <i>already has %s <i>set to %s <i>for %s<i>.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "<g>YES" : "<b>NOO"), rel.getColor() + rel.getDescPlayerMany());
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply
|
||||
faction.setRelationPermitted(perm, rel, value);
|
||||
faction.setRelationPermitted(perm, permissibleId, value);
|
||||
|
||||
// The following is to make sure the leader always has the right to change perms if that is our goal.
|
||||
if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER))
|
||||
if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(PermissibleId.LEADER))
|
||||
{
|
||||
faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true);
|
||||
faction.setRelationPermitted(MPerm.getPermPerms(), PermissibleId.LEADER, true);
|
||||
}
|
||||
|
||||
// Create messages
|
||||
|
@ -1,51 +1,18 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.event.EventFactionsRankChange;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CmdFactionsRank extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// The rank required to do any rank changes.
|
||||
final static Rel rankReq = Rel.OFFICER;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
// These fields are set upon perform() and unset afterwards.
|
||||
|
||||
// Target
|
||||
private Faction targetFaction = null;
|
||||
private MPlayer target = null;
|
||||
|
||||
// End faction (the faction they are changed to)
|
||||
private Faction endFaction = null;
|
||||
private boolean factionChange = false;
|
||||
|
||||
// Ranks
|
||||
private Rel senderRank = null;
|
||||
private Rel targetRank = null;
|
||||
private Rel rank = null;
|
||||
public CmdFactionsRankList cmdFactionsRankList = new CmdFactionsRankList();
|
||||
public CmdFactionsRankShow cmdFactionsRankShow = new CmdFactionsRankShow();
|
||||
public CmdFactionsRankCreate cmdFactionsRankCreate = new CmdFactionsRankCreate();
|
||||
public CmdFactionsRankName cmdFactionsRankName = new CmdFactionsRankName();
|
||||
public CmdFactionsRankOrder cmdFactionsRankOrder = new CmdFactionsRankOrder();
|
||||
public CmdFactionsRankDelete cmdFactionsRankDelete = new CmdFactionsRankDelete();
|
||||
public CmdFactionsRankSet cmdFactionsRankSet = new CmdFactionsRankSet();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
@ -53,341 +20,14 @@ public class CmdFactionsRank extends FactionsCommand
|
||||
|
||||
public CmdFactionsRank()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPlayer.get(), "player");
|
||||
this.addParameter(TypeRank.get(), "action", "show");
|
||||
this.addParameter(TypeFaction.get(), "faction", "their");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// This sets target and much other.
|
||||
this.registerFields();
|
||||
|
||||
// Sometimes we just want to show the rank.
|
||||
if ( ! this.argIsSet(1))
|
||||
{
|
||||
if ( ! Perm.RANK_SHOW.has(sender, true)) return;
|
||||
this.showRank();
|
||||
return;
|
||||
}
|
||||
|
||||
// Permission check.
|
||||
if ( ! Perm.RANK_ACTION.has(sender, true)) return;
|
||||
|
||||
// Is the player allowed or not. Method can be found later down.
|
||||
this.ensureAllowed();
|
||||
|
||||
if (factionChange)
|
||||
{
|
||||
this.changeFaction();
|
||||
}
|
||||
|
||||
// Does the change make sense.
|
||||
this.ensureMakesSense();
|
||||
|
||||
// Event
|
||||
EventFactionsRankChange event = new EventFactionsRankChange(sender, target, rank);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
rank = event.getNewRank();
|
||||
|
||||
// Change the rank.
|
||||
this.changeRank();
|
||||
}
|
||||
|
||||
// This is always run after performing a MassiveCommand.
|
||||
@Override
|
||||
public void senderFields(boolean set)
|
||||
{
|
||||
super.senderFields(set);
|
||||
|
||||
if ( ! set)
|
||||
{
|
||||
this.unregisterFields();
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE: REGISTER & UNREGISTER
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void registerFields() throws MassiveException
|
||||
{
|
||||
// Getting the target and faction.
|
||||
target = this.readArg(msender);
|
||||
targetFaction = target.getFaction();
|
||||
|
||||
|
||||
// Ranks
|
||||
senderRank = msender.getRole();
|
||||
targetRank = target.getRole();
|
||||
|
||||
// Rank if any passed.
|
||||
if (this.argIsSet(1))
|
||||
{
|
||||
this.setParameterType(1, TypeRank.get(targetRank));
|
||||
rank = this.readArg();
|
||||
}
|
||||
|
||||
// Changing peoples faction.
|
||||
endFaction = this.readArgAt(2, targetFaction);
|
||||
factionChange = (endFaction != targetFaction);
|
||||
|
||||
}
|
||||
|
||||
private void unregisterFields()
|
||||
{
|
||||
targetFaction = null;
|
||||
target = null;
|
||||
|
||||
senderRank = null;
|
||||
targetRank = null;
|
||||
rank = null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE: ENSURE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void ensureAllowed() throws MassiveException
|
||||
{
|
||||
// People with permission don't follow the normal rules.
|
||||
if (msender.isOverriding()) return;
|
||||
|
||||
// If somone gets the leadership of wilderness (Which has happened before).
|
||||
// We can at least try to limit their powers.
|
||||
if (endFaction.isNone())
|
||||
{
|
||||
throw new MassiveException().addMsg("%s <b>doesn't use ranks sorry :(", targetFaction.getName() );
|
||||
}
|
||||
|
||||
if (target == msender)
|
||||
{
|
||||
// Don't change your own rank.
|
||||
throw new MassiveException().addMsg("<b>The target player mustn't be yourself.");
|
||||
}
|
||||
|
||||
if (targetFaction != msenderFaction)
|
||||
{
|
||||
// Don't change ranks outside of your faction.
|
||||
throw new MassiveException().addMsg("%s <b>is not in the same faction as you.", target.describeTo(msender, true));
|
||||
}
|
||||
|
||||
if (factionChange)
|
||||
{
|
||||
// Don't change peoples faction
|
||||
throw new MassiveException().addMsg("<b>You can't change %s's <b>faction.", target.describeTo(msender));
|
||||
}
|
||||
|
||||
if (senderRank.isLessThan(rankReq))
|
||||
{
|
||||
// You need a specific rank to change ranks.
|
||||
throw new MassiveException().addMsg("<b>You must be <h>%s <b>or higher to change ranks.", Txt.getNicedEnum(rankReq).toLowerCase());
|
||||
}
|
||||
|
||||
// The following two if statements could be merged.
|
||||
// But isn't for the sake of nicer error messages.
|
||||
if (senderRank == targetRank)
|
||||
{
|
||||
// You can't change someones rank if it is equal to yours.
|
||||
throw new MassiveException().addMsg("<h>%s <b>can't manage eachother.", Txt.getNicedEnum(rankReq)+"s");
|
||||
}
|
||||
|
||||
if (senderRank.isLessThan(targetRank))
|
||||
{
|
||||
// You can't change someones rank if it is higher than yours.
|
||||
throw new MassiveException().addMsg("<b>You can't manage people of higher rank.");
|
||||
}
|
||||
|
||||
// The following two if statements could be merged.
|
||||
// But isn't for the sake of nicer error messages.
|
||||
if (senderRank == rank && senderRank != Rel.LEADER)
|
||||
{
|
||||
// You can't set ranks equal to your own. Unless you are the leader.
|
||||
throw new MassiveException().addMsg("<b>You can't set ranks equal to your own.");
|
||||
}
|
||||
|
||||
if (senderRank.isLessThan(rank))
|
||||
{
|
||||
// You can't set ranks higher than your own.
|
||||
throw new MassiveException().addMsg("<b>You can't set ranks higher than your own.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureMakesSense() throws MassiveException
|
||||
{
|
||||
// Don't change their rank to something they already are.
|
||||
if (target.getRole() == rank)
|
||||
{
|
||||
throw new MassiveException().addMsg("%s <b>is already %s.", target.describeTo(msender), rank.getDescPlayerOne());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE: SHOW
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void showRank()
|
||||
{
|
||||
// Damn you grammar, causing all these checks.
|
||||
String targetName = target.describeTo(msender, true);
|
||||
String isAre = (target == msender) ? "are" : "is"; // "you are" or "he is"
|
||||
String theAan = (targetRank == Rel.LEADER) ? "the" : Txt.aan(targetRank.name()); // "a member", "an officer" or "the leader"
|
||||
String rankName = Txt.getNicedEnum(targetRank).toLowerCase();
|
||||
String ofIn = (targetRank == Rel.LEADER) ? "of" : "in"; // "member in" or "leader of"
|
||||
String factionName = targetFaction.describeTo(msender, true);
|
||||
if (targetFaction == msenderFaction)
|
||||
{
|
||||
// Having the "Y" in "Your faction" being uppercase in the middle of a sentence makes no sense.
|
||||
factionName = factionName.toLowerCase();
|
||||
}
|
||||
if (targetFaction.isNone())
|
||||
{
|
||||
// Wilderness aka none doesn't use ranks
|
||||
msg("%s <i>%s factionless", targetName, isAre);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Derp is a member in Faction
|
||||
msg("%s <i>%s %s <h>%s <i>%s %s<i>.", targetName, isAre, theAan, rankName, ofIn, factionName);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE: CHANGE FACTION
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void changeFaction() throws MassiveException
|
||||
{
|
||||
// Don't change a leader to a new faction.
|
||||
if (targetRank == Rel.LEADER)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>You cannot remove the present leader. Demote them first.");
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, msender, endFaction, MembershipChangeReason.RANK);
|
||||
membershipChangeEvent.run();
|
||||
if (membershipChangeEvent.isCancelled()) throw new MassiveException();
|
||||
|
||||
// Apply
|
||||
target.resetFactionData();
|
||||
target.setFaction(endFaction);
|
||||
|
||||
// No longer invited.
|
||||
endFaction.setInvited(target, false);
|
||||
|
||||
// Create recipients
|
||||
Set<MPlayer> recipients = new HashSet<>();
|
||||
recipients.addAll(targetFaction.getMPlayersWhereOnline(true));
|
||||
recipients.addAll(endFaction.getMPlayersWhereOnline(true));
|
||||
recipients.add(msender);
|
||||
|
||||
// Send message
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("%s <i>was moved from <i>%s to <i>%s<i>.", target.describeTo(recipient), targetFaction.describeTo(recipient), endFaction.describeTo(recipient));
|
||||
}
|
||||
|
||||
// Derplog
|
||||
if (MConf.get().logFactionJoin)
|
||||
{
|
||||
Factions.get().log(Txt.parse("%s moved %s from %s to %s.", msender.getName(), target.getName(), targetFaction.getName(), endFaction.getName()));
|
||||
}
|
||||
|
||||
// Now we don't need the old values.
|
||||
targetFaction = target.getFaction();
|
||||
targetRank = target.getRole();
|
||||
senderRank = msender.getRole(); // In case they changed their own rank
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PRIVATE: CHANGE RANK
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void changeRank() throws MassiveException
|
||||
{
|
||||
// In case of leadership change, we do special things not done in other rank changes.
|
||||
if (rank == Rel.LEADER)
|
||||
{
|
||||
this.changeRankLeader();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.changeRankOther();
|
||||
}
|
||||
}
|
||||
|
||||
private void changeRankLeader()
|
||||
{
|
||||
// If there is a current leader. Demote & inform them.
|
||||
MPlayer targetFactionCurrentLeader = targetFaction.getLeader();
|
||||
if (targetFactionCurrentLeader != null)
|
||||
{
|
||||
// Inform & demote the old leader.
|
||||
targetFactionCurrentLeader.setRole(Rel.OFFICER);
|
||||
if (targetFactionCurrentLeader != msender)
|
||||
{
|
||||
// They kinda know if they fired the command themself.
|
||||
targetFactionCurrentLeader.msg("<i>You have been demoted from the position of faction leader by %s<i>.", msender.describeTo(targetFactionCurrentLeader, true));
|
||||
}
|
||||
}
|
||||
|
||||
// Promote the new leader.
|
||||
target.setRole(Rel.LEADER);
|
||||
|
||||
// Inform everyone, this includes sender and target.
|
||||
for (MPlayer recipient : MPlayerColl.get().getAllOnline())
|
||||
{
|
||||
String changerName = senderIsConsole ? "A server admin" : msender.describeTo(recipient);
|
||||
recipient.msg("%s<i> gave %s<i> the leadership of %s<i>.", changerName, target.describeTo(recipient), targetFaction.describeTo(recipient));
|
||||
}
|
||||
}
|
||||
|
||||
private void changeRankOther() throws MassiveException
|
||||
{
|
||||
// If the target is currently the leader and faction isn't permanent a new leader should be promoted.
|
||||
// Sometimes a bug occurs and multiple leaders exist. Then we should be able to demote without promoting new leader
|
||||
if (targetRank == Rel.LEADER && ( ! MConf.get().permanentFactionsDisableLeaderPromotion || ! targetFaction.getFlag(MFlag.ID_PERMANENT)) && targetFaction.getMPlayersWhereRole(Rel.LEADER).size() == 1)
|
||||
// This if statement is very long. Should I nest it for readability?
|
||||
{
|
||||
targetFaction.promoteNewLeader(); // This might disband the faction.
|
||||
|
||||
// So if the faction disbanded...
|
||||
if (targetFaction.detached())
|
||||
{
|
||||
// ... we inform the sender.
|
||||
target.resetFactionData();
|
||||
throw new MassiveException().addMsg("<i>The target was a leader and got demoted. The faction disbanded and no rank was set.");
|
||||
}
|
||||
}
|
||||
|
||||
// Create recipients
|
||||
Set<MPlayer> recipients = new HashSet<>();
|
||||
recipients.addAll(targetFaction.getMPlayers());
|
||||
recipients.add(msender);
|
||||
|
||||
// Were they demoted or promoted?
|
||||
String change = (rank.isLessThan(targetRank) ? "demoted" : "promoted");
|
||||
|
||||
// The rank will be set before the msg, so they have the appropriate prefix.
|
||||
target.setRole(rank);
|
||||
String oldRankName = Txt.getNicedEnum(targetRank).toLowerCase();
|
||||
String rankName = Txt.getNicedEnum(rank).toLowerCase();
|
||||
|
||||
// Send message
|
||||
for(MPlayer recipient : recipients)
|
||||
{
|
||||
String targetName = target.describeTo(recipient, true);
|
||||
String wasWere = (recipient == target) ? "were" : "was";
|
||||
recipient.msg("%s<i> %s %s from %s to <h>%s <i>in %s<i>.", targetName, wasWere, change, oldRankName, rankName, targetFaction.describeTo(msender));
|
||||
}
|
||||
// Children
|
||||
this.addChild(this.cmdFactionsRankList);
|
||||
this.addChild(this.cmdFactionsRankShow);
|
||||
this.addChild(this.cmdFactionsRankCreate);
|
||||
this.addChild(this.cmdFactionsRankDelete);
|
||||
this.addChild(this.cmdFactionsRankName);
|
||||
this.addChild(this.cmdFactionsRankOrder);
|
||||
this.addChild(this.cmdFactionsRankSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
46
src/com/massivecraft/factions/cmd/CmdFactionsRankCreate.java
Normal file
46
src/com/massivecraft/factions/cmd/CmdFactionsRankCreate.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRankName;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
|
||||
public class CmdFactionsRankCreate extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankCreate()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeRankName.getStrict(), "name");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
String name = this.readArg();
|
||||
|
||||
// Create
|
||||
Rank rank = msenderFaction.createRank(name);
|
||||
|
||||
// Add
|
||||
msenderFaction.addRank(rank);
|
||||
|
||||
// Inform
|
||||
message(mson(
|
||||
"The rank ",
|
||||
TypeRank.get().getVisualMson(rank),
|
||||
" has been created."
|
||||
).color(ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
}
|
69
src/com/massivecraft/factions/cmd/CmdFactionsRankDelete.java
Normal file
69
src/com/massivecraft/factions/cmd/CmdFactionsRankDelete.java
Normal file
@ -0,0 +1,69 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanTrue;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsRankDelete extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankDelete()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeRank.get(), "rank");
|
||||
this.addParameter(TypeBooleanTrue.get(), "ensure");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Rank rank = this.readArg();
|
||||
boolean ensure = this.readArg(false);
|
||||
|
||||
// Ensure
|
||||
if (!ensure) throw new MassiveException().setMsg("<b>You must ensure to delete the rank.");
|
||||
|
||||
// Delete
|
||||
boolean success = msenderFaction.removeRank(rank);
|
||||
|
||||
// On Success
|
||||
if (success) this.demoteMembersWithRank(rank);
|
||||
|
||||
// Inform
|
||||
message(mson(
|
||||
"The Rank ",
|
||||
TypeRank.get().getVisualMson(rank),
|
||||
success ? " could not be " : " has been ",
|
||||
"removed."
|
||||
).color(success ? ChatColor.GREEN : ChatColor.RED));
|
||||
}
|
||||
|
||||
private void demoteMembersWithRank(Rank rank)
|
||||
{
|
||||
// Prepare
|
||||
String visualRankOld = TypeRank.get().getVisual(rank);
|
||||
String visualRankNew = TypeRank.get().getVisual(msenderFaction.getNextLowerRank(rank));
|
||||
String message = Txt.parse("<i>You have been demoted from %s to %s, because your rank has been deleted.", visualRankOld, visualRankNew);
|
||||
|
||||
// Demote & Inform
|
||||
for (MPlayer mplayer : msenderFaction.getMPlayersWhereRank(rank))
|
||||
{
|
||||
msenderFaction.demote(mplayer);
|
||||
mplayer.msg(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
79
src/com/massivecraft/factions/cmd/CmdFactionsRankList.java
Normal file
79
src/com/massivecraft/factions/cmd/CmdFactionsRankList.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Msonifier;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsRankList extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankList()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(Parameter.getPage());
|
||||
this.addParameter(TypeFaction.get(), "faction", "their");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
int page = this.readArg();
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
|
||||
// Are we trying to show other?
|
||||
this.tryShowOther();
|
||||
|
||||
// Pager Prepare
|
||||
Collection<Rank> ranks = faction.getRankCollection();
|
||||
String title = Txt.parse("Ranks for %s", faction.describeTo(msender));
|
||||
List<String> args = MUtil.list(String.valueOf(page), faction.getName());
|
||||
|
||||
// Pager Create
|
||||
final Pager<Rank> pager = new Pager<>(this, title, page, ranks, new Msonifier<Rank>()
|
||||
{
|
||||
@Override
|
||||
public Mson toMson(Rank rank, int index)
|
||||
{
|
||||
return rank.visualize();
|
||||
}
|
||||
});
|
||||
|
||||
// Pager Args
|
||||
pager.setArgs(args);
|
||||
|
||||
// Pager message
|
||||
pager.messageAsync();
|
||||
}
|
||||
|
||||
private void tryShowOther() throws MassiveException
|
||||
{
|
||||
// Are we trying to show other?
|
||||
if (!this.argIsSet(0)) return;
|
||||
|
||||
// Are we overriding?
|
||||
if (msender.isOverriding()) return;
|
||||
|
||||
// Throw if they don't have the permission to show
|
||||
Perm.RANK_SHOW.hasThrow(sender, true);
|
||||
}
|
||||
|
||||
}
|
65
src/com/massivecraft/factions/cmd/CmdFactionsRankName.java
Normal file
65
src/com/massivecraft/factions/cmd/CmdFactionsRankName.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRankName;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
public class CmdFactionsRankName extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankName()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeRank.get(), "rank");
|
||||
this.addParameter(TypeRankName.getLenient(), "name", "show");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Rank rank = this.readArg();
|
||||
Rank oldRank = rank.copy();
|
||||
|
||||
// Are we showing?
|
||||
if (!this.argIsSet(1))
|
||||
{
|
||||
this.inform(rank, false);
|
||||
return;
|
||||
}
|
||||
|
||||
String name = this.readArg();
|
||||
|
||||
// Change
|
||||
rank.setName(name);
|
||||
|
||||
// Add
|
||||
msenderFaction.addRank(rank);
|
||||
|
||||
// Inform
|
||||
this.inform(oldRank, true);
|
||||
}
|
||||
|
||||
private void inform(Rank rank, boolean updated)
|
||||
{
|
||||
message(mson(
|
||||
"The rank name of ",
|
||||
TypeRank.get().getVisualMson(rank),
|
||||
" is ",
|
||||
updated ? "now " : Mson.EMPTY,
|
||||
mson(String.valueOf(rank.getOrder())).color(ChatColor.LIGHT_PURPLE)
|
||||
).color(ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.massivecore.command.Visibility;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
@ -28,7 +27,6 @@ public class CmdFactionsRankOld extends FactionsCommand
|
||||
|
||||
// Parameters
|
||||
this.addParameter(TypeMPlayer.get(), "player");
|
||||
this.addParameter(TypeFaction.get(), "faction", "their");
|
||||
|
||||
// Visibility
|
||||
this.setVisibility(Visibility.INVISIBLE);
|
||||
@ -41,10 +39,9 @@ public class CmdFactionsRankOld extends FactionsCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
CmdFactions.get().cmdFactionsRank.execute(sender, MUtil.list(
|
||||
CmdFactions.get().cmdFactionsRank.cmdFactionsRankSet.execute(sender, MUtil.list(
|
||||
this.argAt(0),
|
||||
this.rankName,
|
||||
this.argAt(1)
|
||||
this.rankName
|
||||
));
|
||||
}
|
||||
|
||||
|
66
src/com/massivecraft/factions/cmd/CmdFactionsRankOrder.java
Normal file
66
src/com/massivecraft/factions/cmd/CmdFactionsRankOrder.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
public class CmdFactionsRankOrder extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankOrder()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeRank.get(), "rank");
|
||||
this.addParameter(TypeInteger.get(), "order", "show");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Rank rank = this.readArg();
|
||||
|
||||
// Are we showing?
|
||||
if (!this.argIsSet(1))
|
||||
{
|
||||
this.inform(rank, false);
|
||||
return;
|
||||
}
|
||||
|
||||
int order = this.readArg();
|
||||
Faction faction = msenderFaction;
|
||||
|
||||
// Already this rank?
|
||||
if (rank.getOrder() == order) throw new MassiveException().setMsg("<b>Rank order for %s is already <h>%d<i>.", rank.getName(), rank.getOrder());
|
||||
|
||||
// Adjust rank
|
||||
faction.adjustRankOrder(rank, order);
|
||||
|
||||
// Inform
|
||||
this.inform(rank, true);
|
||||
}
|
||||
|
||||
private void inform(Rank rank, boolean updated)
|
||||
{
|
||||
message(mson(
|
||||
"The rank order of ",
|
||||
TypeRank.get().getVisualMson(rank),
|
||||
" is ",
|
||||
updated ? "now " : Mson.EMPTY,
|
||||
mson(String.valueOf(rank.getOrder())).color(ChatColor.LIGHT_PURPLE)
|
||||
).color(ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
}
|
226
src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java
Normal file
226
src/com/massivecraft/factions/cmd/CmdFactionsRankSet.java
Normal file
@ -0,0 +1,226 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.factions.event.EventFactionsRankChange;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsRankSet extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final String MESSAGE_FORMAT = "%s <i>Rank has been set to %s<i>.";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankSet()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPlayer.get(), "player");
|
||||
this.addParameter(TypeRank.get(), "rank");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
MPlayer mplayer = this.readArg();
|
||||
Rank rank = this.readArg();
|
||||
|
||||
// Make sure sender can set this rank
|
||||
this.ensureRankSet(mplayer, rank);
|
||||
this.ensureRankUpdate(mplayer, rank);
|
||||
rank = this.ensureRankChangeEvent(mplayer, rank);
|
||||
|
||||
// Set Rank
|
||||
this.setRank(mplayer, rank);
|
||||
|
||||
// Prepare inform
|
||||
boolean same = mplayer == msender;
|
||||
String visualRank = TypeRank.get().getVisual(rank);
|
||||
String visualPlayer = mplayer.describeTo(msender);
|
||||
if (same) visualPlayer += "r";
|
||||
|
||||
// Inform
|
||||
msg(MESSAGE_FORMAT, visualPlayer, visualRank);
|
||||
if (!same) mplayer.msg(MESSAGE_FORMAT, mplayer.describeTo(mplayer), visualRank);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ENSURE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void ensureRankSet(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
// People with permission don't follow the normal rules.
|
||||
if (msender.isOverriding()) return;
|
||||
|
||||
// Prepare
|
||||
MassiveException exception = new MassiveException();
|
||||
Faction faction = mplayer.getFaction();
|
||||
String describe = mplayer.describeTo(msender, true);
|
||||
Rank rankPlayer = mplayer.getRank();
|
||||
Rank rankSender = msender.getRank();
|
||||
Rank rankManager = faction.getRankManager();
|
||||
String rankManagerName = rankManager.getName();
|
||||
|
||||
boolean isPermanent = faction.getFlag(MFlag.ID_PERMANENT);
|
||||
boolean isPermanentDemoteDisabled = MConf.get().permanentFactionsDisableLeaderPromotion;
|
||||
|
||||
// Can't change rank in Wilderness
|
||||
if (faction.isNone()) throw exception.addMsg("%s <b>doesn't use ranks, sorry :(.", faction.getName());
|
||||
|
||||
// Don't change your own rank.
|
||||
if (mplayer == msender) throw exception.addMsg("<b>The target player mustn't be yourself.");
|
||||
|
||||
// Don't change ranks outside of your faction.
|
||||
if (faction != msenderFaction) throw exception.addMsg("%s <b>is not in the same faction as you.", describe);
|
||||
|
||||
// You need to be rank manager to change ranks.
|
||||
if (msender.getRank().isLessThan(rankManager)) throw exception.addMsg("<b>You must be <h>%s <b>or higher to change ranks.", rankManagerName);
|
||||
|
||||
// You can't change someones rank if it is equal to yours.
|
||||
if (rankPlayer == rank) throw exception.addMsg("<h>%s <b>can't manage eachother.", rankManagerName + "s");
|
||||
|
||||
// You can't change someones rank if it is higher than yours.
|
||||
if (rankPlayer.isLessThan(rank)) throw exception.addMsg("<b>You can't manage people of higher rank.");
|
||||
|
||||
// You can't set ranks equal to your own. Unless you are the leader.
|
||||
if (rankSender == rank && !rankSender.isLeader()) throw exception.addMsg("<b>You can't set ranks equal to your own.");
|
||||
|
||||
// You can't promote new leaders for permanent factions if its disabled
|
||||
if (rank.isLeader() && isPermanent && isPermanentDemoteDisabled) throw exception.setMsg("<b>You can't promote a new leader for permanent factions.");
|
||||
}
|
||||
|
||||
private void ensureRankUpdate(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
// Don't change their rank to something they already are.
|
||||
if (!mplayer.getRank().equals(rank)) return;
|
||||
|
||||
// Prepare
|
||||
String describe = mplayer.describeTo(msender);
|
||||
String name = rank.getName();
|
||||
String aan = Txt.aan(name);
|
||||
|
||||
// Inform
|
||||
throw new MassiveException().addMsg("%s <b>is already %s %s.", describe, aan, name);
|
||||
}
|
||||
|
||||
private Rank ensureRankChangeEvent(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
// Create and Run
|
||||
EventFactionsRankChange event = new EventFactionsRankChange(sender, mplayer, rank);
|
||||
event.run();
|
||||
|
||||
// Check
|
||||
if (event.isCancelled()) throw new MassiveException().setMsg("<b>Another plugin has prohibited the rank change.");
|
||||
|
||||
// Return
|
||||
return event.getNewRank();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SET RANK
|
||||
// -------------------------------------------- //
|
||||
|
||||
private void setRank(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
if (rank.isLeader())
|
||||
{
|
||||
this.setRankLeader(mplayer, rank);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setRankOther(mplayer, rank);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRankLeader(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
Faction faction = mplayer.getFaction();
|
||||
MPlayer leaderCurrent = faction.getLeader();
|
||||
if (leaderCurrent != null)
|
||||
{
|
||||
faction.demote(leaderCurrent);
|
||||
if (leaderCurrent != msender)
|
||||
{
|
||||
String visualSender = msender.describeTo(leaderCurrent, true);
|
||||
leaderCurrent.msg("<i>You have been demoted from the position of faction leader by %s<i>.", visualSender);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Set before inform for prefix change
|
||||
mplayer.setRank(rank);
|
||||
|
||||
// Inform everyone, this includes sender and target.
|
||||
for (MPlayer recipient : MPlayerColl.get().getAllOnline())
|
||||
{
|
||||
String changerName = senderIsConsole ? "A server admin" : msender.describeTo(recipient);
|
||||
String visualSender = mplayer.describeTo(recipient);
|
||||
String visualFaction = faction.describeTo(recipient);
|
||||
String message = Txt.parse("%s<i> gave %s<i> the leadership of %s<i>.", changerName, visualSender, visualFaction);
|
||||
|
||||
recipient.message(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRankOther(MPlayer mplayer, Rank rank) throws MassiveException
|
||||
{
|
||||
Faction faction = mplayer.getFaction();
|
||||
Rank rankPlayer = mplayer.getRank();
|
||||
|
||||
// NOTE: There has been occasions where there were more than one leader
|
||||
if (rankPlayer.isLeader() && faction.getMPlayersWhereLeader().size() == 1)
|
||||
{
|
||||
faction.promoteNewLeader();
|
||||
|
||||
// So if the faction disbanded...
|
||||
if (faction.detached())
|
||||
{
|
||||
// ... we inform the sender.
|
||||
mplayer.resetFactionData();
|
||||
throw new MassiveException().addMsg("<i>The target was a leader and got demoted. The faction disbanded and no rank was set.");
|
||||
}
|
||||
}
|
||||
|
||||
// Get recipients
|
||||
Set<MPlayer> recipients = new MassiveSet<>(faction.getMPlayers());
|
||||
recipients.add(msender);
|
||||
|
||||
// Prepare inform
|
||||
String change = (mplayer.getRank().isLessThan(rank) ? "demoted" : "promoted");
|
||||
|
||||
// NOTE: Set before inform for prefix change
|
||||
mplayer.setRank(rank);
|
||||
Mson rankNameOld = TypeRank.get().getVisualMson(rankPlayer);
|
||||
Mson rankNameNew = TypeRank.get().getVisualMson(rank);
|
||||
|
||||
// Inform
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
String describe = mplayer.describeTo(recipient, true);
|
||||
String wasWere = (recipient == mplayer) ? "were" : "was";
|
||||
recipient.msg("%s<i> %s %s from %s to <h>%s<i>.", describe, wasWere, change, rankNameOld, rankNameNew);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
42
src/com/massivecraft/factions/cmd/CmdFactionsRankShow.java
Normal file
42
src/com/massivecraft/factions/cmd/CmdFactionsRankShow.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class CmdFactionsRankShow extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsRankShow()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPlayer.get(), "player");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Rank rank = this.readArg(msender.getRank());
|
||||
|
||||
// Prepare
|
||||
String title = Txt.parse("Rank show %s", TypeRank.get().getVisual(rank));
|
||||
List<Mson> show = TypeRank.get().getShow(rank);
|
||||
|
||||
// Inform
|
||||
message(Txt.getPage(show, 0, title, sender));
|
||||
}
|
||||
|
||||
}
|
@ -44,7 +44,7 @@ public class CmdFactionsTitle extends FactionsCommand
|
||||
if ( ! MPerm.getPermTitle().has(msender, you.getFaction(), true)) return;
|
||||
|
||||
// Rank Check
|
||||
if (!msender.isOverriding() && you.getRole().isMoreThan(msender.getRole()))
|
||||
if (!msender.isOverriding() && you.getRank().isHigherThan(msender.getRank()))
|
||||
{
|
||||
msg("<b>You can not edit titles for higher ranks.");
|
||||
return;
|
||||
|
@ -1,52 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReqRoleIsAtLeast extends RequirementAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// SERIALIZABLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Rel rel;
|
||||
public Rel getRel() { return this.rel; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ReqRoleIsAtLeast get(Rel rel) { return new ReqRoleIsAtLeast(rel); }
|
||||
private ReqRoleIsAtLeast(Rel rel) { this.rel = rel; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
if (MUtil.isntSender(sender)) return false;
|
||||
|
||||
MPlayer mplayer = MPlayer.get(sender);
|
||||
return mplayer.getRole().isAtLeast(this.getRel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
return Txt.parse("<b>You must be <h>%s <b>or higher to %s.", Txt.getNicedEnum(this.getRel()), getDesc(command));
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,21 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.command.type.enumeration.TypeEnum;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeRank extends TypeEnum<Rel>
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstract;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
public class TypeRank extends TypeAbstract<Rank>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
@ -32,97 +35,98 @@ public class TypeRank extends TypeEnum<Rel>
|
||||
"Down"
|
||||
);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Rank startRank;
|
||||
public Rank getStartRank() { return this.startRank; }
|
||||
|
||||
private Faction faction;
|
||||
public Faction getFaction() { return this.faction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
// Because of the caching in TypeAbstractChoice, we want only one of each instance.
|
||||
|
||||
// Null instance, doesn't allow promote and demote.
|
||||
private static final TypeRank i = new TypeRank(null);
|
||||
private static final TypeRank i = new TypeRank(null, null);
|
||||
public static TypeRank get() { return i; }
|
||||
|
||||
// Cached instances, does allow promote and demote.
|
||||
private static final Map<Rel, TypeRank> instances;
|
||||
static
|
||||
{
|
||||
Map<Rel, TypeRank> result = new MassiveMap<>();
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
if ( ! rel.isRank()) continue;
|
||||
result.put(rel, new TypeRank(rel));
|
||||
}
|
||||
result.put(null, i);
|
||||
instances = Collections.unmodifiableMap(result);
|
||||
}
|
||||
public static TypeRank get(Rel rank) { return instances.get(rank); }
|
||||
|
||||
// Constructor
|
||||
public TypeRank(Rel rank)
|
||||
public TypeRank(Rank rank, Faction faction)
|
||||
{
|
||||
super(Rel.class);
|
||||
if (rank != null && ! rank.isRank()) throw new IllegalArgumentException(rank + " is not a valid rank");
|
||||
super(Rank.class);
|
||||
|
||||
this.startRank = rank;
|
||||
|
||||
// Do setAll with only ranks.
|
||||
List<Rel> all = MUtil.list(Rel.values());
|
||||
for (Iterator<Rel> it = all.iterator(); it.hasNext(); )
|
||||
{
|
||||
if ( ! it.next().isRank()) it.remove();
|
||||
this.faction = faction;
|
||||
}
|
||||
|
||||
this.setAll(all);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// This must be final, for caching in TypeAbstractChoice to work.
|
||||
private final Rel startRank;
|
||||
public Rel getStartRank() { return this.startRank; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "rank";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInner(Rel value)
|
||||
{
|
||||
return value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getNamesInner(Rel value)
|
||||
public Set<String> getNamesInner(Rank rank)
|
||||
{
|
||||
// Create
|
||||
Set<String> ret = new MassiveSet<>();
|
||||
|
||||
// Fill Exact
|
||||
ret.addAll(value.getNames());
|
||||
Set<String> ret = new MassiveSet<String>();
|
||||
|
||||
// Fill Relative
|
||||
Rel start = this.getStartRank();
|
||||
Rank start = this.getStartRank();
|
||||
if (start != null)
|
||||
{
|
||||
if (value == Rel.LEADER && start == Rel.OFFICER) ret.addAll(NAMES_PROMOTE);
|
||||
if (start.isHigherThan(rank)) ret.addAll(NAMES_PROMOTE);
|
||||
|
||||
if (value == Rel.OFFICER && start == Rel.MEMBER) ret.addAll(NAMES_PROMOTE);
|
||||
if (value == Rel.OFFICER && start == Rel.LEADER) ret.addAll(NAMES_DEMOTE);
|
||||
|
||||
if (value == Rel.MEMBER && start == Rel.RECRUIT) ret.addAll(NAMES_PROMOTE);
|
||||
if (value == Rel.MEMBER && start == Rel.OFFICER) ret.addAll(NAMES_DEMOTE);
|
||||
|
||||
if (value == Rel.RECRUIT && start == Rel.MEMBER) ret.addAll(NAMES_DEMOTE);
|
||||
if (start.isLessThan(rank)) ret.addAll(NAMES_DEMOTE);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rank read(String arg, CommandSender sender) throws MassiveException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mson getVisualMson(Rank value)
|
||||
{
|
||||
// Create
|
||||
Mson mson = Mson.mson("[", value.getName(), "]");
|
||||
|
||||
// Fill
|
||||
mson = mson.tooltip(Mson.toPlain(this.getShow(value), true));
|
||||
|
||||
// Return
|
||||
return mson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mson> getShowInner(Rank value, CommandSender sender)
|
||||
{
|
||||
Mson order = getShowLine("Order", value.getOrder());
|
||||
Mson prefix = getShowLine("Prefix", value.getPrefix());
|
||||
|
||||
return new MassiveList<>(order, prefix);
|
||||
}
|
||||
|
||||
private static Mson getShowLine(String key, Object value)
|
||||
{
|
||||
return Mson.mson(
|
||||
Mson.mson(key).color(ChatColor.AQUA),
|
||||
Mson.mson(":").color(ChatColor.GRAY),
|
||||
Mson.SPACE,
|
||||
value.toString()
|
||||
).color(ChatColor.YELLOW);
|
||||
}
|
||||
}
|
||||
|
68
src/com/massivecraft/factions/cmd/type/TypeRankName.java
Normal file
68
src/com/massivecraft/factions/cmd/type/TypeRankName.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.command.type.TypeNameAbstract;
|
||||
|
||||
public class TypeRankName extends TypeNameAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeRankName iStrict = new TypeRankName(true);
|
||||
private static TypeRankName iLenient = new TypeRankName(false);
|
||||
public static TypeRankName getStrict() { return iStrict; }
|
||||
public static TypeRankName getLenient() { return iLenient; }
|
||||
|
||||
private TypeRankName(boolean strict)
|
||||
{
|
||||
super(strict);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getLengthMin()
|
||||
{
|
||||
return MConf.get().nameLengthRankMin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getLengthMax()
|
||||
{
|
||||
return MConf.get().nameLengthRankMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Named getCurrent(CommandSender sender, String arg) throws MassiveException
|
||||
{
|
||||
return TypeRank.get().read(arg, sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNameTaken(CommandSender sender, String name) throws MassiveException
|
||||
{
|
||||
MPlayer mplayer = MPlayer.get(sender);
|
||||
if (mplayer == null) return false;
|
||||
|
||||
// TODO: Adjust later for "used" faction
|
||||
Faction faction = mplayer.getFaction();
|
||||
|
||||
for (Rank rank : faction.getRankCollection())
|
||||
{
|
||||
if (!rank.getName().equalsIgnoreCase(name)) continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package com.massivecraft.factions.comparator;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ComparatorMPlayerRole implements Comparator<MPlayer>, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -38,11 +38,9 @@ public class ComparatorMPlayerRole implements Comparator<MPlayer>, Named
|
||||
else if (m2 == null) return +1;
|
||||
|
||||
// Rank
|
||||
Rel r1 = m1.getRole();
|
||||
Rel r2 = m2.getRole();
|
||||
return r2.getValue() - r1.getValue();
|
||||
Rank r1 = m1.getRank();
|
||||
Rank r2 = m2.getRank();
|
||||
return r2.getOrder() - r1.getOrder();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
|
||||
public class EnginePlayerData extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -40,7 +40,7 @@ public class EnginePlayerData extends Engine
|
||||
MPlayer mplayer = MPlayerColl.get().get(player, false);
|
||||
if (mplayer == null) return;
|
||||
|
||||
if (mplayer.getRole() == Rel.LEADER)
|
||||
if (mplayer.getRank().isLeader())
|
||||
{
|
||||
mplayer.getFaction().promoteNewLeader();
|
||||
}
|
||||
|
@ -1,12 +1,25 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.FactionsIndex;
|
||||
import com.massivecraft.factions.FactionsParticipator;
|
||||
import com.massivecraft.factions.PermissionIdentifiable;
|
||||
import com.massivecraft.factions.PredicateRank;
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.predicate.PredicateCommandSenderFaction;
|
||||
import com.massivecraft.factions.predicate.PredicateMPlayerRole;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.factions.util.RelationUtil;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
@ -25,18 +38,6 @@ import com.massivecraft.massivecore.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
{
|
||||
@ -73,6 +74,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
this.setRelationWishes(that.relationWishes);
|
||||
this.setFlagIds(that.flags);
|
||||
this.setPermIds(that.perms);
|
||||
this.setRanks(that.ranks);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -147,7 +149,12 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
|
||||
// The perm overrides are modifications to the default values.
|
||||
// Null means default.
|
||||
private MassiveMapDef<String, Set<Rel>> perms = new MassiveMapDef<>();
|
||||
private MassiveMapDef<String, Set<String>> perms = new MassiveMapDef<>();
|
||||
|
||||
private MassiveMapDef<String, Rank> ranks = new MassiveMapDef<>();
|
||||
//private MassiveTreeSetDef<Rank, ComparatorPrioritized> ranks = new MassiveTreeSetDef<>(ComparatorPrioritized.get());
|
||||
|
||||
private Rank rankManager;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: id
|
||||
@ -162,7 +169,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
|
||||
public boolean isNormal()
|
||||
{
|
||||
return ! this.isNone();
|
||||
return !this.isNone();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -707,62 +714,22 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
// -------------------------------------------- //
|
||||
|
||||
// RAW
|
||||
|
||||
public Map<MPerm, Set<Rel>> getPerms()
|
||||
public MassiveMapDef<String, Set<String>> getPermIds()
|
||||
{
|
||||
// We start with default values ...
|
||||
Map<MPerm, Set<Rel>> ret = new MassiveMap<>();
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
ret.put(mperm, new MassiveSet<>(mperm.getStandard()));
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
// ... and if anything is explicitly set we use that info ...
|
||||
Iterator<Entry<String, Set<Rel>>> iter = this.perms.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
// ... for each entry ...
|
||||
Entry<String, Set<Rel>> entry = iter.next();
|
||||
|
||||
// ... extract id and remove null values ...
|
||||
String id = entry.getKey();
|
||||
if (id == null)
|
||||
{
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// ... resolve object and skip unknowns ...
|
||||
MPerm mperm = MPerm.get(id);
|
||||
if (mperm == null) continue;
|
||||
|
||||
ret.put(mperm, new MassiveSet<>(entry.getValue()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPerms(Map<MPerm, Set<Rel>> perms)
|
||||
{
|
||||
Map<String, Set<Rel>> permIds = new MassiveMap<>();
|
||||
for (Entry<MPerm, Set<Rel>> entry : perms.entrySet())
|
||||
{
|
||||
permIds.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
setPermIds(permIds);
|
||||
}
|
||||
|
||||
public void setPermIds(Map<String, Set<Rel>> perms)
|
||||
public void setPermIds(MassiveMapDef<String, Set<String>> perms)
|
||||
{
|
||||
// Clean input
|
||||
MassiveMapDef<String, Set<Rel>> target = new MassiveMapDef<>();
|
||||
for (Entry<String, Set<Rel>> entry : perms.entrySet())
|
||||
MassiveMapDef<String, Set<String>> target = new MassiveMapDef<String, Set<String>>();
|
||||
for (Entry<String, Set<String>> entry : perms.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
if (key == null) continue;
|
||||
key = key.toLowerCase(); // Lowercased Keys Version 2.6.0 --> 2.7.0
|
||||
|
||||
Set<Rel> value = entry.getValue();
|
||||
Set<String> value = entry.getValue();
|
||||
if (value == null) continue;
|
||||
|
||||
target.put(key, value);
|
||||
@ -778,54 +745,78 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// FINER
|
||||
// Finer
|
||||
public Map<MPerm, Set<String>> getPerms()
|
||||
{
|
||||
// We start with default values ...
|
||||
Map<MPerm, Set<String>> ret = new MassiveMap<>();
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
ret.put(mperm, new MassiveSet<>(mperm.getStandard()));
|
||||
}
|
||||
|
||||
public boolean isPermitted(String permId, Rel rel)
|
||||
// ... and if anything is explicitly set we use that info ...
|
||||
for (Iterator<Entry<String, Set<String>>> it = this.perms.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
// ... for each entry ...
|
||||
Entry<String, Set<String>> entry = it.next();
|
||||
|
||||
// ... extract id and remove null values ...
|
||||
String id = entry.getKey();
|
||||
if (id == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// ... resolve object and skip unknowns ...
|
||||
MPerm mperm = MPerm.get(id);
|
||||
if (mperm == null) continue;
|
||||
|
||||
ret.put(mperm, new MassiveSet<>(entry.getValue()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPerms(Map<MPerm, Set<String>> perms)
|
||||
{
|
||||
// Create
|
||||
MassiveMapDef<String, Set<String>> permIds = new MassiveMapDef<>();
|
||||
|
||||
// Fill
|
||||
for (Entry<MPerm, Set<String>> entry : perms.entrySet())
|
||||
{
|
||||
permIds.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
|
||||
// Set
|
||||
this.setPermIds(permIds);
|
||||
}
|
||||
|
||||
// FINEST
|
||||
private boolean isPermitted(String permId, String permissibleId)
|
||||
{
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels.contains(rel);
|
||||
Set<String> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels.contains(permissibleId);
|
||||
|
||||
MPerm perm = MPerm.get(permId);
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
|
||||
return perm.getStandard().contains(rel);
|
||||
return perm.getStandard().contains(permissibleId);
|
||||
}
|
||||
|
||||
public boolean isPermitted(MPerm perm, Rel rel)
|
||||
public boolean isPermitted(MPerm perm, PermissionIdentifiable permissible)
|
||||
{
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
|
||||
String permId = perm.getId();
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels.contains(rel);
|
||||
|
||||
return perm.getStandard().contains(rel);
|
||||
return this.isPermitted(perm.getId(), permissible.getPermissibleId());
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
public Set<Rel> getPermitted(MPerm perm)
|
||||
private Set<String> getPermitted(String permId)
|
||||
{
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
|
||||
String permId = perm.getId();
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels;
|
||||
|
||||
return perm.getStandard();
|
||||
}
|
||||
|
||||
public Set<Rel> getPermitted(String permId)
|
||||
{
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
Set<String> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels;
|
||||
|
||||
MPerm perm = MPerm.get(permId);
|
||||
@ -834,49 +825,223 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
return perm.getStandard();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
// Use getPermitted instead. It's much quicker although not immutable.
|
||||
public Set<Rel> getPermittedRelations(MPerm perm)
|
||||
public Set<String> getPermitted(MPerm perm)
|
||||
{
|
||||
return this.getPerms().get(perm);
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
return this.getPermitted(perm.getId());
|
||||
}
|
||||
|
||||
// ---
|
||||
// TODO: Fix these below. They are reworking the whole map.
|
||||
|
||||
public void setPermittedRelations(MPerm perm, Set<Rel> rels)
|
||||
public void setPermittedRelations(MPerm perm, Set<String> permissibleIds)
|
||||
{
|
||||
Map<MPerm, Set<Rel>> perms = this.getPerms();
|
||||
perms.put(perm, rels);
|
||||
this.setPerms(perms);
|
||||
this.getPermIds().put(perm.getId(), permissibleIds);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public void setPermittedRelations(MPerm perm, Rel... rels)
|
||||
public void setPermittedRelations(MPerm perm, String... permissibleIds)
|
||||
{
|
||||
Set<Rel> temp = new HashSet<>();
|
||||
temp.addAll(Arrays.asList(rels));
|
||||
this.setPermittedRelations(perm, temp);
|
||||
this.setPermittedRelations(perm, new MassiveSet<>(permissibleIds));
|
||||
}
|
||||
|
||||
public void setRelationPermitted(MPerm perm, Rel rel, boolean permitted)
|
||||
public void setRelationPermitted(MPerm perm, String permissibleId, boolean permitted)
|
||||
{
|
||||
Map<MPerm, Set<Rel>> perms = this.getPerms();
|
||||
// Get
|
||||
Map<String, Set<String>> perms = this.getPermIds();
|
||||
String permId = perm.getId();
|
||||
Set<String> permissibleIds = perms.get(permId);
|
||||
|
||||
Set<Rel> rels = perms.get(perm);
|
||||
|
||||
boolean changed;
|
||||
// Change
|
||||
if (permitted)
|
||||
{
|
||||
changed = rels.add(rel);
|
||||
permissibleIds.add(permissibleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = rels.remove(rel);
|
||||
permissibleIds.remove(permissibleId);
|
||||
}
|
||||
|
||||
this.setPerms(perms);
|
||||
// Set
|
||||
this.setPermittedRelations(perm, permissibleIds);
|
||||
}
|
||||
|
||||
if (changed) this.changed();
|
||||
// -------------------------------------------- //
|
||||
// FIELD: ranks
|
||||
// -------------------------------------------- //
|
||||
|
||||
// RAW
|
||||
public Map<String, Rank> getRanks()
|
||||
{
|
||||
return this.ranks;
|
||||
}
|
||||
|
||||
public void setRanks(Map<String, Rank> ranks)
|
||||
{
|
||||
// NoChange
|
||||
if (MUtil.equals(this.ranks, ranks)) return;
|
||||
|
||||
// Apply
|
||||
this.ranks = new MassiveMapDef<>(ranks);
|
||||
|
||||
// Changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// FINER
|
||||
public Collection<Rank> getRankCollection()
|
||||
{
|
||||
return this.getRanks().values();
|
||||
}
|
||||
|
||||
private List<String> getRankIdsOrdered()
|
||||
{
|
||||
return new MassiveList<>(this.ranks.keySet());
|
||||
}
|
||||
|
||||
public Rank getRankLeader()
|
||||
{
|
||||
return this.ranks.get(this.getRankIdsOrdered().get(0));
|
||||
}
|
||||
|
||||
public Rank getRankLowest()
|
||||
{
|
||||
List<String> ids = this.getRankIdsOrdered();
|
||||
return this.ranks.get(ids.get(ids.size() - 1));
|
||||
}
|
||||
|
||||
public void addRank(Rank rank)
|
||||
{
|
||||
if (rank == null) return;
|
||||
|
||||
// Add
|
||||
this.getRanks().put(rank.getId(), rank);
|
||||
|
||||
// Changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public boolean removeRank(Rank rank)
|
||||
{
|
||||
// Check
|
||||
if (rank == null) return false;
|
||||
if (rank.equals(this.getRankLeader())) return false;
|
||||
if (rank.equals(this.getRankLowest())) return false;
|
||||
|
||||
// Remove
|
||||
Rank ret = this.getRanks().remove(rank.getId());
|
||||
|
||||
// Changed
|
||||
boolean success = ret != null;
|
||||
if (success)
|
||||
{
|
||||
this.adjustRankOrder(rank);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// Return
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean demote(MPlayer mplayer)
|
||||
{
|
||||
if (mplayer.getFaction() != this) return false;
|
||||
if (mplayer.getRank().equals(this.getRankLowest())) return false;
|
||||
|
||||
// Gather
|
||||
Rank current = mplayer.getRank();
|
||||
Rank demoted = this.getNextLowerRank(current);
|
||||
|
||||
// Set
|
||||
mplayer.setRank(demoted);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Rank getNextLowerRank(Rank rank)
|
||||
{
|
||||
// Get order
|
||||
Rank ret = null;
|
||||
|
||||
// Find next lower order
|
||||
for (Rank otherRank : this.getRankCollection())
|
||||
{
|
||||
if (!otherRank.isLessThan(rank)) continue;
|
||||
|
||||
ret = otherRank;
|
||||
break;
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Rank createRank(String name)
|
||||
{
|
||||
// Prepare
|
||||
int order = this.getRankLowest().getOrder() + 1;
|
||||
|
||||
// Create
|
||||
Rank ret = Rank.DEFAULT.copy();
|
||||
|
||||
// Fill
|
||||
ret.setName(name);
|
||||
ret.setOrder(order);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void adjustRankOrder(Rank rank)
|
||||
{
|
||||
for (Rank other : this.getRankCollection())
|
||||
{
|
||||
if (other.isHigherThan(rank)) continue;
|
||||
|
||||
other.setOrder(other.getOrder() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustRankOrder(Rank rank, int order)
|
||||
{
|
||||
// Get List
|
||||
List<String> ids = this.getRankIdsOrdered();
|
||||
|
||||
// Sort in rank
|
||||
String rankId = rank.getId();
|
||||
ids.remove(rankId);
|
||||
ids.add(order - 1, rankId);
|
||||
|
||||
// Create new order
|
||||
Map<String, Rank> rankOrdered = new MassiveMap<>();
|
||||
|
||||
for (int i = 0; i < ids.size(); i++)
|
||||
{
|
||||
String id = ids.get(i);
|
||||
Rank ordered = this.ranks.get(id);
|
||||
ordered.setOrder(i);
|
||||
rankOrdered.put(id, ordered);
|
||||
}
|
||||
|
||||
this.setRanks(rankOrdered);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: rankManager
|
||||
// -------------------------------------------- //
|
||||
|
||||
// RAW
|
||||
public Rank getRankManager()
|
||||
{
|
||||
return this.rankManager;
|
||||
}
|
||||
|
||||
public void setRankManager(Rank rankManager)
|
||||
{
|
||||
// NoChange
|
||||
if (MUtil.equals(this.rankManager, rankManager)) return;
|
||||
|
||||
// Apply
|
||||
this.rankManager = rankManager;
|
||||
|
||||
// Changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -972,6 +1137,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
{
|
||||
return BoardColl.get().getCount(this);
|
||||
}
|
||||
|
||||
public int getLandCountInWorld(String worldName)
|
||||
{
|
||||
return Board.get(worldName).getCount(this);
|
||||
@ -1003,9 +1169,9 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
public List<MPlayer> getMPlayersWhere(Predicate<? super MPlayer> predicate)
|
||||
{
|
||||
List<MPlayer> ret = this.getMPlayers();
|
||||
for (Iterator<MPlayer> it = ret.iterator(); it.hasNext();)
|
||||
for (Iterator<MPlayer> it = ret.iterator(); it.hasNext(); )
|
||||
{
|
||||
if ( ! predicate.apply(it.next())) it.remove();
|
||||
if (!predicate.apply(it.next())) it.remove();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1020,14 +1186,19 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
return this.getMPlayersWhere(PredicateAnd.get(SenderColl.PREDICATE_ONLINE, PredicateVisibleTo.get(senderObject)));
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereRole(Rel role)
|
||||
public List<MPlayer> getMPlayersWhereRank(Rank rank)
|
||||
{
|
||||
return this.getMPlayersWhere(PredicateMPlayerRole.get(role));
|
||||
return this.getMPlayersWhere(PredicateRank.get(rank));
|
||||
}
|
||||
|
||||
public List<MPlayer> getMPlayersWhereLeader()
|
||||
{
|
||||
return this.getMPlayersWhere(PredicateRank.get(this.getRankLeader()));
|
||||
}
|
||||
|
||||
public MPlayer getLeader()
|
||||
{
|
||||
List<MPlayer> ret = this.getMPlayersWhereRole(Rel.LEADER);
|
||||
List<MPlayer> ret = this.getMPlayersWhereLeader();
|
||||
if (ret.size() == 0) return null;
|
||||
return ret.get(0);
|
||||
}
|
||||
@ -1075,35 +1246,28 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
// used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left
|
||||
public void promoteNewLeader()
|
||||
{
|
||||
if ( ! this.isNormal()) return;
|
||||
if (!this.isNormal()) return;
|
||||
if (this.getFlag(MFlag.getFlagPermanent()) && MConf.get().permanentFactionsDisableLeaderPromotion) return;
|
||||
|
||||
MPlayer oldLeader = this.getLeader();
|
||||
Rank rankLeader = this.getRankLeader();
|
||||
Rank nextLower = this.getNextLowerRank(rankLeader);
|
||||
|
||||
// get list of officers, or list of normal members if there are no officers
|
||||
List<MPlayer> replacements = this.getMPlayersWhereRole(Rel.OFFICER);
|
||||
if (replacements == null || replacements.isEmpty())
|
||||
{
|
||||
replacements = this.getMPlayersWhereRole(Rel.MEMBER);
|
||||
}
|
||||
|
||||
List<MPlayer> replacements = this.getMPlayersWhereRank(nextLower);
|
||||
if (replacements == null || replacements.isEmpty())
|
||||
{
|
||||
// faction leader is the only member; one-man faction
|
||||
if (this.getFlag(MFlag.getFlagPermanent()))
|
||||
{
|
||||
if (oldLeader != null)
|
||||
{
|
||||
// TODO: Where is the logic in this? Why MEMBER? Why not LEADER again? And why not OFFICER or RECRUIT?
|
||||
oldLeader.setRole(Rel.MEMBER);
|
||||
}
|
||||
if (oldLeader != null) oldLeader.setRank(rankLeader);
|
||||
return;
|
||||
}
|
||||
|
||||
// no members left and faction isn't permanent, so disband it
|
||||
if (MConf.get().logFactionDisband)
|
||||
{
|
||||
Factions.get().log("The faction "+this.getName()+" ("+this.getId()+") has been disbanded since it has no members left.");
|
||||
Factions.get().log("The faction " + this.getName() + " (" + this.getId() + ") has been disbanded since it has no members left.");
|
||||
}
|
||||
|
||||
for (MPlayer mplayer : MPlayerColl.get().getAllOnline())
|
||||
@ -1116,14 +1280,12 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
else
|
||||
{
|
||||
// promote new faction leader
|
||||
if (oldLeader != null)
|
||||
{
|
||||
oldLeader.setRole(Rel.MEMBER);
|
||||
}
|
||||
if (oldLeader != null) this.demote(oldLeader);
|
||||
replacements.get(0).setRank(rankLeader);
|
||||
|
||||
replacements.get(0).setRole(Rel.LEADER);
|
||||
// Inform
|
||||
this.msg("<i>Faction leader <h>%s<i> has been removed. %s<i> has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
|
||||
Factions.get().log("Faction "+this.getName()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName());
|
||||
Factions.get().log("Faction " + this.getName() + " (" + this.getId() + ") leader was removed. Replacement leader: " + replacements.get(0).getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1157,7 +1319,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
boolean offlineexplosions = this.getFlag(MFlag.getFlagOfflineexplosions());
|
||||
|
||||
if (explosions && offlineexplosions) return true;
|
||||
if ( ! explosions && ! offlineexplosions) return false;
|
||||
if (!explosions && !offlineexplosions) return false;
|
||||
|
||||
boolean online = this.isFactionConsideredOnline();
|
||||
|
||||
|
@ -1,12 +1,5 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -14,6 +7,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.PermissibleId;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
|
||||
public class FactionColl extends Coll<Faction>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -84,12 +85,12 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermBuild(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermDeposit(), Rel.LEADER, Rel.OFFICER); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
faction.setPermittedRelations(MPerm.getPermBuild(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermDeposit(), PermissibleId.LEADER, PermissibleId.OFFICER); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
|
||||
return faction;
|
||||
}
|
||||
@ -120,11 +121,11 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), false);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), false);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), PermissibleId.LEADER, PermissibleId.OFFICER, PermissibleId.MEMBER);
|
||||
|
||||
return faction;
|
||||
}
|
||||
@ -155,11 +156,11 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), PermissibleId.ALL);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), PermissibleId.LEADER, PermissibleId.OFFICER, PermissibleId.MEMBER);
|
||||
|
||||
return faction;
|
||||
}
|
||||
@ -218,15 +219,15 @@ public class FactionColl extends Coll<Faction>
|
||||
|
||||
// Fill
|
||||
// Check minimum length
|
||||
if (MiscUtil.getComparisonString(str).length() < MConf.get().factionNameLengthMin)
|
||||
if (MiscUtil.getComparisonString(str).length() < MConf.get().nameLengthFactionMin)
|
||||
{
|
||||
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", MConf.get().factionNameLengthMin));
|
||||
errors.add(Txt.parse("<i>The faction name can't be shorter than <h>%s<i> chars.", MConf.get().nameLengthFactionMin));
|
||||
}
|
||||
|
||||
// Check maximum length
|
||||
if (str.length() > MConf.get().factionNameLengthMax)
|
||||
if (str.length() > MConf.get().nameLengthFactionMax)
|
||||
{
|
||||
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", MConf.get().factionNameLengthMax));
|
||||
errors.add(Txt.parse("<i>The faction name can't be longer than <h>%s<i> chars.", MConf.get().nameLengthFactionMax));
|
||||
}
|
||||
|
||||
// Check characters used
|
||||
|
@ -1,5 +1,17 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.engine.EngineChat;
|
||||
@ -13,17 +25,6 @@ import com.massivecraft.massivecore.command.type.TypeMillisDiff;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@EditorName("config")
|
||||
public class MConf extends Entity<MConf>
|
||||
@ -134,10 +135,6 @@ public class MConf extends Entity<MConf>
|
||||
// "none" means Wilderness. Remember to specify the id, like "3defeec7-b3b1-48d9-82bb-2a8903df24e3" and not the name.
|
||||
public String defaultPlayerFactionId = Factions.ID_NONE;
|
||||
|
||||
// What rank should new players joining a faction get?
|
||||
// If not RECRUIT then MEMBER might make sense.
|
||||
public Rel defaultPlayerRole = Rel.RECRUIT;
|
||||
|
||||
// What power should the player start with?
|
||||
public double defaultPlayerPower = 0.0;
|
||||
|
||||
@ -190,8 +187,12 @@ public class MConf extends Entity<MConf>
|
||||
public double factionPowerMax = 0.0;
|
||||
|
||||
// Limit the length of faction names here.
|
||||
public int factionNameLengthMin = 3;
|
||||
public int factionNameLengthMax = 16;
|
||||
public int nameLengthFactionMin = 3;
|
||||
public int nameLengthFactionMax = 16;
|
||||
|
||||
// Limit the length of rank names here.
|
||||
public int nameLengthRankMin = 3;
|
||||
public int nameLengthRankMax = 10;
|
||||
|
||||
// Should faction names automatically be converted to upper case?
|
||||
// You probably don't want this feature.
|
||||
@ -396,7 +397,7 @@ public class MConf extends Entity<MConf>
|
||||
Rel.NEUTRAL, new ArrayList<String>(),
|
||||
Rel.TRUCE, new ArrayList<String>(),
|
||||
Rel.ALLY, new ArrayList<String>(),
|
||||
Rel.MEMBER, new ArrayList<String>()
|
||||
Rel.FACTION, new ArrayList<String>()
|
||||
);
|
||||
|
||||
// The distance for denying the following commands. Set to -1 to disable.
|
||||
@ -410,12 +411,12 @@ public class MConf extends Entity<MConf>
|
||||
Rel.NEUTRAL, new ArrayList<String>(),
|
||||
Rel.TRUCE, new ArrayList<String>(),
|
||||
Rel.ALLY, new ArrayList<String>(),
|
||||
Rel.MEMBER, new ArrayList<String>()
|
||||
Rel.FACTION, new ArrayList<String>()
|
||||
);
|
||||
|
||||
// Allow bypassing the above setting when in these territories.
|
||||
public List<Rel> denyCommandsDistanceBypassIn = MUtil.list(
|
||||
Rel.MEMBER,
|
||||
Rel.FACTION,
|
||||
Rel.ALLY
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.PermissionIdentifiable;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.cmd.CmdFactions;
|
||||
@ -8,11 +9,11 @@ import com.massivecraft.factions.event.EventFactionsCreatePerms;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Prioritized;
|
||||
import com.massivecraft.massivecore.Registerable;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -21,6 +22,8 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.massivecraft.factions.PermissibleId.*;
|
||||
|
||||
public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -79,6 +82,32 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
public final static transient int PRIORITY_PERMS = 23000;
|
||||
public final static transient int PRIORITY_STATUS = 24000;
|
||||
|
||||
public final static transient Set<String> STANDARD_BUILD = new MassiveSet<>(LEADER, OFFICER, MEMBER);
|
||||
public final static transient Set<String> STANDARD_PAINBUILD = new MassiveSet<>();
|
||||
public final static transient Set<String> STANDARD_DOOR = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT, ALLY);
|
||||
public final static transient Set<String> STANDARD_BUTTON = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT, ALLY);
|
||||
public final static transient Set<String> STANDARD_LEVER = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT, ALLY);
|
||||
public final static transient Set<String> STANDARD_CONTAINER = new MassiveSet<>(LEADER, OFFICER, MEMBER);
|
||||
|
||||
public final static transient Set<String> STANDARD_NAME = new MassiveSet<>(LEADER);
|
||||
public final static transient Set<String> STANDARD_DESC = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_MOTD = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_INVITE = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_KICK = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_TITLE = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_HOME = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT);
|
||||
public final static transient Set<String> STANDARD_SETHOME = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_DEPOSIT = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT, ALLY, TRUCE, NEUTRAL, ENEMY);
|
||||
public final static transient Set<String> STANDARD_WITHDRAW = new MassiveSet<>(LEADER);
|
||||
public final static transient Set<String> STANDARD_TERRITORY = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_ACCESS = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_CLAIMNEAR = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT, ALLY);
|
||||
public final static transient Set<String> STANDARD_REL = new MassiveSet<>(LEADER, OFFICER);
|
||||
public final static transient Set<String> STANDARD_DISBAND = new MassiveSet<>(LEADER);
|
||||
public final static transient Set<String> STANDARD_FLAGS = new MassiveSet<>(LEADER);
|
||||
public final static transient Set<String> STANDARD_PERMS = new MassiveSet<>(LEADER);
|
||||
public final static transient Set<String> STANDARD_STATUS = new MassiveSet<>(LEADER, OFFICER, MEMBER, RECRUIT);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META: CORE
|
||||
// -------------------------------------------- //
|
||||
@ -130,33 +159,33 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
getPermPerms();
|
||||
}
|
||||
|
||||
public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER), true, true, true); }
|
||||
public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new LinkedHashSet<Rel>(), true, true, true); }
|
||||
public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER), true, true, true); }
|
||||
public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", STANDARD_BUILD, true, true, true); }
|
||||
public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", STANDARD_PAINBUILD, true, true, true); }
|
||||
public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", STANDARD_DOOR, true, true, true); }
|
||||
public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", STANDARD_BUTTON, true, true, true); }
|
||||
public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", STANDARD_LEVER, true, true, true); }
|
||||
public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", STANDARD_CONTAINER, true, true, true); }
|
||||
|
||||
public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermStatus() { return getCreative(PRIORITY_STATUS, ID_STATUS, ID_STATUS, "show status", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermHome() { return getCreative(PRIORITY_HOME, ID_HOME, ID_HOME, "teleport home", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), false, true, true); }
|
||||
public static MPerm getPermSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY), false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", STANDARD_NAME, false, true, true); }
|
||||
public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", STANDARD_DESC, false, true, true); }
|
||||
public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", STANDARD_MOTD, false, true, true); }
|
||||
public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", STANDARD_INVITE, false, true, true); }
|
||||
public static MPerm getPermStatus() { return getCreative(PRIORITY_STATUS, ID_STATUS, ID_STATUS, "show status", STANDARD_STATUS, false, true, true); }
|
||||
public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", STANDARD_KICK, false, true, true); }
|
||||
public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", STANDARD_TITLE, false, true, true); }
|
||||
public static MPerm getPermHome() { return getCreative(PRIORITY_HOME, ID_HOME, ID_HOME, "teleport home", STANDARD_HOME, false, true, true); }
|
||||
public static MPerm getPermSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", STANDARD_SETHOME, false, true, true); }
|
||||
public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", STANDARD_DEPOSIT, false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", STANDARD_WITHDRAW, false, true, true); }
|
||||
public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", STANDARD_TERRITORY, false, true, true); }
|
||||
public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", STANDARD_ACCESS, false, true, true); }
|
||||
public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", STANDARD_CLAIMNEAR, false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", STANDARD_REL, false, true, true); }
|
||||
public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", STANDARD_DISBAND, false, true, true); }
|
||||
public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", STANDARD_FLAGS, false, true, true); }
|
||||
public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", STANDARD_PERMS, false, true, true); }
|
||||
|
||||
public static MPerm getCreative(int priority, String id, String name, String desc, Set<Rel> standard, boolean territory, boolean editable, boolean visible)
|
||||
public static MPerm getCreative(int priority, String id, String name, String desc, Set<String> standard, boolean territory, boolean editable, boolean visible)
|
||||
{
|
||||
MPerm ret = MPermColl.get().get(id, false);
|
||||
if (ret != null)
|
||||
@ -231,9 +260,9 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
// What is the standard (aka default) perm value?
|
||||
// This value will be set for factions from the beginning.
|
||||
// Example: ... set of relations ...
|
||||
private Set<Rel> standard = new LinkedHashSet<>();
|
||||
public Set<Rel> getStandard() { return this.standard; }
|
||||
public MPerm setStandard(Set<Rel> standard) { this.standard = standard; this.changed(); return this; }
|
||||
private Set<String> standard = new LinkedHashSet<String>();
|
||||
public Set<String> getStandard() { return this.standard; }
|
||||
public MPerm setStandard(Set<String> standard) { this.standard = standard; this.changed(); return this; }
|
||||
|
||||
// Is this a territory perm meaning it has to do with territory construction, modification or interaction?
|
||||
// True Examples: build, container, door, lever etc.
|
||||
@ -271,7 +300,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
// No argument constructor for GSON
|
||||
}
|
||||
|
||||
public MPerm(int priority, String name, String desc, Set<Rel> standard, boolean territory, boolean editable, boolean visible)
|
||||
public MPerm(int priority, String name, String desc, Set<String> standard, boolean territory, boolean editable, boolean visible)
|
||||
{
|
||||
this.priority = priority;
|
||||
this.name = name;
|
||||
@ -357,7 +386,8 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
if (mplayer.isOverriding()) return true;
|
||||
|
||||
Rel rel = mplayer.getRelationTo(hostFaction);
|
||||
if (hostFaction.isPermitted(this, rel)) return true;
|
||||
PermissionIdentifiable permissible = rel == Rel.FACTION ? mplayer.getRank() :rel;
|
||||
if (hostFaction.isPermitted(this, permissible)) return true;
|
||||
|
||||
if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
||||
|
||||
@ -408,13 +438,14 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getStateInfo(Set<Rel> value, boolean withDesc)
|
||||
// TODO: get rid of this state info in an earlier commit by re-doing Perm - list/show
|
||||
public String getStateInfo(Set<String> value, boolean withDesc)
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
if (value.contains(rel))
|
||||
if (value.contains(rel.getName().toLowerCase()))
|
||||
{
|
||||
ret += "<g>YES";
|
||||
}
|
||||
|
@ -1,9 +1,21 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.FactionsIndex;
|
||||
import com.massivecraft.factions.FactionsParticipator;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
@ -23,16 +35,6 @@ import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator
|
||||
{
|
||||
@ -60,7 +62,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
{
|
||||
this.setLastActivityMillis(that.lastActivityMillis);
|
||||
this.setFactionId(that.factionId);
|
||||
this.setRole(that.role);
|
||||
this.setRank(that.rank);
|
||||
this.setTitle(that.title);
|
||||
this.setPowerBoost(that.powerBoost);
|
||||
this.setPower(that.power);
|
||||
@ -130,7 +132,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
|
||||
// What role does the player have in the faction?
|
||||
// Null means default.
|
||||
private Rel role = null;
|
||||
private Rank rank = null;
|
||||
|
||||
// What title does the player have in the faction?
|
||||
// The title is just for fun. It's not connected to any game mechanic.
|
||||
@ -196,7 +198,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
{
|
||||
// The default neutral faction
|
||||
this.setFactionId(null);
|
||||
this.setRole(null);
|
||||
this.setRank(null);
|
||||
this.setTitle(null);
|
||||
this.setAutoClaimFaction(null);
|
||||
}
|
||||
@ -301,27 +303,21 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: role
|
||||
// FIELD: rank
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Rel getRole()
|
||||
public Rank getRank()
|
||||
{
|
||||
if (this.isFactionOrphan()) return Rel.RECRUIT;
|
||||
|
||||
if (this.role == null) return MConf.get().defaultPlayerRole;
|
||||
return this.role;
|
||||
return this.rank;
|
||||
}
|
||||
|
||||
public void setRole(Rel role)
|
||||
public void setRank(Rank rank)
|
||||
{
|
||||
// Clean input
|
||||
Rel target = role;
|
||||
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.role, target)) return;
|
||||
if (MUtil.equals(this.rank, rank)) return;
|
||||
|
||||
// Apply
|
||||
this.role = target;
|
||||
this.rank = rank;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
@ -598,12 +594,10 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
}
|
||||
|
||||
// Base concatenations:
|
||||
|
||||
public String getNameAndSomething(String color, String something)
|
||||
{
|
||||
String ret = "";
|
||||
ret += color;
|
||||
ret += this.getRole().getPrefix();
|
||||
if (something != null && something.length() > 0)
|
||||
{
|
||||
ret += something;
|
||||
@ -745,7 +739,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
// Apply
|
||||
|
||||
// Promote a new leader if required.
|
||||
if (this.getRole() == Rel.LEADER)
|
||||
if (this.getRank().isLeader())
|
||||
{
|
||||
Faction faction = this.getFaction();
|
||||
if (faction != null)
|
||||
@ -772,7 +766,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
|
||||
if (myFaction.getMPlayers().size() > 1)
|
||||
{
|
||||
if (!permanent && this.getRole() == Rel.LEADER)
|
||||
if (!permanent && this.getRank().isLeader())
|
||||
{
|
||||
msg("<b>You must give the leader role to someone else first.");
|
||||
return;
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.massivecraft.factions.event;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.massivecraft.factions.Rank;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
|
||||
public class EventFactionsRankChange extends EventFactionsAbstractSender
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -22,15 +23,15 @@ public class EventFactionsRankChange extends EventFactionsAbstractSender
|
||||
private final MPlayer mplayer;
|
||||
public MPlayer getMPlayer() { return this.mplayer; }
|
||||
|
||||
private Rel newRank;
|
||||
public Rel getNewRank() { return this.newRank; }
|
||||
public void setNewRank(Rel newRole) { this.newRank = newRole; }
|
||||
private Rank newRank;
|
||||
public Rank getNewRank() { return this.newRank; }
|
||||
public void setNewRank(Rank newRole) { this.newRank = newRole; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public EventFactionsRankChange(CommandSender sender, MPlayer mplayer, Rel newRank)
|
||||
public EventFactionsRankChange(CommandSender sender, MPlayer mplayer, Rank newRank)
|
||||
{
|
||||
super(sender);
|
||||
this.mplayer = mplayer;
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
|
||||
public class ChannelFactionsAllies extends ChannelFactionsAbstract
|
||||
{
|
||||
public static final Set<Rel> targetRelations = EnumSet.of(Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
|
||||
public static final Set<Rel> targetRelations = EnumSet.of(Rel.FACTION, Rel.ALLY);
|
||||
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
|
||||
|
||||
@Override public String getName() { return MConf.get().herochatAlliesName; }
|
||||
|
@ -1,16 +1,17 @@
|
||||
package com.massivecraft.factions.integration.herochat;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
|
||||
public class ChannelFactionsFaction extends ChannelFactionsAbstract
|
||||
{
|
||||
public static final Set<Rel> targetRelations = EnumSet.of(Rel.MEMBER, Rel.RECRUIT);
|
||||
public static final Set<Rel> targetRelations = EnumSet.of(Rel.FACTION);
|
||||
@Override public Set<Rel> getTargetRelations() { return targetRelations; }
|
||||
|
||||
@Override public String getName() { return MConf.get().herochatFactionName; }
|
||||
|
223
src/com/massivecraft/factions/update/OldConf.java
Normal file
223
src/com/massivecraft/factions/update/OldConf.java
Normal file
@ -0,0 +1,223 @@
|
||||
package com.massivecraft.factions.update;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
||||
public class OldConf extends Entity<OldConf>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferTo(MConf mconf)
|
||||
{
|
||||
//mconf.enabled = this.enabled;
|
||||
//mconf.factionIdNone = this.factionIdNone;
|
||||
//mconf.factionIdSafezone = this.factionIdSafezone;
|
||||
//mconf.factionIdWarzone = this.factionIdWarzone;
|
||||
mconf.defaultPlayerFactionId = this.defaultPlayerFactionId;
|
||||
//mconf.defaultPlayerRole = this.defaultPlayerRole;
|
||||
mconf.defaultPlayerPower = this.defaultPlayerPower;
|
||||
//mconf.defaultFactionOpen = this.defaultFactionOpen;
|
||||
//mconf.defaultFactionFlags = this.defaultFactionFlags;
|
||||
//mconf.defaultFactionPerms = this.defaultFactionPerms;
|
||||
mconf.powerMax = this.powerMax;
|
||||
mconf.powerMin = this.powerMin;
|
||||
mconf.powerPerHour = this.powerPerHour;
|
||||
mconf.powerPerDeath = this.powerPerDeath;
|
||||
mconf.canLeaveWithNegativePower = this.canLeaveWithNegativePower;
|
||||
mconf.factionMemberLimit = this.factionMemberLimit;
|
||||
mconf.factionPowerMax = this.factionPowerMax;
|
||||
mconf.nameLengthFactionMin = this.factionNameLengthMin;
|
||||
mconf.nameLengthFactionMax = this.factionNameLengthMax;
|
||||
mconf.factionNameForceUpperCase = this.factionNameForceUpperCase;
|
||||
mconf.claimsMustBeConnected = this.claimsMustBeConnected;
|
||||
mconf.claimingFromOthersAllowed = this.claimingFromOthersAllowed;
|
||||
mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction = this.claimsCanBeUnconnectedIfOwnedByOtherFaction;
|
||||
mconf.claimsRequireMinFactionMembers = this.claimsRequireMinFactionMembers;
|
||||
mconf.claimedLandsMax = this.claimedLandsMax;
|
||||
mconf.homesEnabled = this.homesEnabled;
|
||||
mconf.homesMustBeInClaimedTerritory = this.homesMustBeInClaimedTerritory;
|
||||
mconf.homesTeleportCommandEnabled = this.homesTeleportCommandEnabled;
|
||||
mconf.homesTeleportAllowedFromEnemyTerritory = this.homesTeleportAllowedFromEnemyTerritory;
|
||||
mconf.homesTeleportAllowedFromDifferentWorld = this.homesTeleportAllowedFromDifferentWorld;
|
||||
mconf.homesTeleportAllowedEnemyDistance = this.homesTeleportAllowedEnemyDistance;
|
||||
mconf.homesTeleportIgnoreEnemiesIfInOwnTerritory = this.homesTeleportIgnoreEnemiesIfInOwnTerritory;
|
||||
mconf.homesTeleportToOnDeathActive = this.homesTeleportToOnDeathActive;
|
||||
mconf.homesTeleportToOnDeathPriority = this.homesTeleportToOnDeathPriority;
|
||||
mconf.permanentFactionsDisableLeaderPromotion = this.permanentFactionsDisableLeaderPromotion;
|
||||
mconf.actionDeniedPainAmount = this.actionDeniedPainAmount;
|
||||
mconf.disablePVPForFactionlessPlayers = this.disablePVPForFactionlessPlayers;
|
||||
mconf.enablePVPAgainstFactionlessInAttackersLand = this.enablePVPAgainstFactionlessInAttackersLand;
|
||||
mconf.territoryShieldFactor = this.territoryShieldFactor;
|
||||
mconf.denyCommandsPermanentFactionMember = this.denyCommandsPermanentFactionMember;
|
||||
mconf.denyCommandsTerritoryRelation = this.denyCommandsTerritoryRelation;
|
||||
mconf.lwcRemoveOnChange = this.lwcRemoveOnChange;
|
||||
mconf.econEnabled = this.econEnabled;
|
||||
mconf.econLandReward = this.econLandReward;
|
||||
mconf.econUniverseAccount = this.econUniverseAccount;
|
||||
mconf.econChunkCost = this.econChunkCost;
|
||||
mconf.econCostCreate = this.econCostCreate;
|
||||
mconf.econCostSethome = this.econCostSethome;
|
||||
mconf.econCostJoin = this.econCostJoin;
|
||||
mconf.econCostLeave = this.econCostLeave;
|
||||
mconf.econCostKick = this.econCostKick;
|
||||
mconf.econCostInvite = this.econCostInvite;
|
||||
mconf.econCostDeinvite = this.econCostDeinvite;
|
||||
mconf.econCostHome = this.econCostHome;
|
||||
mconf.econCostName = this.econCostName;
|
||||
mconf.econCostDescription = this.econCostDescription;
|
||||
mconf.econCostTitle = this.econCostTitle;
|
||||
mconf.econCostFlag = this.econCostOpen;
|
||||
mconf.econRelCost = this.econRelCost;
|
||||
mconf.bankEnabled = this.bankEnabled;
|
||||
mconf.bankFactionPaysCosts = this.bankFactionPaysCosts;
|
||||
mconf.bankFactionPaysLandCosts = this.bankFactionPaysLandCosts;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNIVERSE ENABLE SWITCH
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean enabled = true;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIAL FACTION IDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String factionIdNone = null;
|
||||
public String factionIdSafezone = null;
|
||||
public String factionIdWarzone = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DEFAULTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String defaultPlayerFactionId = null;
|
||||
public Rel defaultPlayerRole = null;
|
||||
public double defaultPlayerPower = 0.0;
|
||||
|
||||
//public boolean defaultFactionOpen = false;
|
||||
//public Map<FFlag, Boolean> defaultFactionFlags = null;
|
||||
//public Map<FPerm, Set<Rel>> defaultFactionPerms = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MESSAGES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean broadcastNameChange = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// POWER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public double powerMax = 10.0;
|
||||
public double powerMin = 0.0;
|
||||
public double powerPerHour = 2.0;
|
||||
public double powerPerDeath = -2.0;
|
||||
|
||||
public boolean canLeaveWithNegativePower = true;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public int factionMemberLimit = 0;
|
||||
public double factionPowerMax = 0.0;
|
||||
|
||||
public int factionNameLengthMin = 3;
|
||||
public int factionNameLengthMax = 16;
|
||||
public boolean factionNameForceUpperCase = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLAIMS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean claimsMustBeConnected = true;
|
||||
public boolean claimingFromOthersAllowed = true;
|
||||
public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false;
|
||||
public int claimsRequireMinFactionMembers = 1;
|
||||
public int claimedLandsMax = 0;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HOMES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean homesEnabled = true;
|
||||
public boolean homesMustBeInClaimedTerritory = true;
|
||||
public boolean homesTeleportCommandEnabled = true;
|
||||
public boolean homesTeleportAllowedFromEnemyTerritory = true;
|
||||
public boolean homesTeleportAllowedFromDifferentWorld = true;
|
||||
public double homesTeleportAllowedEnemyDistance = 32.0;
|
||||
public boolean homesTeleportIgnoreEnemiesIfInOwnTerritory = true;
|
||||
|
||||
public boolean homesTeleportToOnDeathActive = false;
|
||||
public EventPriority homesTeleportToOnDeathPriority = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ASSORTED
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean permanentFactionsDisableLeaderPromotion = false;
|
||||
public double actionDeniedPainAmount = 2.0D;
|
||||
public boolean disablePVPForFactionlessPlayers = false;
|
||||
public boolean enablePVPAgainstFactionlessInAttackersLand = false;
|
||||
public double territoryShieldFactor = 0.3D;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DENY COMMANDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// commands which will be prevented if the player is a member of a permanent faction
|
||||
public List<String> denyCommandsPermanentFactionMember = null;
|
||||
|
||||
// commands which will be prevented when in claimed territory of another faction
|
||||
public Map<Rel, List<String>> denyCommandsTerritoryRelation = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: LWC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Boolean> lwcRemoveOnChange = null;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INTEGRATION: ECONOMY
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean econEnabled = false;
|
||||
|
||||
// TODO: Rename to include unit.
|
||||
public double econLandReward = 0.00;
|
||||
|
||||
public String econUniverseAccount = null;
|
||||
|
||||
public Map<EventFactionsChunkChangeType, Double> econChunkCost = null;
|
||||
|
||||
public double econCostCreate = 200.0;
|
||||
public double econCostSethome = 0.0;
|
||||
public double econCostJoin = 0.0;
|
||||
public double econCostLeave = 0.0;
|
||||
public double econCostKick = 0.0;
|
||||
public double econCostInvite = 0.0;
|
||||
public double econCostDeinvite = 0.0;
|
||||
public double econCostHome = 0.0;
|
||||
public double econCostName = 0.0;
|
||||
public double econCostDescription = 0.0;
|
||||
public double econCostTitle = 0.0;
|
||||
public double econCostOpen = 0.0;
|
||||
|
||||
public Map<Rel, Double> econRelCost = null;
|
||||
|
||||
//Faction banks, to pay for land claiming and other costs instead of individuals paying for them
|
||||
public boolean bankEnabled = true;
|
||||
//public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction
|
||||
public boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome
|
||||
public boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs.
|
||||
}
|
@ -97,11 +97,7 @@ public class RelationUtil
|
||||
Faction thatFaction = getFaction(that);
|
||||
if (thatFaction == null) return Rel.NEUTRAL; // ERROR
|
||||
|
||||
if (myFaction.equals(thatFaction))
|
||||
{
|
||||
if (that instanceof MPlayer) return ((MPlayer) that).getRole();
|
||||
return Rel.MEMBER;
|
||||
}
|
||||
if (myFaction.equals(thatFaction)) return Rel.FACTION;
|
||||
|
||||
MFlag flagPeaceful = MFlag.getFlagPeaceful();
|
||||
if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE;
|
||||
|
Loading…
Reference in New Issue
Block a user