mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-22 09:39:42 +00:00
26.1
This commit is contained in:
1 parent
efe3df228c
commit
63ce089b01
33 files changed
+635
-53
No files matched your search
+1
-1
Submodule client updated: 482519633a...3b14dd91ad.
@@ -14,6 +14,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -123,7 +124,7 @@ public class SideFabric extends BaseSide {
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
return MusicPlayEvent.EVENT.invoker().interact(obj);
|
||||
return MusicPlayEvent.EVENT.invoker().interact(obj) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,7 +134,7 @@ public class SideFabric extends BaseSide {
|
||||
if (sender.getEntity() instanceof ServerPlayer) {
|
||||
entity = (ServerPlayer) sender.getEntity();
|
||||
}
|
||||
return MusicAddEvent.EVENT.invoker().interact(entity, music);
|
||||
return MusicAddEvent.EVENT.invoker().interact(entity, music) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, ByteBuf data) {
|
||||
|
||||
+12
-5
@@ -4,20 +4,27 @@ 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) {
|
||||
boolean result = listener.interact(player, music);
|
||||
InteractionResult result = listener.interact(player, music);
|
||||
|
||||
if (result) {
|
||||
return true;
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
/**
|
||||
* 音乐添加事件,返回PASS表示通过
|
||||
* @param player 玩家
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+13
-4
@@ -3,18 +3,27 @@ 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) {
|
||||
if (listener.interact(music)) {
|
||||
return true;
|
||||
InteractionResult result = listener.interact(music);
|
||||
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(SongInfoObj music);
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ java.targetCompatibility = JavaVersion.VERSION_17
|
||||
dependencies {
|
||||
minecraft("com.mojang:minecraft:1.20.1")
|
||||
mappings(loom.officialMojangMappings())
|
||||
modCompileOnly("net.fabricmc:fabric-loader:0.16.10")
|
||||
modImplementation("net.fabricmc:fabric-loader:0.16.10")
|
||||
|
||||
modCompileOnly("net.fabricmc.fabric-api:fabric-api:0.92.3+1.20.1")
|
||||
modCompileOnly("net.kyori:adventure-platform-fabric:5.9.0")
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:0.92.3+1.20.1")
|
||||
modImplementation("net.kyori:adventure-platform-fabric:5.9.0")
|
||||
|
||||
shadowImplementation("net.kyori:adventure-text-minimessage:4.26.1")
|
||||
shadowImplementation("net.kyori:adventure-api:4.26.1")
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -119,13 +120,13 @@ public class SideFabric extends BaseSide {
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
return !MusicPlayEvent.EVENT.invoker().interact(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);
|
||||
return MusicAddEvent.EVENT.invoker().interact(source.getPlayer(), music) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, ByteBuf data) {
|
||||
|
||||
+6
@@ -20,5 +20,11 @@ public interface MusicAddEvent {
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
/**
|
||||
* 音乐添加事件,返回PASS表示通过
|
||||
* @param player 玩家
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+5
@@ -19,5 +19,10 @@ public interface MusicPlayEvent {
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -120,13 +121,13 @@ public class SideFabric extends BaseSide {
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
return !MusicPlayEvent.EVENT.invoker().interact(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);
|
||||
return MusicAddEvent.EVENT.invoker().interact(source.getPlayer(), music) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, MusicPack data) {
|
||||
|
||||
+13
-5
@@ -4,20 +4,28 @@ 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) {
|
||||
boolean result = listener.interact(player, music);
|
||||
InteractionResult result = listener.interact(player, music);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
/**
|
||||
* 音乐添加事件,返回PASS表示通过
|
||||
* @param player 玩家
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
|
||||
+6
-1
@@ -19,5 +19,10 @@ public interface MusicPlayEvent {
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
}
|
||||
+12
-5
@@ -4,20 +4,27 @@ 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) {
|
||||
boolean result = listener.interact(player, music);
|
||||
InteractionResult result = listener.interact(player, music);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
/**
|
||||
* 音乐添加事件,返回PASS表示通过
|
||||
* @param player 玩家
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+10
-4
@@ -3,20 +3,26 @@ 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) {
|
||||
boolean result = listener.interact(music);
|
||||
InteractionResult result = listener.interact(music);
|
||||
|
||||
if (!result) {
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(SongInfoObj music);
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.io.File;
|
||||
public class AllMusicServer implements DedicatedServerModInitializer {
|
||||
public static MinecraftServer server;
|
||||
|
||||
public static final ResourceLocation ID = new ResourceLocation("allmusic", "channel");
|
||||
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("allmusic", "channel");
|
||||
|
||||
public static final String dir = "allmusic_server/";
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -120,13 +121,13 @@ public class SideFabric extends BaseSide {
|
||||
|
||||
@Override
|
||||
public boolean onMusicPlay(SongInfoObj obj) {
|
||||
return !MusicPlayEvent.EVENT.invoker().interact(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);
|
||||
return MusicAddEvent.EVENT.invoker().interact(source.getPlayer(), music) != InteractionResult.PASS;
|
||||
}
|
||||
|
||||
private void send(ServerPlayer players, MusicPack data) {
|
||||
|
||||
+12
-5
@@ -4,20 +4,27 @@ 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) {
|
||||
boolean result = listener.interact(player, music);
|
||||
InteractionResult result = listener.interact(player, music);
|
||||
|
||||
if (!result) {
|
||||
return false;
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
/**
|
||||
* 音乐添加事件,返回PASS表示通过
|
||||
* @param player 玩家
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+10
-4
@@ -3,20 +3,26 @@ 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) {
|
||||
boolean result = listener.interact(music);
|
||||
InteractionResult result = listener.interact(music);
|
||||
|
||||
if (!result) {
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(SongInfoObj music);
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.coloryr.allmusic.server.event;
|
||||
|
||||
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
|
||||
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;
|
||||
@@ -20,5 +20,5 @@ public interface MusicAddEvent {
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
InteractionResult interact(ServerPlayer player, MusicObj music);
|
||||
InteractionResult interact(ServerPlayer player, PlayerAddMusicObj music);
|
||||
}
|
||||
+10
-4
@@ -3,20 +3,26 @@ 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) {
|
||||
boolean result = listener.interact(music);
|
||||
InteractionResult result = listener.interact(music);
|
||||
|
||||
if (!result) {
|
||||
if (result != InteractionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
|
||||
boolean interact(SongInfoObj music);
|
||||
/**
|
||||
* 音乐播放事件,返回PASS表示通过
|
||||
* @param music 歌曲信息
|
||||
* @return 是否通过
|
||||
*/
|
||||
InteractionResult interact(SongInfoObj music);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom-no-remap") version "1.14-SNAPSHOT"
|
||||
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.1")
|
||||
neoForge("net.neoforged:neoforge:26.1.0.19-beta")
|
||||
|
||||
modImplementation("net.kyori:adventure-platform-neoforge:6.9.0")
|
||||
|
||||
shadowImplementation("net.kyori:adventure-text-minimessage:4.26.1")
|
||||
shadowImplementation("net.kyori:adventure-api:4.26.1")
|
||||
shadowImplementation("net.kyori:adventure-text-serializer-gson:4.8.1")
|
||||
shadowImplementation("net.kyori:adventure-text-serializer-legacy:4.8.1")
|
||||
shadowImplementation("net.kyori:adventure-text-serializer-plain:4.8.1")
|
||||
shadowImplementation("net.kyori:adventure-key:4.8.1")
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
filesMatching("META-INF/mods.toml") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate("net.kyori", "com.coloryr.allmusic.libs.net.kyori")
|
||||
relocate("com.google.gson", "com.coloryr.allmusic.libs.com.google.gson")
|
||||
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
archiveFileName.set("[neoforge-26.1]AllMusic_Server-${project.version}.jar")
|
||||
destinationDirectory.set(file("${parent!!.projectDir}/target"))
|
||||
}
|
||||
|
||||
// remapJar {
|
||||
// inputFile.set(shadowJar.get().archiveFile)
|
||||
// archiveFileName.set("[neoforge-1.21.11]AllMusic_Server-${project.version}.jar")
|
||||
// destinationDirectory.set(file("${parent!!.projectDir}/target"))
|
||||
// }
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
loom.platform = neoforge
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.coloryr.allmusic.comm;
|
||||
|
||||
import com.coloryr.allmusic.buffercodec.MusicPacketCodec;
|
||||
import com.coloryr.allmusic.codec.MusicPack;
|
||||
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,76 @@
|
||||
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 final String dir = "config/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) {
|
||||
LOGGER.info("注册指令");
|
||||
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(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,142 @@
|
||||
package com.coloryr.allmusic.server;
|
||||
|
||||
import com.coloryr.allmusic.codec.CommandType;
|
||||
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, CommandType type, String data, int data1) {
|
||||
if (player instanceof ServerPlayer player1) {
|
||||
send(player1, new MusicPack(type, data, data1));
|
||||
}
|
||||
}
|
||||
|
||||
@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(AllMusicServer.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_Server/issues"
|
||||
|
||||
[[mods]]
|
||||
modId="allmusic_server"
|
||||
version="${version}"
|
||||
displayName="AllMusic Server"
|
||||
displayURL="https://github.com/Coloryr/AllMusic_Server/"
|
||||
logoFile="icon.png"
|
||||
authors="Color_yr"
|
||||
description='''AllMusic Server Mod'''
|
||||
|
||||
[[dependencies.allmusic_server]]
|
||||
modId="neoforge"
|
||||
type="required"
|
||||
versionRange="[26.1.0.19-beta,)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.allmusic_server]]
|
||||
modId="minecraft"
|
||||
type="required"
|
||||
versionRange="[26.1)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
+6
-1
@@ -5,6 +5,8 @@ project(":codec").projectDir = file("client/codec")
|
||||
include(":codec:buffercodec")
|
||||
project(":codec:buffercodec").projectDir = file("client/codec/buffercodec")
|
||||
|
||||
include(":client")
|
||||
project(":client").projectDir = file("client/client")
|
||||
include(":client:core")
|
||||
project(":client:core").projectDir = file("client/client/core")
|
||||
include(":client:fabric_1_16_5")
|
||||
@@ -33,6 +35,8 @@ include(":client:neoforge_1_21_6")
|
||||
project(":client:neoforge_1_21_6").projectDir = file("client/client/neoforge_1_21_6")
|
||||
include(":client:neoforge_1_21_11")
|
||||
project(":client:neoforge_1_21_11").projectDir = file("client/client/neoforge_1_21_11")
|
||||
include(":client:neoforge_26_1")
|
||||
project(":client:neoforge_26_1").projectDir = file("client/client/neoforge_26_1")
|
||||
|
||||
include(":server")
|
||||
include(":server:core")
|
||||
@@ -42,7 +46,7 @@ include(":server:fabric_1_20_1")
|
||||
include(":server:fabric_1_21")
|
||||
include(":server:fabric_1_21_6")
|
||||
include(":server:fabric_1_21_11")
|
||||
//include(":server:fabric_26_1") // adventure未更新
|
||||
include(":server:fabric_26_1")
|
||||
|
||||
include(":server:forge_1_7_10")
|
||||
include(":server:forge_1_12_2")
|
||||
@@ -52,6 +56,7 @@ include(":server:forge_1_20_1")
|
||||
include(":server:neoforge_1_21")
|
||||
include(":server:neoforge_1_21_6")
|
||||
include(":server:neoforge_1_21_11")
|
||||
include(":server:neoforge_26_1")
|
||||
|
||||
include(":server:spigot")
|
||||
include(":server:paper")
|
||||
|
||||
Reference in new issue
Block a user