MinecraftGameRuleServiceImpl .java

net.minecraft.server.jsonrpc.internalapi.MinecraftGameRuleServiceImpl (class): members: getAvailableGameRules, updateGameRule, getRuleValue, getTypedRule.

net.minecraft.server.jsonrpc.internalapiclass54 linesserver2.0 KB

Implements

API Surface (4)

<T> GameRulesService.GameRuleUpdate<T> updateGameRule(final GameRulesService.GameRuleUpdate<T> update, final ClientInfo clientInfo)
<T> GameRulesService.GameRuleUpdate<T> getTypedRule(final GameRule<T> gameRule, final T value)
Stream<GameRule<?>> getAvailableGameRules()
<T> T getRuleValue(final GameRule<T> gameRule)

Fields & Constants (2)

notificationManager
jsonrpcLogger

Full Source

MinecraftGameRuleServiceImpl.java54 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.jsonrpc.internalapi;
2
3
import java.util.Objects;
4
import java.util.stream.Stream;
5
import net.minecraft.server.MinecraftServer;
6
import net.minecraft.server.dedicated.DedicatedServer;
7
import net.minecraft.server.jsonrpc.JsonRpcLogger;
8
import net.minecraft.server.jsonrpc.methods.ClientInfo;
9
import net.minecraft.server.jsonrpc.methods.GameRulesService;
10
import net.minecraft.server.notifications.NotificationManager;
11
import net.minecraft.world.level.gamerules.GameRule;
12
import net.minecraft.world.level.gamerules.GameRules;
13
14
public class MinecraftGameRuleServiceImpl implements MinecraftGameRuleService {
15
	private final NotificationManager notificationManager;
16
	private final JsonRpcLogger jsonrpcLogger;
17
18
	public MinecraftGameRuleServiceImpl(final NotificationManager notificationManager, final JsonRpcLogger jsonrpcLogger) {
19
		this.notificationManager = notificationManager;
20
		this.jsonrpcLogger = jsonrpcLogger;
21
	}
22
23
	private DedicatedServer server() {
24
		return Objects.requireNonNull(this.notificationManager.server());
25
	}
26
27
	@Override
28
	public <T> GameRulesService.GameRuleUpdate<T> updateGameRule(final GameRulesService.GameRuleUpdate<T> update, final ClientInfo clientInfo) {
29
		GameRule<T> gameRule = update.gameRule();
30
		MinecraftServer server = this.server();
31
		GameRules gameRules = server.getGameRules();
32
		T oldValue = gameRules.get(gameRule);
33
		T newValue = update.value();
34
		gameRules.set(gameRule, newValue, server);
35
		this.jsonrpcLogger.log(clientInfo, "Game rule '{}' updated from '{}' to '{}'", gameRule.id(), gameRule.serialize(oldValue), gameRule.serialize(newValue));
36
		return update;
37
	}
38
39
	@Override
40
	public <T> GameRulesService.GameRuleUpdate<T> getTypedRule(final GameRule<T> gameRule, final T value) {
41
		return new GameRulesService.GameRuleUpdate<>(gameRule, value);
42
	}
43
44
	@Override
45
	public Stream<GameRule<?>> getAvailableGameRules() {
46
		return this.server().getGameRules().availableRules();
47
	}
48
49
	@Override
50
	public <T> T getRuleValue(final GameRule<T> gameRule) {
51
		return this.server().getGameRules().get(gameRule);
52
	}
53
}
54

Decompiled Minecraft 26.3 source of MinecraftGameRuleServiceImpl (net/minecraft/server/jsonrpc/internalapi/MinecraftGameRuleServiceImpl.java) with Mojang official mappings, stored verbatim on the site.