up fabric1.21.4

This commit is contained in:
Color_yr committed 2025-01-27 17:31:15 +08:00
1 parent 5185822435
commit ffb979212a
26 files changed
+1305 -4

No files matched your search

+22
View File
@@ -237,6 +237,28 @@ jobs:
with:
name: "allmusic_server_fabric_1_21"
path: build/libs/
build_fabric_1_21_4:
runs-on: windows-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3 # v3.1.0
- name: build
shell: cmd
run: |
link.cmd && cd fabric_1_21_4 && gradlew build
- name: update
uses: actions/upload-artifact@v4
with:
name: "allmusic_server_fabric_1_21_4"
path: build/libs/
build_forge_1_7_10:
runs-on: windows-latest
permissions:
+40
View File
@@ -0,0 +1,40 @@
# gradle
.gradle/
build/
out/
classes/
# eclipse
*.launch
# idea
.idea/
*.iml
*.ipr
*.iws
# vscode
.settings/
.vscode/
bin/
.classpath
.project
# macos
*.DS_Store
# fabric
run/
# java
hs_err_*.log
replay_*.log
*.hprof
*.jfr
+97
View File
@@ -0,0 +1,97 @@
plugins {
id 'fabric-loom' version '1.9-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "2.1.0"
}
def getVersionFromFile() {
def versionFile = file('../version')
if (versionFile.exists()) {
return versionFile.text.trim()
} else {
throw new GradleException("Version file not found: ${versionFile.absolutePath}")
}
}
version = getVersionFromFile()
group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
include modImplementation('com.squareup.okio:okio-jvm:3.6.0')
include modImplementation('com.squareup.okhttp3:okhttp:4.12.0')
include modImplementation('org.xerial:sqlite-jdbc:3.48.0.0')
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = 21
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}
// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
+17
View File
@@ -0,0 +1,17 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.10
fabric_kotlin_version=1.13.0+kotlin.2.1.0
# Mod Properties
maven_group = com.coloryr.allmusic.server
archives_base_name =[fabric-1.21.4]AllMusic_Server
# Dependencies
fabric_version=0.115.0+1.21.4
Binary file not shown.
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
+244
View File
@@ -0,0 +1,244 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
+92
View File
@@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+12
View File
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = 'AllMusic_Server'
@@ -0,0 +1,49 @@
package com.coloryr.allmusic.server;
import com.coloryr.allmusic.server.core.AllMusic;
import com.coloryr.allmusic.server.side.fabric.CommandFabric;
import com.coloryr.allmusic.server.side.fabric.LogFabric;
import com.coloryr.allmusic.server.side.fabric.SideFabric;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class AllMusicFabric implements ModInitializer {
public static MinecraftServer server;
public static final Logger LOGGER = LoggerFactory.getLogger("AllMusic_Server");
public static final Identifier ID = Identifier.of("allmusic", "channel");
@Override
public void onInitialize() {
String path = "allmusic3/";
AllMusic.log = new LogFabric();
AllMusic.side = new SideFabric();
new AllMusic().init(new File(path));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment)
-> CommandFabric.instance.register(dispatcher));
PayloadTypeRegistry.playS2C().register(PackPayload.ID, PackPayload.CODEC);
ServerLifecycleEvents.SERVER_STARTED.register((a) -> {
server = a;
AllMusic.start();
Tasks.init();
});
ServerLifecycleEvents.SERVER_STOPPING.register((a) -> {
AllMusic.stop();
});
}
}
@@ -0,0 +1,18 @@
package com.coloryr.allmusic.server;
import com.coloryr.allmusic.server.core.objs.enums.ComType;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
public record PackPayload(ComType type, String data, int data1) implements CustomPayload {
public static final Id<PackPayload> ID = new CustomPayload.Id<>(AllMusicFabric.ID);
public static final PacketCodec<PacketByteBuf, PackPayload> CODEC =
PacketCodec.of((value, buf) -> com.coloryr.allmusic.server.codec.PacketCodec.pack(buf, value.type, value.data, value.data1),
buffer -> new PackPayload(ComType.CLEAR, null, 0));
@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}
@@ -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() {
AllMusicFabric.server.addServerGuiTickable(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,13 @@
package com.coloryr.allmusic.server.mixin;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.command.ServerCommandSource;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ServerCommandSource.class)
public interface IGetCommandOutput {
@Accessor(value = "output")
CommandOutput getOutput();
}
@@ -0,0 +1,24 @@
package com.coloryr.allmusic.server.mixin;
import com.coloryr.allmusic.server.core.AllMusic;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayerEntity;
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(PlayerManager.class)
public class ServerPlayerMixin {
@Inject(at = @At("HEAD"), method = "remove")
private void remove(ServerPlayerEntity entity, CallbackInfo info) {
AllMusic.removeNowPlayPlayer(entity.getName().getString());
}
@Inject(at = @At("TAIL"), method = "onPlayerConnect")
private void add(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
AllMusic.joinPlay(player.getName().getString());
}
}
@@ -0,0 +1,66 @@
package com.coloryr.allmusic.server.side.fabric;
import com.coloryr.allmusic.server.core.command.CommandEX;
import com.coloryr.allmusic.server.mixin.IGetCommandOutput;
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.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
public class CommandFabric implements Command<ServerCommandSource>, Predicate<ServerCommandSource>, SuggestionProvider<ServerCommandSource> {
public static CommandFabric instance = new CommandFabric();
public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(((CommandManager.literal("music").requires(this)).executes(this))
.then(CommandManager.argument("args", StringArgumentType.greedyString())
.suggests(this).executes(this)));
}
@Override
public int run(CommandContext<ServerCommandSource> context) {
var item = context.getSource();
var source = ((IGetCommandOutput) item).getOutput();
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(source, context.getSource().getName(), arg);
return 0;
}
@Override
public boolean test(ServerCommandSource stack) {
return true;
}
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> 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<String> results = CommandEX.getTabList(context.getSource().getName(), arg);
for (String s : results) {
builder.suggest(s);
}
return builder.buildFuture();
}
}
@@ -0,0 +1,48 @@
package com.coloryr.allmusic.server.side.fabric;
import com.coloryr.allmusic.server.AllMusicFabric;
import com.coloryr.allmusic.server.core.AllMusic;
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
public class FabricApi {
public static void sendMessageRun(Object obj, String message, String end, String command) {
CommandOutput sender = (CommandOutput) obj;
MutableText send = Text.literal(message);
var endText = Text.literal(end);
endText.setStyle(endText.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)));
send.append(endText);
sender.sendMessage(send);
}
public static void sendMessageSuggest(Object obj, String message, String end, String command) {
CommandOutput sender = (CommandOutput) obj;
MutableText send = Text.literal(message);
var endText = Text.literal(end);
endText.setStyle(endText.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
send.append(endText);
sender.sendMessage(send);
}
public static void sendBar(ServerPlayerEntity player, String message) {
var pack = new OverlayMessageS2CPacket(Text.literal(message));
player.networkHandler.sendPacket(pack);
}
public static void sendMessageBqRun(String message, String end, String command) {
MutableText send = Text.literal(message);
MutableText endText = Text.literal(end);
endText.setStyle(endText.getStyle().withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)));
send.append(endText);
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (!AllMusic.getConfig().mutePlayer.contains(player.getName().getString())) {
player.sendMessage(send, false);
}
}
}
}
@@ -0,0 +1,16 @@
package com.coloryr.allmusic.server.side.fabric;
import com.coloryr.allmusic.server.AllMusicFabric;
import com.coloryr.allmusic.server.core.side.IMyLogger;
public class LogFabric implements IMyLogger {
@Override
public void warning(String data) {
AllMusicFabric.LOGGER.warn(data);
}
@Override
public void info(String data) {
AllMusicFabric.LOGGER.info(data);
}
}
@@ -0,0 +1,402 @@
package com.coloryr.allmusic.server.side.fabric;
import com.coloryr.allmusic.server.AllMusicFabric;
import com.coloryr.allmusic.server.PackPayload;
import com.coloryr.allmusic.server.TaskItem;
import com.coloryr.allmusic.server.Tasks;
import com.coloryr.allmusic.server.core.AllMusic;
import com.coloryr.allmusic.server.core.objs.config.SaveObj;
import com.coloryr.allmusic.server.core.objs.enums.ComType;
import com.coloryr.allmusic.server.core.objs.enums.HudType;
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
import com.coloryr.allmusic.server.core.objs.music.SongInfoObj;
import com.coloryr.allmusic.server.core.side.BaseSide;
import com.coloryr.allmusic.server.core.utils.HudUtils;
import com.coloryr.allmusic.server.side.fabric.event.MusicAddEvent;
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SideFabric extends BaseSide {
@Override
public void reload() {
String path = "allmusic/";
new AllMusic().init(new File(path));
}
@Override
public int getPlayerSize() {
return AllMusicFabric.server.getCurrentPlayerCount();
}
@Override
public void runTask(Runnable run) {
AllMusicFabric.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) {
if (player instanceof MinecraftServer) {
return true;
}
if (player instanceof PlayerEntity) {
return ((PlayerEntity) player).hasPermissionLevel(2);
}
return false;
}
@Override
public boolean isPlayer(Object source) {
return source instanceof PlayerEntity;
}
@Override
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}
@Override
public boolean needPlay() {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (!AllMusic.isSkip(player.getName().getString(), null, false)) {
return true;
}
}
return false;
}
@Override
protected void sideSendStop() {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
send(player, new PackPayload(ComType.STOP, null, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
e.printStackTrace();
}
}
@Override
protected void sideSendStop(String name) {
try {
var player = AllMusicFabric.server.getPlayerManager().getPlayer(name);
if (player == null)
return;
send(player, new PackPayload(ComType.STOP, null, 0));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
e.printStackTrace();
}
}
@Override
public void sendMusic(String data) {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (AllMusic.isSkip(player.getName().getString(), null, false))
continue;
send(player, new PackPayload(ComType.PLAY, data, 0));
AllMusic.addNowPlayPlayer(player.getName().getString());
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c歌曲指令发送出错");
e.printStackTrace();
}
}
@Override
protected void sideSendMusic(String player, String data) {
try {
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isSkip(player, null, false))
return;
send(player1, new PackPayload(ComType.PLAY, data, 0));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c歌曲指令发送出错");
e.printStackTrace();
}
}
@Override
public void sendPic(String data) {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (AllMusic.isSkip(player.getName().getString(), null, true))
continue;
String name = player.getName().getString();
SaveObj obj = HudUtils.get(name);
if (!obj.pic.enable)
continue;
send(player, new PackPayload(ComType.IMG, data, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c图片指令发送出错");
e.printStackTrace();
}
}
@Override
public void sendPic(String player, String data) {
try {
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isSkip(player1.getName().getString(), null, true))
return;
send(player1, new PackPayload(ComType.IMG, data, 0));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c图片指令发送出错");
e.printStackTrace();
}
}
@Override
public void sendPos(String player, int pos) {
try {
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isSkip(player1.getName().getString(), null, true))
return;
send(player1, new PackPayload(ComType.POS, null, pos));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错");
e.printStackTrace();
}
}
@Override
public void sendHudLyric(String data) {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (AllMusic.isSkip(player.getName().getString(), null, true))
continue;
String name = player.getName().getString();
SaveObj obj = HudUtils.get(name);
if (!obj.lyric.enable)
continue;
send(player, new PackPayload(ComType.LYRIC, data, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c歌词发送出错");
e.printStackTrace();
}
}
@Override
public void sendHudInfo(String data) {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (AllMusic.isSkip(player.getName().getString(), null, true))
continue;
String name = player.getName().getString();
SaveObj obj = HudUtils.get(name);
if (!obj.info.enable)
continue;
send(player, new PackPayload(ComType.INFO, data, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c歌词信息发送出错");
e.printStackTrace();
}
}
@Override
public void sendHudPos(String name) {
try {
var player = AllMusicFabric.server.getPlayerManager().getPlayer(name);
if (player == null)
return;
SaveObj obj = HudUtils.get(name);
String data = AllMusic.gson.toJson(obj);
send(player, new PackPayload(ComType.HUD, data, 0));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c界面位置发送出错");
e.printStackTrace();
}
}
@Override
public void sendHud(String name, HudType pos, String data) {
try {
if (pos == HudType.PIC) {
return;
}
var player = AllMusicFabric.server.getPlayerManager().getPlayer(name);
if (player == null)
return;
if (AllMusic.isSkip(name, null, true))
return;
switch (pos) {
case INFO:
send(player, new PackPayload(ComType.INFO, data, 0));
break;
case LIST:
send(player, new PackPayload(ComType.LIST, data, 0));
break;
case LYRIC:
send(player, new PackPayload(ComType.LYRIC, data, 0));
break;
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c停止指令发送出错");
e.printStackTrace();
}
}
@Override
public void sendHudList(String data) {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (AllMusic.isSkip(player.getName().getString(), null, true))
continue;
String name = player.getName().getString();
SaveObj obj = HudUtils.get(name);
if (!obj.list.enable)
continue;
send(player, new PackPayload(ComType.LIST, data, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c歌曲列表发送出错");
e.printStackTrace();
}
}
@Override
public void sendHudUtilsAll() {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
String Name = player.getName().getString();
try {
SaveObj obj = HudUtils.get(Name);
String data = AllMusic.gson.toJson(obj);
send(player, new PackPayload(ComType.HUD, data, 0));
} catch (Exception e1) {
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
e1.printStackTrace();
}
}
}
@Override
public void sendBar(String data) {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
try {
if (AllMusic.isSkip(player.getName().getString(), null, true))
continue;
FabricApi.sendBar(player, data);
} catch (Exception e1) {
AllMusic.log.warning("§d[AllMusic]§c数据发送发生错误");
e1.printStackTrace();
}
}
}
@Override
public void clearHud(String name) {
try {
var player = AllMusicFabric.server.getPlayerManager().getPlayer(name);
if (player == null)
return;
send(player, new PackPayload(ComType.CLEAR, null, 0));
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错");
e.printStackTrace();
}
}
@Override
public void clearHud() {
try {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
send(player, new PackPayload(ComType.CLEAR, null, 0));
}
} catch (Exception e) {
AllMusic.log.warning("§d[AllMusic]§c清空Hud发生出错");
e.printStackTrace();
}
}
@Override
public void broadcast(String data) {
for (var player : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
if (!AllMusic.isSkip(player.getName().getString(), null, false)) {
player.sendMessage(Text.of(data), false);
}
}
}
@Override
public void broadcastWithRun(String message, String end, String command) {
FabricApi.sendMessageBqRun(message, end, command);
}
@Override
public void sendMessage(Object obj, String message) {
CommandOutput sender = (CommandOutput) obj;
sender.sendMessage(Text.of(message));
}
@Override
public void sendMessageRun(Object obj, String message, String end, String command) {
FabricApi.sendMessageRun(obj, message, end, command);
}
@Override
public void sendMessageSuggest(Object obj, String message, String end, String command) {
FabricApi.sendMessageSuggest(obj, message, end, command);
}
@Override
public boolean onMusicPlay(SongInfoObj obj) {
return MusicPlayEvent.EVENT.invoker().interact(obj) != ActionResult.PASS;
}
@Override
public boolean onMusicAdd(Object obj, MusicObj music) {
return MusicAddEvent.EVENT.invoker().interact((ServerPlayerEntity) obj, music) != ActionResult.PASS;
}
@Override
public List<String> getPlayerList() {
var list = new ArrayList<String>();
for (var item : AllMusicFabric.server.getPlayerManager().getPlayerList()) {
list.add(item.getGameProfile().getName());
}
return list;
}
private void send(ServerPlayerEntity players, PackPayload data) {
if (players == null)
return;
try {
runTask(() -> ServerPlayNetworking.send(players, data));
} catch (Exception e) {
AllMusic.log.warning("§c数据发送发生错误");
e.printStackTrace();
}
}
}
@@ -0,0 +1,24 @@
package com.coloryr.allmusic.server.side.fabric.event;
import com.coloryr.allmusic.server.core.objs.music.MusicObj;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
public interface MusicAddEvent {
Event<MusicAddEvent> EVENT = EventFactory.createArrayBacked(MusicAddEvent.class,
(listeners) -> (player, music) -> {
for (MusicAddEvent listener : listeners) {
ActionResult result = listener.interact(player, music);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult interact(ServerPlayerEntity player, MusicObj music);
}
@@ -0,0 +1,23 @@
package com.coloryr.allmusic.server.side.fabric.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.util.ActionResult;
public interface MusicPlayEvent {
Event<MusicPlayEvent> EVENT = EventFactory.createArrayBacked(MusicPlayEvent.class,
(listeners) -> (music) -> {
for (MusicPlayEvent listener : listeners) {
ActionResult result = listener.interact(music);
if (result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult interact(SongInfoObj music);
}
@@ -0,0 +1,16 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.coloryr.allmusic.server.mixin",
"compatibilityLevel": "JAVA_21",
"server": [
],
"mixins": [
"IGetCommandOutput",
"ServerPlayerMixin"
],
"injectors": {
"defaultRequire": 1
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

@@ -0,0 +1,38 @@
{
"schemaVersion": 1,
"id": "allmusic_server",
"version": "${version}",
"name": "AllMusic Server",
"description": "AllMusic Server Mod",
"authors": [
"Color_yr"
],
"contact": {
"homepage": "https://github.com/Coloryr/AllMusic_Server",
"sources": "https://github.com/Coloryr/AllMusic_Server"
},
"license": "GPL-3.0",
"icon": "assets/allmusic_server/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.coloryr.allmusic.server.AllMusicFabric"
]
},
"mixins": [
"allmusic_server.mixins.json"
],
"depends": {
"fabricloader": ">=0.16.10",
"minecraft": "~1.21.4",
"java": ">=21",
"fabric-api": "*",
"fabric-language-kotlin": "*"
},
"suggests": {
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ set array=folia server_top server forge_1_20 ^
forge_1_19_2 forge_1_18_2 forge_1_16_5 forge_1_12_2 forge_1_7_10 ^
fabric_1_20_2 fabric_1_20 fabric_1_19_3 fabric_1_19_2 fabric_1_18_2 ^
fabric_1_16_5 fabric_1_20_6 fabric_1_21 neoforge_1_20_4 neoforge_1_20_5 neoforge_1_21 ^
neoforge_1_21_4
neoforge_1_21_4 fabric_1_21_4
for %%i in (%array%) do (
if not exist "%%i\src\main\java\com\coloryr\allmusic\server\core" mklink /j "%%i\src\main\java\com\coloryr\allmusic\server\core" "core"
@@ -21,7 +21,7 @@ set array1=folia server_top forge_1_20 ^
forge_1_19_2 forge_1_18_2 forge_1_16_5 forge_1_12_2 forge_1_7_10 ^
fabric_1_20_2 fabric_1_20 fabric_1_19_3 fabric_1_19_2 fabric_1_18_2 ^
fabric_1_16_5 fabric_1_20_6 fabric_1_21 neoforge_1_20_4 neoforge_1_20_5 neoforge_1_21 ^
neoforge_1_21_4
neoforge_1_21_4 fabric_1_21_4
for %%i in (%array1%) do (
if not exist "%%i\src\main\java\com\coloryr\allmusic\server\codec" mklink /j "%%i\src\main\java\com\coloryr\allmusic\server\codec" "codec"
+2 -2
View File
@@ -9,7 +9,7 @@ set array=folia server_top server forge_1_20 ^
forge_1_19_2 forge_1_18_2 forge_1_16_5 forge_1_12_2 forge_1_7_10 ^
fabric_1_20_2 fabric_1_20 fabric_1_19_3 fabric_1_19_2 fabric_1_18_2 ^
fabric_1_16_5 fabric_1_20_6 fabric_1_21 neoforge_1_20_4 neoforge_1_20_5 neoforge_1_21 ^
neoforge_1_21_4
neoforge_1_21_4 fabric_1_21_4
for %%i in (%array%) do (
if exist "%%i\src\main\java\com\coloryr\allmusic\server\core" rmdir "%%i\src\main\java\com\coloryr\allmusic\server\core" "core"
@@ -21,7 +21,7 @@ set array1=folia server_top forge_1_20 ^
forge_1_19_2 forge_1_18_2 forge_1_16_5 forge_1_12_2 forge_1_7_10 ^
fabric_1_20_2 fabric_1_20 fabric_1_19_3 fabric_1_19_2 fabric_1_18_2 ^
fabric_1_16_5 fabric_1_20_6 fabric_1_21 neoforge_1_20_4 neoforge_1_20_5 neoforge_1_21 ^
neoforge_1_21_4
neoforge_1_21_4 fabric_1_21_4
for %%i in (%array1%) do (
if exist "%%i\src\main\java\com\coloryr\allmusic\server\codec" rmdir "%%i\src\main\java\com\coloryr\allmusic\server\codec" "codec"