Skip to content

Commit

Permalink
fix: Console exception in 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Feb 19, 2024
1 parent 92169d8 commit 2aee5e4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public ContextSet estimatePotentialContexts() {

private void setContextsFromRules(@NotNull ContextConsumer consumer, Rules wilderness) {
consumer.accept(ContextKey.CAN_PLAYER_BUILD.getKey(plugin), wilderness
.cancelOperation(OperationType.BLOCK_BREAK) ? "false" : "true");
.cancelOperation(OperationType.BLOCK_BREAK, plugin.getFlags()) ? "false" : "true");
consumer.accept(ContextKey.CAN_PLAYER_OPEN_CONTAINERS.getKey(plugin), wilderness
.cancelOperation(OperationType.CONTAINER_OPEN) ? "false" : "true");
.cancelOperation(OperationType.CONTAINER_OPEN, plugin.getFlags()) ? "false" : "true");
consumer.accept(ContextKey.CAN_PLAYER_INTERACT.getKey(plugin), wilderness
.cancelOperation(OperationType.BLOCK_INTERACT) ? "false" : "true");
.cancelOperation(OperationType.BLOCK_INTERACT, plugin.getFlags()) ? "false" : "true");
}
}

Expand Down
14 changes: 9 additions & 5 deletions common/src/main/java/net/william278/husktowns/claim/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,27 @@ public boolean hasFlagSet(@NotNull Flag flag) {
public void setFlag(@NotNull Flag flag, boolean value) {
if (flags.containsKey(flag.getName())) {
flags.replace(flag.getName(), value);
calculatedFlags.replace(flag, value);
if (calculatedFlags != null) {
calculatedFlags.replace(flag, value);
}
} else {
flags.put(flag.getName(), value);
calculatedFlags.put(flag, value);
if (calculatedFlags != null) {
calculatedFlags.put(flag, value);
}
}
}

/**
* Whether, for the given operation, the flag rules set indicate it should be cancelled
*
* @param type the operation type that is being performed in a region governed by these rules
* @param type the operation type that is being performed in a region governed by these rules
* @return Whether the operation should be canceled:
* <p>
* {@code true} if no flags have been set to {@code true} that permit the operation; {@code false} otherwise
*/
public boolean cancelOperation(@NotNull OperationType type) {
return calculatedFlags.entrySet().stream()
public boolean cancelOperation(@NotNull OperationType type, @NotNull Flags flagConfig) {
return getCalculatedFlags(flagConfig).entrySet().stream()
.filter(Map.Entry::getValue)
.noneMatch(entry -> entry.getKey().isOperationAllowed(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ && cancelFriendlyFire(optionalUser.get(), optionalVictim.get())) {
// Handle operations in unclaimable worlds
final Optional<ClaimWorld> world = getPlugin().getClaimWorld((World) operation.getOperationPosition().getWorld());
if (world.isEmpty()) {
if (getPlugin().getRulePresets().getUnclaimableWorldRules(getPlugin().getFlags()).cancelOperation(operation.getType())) {
if (getPlugin().getRulePresets().getUnclaimableWorldRules(getPlugin().getFlags())
.cancelOperation(operation.getType(), getPlugin().getFlags())) {
if (operation.isVerbose() && optionalUser.isPresent()) {
getPlugin().getLocales().getLocale("operation_cancelled")
.ifPresent(optionalUser.get()::sendMessage);
Expand All @@ -163,7 +164,7 @@ && cancelFriendlyFire(optionalUser.get(), optionalVictim.get())) {

// Handle operations in claim worlds
if (getPlugin().getRulePresets().getWildernessRules(getPlugin().getFlags())
.cancelOperation(operation.getType())) {
.cancelOperation(operation.getType(), getPlugin().getFlags())) {
if (operation.isVerbose() && optionalUser.isPresent()) {
getPlugin().getLocales().getLocale("operation_cancelled")
.ifPresent(optionalUser.get()::sendMessage);
Expand Down Expand Up @@ -192,11 +193,12 @@ private boolean cancelOperation(@NotNull Operation operation, @NotNull TownClaim
.map(online -> war.isPlayerActive(online.getUuid()))
.orElse(false))
.orElse(false)) {
return getPlugin().getRulePresets().getWartimeRules(getPlugin().getFlags()).cancelOperation(operation.getType());
return getPlugin().getRulePresets().getWartimeRules(getPlugin().getFlags())
.cancelOperation(operation.getType(), getPlugin().getFlags());
}

// If the operation is not allowed by the claim flags
if (town.getRules().get(claim.getType()).cancelOperation(operation.getType())) {
if (town.getRules().get(claim.getType()).cancelOperation(operation.getType(), getPlugin().getFlags())) {
if (optionalUser.isEmpty()) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions docs/Config-Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ flags:
- PLAYER_DAMAGE_PLAYER
monster_spawning:
- MONSTER_SPAWN
- PASSIVE_MOB_SPAWN
- PLAYER_DAMAGE_MONSTER
public_interact_access:
- ENTITY_INTERACT
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ javaVersion=16
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.daemon=true

plugin_version=3.0.1
plugin_version=3.0.2
plugin_archive=husktowns
plugin_description=Simple and elegant proxy-compatible Towny-style protection

Expand Down

0 comments on commit 2aee5e4

Please sign in to comment.