mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-08 18:54:44 +00:00
26.2 server
This commit is contained in:
1 parent
1e3dc17741
commit
80bc2c937d
30 files changed
+1004
No files matched your search
@@ -0,0 +1,37 @@
|
||||
plugins {
|
||||
id("net.fabricmc.fabric-loom") version Versions.fabricLoom
|
||||
}
|
||||
|
||||
java.sourceCompatibility = JavaVersion.VERSION_25
|
||||
java.targetCompatibility = JavaVersion.VERSION_25
|
||||
|
||||
dependencies {
|
||||
minecraft("com.mojang:minecraft:26.2")
|
||||
implementation("net.fabricmc:fabric-loader:0.19.3")
|
||||
|
||||
implementation("net.fabricmc.fabric-api:fabric-api:0.152.1+26.2")
|
||||
|
||||
implementation(include("net.kyori:adventure-platform-fabric:7.0.0")!!)
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand(
|
||||
"version" to project.version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName.set("[fabric-26.2]AllMusic_Server-${project.version}.jar")
|
||||
destinationDirectory.set(file("${parent!!.projectDir}/../build"))
|
||||
|
||||
// relocate("net.kyori", "com.coloryr.allmusic.libs.net.kyori")
|
||||
// relocate("com.google.gson", "com.coloryr.allmusic.libs.com.google.gson")
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.coloryr.allmusic.comm;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
|
||||
public class AllMusicInit implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
PayloadTypeRegistry.clientboundPlay().register(MusicCodec.ID, MusicCodec.CODEC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.coloryr.allmusic.comm;
|
||||
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.codec.MusicPacketCodec;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
public record MusicCodec(MusicPack pack) implements CustomPacketPayload {
|
||||
public static final Identifier ChannelID = Identifier.fromNamespaceAndPath("allmusic", "channel");
|
||||
|
||||
public static final Type<MusicCodec> ID = new Type<>(ChannelID);
|
||||
public static final StreamCodec<FriendlyByteBuf, MusicCodec> CODEC =
|
||||
StreamCodec.of((buf, value) -> MusicPacketCodec.pack(buf, value.pack),
|
||||
buf -> new MusicCodec(MusicPacketCodec.decode(buf)));
|
||||
|
||||
@Override
|
||||
public @NonNull Type<? extends CustomPacketPayload> type() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AllMusicServer implements DedicatedServerModInitializer {
|
||||
public static MinecraftServer server;
|
||||
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
AllMusic.log = new LogFabric();
|
||||
AllMusic.side = new SideFabric();
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment)
|
||||
-> CommandFabric.instance.register(dispatcher));
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register((a) -> {
|
||||
server = a;
|
||||
AllMusic.init(new File(AllMusic.SERVER_DIR));
|
||||
AllMusic.start();
|
||||
Tasks.init();
|
||||
});
|
||||
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register((a) -> {
|
||||
AllMusic.stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.command.CommandEX;
|
||||
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.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CommandFabric implements Command<CommandSourceStack>, Predicate<CommandSourceStack>, SuggestionProvider<CommandSourceStack> {
|
||||
public static CommandFabric instance = new CommandFabric();
|
||||
|
||||
public void register(CommandDispatcher<CommandSourceStack> 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<CommandSourceStack> context) {
|
||||
var item = context.getSource();
|
||||
|
||||
var input = context.getInput();
|
||||
var temp = input.split(" ");
|
||||
var arg = new String[temp.length - 1];
|
||||
System.arraycopy(temp, 1, arg, 0, arg.length);
|
||||
|
||||
CommandEX.execute(item, context.getSource().getTextName(), arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CommandSourceStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) {
|
||||
var item = context.getSource();
|
||||
|
||||
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);
|
||||
|
||||
builder = builder.createOffset(builder.getInput().lastIndexOf(32) + 1);
|
||||
|
||||
List<String> results = CommandEX.getTabList(item, item.getTextName(), arg);
|
||||
|
||||
String remaining = builder.getRemaining().trim();
|
||||
|
||||
for (String s : results) {
|
||||
if (s.startsWith(remaining)) {
|
||||
builder.suggest(s);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.side.IAllMusicLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
|
||||
public class LogFabric implements IAllMusicLogger {
|
||||
@Override
|
||||
public void data(Component data) {
|
||||
AllMusicServer.server.sendMessage(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.comm.MusicCodec;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.side.BaseSide;
|
||||
import com.coloryr.allmusic.server.event.MusicAddEvent;
|
||||
import com.coloryr.allmusic.server.event.MusicPlayEvent;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.permissions.PermissionSet;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public class SideFabric extends BaseSide {
|
||||
@Override
|
||||
public void runTask(Runnable run) {
|
||||
AllMusicServer.server.execute(run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable run1, int delay) {
|
||||
Tasks.add(new TaskItem() {{
|
||||
tick = delay;
|
||||
run = run1;
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(Object player) {
|
||||
CommandSourceStack source = (CommandSourceStack) player;
|
||||
return source.permissions() == PermissionSet.ALL_PERMISSIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer(Object player) {
|
||||
CommandSourceStack source = (CommandSourceStack) player;
|
||||
return source.isPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(Object player, String permission) {
|
||||
return checkPermission(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needPlay(boolean islist) {
|
||||
for (var player : AllMusicServer.server.getPlayerList().getPlayers()) {
|
||||
if (!com.coloryr.allmusic.server.core.AllMusic.isSkip(player.getName().getString(), null, false, islist)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getPlayers() {
|
||||
return AllMusicServer.server.getPlayerList().getPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName(Object player) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
return player1.getName().getString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServer(Object player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object player, MusicPack pack) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
send(player1, pack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayer(String player) {
|
||||
return AllMusicServer.server.getPlayerList().getPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBar(Object player, net.kyori.adventure.text.Component data) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
player1.sendActionBar(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFolder() {
|
||||
return new File(AllMusic.SERVER_DIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(net.kyori.adventure.text.Component message) {
|
||||
for (var player : AllMusicServer.server.getPlayerList().getPlayers()) {
|
||||
if (!AllMusic.isSkip(player.getName().getString(), null, false)) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Object obj, net.kyori.adventure.text.Component message) {
|
||||
if (obj instanceof CommandSourceStack source) {
|
||||
source.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
return MusicPlayEvent.EVENT.invoker().interact(obj) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMusicAdd(Object obj, PlayerAddMusicObj music) {
|
||||
CommandSourceStack source = (CommandSourceStack) obj;
|
||||
return MusicAddEvent.EVENT.invoker().interact(source.getPlayer(), music) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, MusicPack data) {
|
||||
if (players == null)
|
||||
return;
|
||||
runTask(() -> ServerPlayNetworking.send(players, new MusicCodec(data)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
public class TaskItem {
|
||||
public int tick;
|
||||
public Runnable run;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class Tasks {
|
||||
private static final List<TaskItem> taskItems = new CopyOnWriteArrayList<>();
|
||||
|
||||
public static void init() {
|
||||
AllMusicServer.server.addTickable(Tasks::tick);
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
for (var item : new ArrayList<>(taskItems)) {
|
||||
item.tick--;
|
||||
if (item.tick <= 0) {
|
||||
taskItems.remove(item);
|
||||
item.run.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void add(TaskItem item) {
|
||||
taskItems.add(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.coloryr.allmusic.server.event;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public interface MusicAddEvent {
|
||||
Event<MusicAddEvent> EVENT = EventFactory.createArrayBacked(MusicAddEvent.class,
|
||||
(listeners) -> (player, music) -> {
|
||||
for (MusicAddEvent listener : listeners) {
|
||||
InteractionResult result = listener.interact(player, music);
|
||||
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.coloryr.allmusic.server.event;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public interface MusicPlayEvent {
|
||||
Event<MusicPlayEvent> EVENT = EventFactory.createArrayBacked(MusicPlayEvent.class,
|
||||
(listeners) -> (music) -> {
|
||||
for (MusicPlayEvent listener : listeners) {
|
||||
InteractionResult result = listener.interact(music);
|
||||
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
*
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.coloryr.allmusic.server.mixin;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public class ServerPlayerMixin {
|
||||
@Inject(at = @At("HEAD"), method = "remove")
|
||||
private void remove(ServerPlayer entity, CallbackInfo info) {
|
||||
PlayMusic.removeNowPlayPlayer(entity.getName().getString());
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "placeNewPlayer")
|
||||
private void add(Connection connection, ServerPlayer player, CommonListenerCookie clientData, CallbackInfo ci) {
|
||||
AllMusic.joinPlay(player.getName().getString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.coloryr.allmusic.server.mixin",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"server": [
|
||||
],
|
||||
"mixins": [
|
||||
"ServerPlayerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "allmusic_server",
|
||||
"version": "${version}",
|
||||
"name": "AllMusic Server",
|
||||
"description": "AllMusic Server Mod",
|
||||
"authors": [
|
||||
"Color_yr"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://github.com/Coloryr/AllMusic",
|
||||
"sources": "https://github.com/Coloryr/AllMusic"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"icon": "assets/allmusic_server/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.coloryr.allmusic.comm.AllMusicInit"
|
||||
],
|
||||
"server": [
|
||||
"com.coloryr.allmusic.server.AllMusicServer"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
{
|
||||
"config": "allmusic_server.mixins.json",
|
||||
"environment": "server"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.19.3",
|
||||
"minecraft": "~26.2-",
|
||||
"java": ">=25",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom-no-remap") version Versions.architecturyLoom
|
||||
// id("architectury-plugin") version "3.5-SNAPSHOT"
|
||||
}
|
||||
|
||||
java.sourceCompatibility = JavaVersion.VERSION_25
|
||||
java.targetCompatibility = JavaVersion.VERSION_25
|
||||
|
||||
//architectury {
|
||||
// platformSetupLoomIde()
|
||||
// neoForge()
|
||||
//}
|
||||
|
||||
repositories {
|
||||
maven("https://maven.neoforged.net/releases/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft("com.mojang:minecraft:26.2")
|
||||
neoForge("net.neoforged:neoforge:26.2.0.1-beta")
|
||||
|
||||
implementation(include("net.kyori:adventure-platform-neoforge:7.0.0")!!)
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName.set("[neoforge-26.2]AllMusic_Server-${project.version}.jar")
|
||||
destinationDirectory.set(file("${parent!!.projectDir}/../build"))
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
loom.platform=neoforge
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.coloryr.allmusic.comm;
|
||||
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadHandler;
|
||||
|
||||
@Mod(AllMusicInit.MODID)
|
||||
public class AllMusicInit implements IPayloadHandler<MusicCodec> {
|
||||
|
||||
public static final String MODID = "allmusic";
|
||||
|
||||
public static IPayloadHandler<MusicCodec> handler;
|
||||
|
||||
public AllMusicInit(IEventBus modEventBus, ModContainer modContainer) {
|
||||
modEventBus.addListener(this::register);
|
||||
}
|
||||
|
||||
public void register(final RegisterPayloadHandlersEvent event) {
|
||||
event.registrar("1.0")
|
||||
.optional()
|
||||
.playToClient(MusicCodec.TYPE, MusicCodec.CODEC, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MusicCodec data, IPayloadContext iPayloadContext) {
|
||||
if (handler != null) {
|
||||
handler.handle(data, iPayloadContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.coloryr.allmusic.comm;
|
||||
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.codec.MusicPacketCodec;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public record MusicCodec(MusicPack pack) implements CustomPacketPayload {
|
||||
public static final Identifier channel =
|
||||
Identifier.fromNamespaceAndPath("allmusic", "channel");
|
||||
|
||||
public static final Type<MusicCodec> TYPE = new Type<>(channel);
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, MusicCodec> CODEC = StreamCodec.of((buf, value) -> MusicPacketCodec.pack(buf, value.pack),
|
||||
(buf) -> {
|
||||
return new MusicCodec(MusicPacketCodec.decode(buf));
|
||||
});
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.music.PlayMusic;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.kyori.adventure.platform.modcommon.MinecraftServerAudiences;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@EventBusSubscriber(modid = "allmusic_server", value = Dist.DEDICATED_SERVER)
|
||||
public class AllMusicServer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("AllMusic Server");
|
||||
public static MinecraftServer server;
|
||||
public static MinecraftServerAudiences audiences;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void commonSetup(final FMLCommonSetupEvent event) {
|
||||
AllMusic.log = new LogNeoForge();
|
||||
AllMusic.side = new SideNeoForge();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterCommands(RegisterCommandsEvent event) {
|
||||
if (event.getCommandSelection() != Commands.CommandSelection.INTEGRATED) {
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = event.getDispatcher();
|
||||
CommandNeoForge.instance.register(dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStarting(ServerStartedEvent event) {
|
||||
if (event.getServer().isDedicatedServer()) {
|
||||
audiences = MinecraftServerAudiences.of(event.getServer());
|
||||
server = event.getServer();
|
||||
AllMusic.init(new File(AllMusic.SERVER_DIR));
|
||||
AllMusic.start();
|
||||
Tasks.init();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStopping(ServerStoppingEvent event) {
|
||||
if (event.getServer().isDedicatedServer()) {
|
||||
AllMusic.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (server != null) {
|
||||
PlayMusic.removeNowPlayPlayer(event.getEntity().getName().getString());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (server != null) {
|
||||
AllMusic.joinPlay(event.getEntity().getName().getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.command.CommandEX;
|
||||
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.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CommandNeoForge implements Command<CommandSourceStack>, Predicate<CommandSourceStack>, SuggestionProvider<CommandSourceStack> {
|
||||
public static CommandNeoForge instance = new CommandNeoForge();
|
||||
|
||||
public void register(CommandDispatcher<CommandSourceStack> 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<CommandSourceStack> context) {
|
||||
var item = context.getSource();
|
||||
|
||||
var input = context.getInput();
|
||||
var temp = input.split(" ");
|
||||
var arg = new String[temp.length - 1];
|
||||
System.arraycopy(temp, 1, arg, 0, arg.length);
|
||||
|
||||
CommandEX.execute(item, context.getSource().getTextName(), arg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CommandSourceStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) {
|
||||
var item = context.getSource();
|
||||
|
||||
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<String> results = CommandEX.getTabList(item, item.getTextName(), arg);
|
||||
|
||||
for (String s : results) {
|
||||
builder.suggest(s);
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.server.core.side.IAllMusicLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LogNeoForge implements IAllMusicLogger {
|
||||
@Override
|
||||
public void data(Component data) {
|
||||
AllMusicServer.audiences.console().sendMessage(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
import com.coloryr.allmusic.comm.MusicCodec;
|
||||
import com.coloryr.allmusic.server.core.AllMusic;
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import com.coloryr.allmusic.server.core.side.BaseSide;
|
||||
import com.coloryr.allmusic.server.event.MusicAddEvent;
|
||||
import com.coloryr.allmusic.server.event.MusicPlayEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.permissions.PermissionSet;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public class SideNeoForge extends BaseSide {
|
||||
@Override
|
||||
public void runTask(Runnable run) {
|
||||
AllMusicServer.server.execute(run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable run1, int delay) {
|
||||
Tasks.add(new TaskItem() {{
|
||||
tick = delay;
|
||||
run = run1;
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(Object player, String permission) {
|
||||
return checkPermission(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(Object player) {
|
||||
CommandSourceStack source = (CommandSourceStack) player;
|
||||
return source.permissions() == PermissionSet.ALL_PERMISSIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer(Object player) {
|
||||
CommandSourceStack source = (CommandSourceStack) player;
|
||||
return source.isPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needPlay(boolean islist) {
|
||||
for (ServerPlayer player : AllMusicServer.server.getPlayerList().getPlayers()) {
|
||||
if (!AllMusic.isSkip(player.getName().getString(), null, false, islist)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getPlayers() {
|
||||
return AllMusicServer.server.getPlayerList().getPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName(Object player) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
return player1.getName().getString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServer(Object player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object player, MusicPack pack) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
send(player1, pack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayer(String player) {
|
||||
return AllMusicServer.server.getPlayerList().getPlayerByName(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBar(Object player, Component data) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
AllMusicServer.audiences.audience(player1).sendActionBar(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFolder() {
|
||||
return new File(AllMusic.SERVER_DIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(Component message) {
|
||||
for (ServerPlayer player : AllMusicServer.server.getPlayerList().getPlayers()) {
|
||||
if (!AllMusic.isSkip(player.getName().getString(), null, false)) {
|
||||
AllMusicServer.audiences.audience(player).sendActionBar(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(Object obj, Component message) {
|
||||
if (obj instanceof CommandSourceStack source) {
|
||||
AllMusicServer.audiences.audience(source).sendActionBar(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
MusicPlayEvent event = new MusicPlayEvent(obj);
|
||||
NeoForge.EVENT_BUS.post(event);
|
||||
return event.isCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMusicAdd(Object obj, PlayerAddMusicObj music) {
|
||||
CommandSourceStack source = (CommandSourceStack) obj;
|
||||
MusicAddEvent event = new MusicAddEvent(music, source.getPlayer());
|
||||
NeoForge.EVENT_BUS.post(event);
|
||||
return event.isCancel();
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, MusicPack data) {
|
||||
if (players == null)
|
||||
return;
|
||||
runTask(() -> PacketDistributor.sendToPlayer(players, new MusicCodec(data)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
public class TaskItem {
|
||||
public int tick;
|
||||
public Runnable run;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class Tasks {
|
||||
private static final List<TaskItem> taskItems = new CopyOnWriteArrayList<>();
|
||||
|
||||
public static void init() {
|
||||
AllMusicServer.server.addTickable(Tasks::tick);
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
for (TaskItem item : new ArrayList<>(taskItems)) {
|
||||
item.tick--;
|
||||
if (item.tick <= 0) {
|
||||
taskItems.remove(item);
|
||||
item.run.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void add(TaskItem item) {
|
||||
taskItems.add(item);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.coloryr.allmusic.server.event;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.PlayerAddMusicObj;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.neoforged.bus.api.Event;
|
||||
|
||||
public class MusicAddEvent extends Event {
|
||||
/**
|
||||
* 添加的音乐
|
||||
*/
|
||||
private final PlayerAddMusicObj music;
|
||||
/**
|
||||
* 添加者
|
||||
*/
|
||||
private final ServerPlayer player;
|
||||
|
||||
private boolean cancel;
|
||||
|
||||
public MusicAddEvent(PlayerAddMusicObj id, ServerPlayer player) {
|
||||
this.music = id;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public boolean isCancel() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public void setCancel(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
public ServerPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public PlayerAddMusicObj getMusic() {
|
||||
return music;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.coloryr.allmusic.server.event;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
|
||||
import net.neoforged.bus.api.Event;
|
||||
|
||||
public class MusicPlayEvent extends Event {
|
||||
private final SongInfoObj music;
|
||||
private boolean cancel;
|
||||
|
||||
public MusicPlayEvent(SongInfoObj music) {
|
||||
this.music = music;
|
||||
}
|
||||
|
||||
public boolean isCancel() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public void setCancel(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
public SongInfoObj getMusic() {
|
||||
return music;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[2,)"
|
||||
license = "GPL-3.0"
|
||||
issueTrackerURL = "https://github.com/Coloryr/AllMusic/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "allmusic_server"
|
||||
version = "${version}"
|
||||
displayName = "AllMusic Server"
|
||||
displayURL = "https://github.com/Coloryr/AllMusic/"
|
||||
logoFile = "icon.png"
|
||||
authors = "Color_yr"
|
||||
description = '''AllMusic Server Mod'''
|
||||
|
||||
[[dependencies.allmusic_server]]
|
||||
modId = "neoforge"
|
||||
type = "required"
|
||||
versionRange = "[26.2.0.1-beta,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.allmusic_server]]
|
||||
modId = "minecraft"
|
||||
type = "required"
|
||||
versionRange = "[26.2,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -28,6 +28,7 @@ include(":server:fabric_1_21")
|
||||
include(":server:fabric_1_21_6")
|
||||
include(":server:fabric_1_21_11")
|
||||
include(":server:fabric_26_1")
|
||||
include(":server:fabric_26_2")
|
||||
|
||||
//include(":server:forge_1_7_10")
|
||||
//include(":server:forge_1_12_2")
|
||||
@@ -38,6 +39,7 @@ include(":server:neoforge_1_21")
|
||||
include(":server:neoforge_1_21_6")
|
||||
include(":server:neoforge_1_21_11")
|
||||
include(":server:neoforge_26_1")
|
||||
include(":server:neoforge_26_2")
|
||||
|
||||
include(":server:spigot")
|
||||
include(":server:paper")
|
||||
|
||||
Reference in new issue
Block a user