Skip to content

Commit

Permalink
Update to MC 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Oct 26, 2024
1 parent 6856fca commit c58ddcf
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 85 deletions.
6 changes: 3 additions & 3 deletions spark-fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ configurations {

dependencies {
// https://modmuss50.me/fabric.html
minecraft 'com.mojang:minecraft:1.21.2'
mappings 'net.fabricmc:yarn:1.21.2+build.1:v2'
minecraft 'com.mojang:minecraft:1.21.3'
mappings 'net.fabricmc:yarn:1.21.3+build.2:v2'
modImplementation 'net.fabricmc:fabric-loader:0.16.7'

Set<String> apiModules = [
Expand All @@ -40,7 +40,7 @@ dependencies {

// Add each module as a dependency
apiModules.forEach {
modImplementation(fabricApi.module(it, '0.106.1+1.21.2'))
modImplementation(fabricApi.module(it, '0.106.1+1.21.3'))
}

include(modImplementation('me.lucko:fabric-permissions-api:0.3.2'))
Expand Down
4 changes: 2 additions & 2 deletions spark-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tasks.withType(JavaCompile) {
}

minecraft {
mappings channel: 'official', version: '1.21.1'
mappings channel: 'official', version: '1.21.3'
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
reobf = false
}
Expand All @@ -20,7 +20,7 @@ configurations {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.21.1-52.0.2'
minecraft 'net.minecraftforge:forge:1.21.3-53.0.0'
shade project(':spark-common')
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.forge;

import me.lucko.spark.common.command.sender.AbstractCommandSender;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component.Serializer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.Entity;

import java.util.Objects;
import java.util.UUID;

public class ForgeClientCommandSender extends AbstractCommandSender<CommandSourceStack> {
public ForgeClientCommandSender(CommandSourceStack source) {
super(source);
}

@Override
public String getName() {
return this.delegate.getTextName();
}

@Override
public UUID getUniqueId() {
Entity entity = this.delegate.getEntity();
if (entity instanceof LocalPlayer player) {
return player.getUUID();
}
return null;
}

@Override
public void sendMessage(Component message) {
MutableComponent component = Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(message), RegistryAccess.EMPTY);
Objects.requireNonNull(component, "component");
super.delegate.sendSystemMessage(component);
}

@Override
public boolean hasPermission(String permission) {
return true;
}

@Override
protected Object getObjectForComparison() {
return this.delegate.getEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,39 @@
package me.lucko.spark.forge;

import me.lucko.spark.common.command.sender.AbstractCommandSender;
import me.lucko.spark.forge.plugin.ForgeSparkPlugin;
import me.lucko.spark.forge.plugin.ForgeServerSparkPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component.Serializer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.rcon.RconConsoleSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.Entity;

import java.util.Objects;
import java.util.UUID;

public class ForgeCommandSender extends AbstractCommandSender<CommandSource> {
private final ForgeSparkPlugin plugin;
public class ForgeServerCommandSender extends AbstractCommandSender<CommandSourceStack> {
private final ForgeServerSparkPlugin plugin;

public ForgeCommandSender(CommandSource source, ForgeSparkPlugin plugin) {
super(source);
public ForgeServerCommandSender(CommandSourceStack commandSource, ForgeServerSparkPlugin plugin) {
super(commandSource);
this.plugin = plugin;
}

@Override
public String getName() {
if (super.delegate instanceof Player) {
return ((Player) super.delegate).getGameProfile().getName();
} else if (super.delegate instanceof MinecraftServer) {
String name = this.delegate.getTextName();
if (this.delegate.getEntity() != null && name.equals("Server")) {
return "Console";
} else if (super.delegate instanceof RconConsoleSource) {
return "RCON Console";
} else {
return "unknown:" + super.delegate.getClass().getSimpleName();
}
return name;
}

@Override
public UUID getUniqueId() {
if (super.delegate instanceof Player) {
return ((Player) super.delegate).getUUID();
}
return null;
Entity entity = this.delegate.getEntity();
return entity != null ? entity.getUUID() : null;
}

@Override
Expand All @@ -73,6 +65,19 @@ public void sendMessage(Component message) {

@Override
public boolean hasPermission(String permission) {
return this.plugin.hasPermission(super.delegate, permission);
return this.plugin.hasPermission(this.delegate, permission);
}

@Override
protected Object getObjectForComparison() {
UUID uniqueId = getUniqueId();
if (uniqueId != null) {
return uniqueId;
}
Entity entity = this.delegate.getEntity();
if (entity != null) {
return entity;
}
return getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,19 @@ public GameRulesResult pollGameRules() {
GameRulesResult data = new GameRulesResult();
Iterable<ServerLevel> levels = this.server.getAllLevels();

GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() {
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
String defaultValue = type.createRule().serialize();
data.putDefault(key.getId(), defaultValue);
for (ServerLevel level : levels) {
level.getGameRules().visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() {
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
String defaultValue = type.createRule().serialize();
data.putDefault(key.getId(), defaultValue);

for (ServerLevel level : levels) {
String levelName = level.dimension().location().getPath();

String value = level.getGameRules().getRule(key).serialize();
data.put(key.getId(), levelName, value);
}
}
});
});
}

return data;
}
Expand Down Expand Up @@ -190,28 +189,8 @@ public ChunksResult<ForgeChunkInfo> pollChunks() {

@Override
public GameRulesResult pollGameRules() {
ClientLevel level = this.client.level;
if (level == null) {
return null;
}

GameRulesResult data = new GameRulesResult();

String levelName = level.dimension().location().getPath();
GameRules levelRules = level.getGameRules();

GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() {
@Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
String defaultValue = type.createRule().serialize();
data.putDefault(key.getId(), defaultValue);

String value = levelRules.getRule(key).serialize();
data.put(key.getId(), levelName, value);
}
});

return data;
// Not available on client since 24w39a
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.forge.ForgeCommandSender;
import me.lucko.spark.forge.ForgeClientCommandSender;
import me.lucko.spark.forge.ForgePlatformInfo;
import me.lucko.spark.forge.ForgeSparkMod;
import me.lucko.spark.forge.ForgeTickHook;
import me.lucko.spark.forge.ForgeTickReporter;
import me.lucko.spark.forge.ForgeWorldInfoProvider;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
Expand Down Expand Up @@ -85,7 +85,7 @@ public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxE
return 0;
}

this.platform.executeCommand(new ForgeCommandSender(context.getSource().getEntity(), this), args);
this.platform.executeCommand(new ForgeClientCommandSender(context.getSource()), args);
return Command.SINGLE_SUCCESS;
}

Expand All @@ -96,17 +96,12 @@ public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourc
return Suggestions.empty();
}

return generateSuggestions(new ForgeCommandSender(context.getSource().getEntity(), this), args, builder);
return generateSuggestions(new ForgeClientCommandSender(context.getSource()), args, builder);
}

@Override
public boolean hasPermission(CommandSource sender, String permission) {
return true;
}

@Override
public Stream<ForgeCommandSender> getCommandSenders() {
return Stream.of(new ForgeCommandSender(this.minecraft.player, this));
public Stream<ForgeClientCommandSender> getCommandSenders() {
return Stream.of(new ForgeClientCommandSender(ClientCommandHandler.getSource()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.forge.ForgeCommandSender;
import me.lucko.spark.forge.ForgePlatformInfo;
import me.lucko.spark.forge.ForgePlayerPingProvider;
import me.lucko.spark.forge.ForgeServerCommandSender;
import me.lucko.spark.forge.ForgeServerConfigProvider;
import me.lucko.spark.forge.ForgeSparkMod;
import me.lucko.spark.forge.ForgeTickHook;
import me.lucko.spark.forge.ForgeTickReporter;
import me.lucko.spark.forge.ForgeWorldInfoProvider;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -173,8 +172,7 @@ public int run(CommandContext<CommandSourceStack> context) throws CommandSyntaxE
return 0;
}

CommandSource source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer();
this.platform.executeCommand(new ForgeCommandSender(source, this), args);
this.platform.executeCommand(new ForgeServerCommandSender(context.getSource(), this), args);
return Command.SINGLE_SUCCESS;
}

Expand All @@ -185,12 +183,12 @@ public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourc
return Suggestions.empty();
}

return generateSuggestions(new ForgeCommandSender(context.getSource().getPlayerOrException(), this), args, builder);
return generateSuggestions(new ForgeServerCommandSender(context.getSource(), this), args, builder);
}

@Override
public boolean hasPermission(CommandSource sender, String permission) {
if (sender instanceof ServerPlayer) {
public boolean hasPermission(CommandSourceStack stack, String permission) {
ServerPlayer player = stack.getPlayer();
if (player != null) {
if (permission.equals("spark")) {
permission = "spark.all";
}
Expand All @@ -199,18 +197,18 @@ public boolean hasPermission(CommandSource sender, String permission) {
if (permissionNode == null) {
throw new IllegalStateException("spark permission not registered: " + permission);
}
return PermissionAPI.getPermission((ServerPlayer) sender, permissionNode);
return PermissionAPI.getPermission(player, permissionNode);
} else {
return true;
}
}

@Override
public Stream<ForgeCommandSender> getCommandSenders() {
public Stream<ForgeServerCommandSender> getCommandSenders() {
return Stream.concat(
this.server.getPlayerList().getPlayers().stream(),
Stream.of(this.server)
).map(sender -> new ForgeCommandSender(sender, this));
this.server.getPlayerList().getPlayers().stream().map(ServerPlayer::createCommandSourceStack),
Stream.of(this.server.createCommandSourceStack())
).map(stack -> new ForgeServerCommandSender(stack, this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import me.lucko.spark.common.util.SparkThreadFactory;
import me.lucko.spark.forge.ForgeClassSourceLookup;
import me.lucko.spark.forge.ForgeSparkMod;
import net.minecraft.commands.CommandSource;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.forgespi.language.IModInfo;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -76,8 +75,6 @@ public void disable() {
this.scheduler.shutdown();
}

public abstract boolean hasPermission(CommandSource sender, String permission);

@Override
public String getVersion() {
return this.mod.getVersion();
Expand Down
2 changes: 1 addition & 1 deletion spark-neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ java {
}

neoForge {
version = "21.2.0-beta"
version = "21.3.3-beta"
validateAccessTransformers = true

runs {
Expand Down

0 comments on commit c58ddcf

Please sign in to comment.