diff --git a/core/command/TabCommand.java b/core/command/TabCommand.java index 3272c23d..dbe2d90a 100644 --- a/core/command/TabCommand.java +++ b/core/command/TabCommand.java @@ -74,7 +74,7 @@ public class TabCommand { */ public static List getTabList(String name, String[] arg) { List arguments = new ArrayList<>(); - if (arg.length == 1 || arg.length == 0) { + if (arg.length == 0 || arg.length == 1) { arguments.addAll(normal); if (AllMusic.getSearch(name) != null) { arguments.addAll(search); @@ -82,13 +82,18 @@ public class TabCommand { if (AllMusic.getConfig().Admin.contains(name)) { arguments.addAll(admin); } - } else if (arg[0].equalsIgnoreCase("hud")) { - if (arg.length == 2) { + } else if (arg.length == 2) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); + } + else if ("hud".equalsIgnoreCase(arg[0])) { arguments.addAll(hud); - } else if (arg.length == 3) { - if (arg[1].equalsIgnoreCase("enable")) { - arguments.addAll(hudlist); - } + } + } else if (arg.length == 3) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); } } return arguments; diff --git a/forge_1_19_3/build.gradle b/forge_1_19_3/build.gradle index 0aaeb8e9..40dea976 100644 --- a/forge_1_19_3/build.gradle +++ b/forge_1_19_3/build.gradle @@ -2,11 +2,12 @@ plugins { id 'eclipse' id 'maven-publish' id 'net.minecraftforge.gradle' version '5.1.+' + id 'com.github.johnrengelman.shadow' version '7.1.2' } -version = '1.0' -group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'modid' +version = '2.18.5' +group = 'coloryr.allmusic' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = '[Forge1.19.3]AllMusic_Server' // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -49,10 +50,10 @@ minecraft { property 'forge.logging.console.level', 'debug' // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', 'examplemod' + property 'forge.enabledGameTestNamespaces', 'allmusic' mods { - examplemod { + allmusic { source sourceSets.main } } @@ -65,10 +66,10 @@ minecraft { property 'forge.logging.console.level', 'debug' - property 'forge.enabledGameTestNamespaces', 'examplemod' + property 'forge.enabledGameTestNamespaces', 'allmusic' mods { - examplemod { + allmusic { source sourceSets.main } } @@ -84,10 +85,10 @@ minecraft { property 'forge.logging.console.level', 'debug' - property 'forge.enabledGameTestNamespaces', 'examplemod' + property 'forge.enabledGameTestNamespaces', 'allmusic' mods { - examplemod { + allmusic { source sourceSets.main } } @@ -101,10 +102,10 @@ minecraft { property 'forge.logging.console.level', 'debug' // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. - args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + args '--mod', 'allmusic', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') mods { - examplemod { + allmusic { source sourceSets.main } } @@ -123,6 +124,10 @@ repositories { // flatDir { // dir 'libs' // } + + maven { + url 'https://jitpack.io' + } } dependencies { @@ -131,6 +136,12 @@ dependencies { // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.19.3-44.1.20' + shadow 'com.squareup.okhttp3:okhttp:4.10.0' + shadow 'org.xerial:sqlite-jdbc:3.39.3.0' + +// implementation 'com.squareup.okhttp3:okhttp:4.10.0' +// implementation 'org.xerial:sqlite-jdbc:3.39.3.0' + // Real mod deobf dependency examples - these get remapped to your current mappings // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency @@ -142,24 +153,34 @@ dependencies { // http://www.gradle.org/docs/current/userguide/dependency_management.html } +shadowJar { +// relocate 'okhttp3', 'coloryr.allmusic.lib.okhttp3' +// relocate 'okio', 'coloryr.allmusic.lib.okio' +// relocate 'kotlin', 'coloryr.allmusic.lib.kotlin' +// relocate 'org.intellij', 'coloryr.allmusic.lib.org.intellij' +// relocate 'org.jetbrains', 'coloryr.allmusic.lib.org.jetbrains' + configurations = [project.configurations.shadow] + archiveClassifier.set('') +// dependencies { +// include(dependency('com.squareup.okhttp3:okhttp:4.10.0')) +// include(dependency('org.xerial:sqlite-jdbc:3.39.3.0')) +// } +} + // Example for how to get properties into the manifest for reading at runtime. jar { manifest { attributes([ - "Specification-Title" : "examplemod", - "Specification-Vendor" : "examplemodsareus", + "Specification-Title" : "allmusic", + "Specification-Vendor" : "allmusic", "Specification-Version" : "1", // We are version 1 of ourselves "Implementation-Title" : project.name, "Implementation-Version" : project.jar.archiveVersion, - "Implementation-Vendor" : "examplemodsareus", + "Implementation-Vendor" : "allmusic", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } } - -// Example configuration to allow publishing using the maven-publish plugin -// This is the preferred method to reobfuscate your jar file -jar.finalizedBy('reobfJar') // However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing // publish.dependsOn('reobfJar') @@ -179,3 +200,11 @@ publishing { tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } + +reobf { + shadowJar {} +} + +//tasks.build.dependsOn shadowJar +//tasks.build.dependsOn reobfShadowJar +jar.finalizedBy('reobfJar') \ No newline at end of file diff --git a/forge_1_19_3/settings.gradle b/forge_1_19_3/settings.gradle index 3703f364..84b7c081 100644 --- a/forge_1_19_3/settings.gradle +++ b/forge_1_19_3/settings.gradle @@ -3,4 +3,6 @@ pluginManagement { gradlePluginPortal() maven { url = 'https://maven.minecraftforge.net/' } } -} \ No newline at end of file +} + +rootProject.name = 'AllMusic_Server' \ No newline at end of file diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/AllMusicForge.java b/forge_1_19_3/src/main/java/coloryr/allmusic/AllMusicForge.java index 44199e67..dd6752ef 100644 --- a/forge_1_19_3/src/main/java/coloryr/allmusic/AllMusicForge.java +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/AllMusicForge.java @@ -1,7 +1,23 @@ -package com.example.examplemod; +package coloryr.allmusic; +import coloryr.allmusic.core.AllMusic; +import coloryr.allmusic.core.command.CommandEX; +import coloryr.allmusic.side.forge.CommandForge; +import coloryr.allmusic.side.forge.LogForge; +import coloryr.allmusic.side.forge.SideForge; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.ParseResults; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; @@ -10,88 +26,113 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.CreativeModeTabEvent; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.server.ServerStartingEvent; +import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; +import net.minecraftforge.server.command.ForgeCommand; import org.slf4j.Logger; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Locale; +import java.util.function.Supplier; + +import static net.minecraftforge.server.command.ForgeCommand.*; + // The value here should match an entry in the META-INF/mods.toml file -@Mod(ExampleMod.MODID) -public class ExampleMod -{ +@Mod(AllMusicForge.MODID) +public class AllMusicForge { + public static MinecraftServer server; + public static final SimpleChannel channel = NetworkRegistry.newSimpleChannel(new ResourceLocation("allmusic", "channel"), + () -> "1.0", s -> true, s -> true); + // Define mod id in a common place for everything to reference - public static final String MODID = "examplemod"; + public static final String MODID = "allmusic"; // Directly reference a slf4j logger - private static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogUtils.getLogger(); // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace - public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); - // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace - public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - // Creates a new Block with the id "examplemod:example_block", combining the namespace and path - public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of(Material.STONE))); - // Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path - public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties())); - - public ExampleMod() - { + public AllMusicForge() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); // Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); - // Register the Deferred Register to the mod event bus so blocks get registered - BLOCKS.register(modEventBus); - // Register the Deferred Register to the mod event bus so items get registered - ITEMS.register(modEventBus); - // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); - - // Register the item to a creative tab - modEventBus.addListener(this::addCreative); } - private void commonSetup(final FMLCommonSetupEvent event) - { - // Some common setup code - LOGGER.info("HELLO FROM COMMON SETUP"); - LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); + private void commonSetup(final FMLCommonSetupEvent event) { + channel.registerMessage(666, String.class, this::enc, this::dec, this::proc); + + String path = String.format(Locale.ROOT, "config/%s/", "AllMusic"); + + AllMusic.log = new LogForge(); + AllMusic.side = new SideForge(); + + new AllMusic().init(new File(path)); } - private void addCreative(CreativeModeTabEvent.BuildContents event) - { - if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS) - event.accept(EXAMPLE_BLOCK_ITEM); + private void enc(String str, FriendlyByteBuf buffer) { + buffer.writeBytes(str.getBytes(StandardCharsets.UTF_8)); + } + + private String dec(FriendlyByteBuf buffer) { + return buffer.toString(StandardCharsets.UTF_8); + } + + private void proc(String str, Supplier supplier) { + NetworkEvent.Context context = supplier.get(); + context.setPacketHandled(true); + } + + @SubscribeEvent + public void onRegisterCommands(RegisterCommandsEvent event) { + CommandDispatcher dispatcher = event.getDispatcher(); + CommandForge.instance.register(dispatcher); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent - public void onServerStarting(ServerStartingEvent event) - { - // Do something when the server starts - LOGGER.info("HELLO from server starting"); + public void onServerStarting(ServerStartingEvent event) { + server = event.getServer(); + + AllMusic.start(); + Tasks.init(); + + } - // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent - @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) - public static class ClientModEvents - { - @SubscribeEvent - public static void onClientSetup(FMLClientSetupEvent event) - { - // Some client setup code - LOGGER.info("HELLO FROM CLIENT SETUP"); - LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); - } + @SubscribeEvent + public void onServerStopping(ServerStoppingEvent event) { + AllMusic.stop(); + } + + @SubscribeEvent + public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { + AllMusic.removeNowPlayPlayer(event.getEntity().getName().getString()); + } + + @SubscribeEvent + public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedInEvent event) { + AllMusic.joinPlay(event.getEntity().getName().getString()); } } diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/TaskItem.java b/forge_1_19_3/src/main/java/coloryr/allmusic/TaskItem.java new file mode 100644 index 00000000..ed368410 --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/TaskItem.java @@ -0,0 +1,6 @@ +package coloryr.allmusic; + +public class TaskItem { + public int tick; + public Runnable run; +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/Tasks.java b/forge_1_19_3/src/main/java/coloryr/allmusic/Tasks.java new file mode 100644 index 00000000..3a432adb --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/Tasks.java @@ -0,0 +1,24 @@ +package coloryr.allmusic; + +import java.util.ArrayList; +import java.util.List; + +public class Tasks { + public static List taskItems = new ArrayList<>(); + + public static void init() { + AllMusicForge.server.addTickable(Tasks::tick); + } + + public static void tick() { + var li = taskItems.iterator(); + while (li.hasNext()) { + var item = li.next(); + item.tick--; + if (item.tick == 0) { + li.remove(); + item.run.run(); + } + } + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/core/command/TabCommand.java b/forge_1_19_3/src/main/java/coloryr/allmusic/core/command/TabCommand.java index 3272c23d..dbe2d90a 100644 --- a/forge_1_19_3/src/main/java/coloryr/allmusic/core/command/TabCommand.java +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/core/command/TabCommand.java @@ -74,7 +74,7 @@ public class TabCommand { */ public static List getTabList(String name, String[] arg) { List arguments = new ArrayList<>(); - if (arg.length == 1 || arg.length == 0) { + if (arg.length == 0 || arg.length == 1) { arguments.addAll(normal); if (AllMusic.getSearch(name) != null) { arguments.addAll(search); @@ -82,13 +82,18 @@ public class TabCommand { if (AllMusic.getConfig().Admin.contains(name)) { arguments.addAll(admin); } - } else if (arg[0].equalsIgnoreCase("hud")) { - if (arg.length == 2) { + } else if (arg.length == 2) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); + } + else if ("hud".equalsIgnoreCase(arg[0])) { arguments.addAll(hud); - } else if (arg.length == 3) { - if (arg[1].equalsIgnoreCase("enable")) { - arguments.addAll(hudlist); - } + } + } else if (arg.length == 3) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); } } return arguments; diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/CommandForge.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/CommandForge.java new file mode 100644 index 00000000..83e10e03 --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/CommandForge.java @@ -0,0 +1,67 @@ +package coloryr.allmusic.side.forge; + +import coloryr.allmusic.core.command.CommandEX; +import coloryr.allmusic.core.command.TabCommand; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; + +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; + +public class CommandForge implements Command, Predicate, SuggestionProvider { + public static CommandForge instance = new CommandForge(); + + public void register(CommandDispatcher dispatcher) { + dispatcher.register(((Commands.literal("music").requires(this)).executes(this)) + .then(Commands.argument("args", StringArgumentType.greedyString()) + .suggests(this).executes(this))); + } + + @Override + public int run(CommandContext context) { + var item = context.getSource(); + var source = item.source; + + var input = context.getInput(); + var temp = input.split(" "); + var arg = new String[temp.length - 1]; + System.arraycopy(temp, 1, arg, 0, arg.length); + + CommandEX.ex(source, context.getSource().getTextName(), arg); + + return 0; + } + + @Override + public boolean test(CommandSourceStack stack) { + return true; + } + + @Override + public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) { + var input = context.getInput(); + var temp = input.split(" "); + var arg = new String[input.endsWith(" ") ? temp.length : temp.length - 1]; + System.arraycopy(temp, 1, arg, 0, temp.length - 1); + + if (input.endsWith(" ")) + builder = builder.createOffset(builder.getInput().lastIndexOf(32) + 1); + + List results = TabCommand.getTabList(context.getSource().getTextName(), arg); + + for (String s : results) { + builder.suggest(s); + } + + return builder.buildFuture(); + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/ForgeApi.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/ForgeApi.java new file mode 100644 index 00000000..0c81f2d2 --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/ForgeApi.java @@ -0,0 +1,33 @@ +package coloryr.allmusic.side.forge; + +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentUtils; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket; +import net.minecraft.server.level.ServerPlayer; + +public class ForgeApi { + public static void sendMessageRun(Object obj, String message, String command) { + CommandSource sender = (CommandSource) obj; + MutableComponent send =Component.literal(message); + send.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); + sender.sendSystemMessage(send); + } + + public static void sendMessageSuggest(Object obj, String message, String command) { + CommandSource sender = (CommandSource) obj; + MutableComponent send = Component.empty(); + send.append(message).getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)); + sender.sendSystemMessage(send); + } + + public static void sendBar(ServerPlayer player, String message) { + var pack = new ClientboundSetActionBarTextPacket(Component.literal(message) + ); + player.connection.send(pack); + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/LogForge.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/LogForge.java new file mode 100644 index 00000000..4c2705ea --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/LogForge.java @@ -0,0 +1,16 @@ +package coloryr.allmusic.side.forge; + +import coloryr.allmusic.AllMusicForge; +import coloryr.allmusic.core.side.IMyLogger; + +public class LogForge implements IMyLogger { + @Override + public void warning(String data) { + AllMusicForge.LOGGER.warn(data); + } + + @Override + public void info(String data) { + AllMusicForge.LOGGER.info(data); + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/SideForge.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/SideForge.java new file mode 100644 index 00000000..79149897 --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/SideForge.java @@ -0,0 +1,383 @@ +package coloryr.allmusic.side.forge; + +import coloryr.allmusic.AllMusicForge; +import coloryr.allmusic.TaskItem; +import coloryr.allmusic.Tasks; +import coloryr.allmusic.core.AllMusic; +import coloryr.allmusic.core.hud.HudUtils; +import coloryr.allmusic.core.objs.hud.SaveObj; +import coloryr.allmusic.core.objs.music.MusicObj; +import coloryr.allmusic.core.objs.music.SongInfoObj; +import coloryr.allmusic.core.side.ComType; +import coloryr.allmusic.core.side.ISide; +import coloryr.allmusic.side.forge.event.MusicAddEvent; +import coloryr.allmusic.side.forge.event.MusicPlayEvent; +import com.google.gson.Gson; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.minecraft.commands.CommandSource; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.network.PacketDistributor; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Locale; + +public class SideForge extends ISide { + + @Override + public void reload() { + String path = String.format(Locale.ROOT, "config/%s/", "AllMusic"); + new AllMusic().init(new File(path)); + } + + @Override + public int getAllPlayer() { + return AllMusicForge.server.getPlayerCount(); + } + + @Override + public void runTask(Runnable run) { + AllMusicForge.server.execute(run); + } + + @Override + public void runTask(Runnable run1, int delay) { + Tasks.taskItems.add(new TaskItem() {{ + tick = delay; + run = run1; + }}); + } + + @Override + public boolean checkPermission(String player, String permission) { + var player1 = AllMusicForge.server.getPlayerList().getPlayerByName(player); + if (player1 == null) + return false; + + return player1.hasPermissions(2); + } + + @Override + public boolean needPlay() { + int online = getAllPlayer(); + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.getConfig().NoMusicPlayer.contains(player.getName().getString())) { + online--; + } + } + return online > 0; + } + + @Override + public void send(String data, String player) { + send(AllMusicForge.server.getPlayerList().getPlayerByName(player), data); + } + + @Override + protected void topSendStop() { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + send(player, ComType.stop); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错"); + e.printStackTrace(); + } + } + + @Override + protected void topSendStop(String name) { + try { + var player = AllMusicForge.server.getPlayerList().getPlayerByName(name); + if (player == null) + return; + send(player, ComType.stop); + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendMusic(String url) { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.isOK(player.getName().getString(), null, false)) + continue; + send(player, ComType.play + url); + AllMusic.addNowPlayPlayer(player.getName().getString()); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c歌曲指令发送出错"); + e.printStackTrace(); + } + } + + @Override + protected void topSendMusic(String player, String url) { + try { + var player1 = AllMusicForge.server.getPlayerList().getPlayerByName(player); + if (player1 == null) + return; + if (AllMusic.isOK(player, null, false)) + return; + send(ComType.play + url, player); + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c歌曲指令发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendPic(String url) { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.isOK(player.getName().getString(), null, true)) + continue; + String name = player.getName().getString(); + SaveObj obj = HudUtils.get(name); + if (!obj.EnablePic) + continue; + send(player, ComType.img + url); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c图片指令发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendPic(String player, String url) { + try { + var player1 = AllMusicForge.server.getPlayerList().getPlayerByName(player); + if (player1 == null) + return; + if (AllMusic.isOK(player1.getName().getString(), null, true)) + return; + send(ComType.img + url, player); + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c图片指令发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendPos(String player, int pos) { + try { + var player1 = AllMusicForge.server.getPlayerList().getPlayerByName(player); + if (player1 == null) + return; + if (AllMusic.isOK(player1.getName().getString(), null, true)) + return; + send(ComType.pos + pos, player); + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错"); + e.printStackTrace(); + } + } + + @Override + public void sendHudLyric(String data) { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.isOK(player.getName().getString(), null, true)) + continue; + String name = player.getName().getString(); + SaveObj obj = HudUtils.get(name); + if (!obj.EnableLyric) + continue; + send(player, ComType.lyric + data); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c歌词发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendHudInfo(String data) { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.isOK(player.getName().getString(), null, true)) + continue; + String name = player.getName().getString(); + SaveObj obj = HudUtils.get(name); + if (!obj.EnableInfo) + continue; + send(player, ComType.info + data); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c歌词信息发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendHudList(String data) { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (AllMusic.isOK(player.getName().getString(), null, true)) + continue; + String name = player.getName().getString(); + SaveObj obj = HudUtils.get(name); + if (!obj.EnableList) + continue; + send(player, ComType.list + data); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c歌曲列表发送出错"); + e.printStackTrace(); + } + } + + @Override + public void sendHudUtilsAll() { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + String Name = player.getName().getString(); + try { + SaveObj obj = HudUtils.get(Name); + String data = new Gson().toJson(obj); + send(player, data); + } catch (Exception e1) { + AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误"); + e1.printStackTrace(); + } + } + } + + @Override + public void sendBar(String data) { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + try { + if (AllMusic.isOK(player.getName().getString(), null, true)) + continue; + ForgeApi.sendBar(player, data); + } catch (Exception e1) { + AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误"); + e1.printStackTrace(); + } + } + } + + @Override + public void clearHud(String player) { + try { + send(ComType.clear, player); + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错"); + e.printStackTrace(); + } + } + + @Override + public void clearHud() { + try { + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + send(player, ComType.clear); + } + } catch (Exception e) { + AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错"); + e.printStackTrace(); + } + } + + @Override + public void bq(String data) { + if (AllMusic.getConfig().MessageLimit + && data.length() > AllMusic.getConfig().MessageLimitSize) { + data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "..."; + } + for (var player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (!AllMusic.getConfig().NoMusicPlayer.contains(player.getName().getString())) { + player.sendSystemMessage(Component.nullToEmpty(data)); + } + } + } + + @Override + public void bqt(String data) { + if (AllMusic.getConfig().MessageLimit + && data.length() > AllMusic.getConfig().MessageLimitSize) { + data = data.substring(0, AllMusic.getConfig().MessageLimitSize - 1) + "..."; + } + var finalData = Component.literal(data); + runTask(() -> { + for (Player player : AllMusicForge.server.getPlayerList().getPlayers()) { + if (!AllMusic.getConfig().NoMusicPlayer.contains(player.getName().getString())) { + player.sendSystemMessage(finalData); + } + } + }); + } + + @Override + public void sendMessaget(Object obj, String message) { + runTask(() -> ((CommandSource) obj).sendSystemMessage(Component.literal(message))); + } + + @Override + public void sendMessage(Object obj, String message) { + CommandSource sender = (CommandSource) obj; + sender.sendSystemMessage(Component.literal(message)); + } + + @Override + public void sendMessageRun(Object obj, String message, String end, String command) { + ForgeApi.sendMessageRun(obj, message + end, command); + } + + @Override + public void sendMessageSuggest(Object obj, String message, String end, String command) { + ForgeApi.sendMessageSuggest(obj, message + end, command); + } + + @Override + public boolean onMusicPlay(SongInfoObj obj) { + MusicPlayEvent event = new MusicPlayEvent(obj); + return MinecraftForge.EVENT_BUS.post(event); + } + + @Override + public boolean onMusicAdd(Object obj, MusicObj music) { + MusicAddEvent event = new MusicAddEvent(music, (ServerPlayer) obj); + return MinecraftForge.EVENT_BUS.post(event); + } + + @Override + public void updateInfo() { + + } + + @Override + public void updateLyric() { + + } + + @Override + public void ping() { + + } + + private void send(ServerPlayer players, String data) { + if (players == null) + return; + try { +// byte[] bytes = data.getBytes(StandardCharsets.UTF_8); +// ByteBuf buf = Unpooled.buffer(bytes.length + 1); +// buf.writeByte(666); +// buf.writeBytes(bytes); + + runTask(() -> AllMusicForge.channel.send(PacketDistributor.PLAYER.with( + () -> players + ), data)); + } catch (Exception e) { + AllMusic.log.warning("§c数据发送发生错误"); + e.printStackTrace(); + } + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicAddEvent.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicAddEvent.java new file mode 100644 index 00000000..eeb0addf --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicAddEvent.java @@ -0,0 +1,31 @@ +package coloryr.allmusic.side.forge.event; + +import coloryr.allmusic.core.objs.music.MusicObj; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; + +@Cancelable +public class MusicAddEvent extends Event { + /** + * 添加的音乐 + */ + private final MusicObj music; + /** + * 添加者 + */ + private final ServerPlayer player; + + public MusicAddEvent(MusicObj id, ServerPlayer player) { + this.music = id; + this.player = player; + } + + public ServerPlayer getPlayer() { + return player; + } + + public MusicObj getMusic() { + return music; + } +} diff --git a/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicPlayEvent.java b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicPlayEvent.java new file mode 100644 index 00000000..4b455faa --- /dev/null +++ b/forge_1_19_3/src/main/java/coloryr/allmusic/side/forge/event/MusicPlayEvent.java @@ -0,0 +1,18 @@ +package coloryr.allmusic.side.forge.event; + +import coloryr.allmusic.core.objs.music.SongInfoObj; +import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; + +@Cancelable +public class MusicPlayEvent extends Event { + private final SongInfoObj music; + + public MusicPlayEvent(SongInfoObj music) { + this.music = music; + } + + public SongInfoObj getMusic() { + return music; + } +} diff --git a/forge_1_19_3/src/main/resources/META-INF/mods.toml b/forge_1_19_3/src/main/resources/META-INF/mods.toml index a95b4546..06929026 100644 --- a/forge_1_19_3/src/main/resources/META-INF/mods.toml +++ b/forge_1_19_3/src/main/resources/META-INF/mods.toml @@ -15,23 +15,23 @@ license="All rights reserved" # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="examplemod" #mandatory +modId="allmusic" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build version="${file.jarVersion}" #mandatory # A display name for the mod -displayName="Example Mod" #mandatory +displayName="AllMusic" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional # A file name (in the root of the mod JAR) containing a logo for display -logoFile="examplemod.png" #optional +logoFile="icon.png" #optional # A text field displayed in the mod UI -credits="Thanks for this example mod goes to Java" #optional +credits="AllMusic Server Mod" #optional # A text field displayed in the mod UI -authors="Love, Cheese and small house plants" #optional +authors="Color_yr" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. @@ -42,14 +42,10 @@ authors="Love, Cheese and small house plants" #optional # The description text for the mod (multi line!) (#mandatory) description=''' -This is a long form description of the mod. You can write whatever you want here - -Have some lorem ipsum. - -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. +AllMusic Server Mod ''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.examplemod]] #optional +[[dependencies.allmusic]] #optional # the modid of the dependency modId="forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified @@ -59,12 +55,12 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magn # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER - side="BOTH" + side="SERVER" # Here's another dependency -[[dependencies.examplemod]] +[[dependencies.allmusic]] modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version versionRange="[1.19.3,1.20)" ordering="NONE" - side="BOTH" + side="SERVER" diff --git a/forge_1_19_3/src/main/resources/config.json b/forge_1_19_3/src/main/resources/config.json new file mode 100644 index 00000000..ec568863 --- /dev/null +++ b/forge_1_19_3/src/main/resources/config.json @@ -0,0 +1,62 @@ +{ + "MaxList": 10, + "MinVote": 3, + "Delay": 0, + "KDelay": 0, + "Admin": ["CONSOLE","Color_yr"], + "LoginUser": "", + "NoMusicServer": [], + "NoMusicPlayer": [], + "BanMusic": [], + "PlayList": [], + "PlayListSwitch": true, + "PlayListRandom": true, + "SendLyric": true, + "NeedPermission": false, + "DefaultAddMusic": 0, + "TopPAPI": false, + "MessageLimit": false, + "MessageLimitSize": 40, + "MutePlayMessage": false, + "MuteAddMessage": false, + "ShowInBar": false, + "DefaultHud": { + "List": { + "x": 2, + "y": 74 + }, + "Lyric": { + "x": 74, + "y": 53 + }, + "Info": { + "x": 74, + "y": 2 + }, + "Pic": { + "x": 2, + "y": 2 + }, + "PicRotateSpeed": 10, + "EnablePicRotate": true, + "EnableList": true, + "EnableLyric": true, + "EnableInfo": true, + "EnablePic": true + }, + "Economys": { + "MysqlUrl": "jdbc:mysql://localhost:3306/minecraft?autoReconnect=true&autoReconnectForPools=true", + "Vault": true + }, + "UseCost": false, + "SearchCost": 20, + "AddMusicCost": 10, + "MaxMusicTime": 600, + "KtvMode": true, + "MusicBR": "320000", + "FunConfig": { + "Rain": true, + "RainRate": 10 + }, + "Version": "103" +} \ No newline at end of file diff --git a/forge_1_19_3/src/main/resources/icon.png b/forge_1_19_3/src/main/resources/icon.png new file mode 100644 index 00000000..b2b5fa79 Binary files /dev/null and b/forge_1_19_3/src/main/resources/icon.png differ diff --git a/forge_1_19_3/src/main/resources/message.json b/forge_1_19_3/src/main/resources/message.json new file mode 100644 index 00000000..6a435a90 --- /dev/null +++ b/forge_1_19_3/src/main/resources/message.json @@ -0,0 +1,136 @@ +{ + "MusicPlay": { + "StopPlay": "§d[AllMusic]§e已停止你的音乐播放", + "NoMusic": "§d[AllMusic]§e无正在播放的歌曲", + "Play": "§d[AllMusic]§e正在播放:%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia% | by: %PlayerName%", + "NoPlay": "§d[AllMusic]§e队列中无歌曲", + "ListMusic": { + "Head": "§d[AllMusic]§e队列中有歌曲数:&Count&", + "Item": "§e%index%->%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia%", + "Get": "§d[AllMusic]§e歌曲列表%ListName%获取成功" + }, + "NoCanPlay": "§d[AllMusic]§c无法播放歌曲%MusicID%可能该歌曲为VIP歌曲", + "NoPlayMusic": "§d[AllMusic]§e你不会再收到点歌了!想要再次参与点歌就点一首歌或者参与切歌投票吧!", + "Switch": "§d[AllMusic]§e切换到玩家歌曲", + "AddMusic": "§d[AllMusic]§e音乐列表添加%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia%", + "CheckMusic": "§d[AllMusic]§2正在解析歌曲%MusicID%", + "MusicInfo": "%MusicName% | %MusicAuthor% | %MusicAl% | %MusicAlia% | by: %PlayerName%", + "Trail": "§d[AllMusic]§e该音乐为试听音乐", + "Cancel": "§d[AllMusic]§e播放被取消" + }, + "AddMusic": { + "ListFull": "§d[AllMusic]§c错误,队列已满", + "BanMusic": "§d[AllMusic]§c错误,这首歌被禁点了", + "ExistMusic": "§d[AllMusic]§c错误,这首歌已经存在了", + "Success": "§d[AllMusic]§e点歌成功", + "NoPlayer": "§d[AllMusic]§c没有播放的玩家", + "NoID": "§d[AllMusic]§c错误,请输入歌曲数字ID", + "Cancel": "§d[AllMusic]§e点歌被取消", + "TimeOut": "§d[AllMusic]§e点歌被取消,音乐长度过长" + }, + "Page": { + "Choice": "§e%index%->%MusicName% | %MusicAuthor% | %MusicAl%", + "Next": "§e[§n点我下一页§r§e]", + "Last": "§e[§n点我上一页§r§e]" + }, + "Lyric": { + "Data": "%Lyric%", + "TData": "%Lyric%(%TLyric%)" + }, + "Vote": { + "NoPermission": "§d[AllMusic]§c你没有权限切歌", + "DoVote": "§d[AllMusic]§e已发起切歌投票", + "BQ": "§d[AllMusic]§e%PlayerName%发起了切歌投票,30秒后结束,输入/music vote 同意切歌。", + "Agree": "§d[AllMusic]§e你同意切歌", + "BQAgree": "§d[AllMusic]§e%PlayerName%同意切歌,共有%Count%名玩家同意切歌。", + "ARAgree": "§d[AllMusic]§e你已申请切歌", + "TimeOut": "§d[AllMusic]§e切歌时间结束", + "Do": "§d[AllMusic]§e已切歌" + }, + "Search": { + "StartSearch": "§d[AllMusic]§e正在排队搜歌", + "NoPer": "§d[AllMusic]§c你没有权限搜歌", + "CantSearch": "§d[AllMusic]§c无法搜索歌曲:%Music%", + "Res": "§d[AllMusic]§e搜索结果", + "NoSearch": "§d[AllMusic]§c你没有搜索音乐", + "ErrorNum": "§d[AllMusic]§c请输入正确的序号", + "Chose": "§d[AllMusic]§e你选择了序号%Num%", + "CantNext": "§d[AllMusic]§c无法下一页", + "CantLast": "§d[AllMusic]§c无法上一页" + }, + "Hud": { + "State": "§d[AllMusic]§e设置信息位置:%Hud%,状态:%State%", + "Set": "§d[AllMusic]§e已设置%Hud%的坐标为%x%, %y%", + "Reset": "§d[AllMusic]§eHud恢复至默认位置", + "NoMusic": "没有播放的音乐", + "NoList": "队列中无歌曲", + "NoLyric": "无歌词", + "PicSize": "§d[ALLMusic]§e设置图片尺寸为%Size%", + "PicRotate": "§d[AllMusic]§2设置图片旋转为%State%", + "PicRotateSpeed": "§d[AllMusic]§2设置图片旋转速度为%Size%", + "Music": "%Name% %AllTime%/%NowTime%\n%Author%\n%Alia%\n%Al%\nby: %Player%", + "Lyric": "%Lyric%\n%Tlyric%", + "Ktv": "§e%KLyric%§f%Lyric%§r\n%Tlyric%", + "List": "播放列表里面有%Size%首歌\n%List%" + }, + "Command": { + "Error": "§d[AllMusic]§c参数错误,请输入/music help获取帮助", + "NoPer": "§d[AllMusic]§c你没有权限点歌" + }, + "HudList": { + "List": "待播放列表", + "Lyric": "歌词", + "Info": "歌曲信息", + "Pic": "图片", + "All": "所有位置", + "PicRoute": "图片旋转", + "PicRouteSpeed": "图片旋转速度" + }, + "Custom": { + "Info": "自定义音乐" + }, + "PAPI": { + "NoMusic": "没有播放的音乐" + }, + "Cost": { + "Search": "§d[AllMusic]§e你搜歌花费了%Cost%", + "AddMusic": "§d[AllMusic]§e你点歌花费了%Cost%", + "NoMoney": "§d[AllMusic]§c你没有足够的钱", + "CostFail": "§d[ALLMusic]§c扣钱过程中错误" + }, + "Click": { + "This": "§b[§n点我选择§r§b]", + "Check": "§b[§n点我查看§r§b]" + }, + "Help": { + "Normal": { + "Head": "§d[AllMusic]§e帮助手册", + "Base": "§d[AllMusic]§e使用/music [音乐ID] 来点歌", + "Stop": "§d[AllMusic]§e使用/music stop 停止播放歌曲", + "List": "§d[AllMusic]§e使用/music list 查看歌曲队列", + "Vote": "§d[AllMusic]§e使用/music vote 投票切歌", + "NoMusic": "§d[AllMusic]§e使用/music nomusic 不再参与点歌", + "Search": "§d[AllMusic]§e使用/music search [歌名] 搜索歌曲", + "Select": "§d[AllMusic]§e使用/music select [序列] 选择歌曲", + "Hud1": "§d[AllMusic]§e使用/music hud enable [位置] 启用关闭Hud", + "Hud2": "§d[AllMusic]§e使用/music hud [位置] [x] [y] 设置某个Hud的位置", + "Hud3": "§d[AllMusic]§e使用/music hud picsize [尺寸] 设置图片尺寸", + "Hud4": "§d[AllMusic]§e使用/music hud picrotate [开关] 设置图片旋转模式", + "Hud5": "§d[AllMusic]§e使用/music hud picrotatespeed [数值] 设置图片旋转速度" + }, + "Admin": { + "Reload": "§d[AllMusic]§e使用/music reload 重读配置文件", + "Next": "§d[AllMusic]§e使用/music next 强制切歌", + "Ban": "§d[AllMusic]§e使用/music ban [ID] 禁止点这首歌", + "Url": "§d[AllMusic]§e使用/music url [url] 播放一首自定义歌曲", + "Delete": "§d[AllMusic]§e使用/music delete [序号] 删除队列中的歌曲", + "AddList": "§d[AllMusic]§e使用/music addlist [歌单ID] 添加歌单到空闲列表", + "ClearList": "§d[AllMusic]§e使用/music clearlist 清空空闲歌单", + "Login": "§d[AllMusic]§e使用/music login 重新登录账户" + } + }, + "Fun": { + "Rain": "§d[AllMusic]§e天空开始变得湿润" + }, + "Version": "103" +} \ No newline at end of file diff --git a/server/src/main/java/coloryr/allmusic/core/command/TabCommand.java b/server/src/main/java/coloryr/allmusic/core/command/TabCommand.java index 3272c23d..dbe2d90a 100644 --- a/server/src/main/java/coloryr/allmusic/core/command/TabCommand.java +++ b/server/src/main/java/coloryr/allmusic/core/command/TabCommand.java @@ -74,7 +74,7 @@ public class TabCommand { */ public static List getTabList(String name, String[] arg) { List arguments = new ArrayList<>(); - if (arg.length == 1 || arg.length == 0) { + if (arg.length == 0 || arg.length == 1) { arguments.addAll(normal); if (AllMusic.getSearch(name) != null) { arguments.addAll(search); @@ -82,13 +82,18 @@ public class TabCommand { if (AllMusic.getConfig().Admin.contains(name)) { arguments.addAll(admin); } - } else if (arg[0].equalsIgnoreCase("hud")) { - if (arg.length == 2) { + } else if (arg.length == 2) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); + } + else if ("hud".equalsIgnoreCase(arg[0])) { arguments.addAll(hud); - } else if (arg.length == 3) { - if (arg[1].equalsIgnoreCase("enable")) { - arguments.addAll(hudlist); - } + } + } else if (arg.length == 3) { + if ("hud".equalsIgnoreCase(arg[0]) && + "enable".equalsIgnoreCase(arg[1])) { + arguments.addAll(hudlist); } } return arguments;