diff --git a/gradle.properties b/gradle.properties index 6c25a02..d3a076f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,7 +34,7 @@ mod_name=Area Control # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=BSD-3-Clause # The mod version. See https://semver.org/ -mod_version=0.8.16 +mod_version=0.8.17 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/org/teacon/areacontrol/AreaControl.java b/src/main/java/org/teacon/areacontrol/AreaControl.java index d374a4f..5d2ff5f 100644 --- a/src/main/java/org/teacon/areacontrol/AreaControl.java +++ b/src/main/java/org/teacon/areacontrol/AreaControl.java @@ -34,6 +34,7 @@ @Mod("area_control") @EventBusSubscriber(modid = "area_control") public final class AreaControl { + public static String VERSION = ""; private static final Logger LOGGER = LoggerFactory.getLogger("AreaControl"); @@ -42,6 +43,8 @@ public final class AreaControl { public static Predicate singlePlayerServerChecker; public AreaControl(ModContainer container, IEventBus modBus) { + VERSION = container.getModInfo().getVersion().toString(); + AreaRepositoryManager.init(); container.registerConfig(ModConfig.Type.SERVER, AreaControlConfig.setup(new ModConfigSpec.Builder())); singlePlayerServerChecker = switch (FMLEnvironment.dist) { diff --git a/src/main/java/org/teacon/areacontrol/AreaControlCommand.java b/src/main/java/org/teacon/areacontrol/AreaControlCommand.java index 948d43c..4e6a891 100644 --- a/src/main/java/org/teacon/areacontrol/AreaControlCommand.java +++ b/src/main/java/org/teacon/areacontrol/AreaControlCommand.java @@ -14,15 +14,12 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.SectionPos; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; @@ -81,7 +78,6 @@ public AreaControlCommand(CommandDispatcher dispatcher) { dispatcher.register(Commands.literal("ac") .redirect(dispatcher.register(Commands.literal("areacontrol") .then(Commands.literal("about").executes(AreaControlCommand::about)) - .then(Commands.literal("help").executes(AreaControlCommand::help)) .then(Commands.literal("admin").requires(ADMIN) .then(Commands.literal("rebuild").executes(AreaControlCommand::rebuildAreaModel)) ) @@ -211,21 +207,7 @@ private static int openConfiscatedItemInv(CommandContext con } private static int about(CommandContext context) { - context.getSource().sendSuccess(() -> Component.literal("AreaControl 0.8.16"), false); - return Command.SINGLE_SUCCESS; - } - - private static int help(CommandContext context) { - var markerTool = new ItemStack(BuiltInRegistries.ITEM.get(ResourceLocation.parse(AreaControlConfig.areaClaimTool.get()))); - var markerToolName = markerTool.getDisplayName(); - var displayName = markerToolName.copy() - .withStyle(Style.EMPTY - .withColor(ChatFormatting.BLUE) - .withUnderlined(Boolean.TRUE) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, markerTool.getHoverName().copy() - .append(Component.translatable("area_control.claim.how_to.give_item").withStyle(ChatFormatting.GRAY)))) - .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/give @s " + AreaControlConfig.areaClaimTool.get()))); - context.getSource().sendSuccess(() -> Component.translatable("area_control.claim.how_to", displayName), false); + context.getSource().sendSuccess(() -> Component.literal("AreaControl " + AreaControl.VERSION), false); return Command.SINGLE_SUCCESS; } diff --git a/src/main/java/org/teacon/areacontrol/impl/AreaChecks.java b/src/main/java/org/teacon/areacontrol/impl/AreaChecks.java index 8406d3d..89878e5 100644 --- a/src/main/java/org/teacon/areacontrol/impl/AreaChecks.java +++ b/src/main/java/org/teacon/areacontrol/impl/AreaChecks.java @@ -24,6 +24,7 @@ import org.teacon.areacontrol.impl.seizer.ConfiscationInv; import java.util.List; +import java.util.Optional; import java.util.function.Supplier; public class AreaChecks { @@ -111,14 +112,17 @@ public static void checkInv(IItemHandler inv, Area currentArea, Player player) { // This is a separate method because area.allow_possess currently has a different logic public static boolean checkPossess(Area area, Item item) { var targetId = BuiltInRegistries.ITEM.getKey(item); - if (targetId != null) { - var objSpecific = AreaProperties.getBoolOptional(area, AreaProperties.ALLOW_POSSESS + "." + targetId); - if (objSpecific.isPresent()) { - return objSpecific.get(); + var objSpecific = AreaProperties.getBoolOptional(area, AreaProperties.ALLOW_POSSESS + "." + targetId); + if (objSpecific.isPresent()) { + return objSpecific.get(); + } else { + var modSpecific = AreaProperties.getBoolOptional(area, AreaProperties.ALLOW_POSSESS + "." + targetId.getNamespace()); + if (modSpecific.isPresent()) { + return modSpecific.get(); } else { - var modSpecific = AreaProperties.getBoolOptional(area, AreaProperties.ALLOW_POSSESS + "." + targetId.getNamespace()); - if (modSpecific.isPresent()) { - return modSpecific.get(); + Optional globalSpecific = AreaProperties.getBoolOptional(area, AreaProperties.ALLOW_POSSESS); + if (globalSpecific.isPresent()) { + return globalSpecific.get(); } } } diff --git a/src/main/java/org/teacon/areacontrol/network/ACNetworking.java b/src/main/java/org/teacon/areacontrol/network/ACNetworking.java index 2d5fa5a..36cd8ab 100644 --- a/src/main/java/org/teacon/areacontrol/network/ACNetworking.java +++ b/src/main/java/org/teacon/areacontrol/network/ACNetworking.java @@ -6,14 +6,14 @@ import net.minecraft.server.level.ServerPlayer; import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.registration.HandlerThread; import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.jetbrains.annotations.Nullable; +import org.teacon.areacontrol.AreaControl; public class ACNetworking { public static void init(RegisterPayloadHandlersEvent event) { - PayloadRegistrar registrar = event.registrar("area_control") - .versioned("0.8.16") - .optional(); + PayloadRegistrar registrar = event.registrar(AreaControl.VERSION).executesOn(HandlerThread.NETWORK).optional(); registrar.playToServer(ACPingServer.TYPE, ACPingServer.STREAM_CODEC, ACPingServer::handle); registrar.playToClient(ACSendNearbyArea.TYPE, ACSendNearbyArea.STREAM_CODEC, ACSendNearbyArea::handle); diff --git a/src/main/java/org/teacon/areacontrol/network/ACPingServer.java b/src/main/java/org/teacon/areacontrol/network/ACPingServer.java index 0683d4e..96e5a2f 100644 --- a/src/main/java/org/teacon/areacontrol/network/ACPingServer.java +++ b/src/main/java/org/teacon/areacontrol/network/ACPingServer.java @@ -24,8 +24,10 @@ public void encode(@NotNull ByteBuf o, @NotNull ACPingServer instance) { }; public void handle(IPayloadContext context) { - var player = context.player(); - AreaControlPlayerTracker.getFrom(player).clientExtensionEnabled = true; + context.enqueueWork(() -> { + var player = context.player(); + AreaControlPlayerTracker.getFrom(player).clientExtensionEnabled = true; + }); } @Override