From d377b71f2deabe160c621762234868432dfe52ac Mon Sep 17 00:00:00 2001 From: Coloryr <402067010@qq.com> Date: Sun, 9 Jun 2024 20:41:33 +0800 Subject: [PATCH] up --- core/command/CommandEX.java | 4 ++-- core/command/CommandMute.java | 2 +- core/command/CommandNext.java | 2 +- core/command/CommandPush.java | 2 +- core/command/CommandVote.java | 2 +- core/music/play/PlayMusic.java | 7 +++++- core/objs/config/ConfigObj.java | 4 ++-- forge_1_20/gradle.properties | 2 +- .../allmusic/server/AllMusicForge.java | 24 +------------------ .../allmusic/server/side/forge/SideForge.java | 7 ++++-- 10 files changed, 21 insertions(+), 35 deletions(-) diff --git a/core/command/CommandEX.java b/core/command/CommandEX.java index 3cd89d04..48248b20 100644 --- a/core/command/CommandEX.java +++ b/core/command/CommandEX.java @@ -170,7 +170,7 @@ public static void addMusic(Object sender, String name, String[] args) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.banMusic); } else if (PlayMusic.haveMusic(musicID)) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.existMusic); - } else if (PlayMusic.havePlayer(name)) { + } else if (PlayMusic.isPlayerMax(name)) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.playerToMany); } else if (AllMusic.getConfig().banPlayer.contains(name)) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.playerBan); @@ -182,7 +182,7 @@ public static void addMusic(Object sender, String name, String[] args) { AllMusic.getMessage().cost.addMusic)) { return; } - AllMusic.getConfig().RemoveNoMusicPlayer(name); + AllMusic.getConfig().removeNoMusicPlayer(name); if (AllMusic.side.needPlay()) { MusicObj obj = new MusicObj(); obj.sender = sender; diff --git a/core/command/CommandMute.java b/core/command/CommandMute.java index 0298611c..62b39666 100644 --- a/core/command/CommandMute.java +++ b/core/command/CommandMute.java @@ -7,7 +7,7 @@ public class CommandMute extends ACommand { public void ex(Object sender, String name, String[] args) { AllMusic.side.sendStop(name); AllMusic.side.clearHud(name); - AllMusic.getConfig().AddNoMusicPlayer(name); + AllMusic.getConfig().addNoMusicPlayer(name); AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.mute); } } diff --git a/core/command/CommandNext.java b/core/command/CommandNext.java index 976cec38..5a23de58 100644 --- a/core/command/CommandNext.java +++ b/core/command/CommandNext.java @@ -9,6 +9,6 @@ public class CommandNext extends ACommand { public void ex(Object sender, String name, String[] args) { PlayMusic.musicLessTime = 1; AllMusic.side.sendMessage(sender, "§d[AllMusic3]§2已强制切歌"); - AllMusic.getConfig().RemoveNoMusicPlayer(name); + AllMusic.getConfig().removeNoMusicPlayer(name); } } diff --git a/core/command/CommandPush.java b/core/command/CommandPush.java index 698e1718..22446e15 100644 --- a/core/command/CommandPush.java +++ b/core/command/CommandPush.java @@ -94,7 +94,7 @@ public void ex(Object sender, String name, String[] args) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().push.arAgree); } } - AllMusic.getConfig().RemoveNoMusicPlayer(name); + AllMusic.getConfig().removeNoMusicPlayer(name); } @Override diff --git a/core/command/CommandVote.java b/core/command/CommandVote.java index b2d04433..c164459e 100644 --- a/core/command/CommandVote.java +++ b/core/command/CommandVote.java @@ -52,6 +52,6 @@ public void ex(Object sender, String name, String[] args) { AllMusic.side.sendMessage(sender, AllMusic.getMessage().vote.arAgree); } } - AllMusic.getConfig().RemoveNoMusicPlayer(name); + AllMusic.getConfig().removeNoMusicPlayer(name); } } diff --git a/core/music/play/PlayMusic.java b/core/music/play/PlayMusic.java index 9a82b973..7971a653 100644 --- a/core/music/play/PlayMusic.java +++ b/core/music/play/PlayMusic.java @@ -317,7 +317,12 @@ private static void addUrl(String url) { } } - public static boolean havePlayer(String name) { + /** + * 判断玩家点歌数量是否超上限 + * @param name 玩家名 + * @return + */ + public static boolean isPlayerMax(String name) { int list = AllMusic.getConfig().maxPlayerList; if (list == 0) { return false; diff --git a/core/objs/config/ConfigObj.java b/core/objs/config/ConfigObj.java index 42283acf..ec254e8e 100644 --- a/core/objs/config/ConfigObj.java +++ b/core/objs/config/ConfigObj.java @@ -143,12 +143,12 @@ public void addBanPlayer(String id) { AllMusic.saveConfig(); } - public void AddNoMusicPlayer(String ID) { + public void addNoMusicPlayer(String ID) { mutePlayer.add(ID); AllMusic.saveConfig(); } - public void RemoveNoMusicPlayer(String ID) { + public void removeNoMusicPlayer(String ID) { mutePlayer.remove(ID); AllMusic.saveConfig(); } diff --git a/forge_1_20/gradle.properties b/forge_1_20/gradle.properties index 889b7a19..d3864311 100644 --- a/forge_1_20/gradle.properties +++ b/forge_1_20/gradle.properties @@ -48,7 +48,7 @@ mod_name=AllMusic Server # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPL-3.0 # The mod version. See https://semver.org/ -mod_version=3.1.2 +mod_version=3.1.3 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/forge_1_20/src/main/java/com/coloryr/allmusic/server/AllMusicForge.java b/forge_1_20/src/main/java/com/coloryr/allmusic/server/AllMusicForge.java index 024f1a67..aac00706 100644 --- a/forge_1_20/src/main/java/com/coloryr/allmusic/server/AllMusicForge.java +++ b/forge_1_20/src/main/java/com/coloryr/allmusic/server/AllMusicForge.java @@ -6,7 +6,6 @@ import com.coloryr.allmusic.server.side.forge.SideForge; import com.mojang.brigadier.CommandDispatcher; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.MinecraftForge; @@ -19,22 +18,16 @@ import net.minecraftforge.fml.common.Mod; 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 org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.nio.charset.StandardCharsets; import java.util.Locale; -import java.util.function.Supplier; // The value here should match an entry in the META-INF/mods.toml file @Mod(AllMusicForge.MODID) public class AllMusicForge { - public static final SimpleChannel channel = NetworkRegistry.newSimpleChannel(new ResourceLocation("allmusic", "channel"), - () -> "1.0", s -> true, s -> true); + public static final ResourceLocation channel = new ResourceLocation("allmusic", "channel"); // Define mod id in a common place for everything to reference public static final String MODID = "allmusic_server"; // Directly reference a slf4j logger @@ -53,8 +46,6 @@ public AllMusicForge() { } private void commonSetup(final FMLCommonSetupEvent event) { - channel.registerMessage(0, String.class, this::enc, this::dec, this::proc); - String path = String.format(Locale.ROOT, "config/%s/", "AllMusic3"); AllMusic.log = new LogForge(); @@ -63,19 +54,6 @@ private void commonSetup(final FMLCommonSetupEvent event) { new AllMusic().init(new File(path)); } - 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(); diff --git a/forge_1_20/src/main/java/com/coloryr/allmusic/server/side/forge/SideForge.java b/forge_1_20/src/main/java/com/coloryr/allmusic/server/side/forge/SideForge.java index df78beff..71d2acfe 100644 --- a/forge_1_20/src/main/java/com/coloryr/allmusic/server/side/forge/SideForge.java +++ b/forge_1_20/src/main/java/com/coloryr/allmusic/server/side/forge/SideForge.java @@ -17,7 +17,9 @@ import com.google.gson.Gson; import io.netty.buffer.ByteBuf; import net.minecraft.commands.CommandSource; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.network.PacketDistributor; @@ -407,9 +409,10 @@ private void send(ServerPlayer players, ByteBuf data) { if (players == null) return; try { - runTask(() -> AllMusicForge.channel.send(PacketDistributor.PLAYER.with( + runTask(() -> PacketDistributor.PLAYER.with( () -> players - ), data)); + ).send(new ClientboundCustomPayloadPacket(AllMusicForge.channel, + new FriendlyByteBuf(data)))); } catch (Exception e) { AllMusic.log.warning("§c数据发送发生错误"); e.printStackTrace();