Skip to content

Commit a1b2f2a

Browse files
committed
fix errors from cherry pick
1 parent 04fd38f commit a1b2f2a

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

common/src/main/java/de/z0rdak/yawp/api/FlagTagRegister.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class FlagTagRegister {
1717
* {@code USE_ITEM}, etc. </p>
1818
*/
1919
public static final FlagTag PLAYER = register(new FlagTag(
20-
ResourceLocation.fromNamespaceAndPath("yawp", "player"),
20+
new ResourceLocation("yawp", "player"),
2121
"Flags that evaluate per-player context or directly affect player actions. Examples: BREAK_BLOCKS, PLACE_BLOCKS, USE_ITEM, etc."
2222
));
2323

@@ -30,7 +30,7 @@ public final class FlagTagRegister {
3030
* Usually combined with {@link #PLAYER}.
3131
*/
3232
public static final FlagTag BENEFICIAL = register(new FlagTag(
33-
ResourceLocation.fromNamespaceAndPath("yawp", "beneficial"),
33+
new ResourceLocation("yawp", "beneficial"),
3434
"Flags granting advantages or permissions to players. Denying these feels wrong from a player perspective. Usually combined with PLAYER. Examples: INVINCIBLE, KEEP_INV, KEEP_XP."
3535
));
3636

@@ -41,7 +41,7 @@ public final class FlagTagRegister {
4141
* Always implies {@link #PLAYER}.
4242
*/
4343
public static final FlagTag PLAYER_PREVENTION = register(new FlagTag(
44-
ResourceLocation.fromNamespaceAndPath("yawp", "prevention"),
44+
new ResourceLocation("yawp", "prevention"),
4545
"Flags that actively block or prevent a player’s attempted action. Always implies PLAYER. Examples: BREAK_BLOCKS, PLACE_BLOCKS, USE_ITEM."
4646
));
4747

@@ -51,7 +51,7 @@ public final class FlagTagRegister {
5151
* {@code BLOCK_BREAK}, etc.</p>
5252
*/
5353
public static final FlagTag BLOCK = register(new FlagTag(
54-
ResourceLocation.fromNamespaceAndPath("yawp", "block"),
54+
new ResourceLocation("yawp", "block"),
5555
"Flags concerning block-based events or world state. Examples: FIRE_SPREAD, TNT_EXPLODE, BLOCK_BREAK."
5656
));
5757

@@ -62,7 +62,7 @@ public final class FlagTagRegister {
6262
* Often combined with {@link #PLAYER}.
6363
*/
6464
public static final FlagTag ITEM = register(new FlagTag(
65-
ResourceLocation.fromNamespaceAndPath("yawp", "item"),
65+
new ResourceLocation("yawp", "item"),
6666
"Flags tied to item actions or mechanics. Examples: USE_ITEM, DROP_ITEM, PICKUP_ITEM. Often combined with PLAYER."
6767
));
6868

@@ -71,7 +71,7 @@ public final class FlagTagRegister {
7171
* <p>Examples: {@code INTERACT_ENTITY}.</p>
7272
*/
7373
public static final FlagTag ENTITY = register(new FlagTag(
74-
ResourceLocation.fromNamespaceAndPath("yawp", "entity"),
74+
new ResourceLocation("yawp", "entity"),
7575
"Flags involving entities as targets or sources. Examples: INTERACT_ENTITY."
7676
));
7777

@@ -82,7 +82,7 @@ public final class FlagTagRegister {
8282
* {@code FLUID_FLOW}, {@code ICE_MELT}.</p>
8383
*/
8484
public static final FlagTag ENVIRONMENT = register(new FlagTag(
85-
ResourceLocation.fromNamespaceAndPath("yawp", "environment"),
85+
new ResourceLocation("yawp", "environment"),
8686
"Flags controlling world-level effects or non-entity mechanics. Examples: FIRE_TICK, LEAF_DECAY, FLUID_FLOW, ICE_MELT."
8787
));
8888

@@ -92,7 +92,7 @@ public final class FlagTagRegister {
9292
* <p>Examples: {@code MOVE}, {@code FIRE_TICK}, {@code FLUID_FLOW}.</p>
9393
*/
9494
public static final FlagTag HIGH_FREQUENCY = register(new FlagTag(
95-
ResourceLocation.fromNamespaceAndPath("yawp", "high-frequency"),
95+
new ResourceLocation("yawp", "high-frequency"),
9696
"Flags checked repeatedly per n-ticks, usually for movement or environment updates. Examples: MOVE, FIRE_TICK, FLUID_FLOW."
9797
));
9898

@@ -102,7 +102,7 @@ public final class FlagTagRegister {
102102
* <p>Examples: {@code BLOCK_EXPLODE}, {@code griefing}, etc.</p>
103103
*/
104104
public static final FlagTag PROTECTION = register(new FlagTag(
105-
ResourceLocation.fromNamespaceAndPath("yawp", "protection"),
105+
new ResourceLocation("yawp", "protection"),
106106
"Flags defining preventive or defensive behavior rather than granting permissions. Examples: BLOCK_EXPLODE, griefing."
107107
));
108108

fabric/src/main/java/de/z0rdak/yawp/config/ConfigRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static void onModLoading(ModConfig modConfig) {
9797
LOGGING_CONFIG_LOGGER.info("Logging flag checks: {}", LoggingConfig.shouldLogFlagChecks());
9898
LOGGING_CONFIG_LOGGER.info("Logging flag check results: {}", LoggingConfig.shouldLogFlagCheckResults());
9999
LOGGING_CONFIG_LOGGER.info("Logging empty flag results: {}", LoggingConfig.shouldLogEmptyResults());
100-
LOGGING_CONFIG_LOGGER.info("Logging flag categories: [{}]", String.join(",", LoggingConfig.getFlagCategories()));
100+
LOGGING_CONFIG_LOGGER.info("Logging flag categories: [{}]", String.join(",", LoggingConfig.getFlagTags()));
101101
LOGGING_CONFIG_LOGGER.info("Logging flag results: [{}]", String.join(",", LoggingConfig.getResultValuesToLog()));
102102
LOGGING_CONFIG_LOGGER.info("Logging flags: [{}]", String.join(",", LoggingConfig.getFlagsToLog()));
103103
// LOGGING_CONFIG_LOGGER.info("Logging detailed player flag checks: {}", LoggingConfig.shouldLogDetailedPlayerFlags());

fabric/src/main/java/de/z0rdak/yawp/config/server/PermissionConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class PermissionConfig {
5050
.define("disable_cmd_for_non_op", false);
5151

5252
OP_BYPASS_FLAGS = BUILDER.comment("Defines whether OPs/permitted players are allowed to bypass flags set in regions.")
53-
.define("op_bypass_flags", true);
53+
.define("op_bypass_flags", false);
5454

5555
ENABLE_HIERARCHY_OWNERSHIP = BUILDER.comment("Defines whether owners of parent regions have implicit ownership rights for child regions as well")
5656
.define("hierarchy_ownership", true);

forge/src/main/java/de/z0rdak/yawp/config/ConfigRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static void onConfigLoading(ModConfigEvent.Loading event) {
9393
LOGGING_CONFIG_LOGGER.info("Logging flag checks: {}", LoggingConfig.shouldLogFlagChecks());
9494
LOGGING_CONFIG_LOGGER.info("Logging flag check results: {}", LoggingConfig.shouldLogFlagCheckResults());
9595
LOGGING_CONFIG_LOGGER.info("Logging empty flag results: {}", LoggingConfig.shouldLogEmptyResults());
96-
LOGGING_CONFIG_LOGGER.info("Logging flag categories: [{}]", String.join(",", LoggingConfig.getFlagCategories()));
96+
LOGGING_CONFIG_LOGGER.info("Logging flag categories: [{}]", String.join(",", LoggingConfig.getFlagTags()));
9797
LOGGING_CONFIG_LOGGER.info("Logging flag results: [{}]", String.join(",", LoggingConfig.getResultValuesToLog()));
9898
LOGGING_CONFIG_LOGGER.info("Logging flags: [{}]", String.join(",", LoggingConfig.getFlagsToLog()));
9999
// LOGGING_CONFIG_LOGGER.info("Logging detailed player flag checks: {}", LoggingConfig.shouldLogDetailedPlayerFlags());

forge/src/main/java/de/z0rdak/yawp/config/server/LoggingConfig.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package de.z0rdak.yawp.config.server;
22

3+
import de.z0rdak.yawp.api.FlagTagRegister;
4+
import de.z0rdak.yawp.api.events.region.FlagCheckEvent;
5+
import de.z0rdak.yawp.api.events.region.FlagCheckResult;
36
import de.z0rdak.yawp.api.events.region.ForgeFlagCheckEvent;
47
import de.z0rdak.yawp.api.events.region.ForgeFlagCheckResult;
58
import de.z0rdak.yawp.constants.Constants;
6-
import de.z0rdak.yawp.core.flag.FlagState;
7-
import de.z0rdak.yawp.core.flag.FlagTag;
8-
import de.z0rdak.yawp.core.flag.IFlag;
9-
import de.z0rdak.yawp.core.flag.RegionFlag;
9+
import de.z0rdak.yawp.core.flag.*;
1010
import de.z0rdak.yawp.core.region.RegionType;
1111
import de.z0rdak.yawp.util.AreaUtil;
12+
import net.minecraft.resources.ResourceLocation;
1213
import net.minecraftforge.common.ForgeConfigSpec;
1314
import org.apache.logging.log4j.LogManager;
1415
import org.apache.logging.log4j.Logger;
@@ -29,7 +30,7 @@ public class LoggingConfig {
2930
private static final ForgeConfigSpec.ConfigValue<Boolean> LOG_EMPTY_RESULTS;
3031
// private static final ForgeConfigSpec.ConfigValue<Boolean> DETAILED_PLAYER_FLAG_LOG;
3132
private static final ForgeConfigSpec.ConfigValue<List<? extends String>> LOG_RESULT_VALUES;
32-
private static final ForgeConfigSpec.ConfigValue<List<? extends String>> LOG_FLAG_CATEGORIES;
33+
private static final ForgeConfigSpec.ConfigValue<List<? extends String>> LOG_FLAG_TAGS;
3334
private static final ForgeConfigSpec.ConfigValue<List<? extends String>> LOG_FLAGS;
3435

3536
static {
@@ -41,16 +42,16 @@ public class LoggingConfig {
4142
.define("log_flag_check", false);
4243

4344
FLAG_RESULT_LOG = BUILDER.comment("Enable logging of flag check results.")
44-
.define("log_flag_result", true);
45+
.define("log_flag_result", false);
4546

4647
LOG_EMPTY_RESULTS = BUILDER.comment("Enable logging of empty (without responsible region) flag check results.")
4748
.define("log_empty_results", false);
4849

4950
LOG_RESULT_VALUES = BUILDER.comment("List of flags result states which shall be logged. By default only denied results will be logged.\n Valid FlagStates are: allowed and denied")
5051
.defineListAllowEmpty(List.of("log_result_values"), () -> Collections.singletonList(FlagState.DENIED.name), LoggingConfig::isValidFlagState);
5152

52-
LOG_FLAG_CATEGORIES = BUILDER.comment("List of flag categories which shall be logged.\nValid categories are: player, block, entity, item, environment, protection and * (for all).")
53-
.defineListAllowEmpty(List.of("log_flag_categories"), () -> Collections.singletonList(FlagTag.PLAYER.name), LoggingConfig::isValidCategory);
53+
LOG_FLAG_TAGS = BUILDER.comment("List of flag tags which shall be logged.\nValid tags are: player, beneficial, block, entity, item, environment, protection, high-frequency and * (for all).")
54+
.defineListAllowEmpty(List.of("log_flag_tags"), () -> Collections.singletonList(FlagTagRegister.PLAYER.tagRl().toString()), LoggingConfig::isValidTag);
5455

5556
LOG_FLAGS = BUILDER.comment("List of flags which shall be logged.")
5657
.defineListAllowEmpty(List.of("log_flags"), () -> Arrays.asList(RegionFlag.BREAK_BLOCKS.name, RegionFlag.PLACE_BLOCKS.name), LoggingConfig::isValidFlag);
@@ -62,8 +63,8 @@ public class LoggingConfig {
6263

6364
}
6465

65-
public static Set<String> getFlagCategories() {
66-
return LOG_FLAG_CATEGORIES.get().stream()
66+
public static Set<String> getFlagTags() {
67+
return LOG_FLAG_TAGS.get().stream()
6768
.filter(Objects::nonNull)
6869
.map(String::toString)
6970
.collect(Collectors.toSet());
@@ -83,11 +84,15 @@ public static Set<String> getResultValuesToLog() {
8384
.collect(Collectors.toSet());
8485
}
8586

86-
private static boolean isValidCategory(Object entity) {
87+
private static boolean isValidTag(Object entity) {
8788
if (entity instanceof String str) {
8889
try {
89-
FlagTag category = FlagTag.from(str);
90-
return category != null || str.equalsIgnoreCase("*");
90+
if (str.equals("*")) {
91+
return true;
92+
}
93+
FlagTag tag = FlagTagRegister.from(ResourceLocation.tryParse(str));
94+
// if no exception was thrown, it's a valid tag
95+
return tag != null;
9196
} catch (IllegalArgumentException e) {
9297
LOGGING_CONFIG_LOGGER.warn("Invalid flag category supplied for 'log_flag_categories': {}", entity);
9398
return false;
@@ -187,7 +192,7 @@ public static boolean matchesResult(ForgeFlagCheckResult result) {
187192
}
188193

189194
public static boolean flagMatchesCategory(ForgeFlagCheckEvent check) {
190-
return RegionFlag.matchesCategory(check.getRegionFlag(), getFlagCategories());
195+
return RegionFlag.matchesCategory(check.getRegionFlag(), getFlagTags());
191196
}
192197

193198
public static boolean matchesFlag(ForgeFlagCheckEvent check) {

0 commit comments

Comments
 (0)