diff --git a/common/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/common/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index f2699fa..6cba800 100644 --- a/common/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/common/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.20.2 2024-07-20T12:53:36.9764242 Languages: en_us -e3979f69d6f26453fdf1227dc1d640cc4143c3ff assets/theatrical/lang/en_us.json +// 1.20.2 2024-07-29T23:11:39.1659592 Languages: en_us +51f24e3b8b2d0667dec3cce6b38b13b241264dc8 assets/theatrical/lang/en_us.json diff --git a/common/src/generated/resources/assets/theatrical/lang/en_us.json b/common/src/generated/resources/assets/theatrical/lang/en_us.json index 52058cc..f6bec6a 100644 --- a/common/src/generated/resources/assets/theatrical/lang/en_us.json +++ b/common/src/generated/resources/assets/theatrical/lang/en_us.json @@ -14,10 +14,24 @@ "block.theatrical.redstone_interface": "Redstone Interface", "block.theatrical.tank_trap": "Tank Trap", "block.theatrical.truss": "MT100 Truss", + "button.artnetconfig": "ArtNet Config", + "commands.network": "%s (%s) has %s member(s)", + "commands.network.created": "Network created", + "commands.network.deleted": "Network deleted", + "commands.network.invalid": "Unknown network mode: %s", + "commands.network.members": "There are %s network member(s): %s.", + "commands.network.members.add.failed": "Player already member of network.", + "commands.network.members.add.success": "Added %s to the network.", + "commands.network.members.remove.success": "Removed %s from the network.", + "commands.network.notfound": "Network not found.", + "commands.network.role.invalid": "Unknown member role: %s", + "commands.network.updated": "Network updated", + "commands.networks": "There are %s network(s): %s.", "fixture.dmxStart": "DMX Address", "fixture.pan": "Pan", "fixture.tilt": "Tilt", "itemGroup.theatrical": "Theatrical", + "screen.artnetconfig.enabled": "ArtNet Enabled: %s", "screen.movinglight": "Moving Light", "ui.control.cue": "Cue - %s", "ui.control.cues": "Cues", diff --git a/common/src/main/java/dev/imabad/theatrical/Theatrical.java b/common/src/main/java/dev/imabad/theatrical/Theatrical.java index 1e11348..51e9bf2 100644 --- a/common/src/main/java/dev/imabad/theatrical/Theatrical.java +++ b/common/src/main/java/dev/imabad/theatrical/Theatrical.java @@ -1,41 +1,40 @@ package dev.imabad.theatrical; -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.arguments.StringArgumentType; import dev.architectury.event.events.common.CommandRegistrationEvent; +import dev.architectury.event.events.common.LifecycleEvent; import dev.architectury.event.events.common.PlayerEvent; import dev.architectury.platform.Platform; import dev.architectury.registry.CreativeTabRegistry; import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.Registrar; import dev.architectury.registry.registries.RegistrySupplier; import dev.imabad.theatrical.blockentities.BlockEntities; import dev.imabad.theatrical.blocks.Blocks; +import dev.imabad.theatrical.commands.CommandArguments; +import dev.imabad.theatrical.commands.DMXNetworkModeArgument; +import dev.imabad.theatrical.commands.MemberRoleArgument; +import dev.imabad.theatrical.commands.NetworkCommand; import dev.imabad.theatrical.config.ConfigHandler; import dev.imabad.theatrical.config.TheatricalConfig; -import dev.imabad.theatrical.dmx.DMXDevice; -import dev.imabad.theatrical.dmx.DMXNetwork; -import dev.imabad.theatrical.dmx.DMXNetworkData; -import dev.imabad.theatrical.dmx.DMXNetworkMember; +import dev.imabad.theatrical.dmx.*; import dev.imabad.theatrical.fixtures.Fixtures; import dev.imabad.theatrical.items.Items; +import dev.imabad.theatrical.mixin.ArgumentTypeInfosAccessor; import dev.imabad.theatrical.net.artnet.ListConsumers; import dev.imabad.theatrical.net.TheatricalNet; -import net.minecraft.commands.Commands; +import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.commands.synchronization.SingletonArgumentInfo; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; -import net.minecraft.server.players.GameProfileCache; -import net.minecraft.util.Tuple; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.swing.text.html.Option; import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; public class Theatrical { public static final String MOD_ID = "theatrical"; @@ -60,6 +59,11 @@ public static void init() { TheatricalNet.init(); Blocks.BLOCKS.register(); BlockEntities.BLOCK_ENTITIES.register(); + + DeferredRegister> argTypes = TheatricalRegistry.get(Registries.COMMAND_ARGUMENT_TYPE); + registerArgument(argTypes, SingletonArgumentInfo.contextFree(DMXNetworkModeArgument::networkMode), "network_mode", DMXNetworkModeArgument.class); + registerArgument(argTypes, SingletonArgumentInfo.contextFree(MemberRoleArgument::memberRole), "member_role", MemberRoleArgument.class); + dev.imabad.theatrical.items.Items.ITEMS.register(); PlayerEvent.PLAYER_JOIN.register((event) -> { DMXNetworkData instance = DMXNetworkData.getInstance(event.server.overworld()); @@ -75,53 +79,19 @@ public static void init() { } } }); + LifecycleEvent.SERVER_LEVEL_UNLOAD.register(world -> { + if(world.dimension().equals(Level.OVERWORLD)){ + DMXNetworkData.unloadLevel(); + } + }); CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> { - dispatcher.register(Commands.literal("theatrical") - .then(Commands.literal("networks") - .executes(context -> { - DMXNetworkData instance = DMXNetworkData. - getInstance(context.getSource().getServer().overworld()); - String networks; - if(context.getSource().hasPermission(context.getSource().getServer().getOperatorUserPermissionLevel())){ - networks = instance.getAllNetworks().stream() - .map(DMXNetwork::name).collect(Collectors.joining(",")); - } else { - networks = instance.getNetworksForPlayer(context.getSource().getPlayer().getUUID()).stream() - .map(DMXNetwork::name).collect(Collectors.joining(",")); - } - context.getSource().sendSystemMessage(Component.literal("Networks: " + networks)); - return 1; - }) - ) - .then(Commands.literal("network") - .then(Commands.argument("id", StringArgumentType.string()) - .then(Commands.literal("members") - .executes(context -> { - DMXNetworkData instance = DMXNetworkData. - getInstance(context.getSource().getServer().overworld()); - try { - String id = context.getArgument("id", String.class); - UUID uuid = UUID.fromString(id); - DMXNetwork network = instance.getNetwork(uuid); - if(network != null) { - GameProfileCache profileCache = context.getSource().getServer().getProfileCache(); - String collect = network.members() - .stream().map(DMXNetworkMember::playerId) - .map((playerUUID) -> new Tuple<>(playerUUID, profileCache.get(playerUUID))) - .map(uuidOptionalTuple -> uuidOptionalTuple.getB().isPresent() ? uuidOptionalTuple.getB().get().getName() : uuidOptionalTuple.getA().toString()) - .toList().stream().collect(Collectors.joining(",")); - context.getSource().sendSystemMessage(Component.literal("Members: " + collect)); - } - } catch (Exception e){ - context.getSource().sendSystemMessage(Component.literal("Invalid network")); - return -1; - } - return 1; - }) - ) - ) - ) - ); + NetworkCommand.register(dispatcher); }); } + + private static void registerArgument(DeferredRegister> argTypes, + ArgumentTypeInfo serializer, String id, Class clazz) { + argTypes.register(new ResourceLocation(Theatrical.MOD_ID, id), () -> serializer); + ArgumentTypeInfosAccessor.classMap().put(clazz, serializer); + } } diff --git a/common/src/main/java/dev/imabad/theatrical/blockentities/control/BasicLightingDeskBlockEntity.java b/common/src/main/java/dev/imabad/theatrical/blockentities/control/BasicLightingDeskBlockEntity.java index 48e77f1..76260b2 100644 --- a/common/src/main/java/dev/imabad/theatrical/blockentities/control/BasicLightingDeskBlockEntity.java +++ b/common/src/main/java/dev/imabad/theatrical/blockentities/control/BasicLightingDeskBlockEntity.java @@ -119,7 +119,7 @@ public void tick(){ public void update(byte[] data) { if(level != null && level.getServer() != null) { - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if(dmxData != null) { dmxData.getConsumers(universe).forEach(consumer -> consumer.consume(data)); } @@ -195,6 +195,7 @@ public void read(CompoundTag compoundTag) { public void setFaders(byte[] faders){ this.faders = Arrays.copyOf(faders, faders.length); + setChanged(); } public void setFader(int fader, int value){ @@ -203,6 +204,7 @@ public void setFader(int fader, int value){ } else { this.grandMaster = (byte) value; } + setChanged(); } public int getCurrentStep() { diff --git a/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/ArtNetInterfaceBlockEntity.java b/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/ArtNetInterfaceBlockEntity.java index fa38c18..af4b051 100644 --- a/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/ArtNetInterfaceBlockEntity.java +++ b/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/ArtNetInterfaceBlockEntity.java @@ -59,7 +59,7 @@ public void read(CompoundTag compoundTag) { public void update(byte[] data) { if(level != null && level.getServer() != null) { - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if(dmxData != null) { dmxData.getConsumersInRange(universe, getBlockPos(), TheatricalConfig.INSTANCE.COMMON.wirelessDMXRadius).forEach(dmxConsumer -> dmxConsumer.consume(data)); } diff --git a/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/RedstoneInterfaceBlockEntity.java b/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/RedstoneInterfaceBlockEntity.java index cd4431f..4b62732 100644 --- a/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/RedstoneInterfaceBlockEntity.java +++ b/common/src/main/java/dev/imabad/theatrical/blockentities/interfaces/RedstoneInterfaceBlockEntity.java @@ -162,14 +162,14 @@ public void setUniverse(int universe) { } private void updateConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { dmxData.updateConsumer(this); } } private void addConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { if(deviceId == null){ generateDeviceId(); @@ -179,7 +179,7 @@ private void addConsumer(){ } private void removeConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { dmxData.removeConsumer(this, getBlockPos()); } diff --git a/common/src/main/java/dev/imabad/theatrical/blockentities/light/BaseDMXConsumerLightBlockEntity.java b/common/src/main/java/dev/imabad/theatrical/blockentities/light/BaseDMXConsumerLightBlockEntity.java index 09a241f..9124eeb 100644 --- a/common/src/main/java/dev/imabad/theatrical/blockentities/light/BaseDMXConsumerLightBlockEntity.java +++ b/common/src/main/java/dev/imabad/theatrical/blockentities/light/BaseDMXConsumerLightBlockEntity.java @@ -117,19 +117,19 @@ public void setChannelStartPoint(int channelStartPoint) { level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS); } private void updateConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { dmxData.updateConsumer(this); } } private void removeConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { dmxData.removeConsumer(this, getBlockPos()); } } private void addConsumer(){ - var dmxData = DMXNetworkData.getInstance(level).getNetwork(networkId); + var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if (dmxData != null) { if(deviceId == null){ generateDeviceId(); diff --git a/common/src/main/java/dev/imabad/theatrical/blocks/light/BaseLightBlock.java b/common/src/main/java/dev/imabad/theatrical/blocks/light/BaseLightBlock.java index 07669f3..4f624d7 100644 --- a/common/src/main/java/dev/imabad/theatrical/blocks/light/BaseLightBlock.java +++ b/common/src/main/java/dev/imabad/theatrical/blocks/light/BaseLightBlock.java @@ -62,7 +62,7 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L if(!level.isClientSide){ BlockEntity be = level.getBlockEntity(pos); if(be instanceof BaseDMXConsumerLightBlockEntity consumerLightBlockEntity && placer instanceof ServerPlayer player){ - consumerLightBlockEntity.setNetworkId(DMXNetworkData.getInstance(level).getDefaultNetworkForPlayer(player).id()); + consumerLightBlockEntity.setNetworkId(DMXNetworkData.getInstance(level.getServer().overworld()).getDefaultNetworkForPlayer(player).id()); } } } diff --git a/common/src/main/java/dev/imabad/theatrical/client/gui/screen/BasicLightingDeskScreen.java b/common/src/main/java/dev/imabad/theatrical/client/gui/screen/BasicLightingDeskScreen.java index 05c7036..b930aef 100644 --- a/common/src/main/java/dev/imabad/theatrical/client/gui/screen/BasicLightingDeskScreen.java +++ b/common/src/main/java/dev/imabad/theatrical/client/gui/screen/BasicLightingDeskScreen.java @@ -120,7 +120,7 @@ protected void init() { ).withValues(CycleButton.ValueListSupplier.create(Stream.concat(Stream.of(UUIDUtil.NULL), TheatricalClient.getArtNetManager().getKnownNetworks().keySet().stream()).collect(Collectors.toList()))) .displayOnlyValue().withInitialValue(networkId) - .create(xCenter, yCenter, 150, 20, + .create(xCenter + 45, yCenter + 130, 150, 20, Component.translatable("screen.artnetconfig.network"), (obj, val) -> { this.networkId = val; new UpdateNetworkId(be.getBlockPos(), networkId).sendToServer(); diff --git a/common/src/main/java/dev/imabad/theatrical/commands/CommandArguments.java b/common/src/main/java/dev/imabad/theatrical/commands/CommandArguments.java new file mode 100644 index 0000000..3b16d47 --- /dev/null +++ b/common/src/main/java/dev/imabad/theatrical/commands/CommandArguments.java @@ -0,0 +1,15 @@ +package dev.imabad.theatrical.commands; + +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import dev.imabad.theatrical.TheatricalRegistry; +import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.commands.synchronization.SingletonArgumentInfo; +import net.minecraft.core.registries.Registries; + +public class CommandArguments { + + public static final DeferredRegister> ARGUMENTS = TheatricalRegistry.get(Registries.COMMAND_ARGUMENT_TYPE); + + public static final RegistrySupplier> NETWORK_MODE = ARGUMENTS.register("network_mode", () -> SingletonArgumentInfo.contextFree(DMXNetworkModeArgument::networkMode)); +} diff --git a/common/src/main/java/dev/imabad/theatrical/commands/DMXNetworkModeArgument.java b/common/src/main/java/dev/imabad/theatrical/commands/DMXNetworkModeArgument.java new file mode 100644 index 0000000..d94ef0b --- /dev/null +++ b/common/src/main/java/dev/imabad/theatrical/commands/DMXNetworkModeArgument.java @@ -0,0 +1,48 @@ +package dev.imabad.theatrical.commands; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import dev.imabad.theatrical.dmx.DMXNetworkMode; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; + +public class DMXNetworkModeArgument implements ArgumentType { + private static final DynamicCommandExceptionType ERROR_INVALID = new DynamicCommandExceptionType( + object -> Component.translatable("commands.network.invalid", object) + ); + private static final DMXNetworkMode[] VALUES = DMXNetworkMode.values(); + + @Override + public CompletableFuture listSuggestions(CommandContext commandContext, SuggestionsBuilder suggestionsBuilder) { + return commandContext.getSource() instanceof SharedSuggestionProvider + ? SharedSuggestionProvider.suggest(Arrays.stream(VALUES).map(DMXNetworkMode::getName), suggestionsBuilder) + : Suggestions.empty(); + } + + @Override + public DMXNetworkMode parse(StringReader reader) throws CommandSyntaxException { + String string = reader.readUnquotedString(); + DMXNetworkMode networkMode = DMXNetworkMode.byName(string); + if (networkMode == null) { + throw ERROR_INVALID.createWithContext(reader, string); + } else { + return networkMode; + } + } + + public static DMXNetworkModeArgument networkMode() { + return new DMXNetworkModeArgument(); + } + public static DMXNetworkMode getMode(CommandContext context, String name) { + return context.getArgument(name, DMXNetworkMode.class); + } +} diff --git a/common/src/main/java/dev/imabad/theatrical/commands/MemberRoleArgument.java b/common/src/main/java/dev/imabad/theatrical/commands/MemberRoleArgument.java new file mode 100644 index 0000000..3f7ead4 --- /dev/null +++ b/common/src/main/java/dev/imabad/theatrical/commands/MemberRoleArgument.java @@ -0,0 +1,49 @@ +package dev.imabad.theatrical.commands; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import dev.imabad.theatrical.dmx.DMXNetworkMemberRole; +import dev.imabad.theatrical.dmx.DMXNetworkMode; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; + +public class MemberRoleArgument implements ArgumentType { + private static final DynamicCommandExceptionType ERROR_INVALID = new DynamicCommandExceptionType( + object -> Component.translatable("commands.network.role.invalid", object) + ); + private static final DMXNetworkMemberRole[] VALUES = DMXNetworkMemberRole.values(); + + @Override + public CompletableFuture listSuggestions(CommandContext commandContext, SuggestionsBuilder suggestionsBuilder) { + return commandContext.getSource() instanceof SharedSuggestionProvider + ? SharedSuggestionProvider.suggest(Arrays.stream(VALUES).map(DMXNetworkMemberRole::getName), suggestionsBuilder) + : Suggestions.empty(); + } + + @Override + public DMXNetworkMemberRole parse(StringReader reader) throws CommandSyntaxException { + String string = reader.readUnquotedString(); + DMXNetworkMemberRole networkMode = DMXNetworkMemberRole.byName(string); + if (networkMode == null) { + throw ERROR_INVALID.createWithContext(reader, string); + } else { + return networkMode; + } + } + + public static MemberRoleArgument memberRole() { + return new MemberRoleArgument(); + } + public static DMXNetworkMemberRole getMode(CommandContext context, String name) { + return context.getArgument(name, DMXNetworkMemberRole.class); + } +} diff --git a/common/src/main/java/dev/imabad/theatrical/commands/NetworkCommand.java b/common/src/main/java/dev/imabad/theatrical/commands/NetworkCommand.java new file mode 100644 index 0000000..da9c554 --- /dev/null +++ b/common/src/main/java/dev/imabad/theatrical/commands/NetworkCommand.java @@ -0,0 +1,342 @@ +package dev.imabad.theatrical.commands; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import dev.imabad.theatrical.dmx.*; +import dev.imabad.theatrical.net.artnet.NotifyNetworks; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.players.GameProfileCache; +import net.minecraft.server.players.PlayerList; +import net.minecraft.util.Tuple; + +import java.util.*; +import java.util.stream.Collectors; + +public class NetworkCommand { + + private static final SimpleCommandExceptionType ERROR_NETWORK_DOES_NOT_EXIST = new SimpleCommandExceptionType( + Component.translatable("commands.network.notfound") + ); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(Commands.literal("theatrical") + .then(Commands.literal("networks") + .executes(NetworkCommand::listNetworks) + ) + .then(Commands.literal("network") + .then(Commands.literal("new") + .then(Commands.argument("mode", DMXNetworkModeArgument.networkMode()) + .then(Commands.argument("name", StringArgumentType.greedyString()) + .executes(NetworkCommand::createNetwork)))) + .then(Commands.argument("id", StringArgumentType.string()) + .suggests((commandContext, suggestionsBuilder) -> SharedSuggestionProvider.suggest( + getNetworksForPlayer(commandContext) + .stream() + .map(serverPlayer -> serverPlayer.id().toString()), + suggestionsBuilder + )) + .executes(NetworkCommand::getNetwork) + .then(Commands.literal("members") + .executes(NetworkCommand::listNetworkMembers) + ).then(Commands.literal("rename") + .then(Commands.argument("name", StringArgumentType.greedyString()) + .executes(NetworkCommand::renameNetwork) + ) + ).then(Commands.literal("delete") + .executes(NetworkCommand::deleteNetwork) + ).then(Commands.literal("mode") + .then(Commands.argument("mode", DMXNetworkModeArgument.networkMode()) + .executes(NetworkCommand::changeNetworkMode)) + ).then(Commands.literal("setrole") + .then(Commands.argument("target", GameProfileArgument.gameProfile()) + .suggests( + (commandContext, suggestionsBuilder) -> { + Set members = + getDMXNetwork(commandContext).members(); + GameProfileCache profileCache = commandContext.getSource() + .getServer().getProfileCache(); + return SharedSuggestionProvider.suggest( + members.stream() + .map(serverPlayer -> profileCache + .get(serverPlayer.playerId()) + .orElse(new GameProfile( + serverPlayer.playerId(), + serverPlayer.playerId() + .toString() + )).getName()), + suggestionsBuilder + ); + } + ).then(Commands.argument("role", MemberRoleArgument.memberRole()) + .executes(NetworkCommand::changeMemberRole))) + ) + .then(Commands.literal("add") + .then(Commands.argument("targets", GameProfileArgument.gameProfile()) + .suggests( + (commandContext, suggestionsBuilder) -> { + PlayerList playerList = commandContext.getSource().getServer().getPlayerList(); + return SharedSuggestionProvider.suggest( + playerList.getPlayers() + .stream() + .map(serverPlayer -> serverPlayer.getGameProfile().getName()), + suggestionsBuilder + ); + } + ) + .executes(NetworkCommand::addPlayer))) + .then(Commands.literal("remove") + .then(Commands.argument("targets", GameProfileArgument.gameProfile()) + .suggests( + (commandContext, suggestionsBuilder) -> { + Set members = + getDMXNetwork(commandContext).members(); + GameProfileCache profileCache = commandContext.getSource() + .getServer().getProfileCache(); + return SharedSuggestionProvider.suggest( + members.stream() + .map(serverPlayer -> profileCache + .get(serverPlayer.playerId()) + .orElse(new GameProfile( + serverPlayer.playerId(), + serverPlayer.playerId() + .toString() + )).getName()), + suggestionsBuilder + ); + } + ) + .executes(NetworkCommand::removePlayer))) + ) + ) + ); + } + + private static int changeMemberRole(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + Collection players = GameProfileArgument.getGameProfiles(context, "targets"); + DMXNetworkMemberRole role = MemberRoleArgument.getMode(context, "role"); + for (GameProfile player : players) { + dmxNetwork.setMemberRole(player.getId(), role); + } + context.getSource().sendSuccess(() -> Component.translatable("commands.network.updated"), false); + return 0; + } + + private static int changeNetworkMode(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + DMXNetworkMode mode = DMXNetworkModeArgument.getMode(context, "mode"); + DMXNetworkMode oldMode = dmxNetwork.mode(); + dmxNetwork.setMode(mode); + List members = new ArrayList<>(); + for (DMXNetworkMember member : dmxNetwork.members()) { + ServerPlayer player = context.getSource().getServer().getPlayerList().getPlayer(member.playerId()); + if(player != null){ + DMXNetworkData.getInstance(context.getSource().getLevel()).notifyNetworks(player); + members.add(player.getUUID()); + } + } + if(dmxNetwork.mode() == DMXNetworkMode.PUBLIC || oldMode == DMXNetworkMode.PUBLIC){ + for (ServerPlayer player : context.getSource().getServer().getPlayerList().getPlayers()) { + if(!members.contains(player.getUUID())){ + DMXNetworkData.getInstance(context.getSource().getServer().overworld()).notifyNetworks(player); + } + } + } + context.getSource().sendSuccess(() -> Component.translatable("commands.network.updated"), false); + return 1; + } + + private static int createNetwork(CommandContext context) { + String newName = StringArgumentType.getString(context, "name"); + DMXNetworkMode mode = DMXNetworkModeArgument.getMode(context, "mode"); + DMXNetwork network = DMXNetworkData.getInstance(context.getSource().getServer().overworld()).createNetwork(newName, mode); + if(context.getSource().isPlayer()){ + network.addMember(context.getSource().getPlayer().getUUID(), DMXNetworkMemberRole.ADMIN); + } + if(network.mode() == DMXNetworkMode.PUBLIC){ + for (ServerPlayer player : context.getSource().getServer().getPlayerList().getPlayers()) { + DMXNetworkData.getInstance(context.getSource().getServer().overworld()).notifyNetworks(player); + } + } + context.getSource().sendSuccess(() -> Component.translatable("commands.network.created"), false); + + return 1; + } + + private static int listNetworkMembers(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + GameProfileCache profileCache = context.getSource().getServer().getProfileCache(); + List list = dmxNetwork.members() + .stream().map(DMXNetworkMember::playerId) + .map((playerUUID) -> new Tuple<>(playerUUID, profileCache.get(playerUUID))) + .map(uuidOptionalTuple -> uuidOptionalTuple.getB().isPresent() ? uuidOptionalTuple.getB().get().getName() : uuidOptionalTuple.getA().toString()) + .toList(); + context.getSource().sendSuccess(() -> Component.translatable("commands.network.members", list.size(), String.join(", ", list)), false); + return 1; + } + private static int getNetwork(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + int i = 0; + context.getSource().sendSuccess(() -> Component.translatable("commands.network", Component.literal(dmxNetwork.name()), dmxNetwork.id().toString(), dmxNetwork.members().size()), false); + return i; + } + private static int addPlayer(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + int i = 0; + Collection players = GameProfileArgument.getGameProfiles(context, "targets"); + for (GameProfile player : players) { + if(!dmxNetwork.isMember(player.getId())) { + dmxNetwork.addMember(player.getId(), DMXNetworkMemberRole.NONE); + context.getSource().sendSuccess(() -> Component.translatable("commands.network.members.add.success", Component.literal(player.getName())), false); + i++; + } + } + return i; + } + + private static int renameNetwork(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + String newName = StringArgumentType.getString(context, "name"); + dmxNetwork.setName(newName); + List members = new ArrayList<>(); + for (DMXNetworkMember member : dmxNetwork.members()) { + ServerPlayer player = context.getSource().getServer().getPlayerList().getPlayer(member.playerId()); + if(player != null){ + DMXNetworkData.getInstance(context.getSource().getLevel()).notifyNetworks(player); + members.add(player.getUUID()); + } + } + if(dmxNetwork.mode() == DMXNetworkMode.PUBLIC){ + for (ServerPlayer player : context.getSource().getServer().getPlayerList().getPlayers()) { + if(!members.contains(player.getUUID())){ + DMXNetworkData.getInstance(context.getSource().getServer().overworld()).notifyNetworks(player); + } + } + } + return 1; + } + + private static int deleteNetwork(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + + DMXNetworkData.getInstance(context.getSource().getLevel()).deleteNetwork(dmxNetwork); + List members = new ArrayList<>(); + for (DMXNetworkMember member : dmxNetwork.members()) { + ServerPlayer player = context.getSource().getServer().getPlayerList().getPlayer(member.playerId()); + if(player != null){ + DMXNetworkData.getInstance(context.getSource().getLevel()).notifyNetworks(player); + members.add(player.getUUID()); + } + } + if(dmxNetwork.mode() == DMXNetworkMode.PUBLIC){ + for (ServerPlayer player : context.getSource().getServer().getPlayerList().getPlayers()) { + if(!members.contains(player.getUUID())){ + DMXNetworkData.getInstance(context.getSource().getServer().overworld()).notifyNetworks(player); + } + } + } + context.getSource().sendSuccess(() -> Component.translatable("commands.network.deleted"), false); + return 1; + } + + private static int removePlayer(CommandContext context) throws CommandSyntaxException { + DMXNetwork dmxNetwork = getDMXNetwork(context); + if (!isSourceOperator(context)) { + if (context.getSource().isPlayer() && !dmxNetwork.isAdmin(context.getSource().getPlayer().getUUID())) { + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } + } + Collection players = GameProfileArgument.getGameProfiles(context, "targets"); + for (GameProfile player : players) { + if(dmxNetwork.isMember(player.getId())){ + dmxNetwork.removeMember(player.getId()); + context.getSource().sendSuccess(() -> Component.translatable("commands.network.members.remove.success", Component.literal(player.getName())), false); + } + } + return 0; + } + + private static Collection getNetworksForPlayer(CommandContext context) { + DMXNetworkData instance = DMXNetworkData. + getInstance(context.getSource().getServer().overworld()); + if (isSourceOperator(context)) { + return instance.getAllNetworks(); + } else { + return instance.getNetworksForPlayer(context.getSource().getPlayer().getUUID()); + } + } + + private static int listNetworks(CommandContext context) { + DMXNetworkData instance = DMXNetworkData. + getInstance(context.getSource().getServer().overworld()); + List networks; + if (isSourceOperator(context)) { + networks = instance.getAllNetworks().stream() + .map(DMXNetwork::name).collect(Collectors.toList()); + } else { + networks = instance.getNetworksForPlayer(context.getSource().getPlayer().getUUID()).stream() + .map(DMXNetwork::name).collect(Collectors.toList()); + } + context.getSource().sendSuccess(() -> Component.translatable("commands.networks", + networks.size(), String.join(", ", networks)), false); + return 1; + } + + private static boolean isSourceOperator(CommandContext context) { + return context.getSource().hasPermission(context.getSource().getServer().getOperatorUserPermissionLevel()); + } + + private static DMXNetwork getDMXNetwork(CommandContext context) throws CommandSyntaxException { + DMXNetworkData instance = DMXNetworkData. + getInstance(context.getSource().getServer().overworld()); + try { + String id = context.getArgument("id", String.class); + UUID uuid = UUID.fromString(id); + DMXNetwork network = instance.getNetwork(uuid); + if (network != null) { + return network; + } + } catch (Exception ignored) { + } + throw ERROR_NETWORK_DOES_NOT_EXIST.create(); + } +} diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java index 32a8d6e..a54a830 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java @@ -5,19 +5,21 @@ import dev.imabad.theatrical.net.artnet.NotifyConsumerChange; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; +import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import org.jetbrains.annotations.Nullable; import java.util.*; public class DMXNetwork { private final UUID id; - private final String name; - private final DMXNetworkMode mode; + private String name; + private DMXNetworkMode mode; private final Set members; private final IntObjectMap> universeToNodeMap = new IntObjectHashMap<>(); private final Set knownSenders = new HashSet<>(); @@ -51,6 +53,7 @@ public CompoundTag save(){ CompoundTag tag = new CompoundTag(); tag.putUUID("id", id); tag.putString("mode", mode.toString()); + tag.putString("name", name); ListTag membersList = new ListTag(); for (DMXNetworkMember member : members) { CompoundTag memberTag = new CompoundTag(); @@ -163,6 +166,12 @@ public Set getUniverses(){ public void addMember(UUID playerUUID, DMXNetworkMemberRole role){ members.add(new DMXNetworkMember(playerUUID, role)); + DMXNetworkData.getInstance().setDirty(); + } + public void removeMember(UUID playerUUID){ + DMXNetworkMember dmxNetworkMember = getDmxNetworkMember(playerUUID); + members.remove(dmxNetworkMember); + DMXNetworkData.getInstance().setDirty(); } public boolean isMember(UUID playerUUID){ @@ -170,12 +179,39 @@ public boolean isMember(UUID playerUUID){ } public boolean canSendDMX(UUID uuid) { + DMXNetworkMember dmxNetworkMember = getDmxNetworkMember(uuid); + if (dmxNetworkMember == null) return false; + return dmxNetworkMember.role() == DMXNetworkMemberRole.SEND || dmxNetworkMember.role() == DMXNetworkMemberRole.ADMIN; + } + + public boolean isAdmin(UUID uuid){ + DMXNetworkMember dmxNetworkMember = getDmxNetworkMember(uuid); + if (dmxNetworkMember == null) return false; + return dmxNetworkMember.role() == DMXNetworkMemberRole.ADMIN; + } + + public void setMemberRole(UUID playerId, DMXNetworkMemberRole role){ + DMXNetworkMember dmxNetworkMember = getDmxNetworkMember(playerId); + if(dmxNetworkMember != null) { + dmxNetworkMember.setRole(role); + DMXNetworkData.getInstance().setDirty(); + } + } + + @Nullable + private DMXNetworkMember getDmxNetworkMember(UUID uuid) { Optional first = members.stream() .filter(dmxNetworkMember -> dmxNetworkMember.playerId() == uuid).findFirst(); - if(first.isEmpty()){ - return false; - } - DMXNetworkMember dmxNetworkMember = first.get(); - return dmxNetworkMember.role() == DMXNetworkMemberRole.SEND || dmxNetworkMember.role() == DMXNetworkMemberRole.ADMIN; + return first.orElse(null); + } + + public void setName(String name) { + this.name = name; + DMXNetworkData.getInstance().setDirty(); + } + + public void setMode(DMXNetworkMode mode) { + this.mode = mode; + DMXNetworkData.getInstance().setDirty(); } } diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkData.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkData.java index ead3a63..e29eb81 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkData.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkData.java @@ -1,17 +1,10 @@ package dev.imabad.theatrical.dmx; -import ch.bildspur.artnet.rdm.RDMDeviceId; -import dev.imabad.theatrical.api.dmx.DMXConsumer; -import dev.imabad.theatrical.net.artnet.NotifyConsumerChange; +import dev.architectury.utils.GameInstance; import dev.imabad.theatrical.net.artnet.NotifyNetworks; -import io.netty.util.collection.IntObjectHashMap; -import io.netty.util.collection.IntObjectMap; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; @@ -32,6 +25,11 @@ public class DMXNetworkData extends SavedData { DMXNetworkData::read, null ); + + public static void unloadLevel(){ + INSTANCE = null; + } + public static DMXNetworkData getInstance(Level level){ if(INSTANCE == null){ INSTANCE = level.getServer() @@ -40,6 +38,14 @@ public static DMXNetworkData getInstance(Level level){ return INSTANCE; } + public static DMXNetworkData getInstance(){ + if(INSTANCE == null){ + INSTANCE = GameInstance.getServer().overworld().getDataStorage().computeIfAbsent(factory, KEY); + } + return INSTANCE; + } + + @Nullable public DMXNetwork getNetwork(UUID networkId){ return networks.get(networkId); @@ -50,8 +56,21 @@ public DMXNetwork createNetwork(Player player){ network.addMember(player.getUUID(), DMXNetworkMemberRole.ADMIN); networks.put(network.id(), network); notifyNetworks(player); + setDirty(); return network; } + public DMXNetwork createNetwork(String name, DMXNetworkMode mode){ + DMXNetwork network = new DMXNetwork(name); + network.setMode(mode); + networks.put(network.id(), network); + setDirty(); + return network; + } + + public void deleteNetwork(DMXNetwork dmxNetwork){ + networks.remove(dmxNetwork.id()); + setDirty(); + } public void notifyNetworks(Player player){ Map collect = getNetworksForPlayer(player.getUUID()).stream().collect(Collectors.toMap(DMXNetwork::id, DMXNetwork::name)); diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMember.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMember.java index 0ab0a91..a23efb8 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMember.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMember.java @@ -1,6 +1,48 @@ package dev.imabad.theatrical.dmx; +import java.util.Objects; import java.util.UUID; -public record DMXNetworkMember(UUID playerId, DMXNetworkMemberRole role) { +public final class DMXNetworkMember { + private final UUID playerId; + private DMXNetworkMemberRole role; + + public DMXNetworkMember(UUID playerId, DMXNetworkMemberRole role) { + this.playerId = playerId; + this.role = role; + } + + public UUID playerId() { + return playerId; + } + + public DMXNetworkMemberRole role() { + return role; + } + + public void setRole(DMXNetworkMemberRole role) { + this.role = role; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (DMXNetworkMember) obj; + return Objects.equals(this.playerId, that.playerId) && + Objects.equals(this.role, that.role); + } + + @Override + public int hashCode() { + return Objects.hash(playerId, role); + } + + @Override + public String toString() { + return "DMXNetworkMember[" + + "playerId=" + playerId + ", " + + "role=" + role + ']'; + } + } diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMemberRole.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMemberRole.java index a117b88..5cd52b6 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMemberRole.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMemberRole.java @@ -1,7 +1,34 @@ package dev.imabad.theatrical.dmx; -public enum DMXNetworkMemberRole { - NONE, - SEND, - ADMIN; +import net.minecraft.util.StringRepresentable; +import org.jetbrains.annotations.NotNull; + +public enum DMXNetworkMemberRole implements StringRepresentable { + NONE("NONE"), + SEND("SEND"), + ADMIN("ADMIN"); + + private final String name; + + DMXNetworkMemberRole(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public @NotNull String getSerializedName() { + return name; + } + + public static DMXNetworkMemberRole byName(String name){ + for (DMXNetworkMemberRole value : values()) { + if(value.getName().equals(name)){ + return value; + } + } + return null; + } } diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMode.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMode.java index df97066..0e23b0b 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMode.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetworkMode.java @@ -1,9 +1,35 @@ package dev.imabad.theatrical.dmx; -public enum DMXNetworkMode { +import net.minecraft.util.StringRepresentable; +import org.jetbrains.annotations.NotNull; - PUBLIC, - INVITE, - PRIVATE; +public enum DMXNetworkMode implements StringRepresentable { + PUBLIC("PUBLIC"), + INVITE("INVITE"), + PRIVATE("PRIVATE"); + + private final String name; + + DMXNetworkMode(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public @NotNull String getSerializedName() { + return name; + } + + public static DMXNetworkMode byName(String name){ + for (DMXNetworkMode value : values()) { + if(value.getName().equals(name)){ + return value; + } + } + return null; + } } diff --git a/common/src/main/java/dev/imabad/theatrical/mixin/ArgumentTypeInfosAccessor.java b/common/src/main/java/dev/imabad/theatrical/mixin/ArgumentTypeInfosAccessor.java new file mode 100644 index 0000000..a7b394d --- /dev/null +++ b/common/src/main/java/dev/imabad/theatrical/mixin/ArgumentTypeInfosAccessor.java @@ -0,0 +1,18 @@ +package dev.imabad.theatrical.mixin; + +import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.commands.synchronization.ArgumentTypeInfos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(ArgumentTypeInfos.class) +public interface ArgumentTypeInfosAccessor { + + @Accessor("BY_CLASS") + static Map, ArgumentTypeInfo> classMap(){ + throw new UnsupportedOperationException(); + } + +} diff --git a/common/src/main/java/dev/imabad/theatrical/net/artnet/RDMUpdateConsumer.java b/common/src/main/java/dev/imabad/theatrical/net/artnet/RDMUpdateConsumer.java index 8ea7882..bed96c4 100644 --- a/common/src/main/java/dev/imabad/theatrical/net/artnet/RDMUpdateConsumer.java +++ b/common/src/main/java/dev/imabad/theatrical/net/artnet/RDMUpdateConsumer.java @@ -56,7 +56,7 @@ public void handle(NetworkManager.PacketContext context) { Level level = context.getPlayer().level(); if(level.getServer() != null ) { if (context.getPlayer().hasPermissions(level.getServer().getOperatorUserPermissionLevel())) { - DMXNetwork network = DMXNetworkData.getInstance(level).getNetwork(networkId); + DMXNetwork network = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if(network == null){ return; } diff --git a/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestConsumers.java b/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestConsumers.java index ab34f41..2a60d72 100644 --- a/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestConsumers.java +++ b/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestConsumers.java @@ -49,7 +49,7 @@ public void handle(NetworkManager.PacketContext context) { Level level = context.getPlayer().level(); if(level.getServer() != null ) { if (context.getPlayer().hasPermissions(level.getServer().getOperatorUserPermissionLevel())) { - DMXNetwork network = DMXNetworkData.getInstance(level).getNetwork(networkId); + DMXNetwork network = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); if(network != null && network.isMember(context.getPlayer().getUUID())){ List devices = new ArrayList<>(); Collection consumers = network.getConsumers(universe); diff --git a/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestNetworks.java b/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestNetworks.java index f6738da..ee4bc85 100644 --- a/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestNetworks.java +++ b/common/src/main/java/dev/imabad/theatrical/net/artnet/RequestNetworks.java @@ -37,7 +37,7 @@ public void write(FriendlyByteBuf buf) { public void handle(NetworkManager.PacketContext context) { Level level = context.getPlayer().level(); if(level.getServer() != null ) { - List networksForPlayer = DMXNetworkData.getInstance(level) + List networksForPlayer = DMXNetworkData.getInstance(level.getServer().overworld()) .getNetworksForPlayer(context.getPlayer().getUUID()); Map collect = networksForPlayer.stream().collect(Collectors.toMap(DMXNetwork::id, DMXNetwork::name)); new NotifyNetworks(collect).sendTo((ServerPlayer) context.getPlayer()); diff --git a/common/src/main/java/dev/imabad/theatrical/net/artnet/SendArtNetData.java b/common/src/main/java/dev/imabad/theatrical/net/artnet/SendArtNetData.java index 1867779..b91cb69 100644 --- a/common/src/main/java/dev/imabad/theatrical/net/artnet/SendArtNetData.java +++ b/common/src/main/java/dev/imabad/theatrical/net/artnet/SendArtNetData.java @@ -46,7 +46,7 @@ public void write(FriendlyByteBuf buf) { public void handle(NetworkManager.PacketContext context) { Level level = context.getPlayer().level(); if(level.getServer() != null) { - DMXNetwork network = DMXNetworkData.getInstance(level).getNetwork(networkId); + DMXNetwork network = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId); UUID uuid = context.getPlayer().getUUID(); if(network != null) { if (network.isMember(uuid) && network.canSendDMX(uuid)) { diff --git a/common/src/main/resources/theatrical-common.mixins.json b/common/src/main/resources/theatrical-common.mixins.json index 24ede0b..6987d5f 100644 --- a/common/src/main/resources/theatrical-common.mixins.json +++ b/common/src/main/resources/theatrical-common.mixins.json @@ -8,6 +8,7 @@ "maxShiftBy": 5 }, "mixins": [ + "ArgumentTypeInfosAccessor", "ClipContextAccessor" ], "client": [ diff --git a/neoforge/src/main/java/dev/imabad/theatrical/neoforge/DataEvent.java b/neoforge/src/main/java/dev/imabad/theatrical/neoforge/DataEvent.java index bc93ba5..af91081 100644 --- a/neoforge/src/main/java/dev/imabad/theatrical/neoforge/DataEvent.java +++ b/neoforge/src/main/java/dev/imabad/theatrical/neoforge/DataEvent.java @@ -108,6 +108,18 @@ protected void addTranslations() { add("ui.control.cue", "Cue - %s"); add("ui.control.fadeIn", "Fade in"); add("ui.control.fadeOut", "Fade out"); + add("commands.network.notfound", "Network not found."); + add("commands.networks", "There are %s network(s): %s."); + add("commands.network.members", "There are %s network member(s): %s."); + add("commands.network.members.add.success", "Added %s to the network."); + add("commands.network.members.add.failed", "Player already member of network."); + add("commands.network.members.remove.success", "Removed %s from the network."); + add("commands.network", "%s (%s) has %s member(s)"); + add("commands.network.invalid", "Unknown network mode: %s"); + add("commands.network.role.invalid", "Unknown member role: %s"); + add("commands.network.created", "Network created"); + add("commands.network.deleted", "Network deleted"); + add("commands.network.updated", "Network updated"); } }