Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Jun 9, 2024
1 parent 65c91a9 commit d377b71
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions core/command/CommandEX.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion core/command/CommandMute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion core/command/CommandNext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion core/command/CommandPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/command/CommandVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion core/music/play/PlayMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/objs/config/ConfigObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion forge_1_20/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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<NetworkEvent.Context> supplier) {
NetworkEvent.Context context = supplier.get();
context.setPacketHandled(true);
}

@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d377b71

Please sign in to comment.