Add server context support. Fixes #88

* Fix user permission check.
* Add check for max inspection distance.
* Add radius-inspect option to config.
* Add active contexts when checking permissions.
This commit is contained in:
bloodshot 2019-12-31 20:12:55 -05:00
parent 3c1a515e34
commit 90d7db65cc
14 changed files with 93 additions and 46 deletions

View File

@ -950,12 +950,21 @@ private Consumer<CommandSender> createFlagConsumer(GDPermissionUser src, GDClaim
newContexts.addAll(contexts);
}
// Remove server context
// Check server context
final Iterator<Context> iterator = newContexts.iterator();
boolean hasServerContext = false;
while (iterator.hasNext()) {
final Context context = iterator.next();
if (context.getKey().equals("server")) {
iterator.remove();
hasServerContext = true;
break;
}
}
if (!hasServerContext) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
newContexts.add(new Context("server", serverName));
}
}

View File

@ -789,15 +789,23 @@ private Consumer<CommandSender> newOptionValueConsumer(GDPermissionUser src, GDC
newContexts.addAll(contexts);
}
// Remove server context
// Check server context
final Iterator<Context> iterator = newContexts.iterator();
boolean hasServerContext = false;
while (iterator.hasNext()) {
final Context context = iterator.next();
if (context.getKey().equals("server")) {
iterator.remove();
hasServerContext = true;
break;
}
}
if (!hasServerContext) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
newContexts.add(new Context("server", serverName));
}
}
final PermissionResult result = PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts);
if (result.successful()) {
if (option == Options.PLAYER_WEATHER) {

View File

@ -75,24 +75,19 @@ public DefaultPermissionCategory() {
this.defaultClaimFlags.put(ClaimTypes.WILDERNESS.getName().toLowerCase(), wildernessFlagMap);
final int maxAccruedBlocks = GriefDefenderPlugin.CLAIM_BLOCK_SYSTEM == ClaimBlockSystem.VOLUME ? 20480000 : 80000;
this.defaultUserOptions.put(Options.EXPIRATION.getName(), "14");
this.defaultUserOptions.put(Options.TAX_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.TAX_EXPIRATION_DAYS_KEEP.getName(), "7");
this.defaultUserOptions.put(Options.TAX_RATE.getName(), "1.0");
this.defaultUserOptions.put(Options.ABANDON_DELAY.getName(), "0");
this.defaultUserOptions.put(Options.ABANDON_RETURN_RATIO.getName(), "1.0");
this.defaultUserOptions.put(Options.BLOCKS_ACCRUED_PER_HOUR.getName(), "120");
this.defaultUserOptions.put(Options.CHEST_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.CREATE_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.CREATE_MODE.getName(), "undefined");
this.defaultUserOptions.put(Options.ECONOMY_BLOCK_COST.getName(), "0.0");
this.defaultUserOptions.put(Options.ECONOMY_BLOCK_SELL_RETURN.getName(), "0.0");
this.defaultUserOptions.put(Options.EXPIRATION.getName(), "14");
this.defaultUserOptions.put(Options.INITIAL_BLOCKS.getName(), "120");
this.defaultUserOptions.put(Options.MAX_ACCRUED_BLOCKS.getName(), Integer.toString(maxAccruedBlocks));
this.defaultUserOptions.put(Options.MIN_LEVEL.getName(), "0");
this.defaultUserOptions.put(Options.MAX_LEVEL.getName(), "255");
this.defaultUserOptions.put(Options.ABANDON_DELAY.getName(), "0");
this.defaultUserOptions.put(Options.ABANDON_RETURN_RATIO.getName(), "1.0");
this.defaultUserOptions.put(Options.RAID.getName(), "true");
this.defaultUserOptions.put(Options.SPAWN_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.PLAYER_DENY_FLIGHT.getName(), "false");
this.defaultUserOptions.put(Options.PLAYER_DENY_GODMODE.getName(), "false");
this.defaultUserOptions.put(Options.PLAYER_DENY_HUNGER.getName(), "false");
@ -107,6 +102,12 @@ public DefaultPermissionCategory() {
this.defaultUserOptions.put(Options.PVP_COMBAT_COMMAND.getName(), "false");
this.defaultUserOptions.put(Options.PVP_COMBAT_TELEPORT.getName(), "false");
this.defaultUserOptions.put(Options.PVP_COMBAT_TIMEOUT.getName(), "15");
this.defaultUserOptions.put(Options.RAID.getName(), "true");
this.defaultUserOptions.put(Options.RADIUS_INSPECT.getName(), "100");
this.defaultUserOptions.put(Options.SPAWN_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.TAX_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.TAX_EXPIRATION_DAYS_KEEP.getName(), "7");
this.defaultUserOptions.put(Options.TAX_RATE.getName(), "1.0");
this.defaultBasicOptions.put(Options.MIN_SIZE_X.getName(), "5");
this.defaultBasicOptions.put(Options.MIN_SIZE_Y.getName(), "5");

View File

@ -1539,6 +1539,9 @@ private boolean investigateClaim(PlayerInteractEvent event, Player player, Block
}
private GDClaim findNearbyClaim(Player player, int maxDistance) {
if (maxDistance <= 0) {
maxDistance = 100;
}
BlockRay blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
GDClaim claim = null;

View File

@ -313,12 +313,18 @@ private Tristate getUserPermission(GDPermissionHolder holder, Claim claim, Strin
contexts.remove(parent.getContext());
}
// Check claim context
contexts.add(claim.getContext());
contexts.add(claim.getType().getContext());
Tristate value = PermissionUtil.getInstance().getPermissionValue((GDClaim) claim, holder, permission, contexts);
if (value != Tristate.UNDEFINED) {
return processResult(claim, permission, value, holder);
}
// Check default type context
contexts.add(claim.getType().getContext());
value = PermissionUtil.getInstance().getPermissionValue((GDClaim) claim, holder, permission, contexts);
if (value != Tristate.UNDEFINED) {
return processResult(claim, permission, value, holder);
}
if (holder == GriefDefenderPlugin.DEFAULT_HOLDER) {
return getFlagDefaultPermission(claim, permission, contexts);

View File

@ -561,16 +561,7 @@ public Map<Set<Context>, Map<String, Boolean>> getAllPermissions(GDPermissionHol
public Set<Context> getGPContexts(ContextSet contextSet) {
final Set<Context> gpContexts = new HashSet<>();
for (net.luckperms.api.context.Context context : contextSet.toSet()) {
if (context.getKey().startsWith("gd_") || context.getKey().equals("used_item")
|| context.getKey().equals("source") || context.getKey().equals("target")
|| context.getKey().equals("world") || context.getKey().equals("server")
|| context.getKey().equals("state")) {
if (contextSet.containsKey(ContextKeys.CLAIM) && context.getKey().equals("server")) {
continue;
}
gpContexts.add(new Context(context.getKey(), context.getValue()));
}
gpContexts.add(new Context(context.getKey(), context.getValue()));
}
return gpContexts;
}
@ -586,6 +577,7 @@ public Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, Str
}
public Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, String permission, Set<Context> contexts) {
this.addActiveContexts(contexts, holder, null, claim);
return this.getPermissionValue(holder, permission, contexts);
}

View File

@ -378,6 +378,10 @@ public void setDefaultGlobalPermissions() {
}
private void setDefaultFlags(Set<Context> contexts, Map<String, Boolean> defaultFlags) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
contexts.add(new Context("server", serverName));
}
GriefDefenderPlugin.getInstance().executor.execute(() -> {
for (Map.Entry<String, Boolean> mapEntry : defaultFlags.entrySet()) {
final Flag flag = FlagRegistryModule.getInstance().getById(mapEntry.getKey()).orElse(null);

View File

@ -950,12 +950,21 @@ private Consumer<CommandSource> createFlagConsumer(GDPermissionUser src, GDClaim
newContexts.addAll(contexts);
}
// Remove server context
// Check server context
final Iterator<Context> iterator = newContexts.iterator();
boolean hasServerContext = false;
while (iterator.hasNext()) {
final Context context = iterator.next();
if (context.getKey().equals("server")) {
iterator.remove();
hasServerContext = true;
break;
}
}
if (!hasServerContext) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
newContexts.add(new Context("server", serverName));
}
}

View File

@ -789,15 +789,24 @@ private Consumer<CommandSource> newOptionValueConsumer(GDPermissionUser src, GDC
newContexts.addAll(contexts);
}
// Remove server context
// Check server context
final Iterator<Context> iterator = newContexts.iterator();
boolean hasServerContext = false;
while (iterator.hasNext()) {
final Context context = iterator.next();
if (context.getKey().equals("server")) {
iterator.remove();
//iterator.remove();
hasServerContext = true;
break;
}
}
if (!hasServerContext) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
newContexts.add(new Context("server", serverName));
}
}
final PermissionResult result = PermissionUtil.getInstance().setOptionValue(this.subject, option.getPermission(), newValue, newContexts);
if (result.successful()) {
if (option == Options.PLAYER_WEATHER) {

View File

@ -75,24 +75,19 @@ public DefaultPermissionCategory() {
this.defaultClaimFlags.put(ClaimTypes.WILDERNESS.getName().toLowerCase(), wildernessFlagMap);
final int maxAccruedBlocks = GriefDefenderPlugin.CLAIM_BLOCK_SYSTEM == ClaimBlockSystem.VOLUME ? 20480000 : 80000;
this.defaultUserOptions.put(Options.EXPIRATION.getName(), "14");
this.defaultUserOptions.put(Options.TAX_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.TAX_EXPIRATION_DAYS_KEEP.getName(), "7");
this.defaultUserOptions.put(Options.TAX_RATE.getName(), "1.0");
this.defaultUserOptions.put(Options.ABANDON_DELAY.getName(), "0");
this.defaultUserOptions.put(Options.ABANDON_RETURN_RATIO.getName(), "1.0");
this.defaultUserOptions.put(Options.BLOCKS_ACCRUED_PER_HOUR.getName(), "120");
this.defaultUserOptions.put(Options.CHEST_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.CREATE_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.CREATE_MODE.getName(), "undefined");
this.defaultUserOptions.put(Options.ECONOMY_BLOCK_COST.getName(), "0.0");
this.defaultUserOptions.put(Options.ECONOMY_BLOCK_SELL_RETURN.getName(), "0.0");
this.defaultUserOptions.put(Options.EXPIRATION.getName(), "14");
this.defaultUserOptions.put(Options.INITIAL_BLOCKS.getName(), "120");
this.defaultUserOptions.put(Options.MAX_ACCRUED_BLOCKS.getName(), Integer.toString(maxAccruedBlocks));
this.defaultUserOptions.put(Options.MIN_LEVEL.getName(), "0");
this.defaultUserOptions.put(Options.MAX_LEVEL.getName(), "255");
this.defaultUserOptions.put(Options.ABANDON_DELAY.getName(), "0");
this.defaultUserOptions.put(Options.ABANDON_RETURN_RATIO.getName(), "1.0");
this.defaultUserOptions.put(Options.RAID.getName(), "true");
this.defaultUserOptions.put(Options.SPAWN_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.PLAYER_DENY_FLIGHT.getName(), "false");
this.defaultUserOptions.put(Options.PLAYER_DENY_GODMODE.getName(), "false");
this.defaultUserOptions.put(Options.PLAYER_DENY_HUNGER.getName(), "false");
@ -107,6 +102,12 @@ public DefaultPermissionCategory() {
this.defaultUserOptions.put(Options.PVP_COMBAT_COMMAND.getName(), "false");
this.defaultUserOptions.put(Options.PVP_COMBAT_TELEPORT.getName(), "false");
this.defaultUserOptions.put(Options.PVP_COMBAT_TIMEOUT.getName(), "15");
this.defaultUserOptions.put(Options.RAID.getName(), "true");
this.defaultUserOptions.put(Options.RADIUS_INSPECT.getName(), "100");
this.defaultUserOptions.put(Options.SPAWN_LIMIT.getName(), "-1");
this.defaultUserOptions.put(Options.TAX_EXPIRATION.getName(), "7");
this.defaultUserOptions.put(Options.TAX_EXPIRATION_DAYS_KEEP.getName(), "7");
this.defaultUserOptions.put(Options.TAX_RATE.getName(), "1.0");
this.defaultBasicOptions.put(Options.MIN_SIZE_X.getName(), "5");
this.defaultBasicOptions.put(Options.MIN_SIZE_Y.getName(), "5");

View File

@ -1668,6 +1668,9 @@ private boolean investigateClaim(InteractEvent event, Player player, BlockSnapsh
}
private GDClaim findNearbyClaim(Player player, int maxDistance) {
if (maxDistance <= 0) {
maxDistance = 100;
}
BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
GDClaim claim = null;

View File

@ -357,12 +357,18 @@ private Tristate getUserPermission(GDPermissionHolder holder, Claim claim, Strin
contexts.remove(parent.getContext());
}
// Check claim context
contexts.add(claim.getContext());
contexts.add(claim.getType().getContext());
Tristate value = PermissionUtil.getInstance().getPermissionValue((GDClaim) claim, holder, permission, contexts);
if (value != Tristate.UNDEFINED) {
return processResult(claim, permission, value, holder);
}
// Check default type context
contexts.add(claim.getType().getContext());
value = PermissionUtil.getInstance().getPermissionValue((GDClaim) claim, holder, permission, contexts);
if (value != Tristate.UNDEFINED) {
return processResult(claim, permission, value, holder);
}
if (holder == GriefDefenderPlugin.DEFAULT_HOLDER) {
return getFlagDefaultPermission(claim, permission, contexts);

View File

@ -557,16 +557,7 @@ public Map<Set<Context>, Map<String, Boolean>> getAllPermissions(GDPermissionHol
public Set<Context> getGPContexts(ContextSet contextSet) {
final Set<Context> gpContexts = new HashSet<>();
for (net.luckperms.api.context.Context context : contextSet.toSet()) {
if (context.getKey().startsWith("gd_") || context.getKey().equals("used_item")
|| context.getKey().equals("source") || context.getKey().equals("target")
|| context.getKey().equals("world") || context.getKey().equals("server")
|| context.getKey().equals("state")) {
if (contextSet.containsKey(ContextKeys.CLAIM) && context.getKey().equals("server")) {
continue;
}
gpContexts.add(new Context(context.getKey(), context.getValue()));
}
gpContexts.add(new Context(context.getKey(), context.getValue()));
}
return gpContexts;
}
@ -582,6 +573,7 @@ public Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, Str
}
public Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, String permission, Set<Context> contexts) {
this.addActiveContexts(contexts, holder, null, claim);
return this.getPermissionValue(holder, permission, contexts);
}

View File

@ -377,6 +377,10 @@ public void setDefaultGlobalPermissions() {
}
private void setDefaultFlags(Set<Context> contexts, Map<String, Boolean> defaultFlags) {
final String serverName = PermissionUtil.getInstance().getServerName();
if (serverName != null) {
contexts.add(new Context("server", serverName));
}
GriefDefenderPlugin.getInstance().executor.execute(() -> {
for (Map.Entry<String, Boolean> mapEntry : defaultFlags.entrySet()) {
final Flag flag = FlagRegistryModule.getInstance().getById(mapEntry.getKey()).orElse(null);