Change permission checking in preparation for permission rework
This commit is contained in:
parent
f347c1058a
commit
0efccf335c
@ -170,8 +170,7 @@ public class EngineChunkChange extends Engine
|
|||||||
MPerm claimnear = MPerm.getPermClaimnear();
|
MPerm claimnear = MPerm.getPermClaimnear();
|
||||||
for (Faction nearbyFaction : nearbyFactions)
|
for (Faction nearbyFaction : nearbyFactions)
|
||||||
{
|
{
|
||||||
if (claimnear.has(newFaction, nearbyFaction)) continue;
|
if (claimnear.has(mplayer, nearbyFaction, true)) continue;
|
||||||
mplayer.message(claimnear.createDeniedMessage(mplayer, nearbyFaction));
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Faction extends Entity<Faction> implements FactionsParticipator
|
public class Faction extends Entity<Faction> implements FactionsParticipator, MPerm.MPermable
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
@ -761,13 +761,53 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
|||||||
|
|
||||||
// IS PERMITTED
|
// IS PERMITTED
|
||||||
|
|
||||||
public boolean isPermitted(MPerm.MPermable mpermable, String permId)
|
public boolean isPlayerPermitted(MPlayer mplayer, String permId)
|
||||||
{
|
{
|
||||||
if (mpermable == null) throw new NullPointerException("mpermable");
|
if (isPermitted(mplayer.getId(), permId)) return true;
|
||||||
|
if (isPermitted(mplayer.getFaction().getId(), permId)) return true;
|
||||||
|
if (isPermitted(mplayer.getRank().getId(), permId)) return true;
|
||||||
|
if (isPermitted(RelationUtil.getRelationOfThatToMe(mplayer, this).toString(), permId)) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayerPermitted(MPlayer mplayer, MPerm mperm)
|
||||||
|
{
|
||||||
|
return isPlayerPermitted(mplayer, mperm.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFactionPermitted(Faction faction, String permId)
|
||||||
|
{
|
||||||
|
if (isPermitted(faction.getId(), permId)) return true;
|
||||||
|
if (isPermitted(RelationUtil.getRelationOfThatToMe(faction, this).toString(), permId)) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFactionPermitted(Faction faction, MPerm mperm)
|
||||||
|
{
|
||||||
|
return isFactionPermitted(faction, mperm.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public boolean isPermablePermitted(MPerm.MPermable permable, String permId)
|
||||||
|
{
|
||||||
|
return isPermitted(permable.getId(), permId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public boolean isPermablePermitted(MPerm.MPermable permable, MPerm mperm)
|
||||||
|
{
|
||||||
|
return isPermablePermitted(permable, mperm.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPermitted(String permableId, String permId)
|
||||||
|
{
|
||||||
|
if (permableId == null) throw new NullPointerException("permableId");
|
||||||
if (permId == null) throw new NullPointerException("permId");
|
if (permId == null) throw new NullPointerException("permId");
|
||||||
|
|
||||||
var perms = this.perms.get(permId);
|
var permables = this.perms.get(permId);
|
||||||
if (perms == null)
|
if (permables == null)
|
||||||
{
|
{
|
||||||
// No perms was found, but likely this is just a new MPerm.
|
// No perms was found, but likely this is just a new MPerm.
|
||||||
// So if this does not exist in the database, throw an error.
|
// So if this does not exist in the database, throw an error.
|
||||||
@ -777,14 +817,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return perms.contains(mpermable.getId());
|
return permables.contains(permableId);
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPermitted(MPerm.MPermable mpermable, MPerm mperm)
|
|
||||||
{
|
|
||||||
if (mpermable == null) throw new NullPointerException("mpermable");
|
|
||||||
if (mperm == null) throw new NullPointerException("mperm");
|
|
||||||
return isPermitted(mpermable, mperm.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SET PERMITTED
|
// SET PERMITTED
|
||||||
|
@ -351,8 +351,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
|||||||
if (faction == null) throw new NullPointerException("faction");
|
if (faction == null) throw new NullPointerException("faction");
|
||||||
if (hostFaction == null) throw new NullPointerException("hostFaction");
|
if (hostFaction == null) throw new NullPointerException("hostFaction");
|
||||||
|
|
||||||
Rel rel = faction.getRelationTo(hostFaction);
|
return hostFaction.isFactionPermitted(faction, this);
|
||||||
return hostFaction.isPermitted(rel, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose)
|
public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose)
|
||||||
@ -365,7 +364,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
|||||||
|
|
||||||
Rel rel = mplayer.getRelationTo(hostFaction);
|
Rel rel = mplayer.getRelationTo(hostFaction);
|
||||||
MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel;
|
MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel;
|
||||||
if (hostFaction.isPermitted(permable, this)) return true;
|
if (hostFaction.isPlayerPermitted(mplayer, this)) return true;
|
||||||
|
|
||||||
if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
||||||
|
|
||||||
@ -441,7 +440,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
|||||||
|
|
||||||
for (MPermable permable : getPermables(faction))
|
for (MPermable permable : getPermables(faction))
|
||||||
{
|
{
|
||||||
if (faction.isPermitted(permable, this))
|
if (faction.isPermablePermitted(permable, this))
|
||||||
{
|
{
|
||||||
ret += "<g>YES";
|
ret += "<g>YES";
|
||||||
}
|
}
|
||||||
@ -504,6 +503,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
|||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator
|
public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipator, MPerm.MPermable {
|
||||||
{
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// META
|
// META
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -45,8 +44,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
// META
|
// META
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static MPlayer get(Object oid)
|
public static MPlayer get(Object oid) {
|
||||||
{
|
|
||||||
return MPlayerColl.get().get(oid);
|
return MPlayerColl.get().get(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +59,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MPlayer load(MPlayer that)
|
public MPlayer load(MPlayer that) {
|
||||||
{
|
|
||||||
this.setLastActivityMillis(that.lastActivityMillis);
|
this.setLastActivityMillis(that.lastActivityMillis);
|
||||||
this.setFactionId(that.factionId);
|
this.setFactionId(that.factionId);
|
||||||
this.rankId = that.rankId;
|
this.rankId = that.rankId;
|
||||||
@ -81,8 +78,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefault()
|
public boolean isDefault() {
|
||||||
{
|
|
||||||
// Last activity millis is data we use for clearing out cleanable players. So it does not in itself make the player data worth keeping.
|
// Last activity millis is data we use for clearing out cleanable players. So it does not in itself make the player data worth keeping.
|
||||||
if (this.hasFaction()) return false;
|
if (this.hasFaction()) return false;
|
||||||
// Role means nothing without a faction.
|
// Role means nothing without a faction.
|
||||||
@ -101,22 +97,18 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postAttach(String id)
|
public void postAttach(String id) {
|
||||||
{
|
|
||||||
FactionsIndex.get().update(this);
|
FactionsIndex.get().update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preDetach(String id)
|
public void preDetach(String id) {
|
||||||
{
|
|
||||||
FactionsIndex.get().update(this);
|
FactionsIndex.get().update(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preClean()
|
public void preClean() {
|
||||||
{
|
if (this.getRank().isLeader()) {
|
||||||
if (this.getRank().isLeader())
|
|
||||||
{
|
|
||||||
this.getFaction().promoteNewLeader();
|
this.getFaction().promoteNewLeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user