Perm rework
This commit is contained in:
parent
cee15b6333
commit
595a051a23
1
pom.xml
1
pom.xml
@ -76,7 +76,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
|
@ -58,6 +58,7 @@ public enum Perm implements Identified
|
||||
PERM_LIST,
|
||||
PERM_SET,
|
||||
PERM_SHOW,
|
||||
PERM_SHOW2,
|
||||
PLAYER,
|
||||
POWERBOOST,
|
||||
POWERBOOST_PLAYER,
|
||||
|
@ -115,6 +115,12 @@ public enum Rel implements Colorized, Named, MPerm.MPermable
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Object senderObject)
|
||||
{
|
||||
return this.getColor() + this.getName();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
@ -55,7 +55,6 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
|
||||
public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
|
||||
public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
|
||||
public CmdFactionsExpansions cmdFactionsExpansions = new CmdFactionsExpansions();
|
||||
public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride();
|
||||
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
|
||||
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
|
||||
|
@ -1,40 +0,0 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.event.EventFactionsExpansions;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class CmdFactionsExpansions extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Event
|
||||
EventFactionsExpansions event = new EventFactionsExpansions(sender);
|
||||
event.run();
|
||||
|
||||
// Title
|
||||
Object title = "Factions Expansions";
|
||||
title = Txt.titleize(title);
|
||||
message(title);
|
||||
|
||||
// Lines
|
||||
for (Entry<String, Boolean> entry : event.getExpansions().entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
Boolean installed = entry.getValue();
|
||||
String format = (installed ? "<g>[X] <h>%s" : "<b>[ ] <h>%s");
|
||||
msg(format, name);
|
||||
}
|
||||
|
||||
// URL Suggestion
|
||||
msg("<i>Learn all about expansions in the online documentation:");
|
||||
msg("<aqua>https://www.massivecraft.com/factions");
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ public class CmdFactionsPerm extends FactionsCommand
|
||||
|
||||
CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList();
|
||||
CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow();
|
||||
CmdFactionsPermShow2 cmdFactionsPermShow2 = new CmdFactionsPermShow2();
|
||||
CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet();
|
||||
|
||||
}
|
||||
|
@ -14,19 +14,6 @@ import java.util.List;
|
||||
|
||||
public class CmdFactionsPermList extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REUSABLE PREDICATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final Predicate<MPerm> PREDICATE_MPERM_VISIBLE = new Predicate<MPerm>()
|
||||
{
|
||||
@Override
|
||||
public boolean apply(MPerm mperm)
|
||||
{
|
||||
return mperm.isVisible();
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -49,16 +36,8 @@ public class CmdFactionsPermList extends FactionsCommand
|
||||
|
||||
// Pager create
|
||||
String title = String.format("Perms for %s", msenderFaction.describeTo(msender));
|
||||
final Pager<MPerm> pager = new Pager<>(this, title, page, new Stringifier<MPerm>()
|
||||
{
|
||||
@Override
|
||||
public String toString(MPerm mperm, int index)
|
||||
{
|
||||
return mperm.getDesc(true, true);
|
||||
}
|
||||
});
|
||||
|
||||
final Predicate<MPerm> predicate = msender.isOverriding() ? null : PREDICATE_MPERM_VISIBLE;
|
||||
final Pager<MPerm> pager = new Pager<>(this, title, page, (Stringifier<MPerm>) (mp, i) -> mp.getDesc(true, true));
|
||||
final Predicate<MPerm> predicate = msender.isOverriding() ? null : MPerm::isVisible;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
||||
{
|
||||
|
@ -4,17 +4,12 @@ import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPermable;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsPermChange;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CmdFactionsPermSet extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -44,15 +39,18 @@ public class CmdFactionsPermSet extends FactionsCommand
|
||||
|
||||
MPerm.MPermable permable = TypeMPermable.get(faction).read(this.argAt(1), sender);
|
||||
|
||||
|
||||
// Do the sender have the right to change perms for this faction?
|
||||
if ( ! MPerm.getPermPerms().has(msender, faction, true)) return;
|
||||
|
||||
// Is this perm editable?
|
||||
if ( ! msender.isOverriding() && ! perm.isEditable())
|
||||
{
|
||||
msg("<b>The perm <h>%s <b>is not editable.", perm.getName());
|
||||
return;
|
||||
throw new MassiveException().addMsg("<b>The perm <h>%s <b>is not editable.", perm.getName());
|
||||
}
|
||||
|
||||
if (permable == faction)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>A faction can't have perms for itself. Perhaps try ranks.");
|
||||
}
|
||||
|
||||
// Event
|
||||
@ -67,35 +65,18 @@ public class CmdFactionsPermSet extends FactionsCommand
|
||||
// No change
|
||||
if (!change)
|
||||
{
|
||||
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"), permable.getColor() + permable.getName() + "s");
|
||||
return;
|
||||
throw new MassiveException().addMsg("%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"), permable.getDisplayName(msender));
|
||||
}
|
||||
|
||||
|
||||
// The following is to make sure the leader always has the right to change perms if that is our goal.
|
||||
if (perm == MPerm.getPermPerms() && MConf.get().defaultPermsLeader.contains(MPerm.ID_PERMS))
|
||||
if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains("LEADER"))
|
||||
{
|
||||
faction.setPermitted( faction.getLeaderRank(), MPerm.getPermPerms(), true);
|
||||
}
|
||||
|
||||
// Create messages
|
||||
List<Object> messages = new ArrayList<>();
|
||||
|
||||
// Inform sender
|
||||
messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
|
||||
messages.add(MPerm.getStateHeaders(faction));
|
||||
messages.add(Txt.parse(perm.getStateInfo(faction, true)));
|
||||
message(messages);
|
||||
|
||||
// Inform faction (their message is slighly different)
|
||||
List<MPlayer> recipients = faction.getMPlayers();
|
||||
recipients.remove(msender);
|
||||
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s <i>set a perm for <h>%s<i>.", msender.describeTo(recipient, true), faction.describeTo(recipient, true));
|
||||
recipient.message(messages);
|
||||
}
|
||||
String yesNo = Txt.parse(value ? "<g>YES" : "<b>NOO");
|
||||
msg("<i>Set perm <h>%s <i>to <h>%s <i>for <reset>%s<i> in <reset>%s<i>.", perm.getName(), yesNo, permable.getDisplayName(msender), faction.describeTo(msender));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.MPlayerColl;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.container.TypeSet;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CmdFactionsPermShow extends FactionsCommand
|
||||
{
|
||||
@ -21,8 +24,8 @@ public class CmdFactionsPermShow extends FactionsCommand
|
||||
public CmdFactionsPermShow()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPerm.get(), "perm");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
this.addParameter(TypeSet.get(TypeMPerm.get()), "perms", "all", true);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -33,21 +36,48 @@ public class CmdFactionsPermShow extends FactionsCommand
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Arg: Faction
|
||||
MPerm mperm = this.readArg();
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
Collection<MPerm> mperms = this.readArg(MPerm.getAll());
|
||||
|
||||
// Create messages
|
||||
List<Object> messages = new ArrayList<>();
|
||||
var permittedIds = faction.getPerms().get(mperm.getId());
|
||||
var permables = new MassiveList<MPerm.MPermable>();
|
||||
|
||||
messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
|
||||
messages.add(MPerm.getStateHeaders(faction));
|
||||
for (MPerm mperm : mperms)
|
||||
for (var permitted : permittedIds)
|
||||
{
|
||||
messages.add(Txt.parse(mperm.getStateInfo(faction, true)));
|
||||
permables.add(idToMPermable(permitted));
|
||||
}
|
||||
|
||||
// Send messages
|
||||
message(messages);
|
||||
var removeString = Txt.parse(" of ") + faction.getDisplayName(msender);
|
||||
var permableList = permables.stream()
|
||||
.map(permable -> permable.getDisplayName(msender))
|
||||
.map(s -> s.replace(removeString, ""))
|
||||
.collect(Collectors.toList());
|
||||
String permableNames = Txt.implodeCommaAnd(permableList, Txt.parse("<i>"));
|
||||
|
||||
// Create messages
|
||||
msg("<i>In <reset>%s <i>permission <h>%s <i>is granted to <reset>%s<i>.", faction.describeTo(msender), mperm.getName(), permableNames);
|
||||
}
|
||||
|
||||
public static MPerm.MPermable idToMPermable(String id)
|
||||
{
|
||||
MPlayer mplayer = MPlayerColl.get().get(id, false);
|
||||
if (mplayer != null) return mplayer;
|
||||
|
||||
Faction faction = Faction.get(id);
|
||||
if (faction != null) return faction;
|
||||
|
||||
for (var f : FactionColl.get().getAll())
|
||||
{
|
||||
Rank rank = f.getRank(id);
|
||||
if (rank != null) return rank;
|
||||
}
|
||||
|
||||
if (Rel.ALLY.name().equalsIgnoreCase(id)) return Rel.ALLY;
|
||||
if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Rel.TRUCE;
|
||||
if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Rel.NEUTRAL;
|
||||
if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Rel.ENEMY;
|
||||
|
||||
throw new RuntimeException(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
100
src/com/massivecraft/factions/cmd/CmdFactionsPermShow2.java
Normal file
100
src/com/massivecraft/factions/cmd/CmdFactionsPermShow2.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPermable;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CmdFactionsPermShow2 extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermShow2()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPermable.get(), "rank/rel/player/faction");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Arg: Faction
|
||||
Faction faction = this.readArgAt(1, msenderFaction);
|
||||
var permableType = TypeMPermable.get(faction);
|
||||
MPerm.MPermable permable = permableType.read(this.argAt(0), sender);
|
||||
|
||||
if (permable == faction)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>A faction can't have perms for itself.");
|
||||
}
|
||||
|
||||
var perms = new MassiveList<MPerm>();
|
||||
|
||||
for (var mperm : MPerm.getAll())
|
||||
{
|
||||
if (faction.isPermitted(permable.getId(), mperm.getId())) perms.add(mperm);
|
||||
}
|
||||
|
||||
if (perms.isEmpty())
|
||||
{
|
||||
msg("<i>In <reset>%s <reset>%s <i>specifically has <b>no permissions<i>.", faction.describeTo(msender), permable.getDisplayName(sender));
|
||||
}
|
||||
else
|
||||
{
|
||||
var permNames = perms.stream().map(perm -> Txt.parse("<h>") + perm.getName()).collect(Collectors.toList());
|
||||
String names = Txt.implodeCommaAnd(permNames, Txt.parse("<i>"));
|
||||
|
||||
// Create messages
|
||||
var permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions";
|
||||
msg("<i>In <reset>%s <reset>%s <i>specifically has the %s: <reset>%s<i>.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names);
|
||||
}
|
||||
if (permable instanceof MPlayer)
|
||||
{
|
||||
MPlayer mplayer = (MPlayer) permable;
|
||||
msg("<i>They may have other permissions through their faction membership, rank or relation to <reset>%s<i>.", faction.describeTo(msender));
|
||||
|
||||
var msons = new MassiveList<Mson>();
|
||||
|
||||
if (mplayer.getFaction() != faction) msons.add(Mson.parse("<command>[faction]").command(this, mplayer.getFaction().getName(), faction.getName()));
|
||||
msons.add(Mson.parse("<command>[rank]").command(this, mplayer.getFaction().getName() + "-" + mplayer.getRank().getName(), faction.getName()));
|
||||
if (mplayer.getFaction() != faction) msons.add(Mson.parse("<command>[relation]").command(this, faction.getRelationTo(mplayer).toString(), faction.getName()));
|
||||
Mson msons2 = Mson.implode(msons, Mson.SPACE);
|
||||
message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons2));
|
||||
}
|
||||
if (permable instanceof Faction)
|
||||
{
|
||||
Faction faction1 = (Faction) permable;
|
||||
msg("<i>They may have other permissions through their relation to <reset>%s<i>.", faction.describeTo(msender));
|
||||
Mson msonRelation = Mson.parse("<command>[relation]").command(this, faction.getRelationTo(faction1).toString(), faction.getName());
|
||||
Mson msons = Mson.implode(MUtil.list(msonRelation), Mson.SPACE);
|
||||
message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons));
|
||||
}
|
||||
if (permable instanceof Rank && !faction.hasRank((Rank) permable))
|
||||
{
|
||||
Rank rank = (Rank) permable;
|
||||
msg("<i>They may have other permissions thorugh their faction membership or relation to <reset>%s<i>.", faction.describeTo(msender));
|
||||
Mson msonFaction = Mson.parse("<command>[faction]").command(this, rank.getFaction().getName(), faction.getName());
|
||||
Mson msonRelation = Mson.parse("<command>[relation]").command(this, faction.getRelationTo(rank.getFaction()).toString(), faction.getName());
|
||||
Mson msons = Mson.implode(MUtil.list(msonFaction, msonRelation), Mson.SPACE);
|
||||
message(mson(mson("Commands: ").color(ChatColor.YELLOW), msons));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed;
|
||||
|
||||
public class CmdFactionsRankEditCreate extends FactionsCommand
|
||||
{
|
||||
@ -18,7 +19,7 @@ public class CmdFactionsRankEditCreate extends FactionsCommand
|
||||
// Parameters
|
||||
this.addParameter(TypeString.get(), "name");
|
||||
this.addParameter(TypeInteger.get(), "priority");
|
||||
this.addParameter("", TypeString.get(), "prefix", "none");
|
||||
this.addParameter("", TypeStringParsed.get(), "prefix", "none");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,20 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstract;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeMPermable extends TypeAbstractChoice<MPerm.MPermable>
|
||||
public class TypeMPermable extends TypeAbstract<MPerm.MPermable>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
@ -20,7 +27,6 @@ public class TypeMPermable extends TypeAbstractChoice<MPerm.MPermable>
|
||||
super(Rank.class);
|
||||
|
||||
this.faction = null;
|
||||
this.setAll(Collections.emptyList());
|
||||
}
|
||||
|
||||
public static TypeMPermable get(Faction faction) { return new TypeMPermable(faction); }
|
||||
@ -30,10 +36,6 @@ public class TypeMPermable extends TypeAbstractChoice<MPerm.MPermable>
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
this.faction = faction;
|
||||
|
||||
var permables = MPerm.getPermables(faction);
|
||||
|
||||
this.setAll(permables);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -43,4 +45,100 @@ public class TypeMPermable extends TypeAbstractChoice<MPerm.MPermable>
|
||||
private final Faction faction;
|
||||
public Faction getFaction() { return this.faction; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public MPerm.MPermable read(String arg, CommandSender sender) throws MassiveException
|
||||
{
|
||||
TypeRank typeRank = new TypeRank(this.getFaction());
|
||||
try
|
||||
{
|
||||
Rank rank = typeRank.read(arg, sender);
|
||||
return rank;
|
||||
}
|
||||
catch (MassiveException ex)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Rel rel = TypeRelation.get().read(arg, sender);
|
||||
return rel;
|
||||
}
|
||||
catch (MassiveException ex)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
MPlayer mplayer = TypeMPlayer.get().read(arg, sender);
|
||||
return mplayer;
|
||||
}
|
||||
catch (MassiveException ex)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Faction faction = TypeFaction.get().read(arg, sender);
|
||||
return faction;
|
||||
}
|
||||
catch (MassiveException ex)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
if (arg.contains("-"))
|
||||
{
|
||||
int idx = arg.indexOf('-');
|
||||
String factionName = arg.substring(0, idx);
|
||||
String rankName = arg.substring(idx+1);
|
||||
|
||||
Faction faction = TypeFaction.get().read(factionName, sender);
|
||||
Rank rank = TypeRank.get(faction).read(rankName, sender);
|
||||
return rank;
|
||||
}
|
||||
|
||||
throw new MassiveException().addMsg("<b>No rank, relation, player or faction matches: <h>%s<b>.", arg);
|
||||
}
|
||||
|
||||
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||
{
|
||||
var ret = new MassiveList<String>();
|
||||
var faction = this.getFaction();
|
||||
if (faction == null) faction = MPlayer.get(sender).getFaction();
|
||||
ret.addAll(faction.getRanks().getAll().stream().map(Rank::getName).collect(Collectors.toList()));
|
||||
ret.addAll(TypeRelation.get().getTabList(sender, arg));
|
||||
ret.addAll(TypeFaction.get().getTabList(sender, arg));
|
||||
|
||||
// Faction specific ranks
|
||||
if (arg.length() >= 3)
|
||||
{
|
||||
for (var f : FactionColl.get().getAll())
|
||||
{
|
||||
String name = f.getName();
|
||||
if (arg.length() <= name.length() && !name.toLowerCase().startsWith(arg.toLowerCase())) continue;
|
||||
if (arg.length() > name.length() && !arg.toLowerCase().startsWith(name.toLowerCase())) continue;
|
||||
|
||||
ret.addAll(f.getRanks().getAll().stream().map(r -> name + "-" + r.getName()).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isValid(String arg, CommandSender sender)
|
||||
{
|
||||
// In the generic case accept all
|
||||
if (this.getFaction() == null) return true;
|
||||
else return super.isValid(arg, sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
|
||||
// The perm overrides are modifications to the default values.
|
||||
// Null means default.
|
||||
private Map<String, Set<String>> perms = new MassiveMap<>();
|
||||
private Map<String, Set<String>> perms = this.createNewPermMap();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: id
|
||||
@ -751,7 +751,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: permOverrides
|
||||
// FIELD: perms
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Map<String, Set<String>> getPerms()
|
||||
@ -759,6 +759,32 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
public Map<String, Set<String>> createNewPermMap()
|
||||
{
|
||||
Map<String, Set<String>> ret = new MassiveMap<>();
|
||||
|
||||
var leaderId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("leader")).map(Rank::getId).findFirst();
|
||||
var officerId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("officer")).map(Rank::getId).findFirst();
|
||||
var memberId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("member")).map(Rank::getId).findFirst();
|
||||
var recruitId = this.getRanks().getAll().stream().filter(r -> r.getName().equalsIgnoreCase("recruit")).map(Rank::getId).findAny();
|
||||
|
||||
for (var mperm : MPerm.getAll())
|
||||
{
|
||||
var id = mperm.getId();
|
||||
var value = new MassiveSet<>(mperm.getStandard());
|
||||
|
||||
if (value.remove("LEADER") && leaderId.isPresent()) value.add(leaderId.get());
|
||||
if (value.remove("OFFICER") && officerId.isPresent()) value.add(officerId.get());
|
||||
if (value.remove("MEMBER") && memberId.isPresent()) value.add(memberId.get());
|
||||
if (value.remove("RECRUIT") && recruitId.isPresent()) value.add(recruitId.get());
|
||||
|
||||
ret.put(mperm.getId(), value);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// IS PERMITTED
|
||||
|
||||
public boolean isPlayerPermitted(MPlayer mplayer, String permId)
|
||||
@ -789,19 +815,30 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
return isFactionPermitted(faction, mperm.getId());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isPermablePermitted(MPerm.MPermable permable, String permId)
|
||||
public Set<String> getPermitted(String permId)
|
||||
{
|
||||
return isPermitted(permable.getId(), permId);
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
var permables = this.perms.get(permId);
|
||||
|
||||
if (permables == null)
|
||||
{
|
||||
// No perms was found, but likely this is just a new MPerm.
|
||||
// So if this does not exist in the database, throw an error.
|
||||
if (!doesPermExist(permId)) throw new NullPointerException(permId + " caused null");
|
||||
|
||||
permables = new MassiveSet<>();
|
||||
this.perms.put(permId, permables);
|
||||
}
|
||||
|
||||
return permables;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isPermablePermitted(MPerm.MPermable permable, MPerm mperm)
|
||||
public Set<String> getPermitted(MPerm mperm)
|
||||
{
|
||||
return isPermablePermitted(permable, mperm.getId());
|
||||
return getPermitted(mperm.getId());
|
||||
}
|
||||
|
||||
private boolean isPermitted(String permableId, String permId)
|
||||
public boolean isPermitted(String permableId, String permId)
|
||||
{
|
||||
if (permableId == null) throw new NullPointerException("permableId");
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
@ -817,7 +854,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
return false;
|
||||
}
|
||||
|
||||
return permables.contains(permableId);
|
||||
return getPermitted(permId).contains(permableId);
|
||||
}
|
||||
|
||||
// SET PERMITTED
|
||||
@ -873,7 +910,6 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
return MPermColl.get().getFixed(permId) != null;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: RelationParticipator
|
||||
// -------------------------------------------- //
|
||||
@ -908,6 +944,19 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
return RelationUtil.getColorOfThatToMe(this, observer);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: permable
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Object senderObject)
|
||||
{
|
||||
MPlayer mplayer = MPlayer.get(senderObject);
|
||||
if (mplayer == null) return this.getName();
|
||||
|
||||
return this.describeTo(mplayer);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// POWER
|
||||
// -------------------------------------------- //
|
||||
|
@ -280,14 +280,14 @@ public class MConf extends Entity<MConf>
|
||||
// PERMS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<String> defaultPermsEnemy = MUtil.list(MPerm.ID_DEPOSIT);
|
||||
/*public List<String> defaultPermsEnemy = MUtil.list(MPerm.ID_DEPOSIT);
|
||||
public List<String> defaultPermsNeutral = MUtil.list(MPerm.ID_DEPOSIT);
|
||||
public List<String> defaultPermsTruce = MUtil.list(MPerm.ID_DEPOSIT);
|
||||
public List<String> defaultPermsAlly = MUtil.list(MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_HOME, MPerm.ID_CLAIMNEAR);
|
||||
public List<String> defaultPermsRecruit = MUtil.list(MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_LEVER, MPerm.ID_HOME, MPerm.ID_CLAIMNEAR);
|
||||
public List<String> defaultPermsMember = MUtil.list(MPerm.ID_BUILD, MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_LEVER, MPerm.ID_CONTAINER, MPerm.ID_HOME, MPerm.ID_CLAIMNEAR);
|
||||
public List<String> defaultPermsOfficer = MUtil.list(MPerm.ID_BUILD, MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_LEVER, MPerm.ID_CONTAINER, MPerm.ID_DESC, MPerm.ID_MOTD, MPerm.ID_INVITE, MPerm.ID_KICK, MPerm.ID_RANK, MPerm.ID_TITLE, MPerm.ID_HOME, MPerm.ID_SETHOME, MPerm.ID_TERRITORY, MPerm.ID_ACCESS, MPerm.ID_CLAIMNEAR, MPerm.ID_REL);
|
||||
public List<String> defaultPermsLeader = MUtil.list(MPerm.ID_BUILD, MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_LEVER, MPerm.ID_CONTAINER, MPerm.ID_NAME, MPerm.ID_DESC, MPerm.ID_MOTD, MPerm.ID_INVITE, MPerm.ID_KICK, MPerm.ID_RANK, MPerm.ID_TITLE, MPerm.ID_HOME, MPerm.ID_SETHOME, MPerm.ID_WITHDRAW, MPerm.ID_TERRITORY, MPerm.ID_ACCESS, MPerm.ID_CLAIMNEAR, MPerm.ID_REL, MPerm.ID_DISBAND, MPerm.ID_FLAGS, MPerm.ID_FLAGS);
|
||||
public List<String> defaultPermsLeader = MUtil.list(MPerm.ID_BUILD, MPerm.ID_DOOR, MPerm.ID_BUTTON, MPerm.ID_LEVER, MPerm.ID_LEVER, MPerm.ID_CONTAINER, MPerm.ID_NAME, MPerm.ID_DESC, MPerm.ID_MOTD, MPerm.ID_INVITE, MPerm.ID_KICK, MPerm.ID_RANK, MPerm.ID_TITLE, MPerm.ID_HOME, MPerm.ID_SETHOME, MPerm.ID_WITHDRAW, MPerm.ID_TERRITORY, MPerm.ID_ACCESS, MPerm.ID_CLAIMNEAR, MPerm.ID_REL, MPerm.ID_DISBAND, MPerm.ID_FLAGS, MPerm.ID_FLAGS);*/
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TERRITORY INFO
|
||||
|
@ -18,7 +18,6 @@ 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.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -417,7 +416,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String getStateHeaders(Faction faction)
|
||||
/*public static String getStateHeaders(Faction faction)
|
||||
{
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
@ -469,7 +468,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
if (withDesc) ret += " <i>" + this.getDesc();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}*/
|
||||
|
||||
public interface MPermable extends Named, Identified
|
||||
{
|
||||
@ -488,22 +487,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
return this.getName().substring(0, 3).toUpperCase();
|
||||
}
|
||||
|
||||
default ChatColor getColor()
|
||||
{
|
||||
if (this.isRelation())
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
else if (this.isRank())
|
||||
{
|
||||
return MConf.get().colorMember;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
String getDisplayName(Object senderObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.massivecore.store.EntityInternal;
|
||||
import com.massivecraft.massivecore.store.EntityInternalMap;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Rank extends EntityInternal<Rank> implements MPerm.MPermable
|
||||
@ -17,6 +19,20 @@ public class Rank extends EntityInternal<Rank> implements MPerm.MPermable
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preDetach(String id)
|
||||
{
|
||||
for (var f : FactionColl.get().getAll())
|
||||
{
|
||||
for (var it = f.getPerms().entrySet().iterator(); it.hasNext();)
|
||||
{
|
||||
var entry = it.next();
|
||||
var value = entry.getValue();
|
||||
value.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
@ -33,6 +49,13 @@ public class Rank extends EntityInternal<Rank> implements MPerm.MPermable
|
||||
public String getPrefix() { return this.prefix; }
|
||||
public void setPrefix(String prefix) { this.prefix = prefix; this.changed(); }
|
||||
|
||||
public Faction getFaction()
|
||||
{
|
||||
var internalMap = (EntityInternalMap<Rank>) this.getContainer();
|
||||
var faction = (Faction) internalMap.getEntity();
|
||||
return faction;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -54,6 +77,14 @@ public class Rank extends EntityInternal<Rank> implements MPerm.MPermable
|
||||
// VISUAL
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getDisplayName(Object senderObject)
|
||||
{
|
||||
String ret = this.getVisual();
|
||||
ret += Txt.parse(" of ") + this.getFaction().getDisplayName(senderObject);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getVisual()
|
||||
{
|
||||
String ret = "";
|
||||
|
Loading…
Reference in New Issue
Block a user