Skip to content

Commit

Permalink
添加规则“simulationDistance”,用以设置服务器的默认模拟距离
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Nov 9, 2024
1 parent 64b2f75 commit 8ae9edc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/main/java/dev/anvilcraft/rg/RollingGateServerRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public static class ViewDistanceValidator extends RGValidator.IntegerValidator {
validator = ViewDistanceValidator.class
)
public static int viewDistance = 0;

@Rule(
allowed = {"0", "12", "16", "32"},
categories = RollingGateCategories.CREATIVE,
validator = ViewDistanceValidator.class
)
public static int simulationDistance = 0;
}
4 changes: 3 additions & 1 deletion src/main/java/dev/anvilcraft/rg/api/RGRuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* RollingGate规则管理器,负责处理和存储规则配置
Expand All @@ -35,7 +37,7 @@ public class RGRuleManager {
// 默认命名空间
protected String namespace = "rolling_gate";
// 存储规则类别的列表
protected final List<String> categories = new ArrayList<>();
protected final Set<String> categories = new HashSet<>();

// 静态代码块,初始化Gson实例
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ private void listCommand(LiteralArgumentBuilder<CommandSourceStack> builder, Tri
RGRule<?> rgRule = entry.getValue();
LiteralArgumentBuilder<CommandSourceStack> keyNode = Commands.literal(rgRule.name());
if (list) keyNode.executes(ctx -> this.ruleInfoCommand(ctx, rgRule));
for (String value : rgRule.allowed()) {
keyNode.then(Commands.literal(value).executes(ctx -> execute.apply(ctx, rgRule, value)));
}
keyNode.then(
Commands.argument("value", StringArgumentType.word())
.suggests((context, builder1) -> SharedSuggestionProvider.suggest(rgRule.allowed(), builder1))
.executes(context -> execute.apply(context, rgRule, StringArgumentType.getString(context, "value")))
);
builder.then(keyNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
public class RGRuleChangeEventListener {
@SubscribeEvent
public static void onRuleChange(@NotNull RGRuleChangeEvent.Server<Integer> event) {
if (event.getRule().name().equals("viewDistance")) changeViewDistance(event.getServer(), event.getNewValue());
if (event.getRule().name().equals("viewDistance")) {
changeViewDistance(event.getServer(), event.getNewValue());
} else if (event.getRule().name().equals("simulationDistance")) {
changeSimulationDistance(event.getServer(), event.getNewValue());
}
}

public static void changeViewDistance(@NotNull MinecraftServer server, int value) {
if (!server.isDedicatedServer()) return;
int distance = value >= 2 ? value : ((DedicatedServerAccessor) server).getSettings().getProperties().viewDistance;
server.getPlayerList().setViewDistance(distance);
}

public static void changeSimulationDistance(@NotNull MinecraftServer server, int value) {
if (!server.isDedicatedServer()) return;
int distance = value >= 2 ? value : ((DedicatedServerAccessor) server).getSettings().getProperties().simulationDistance;
server.getPlayerList().setSimulationDistance(distance);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/rolling_gate/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"rolling_gate.rolling_gate.rule.view_distance": "View Distance",
"rolling_gate.rolling_gate.rule.view_distance.desc": "Set the default view distance for server",

"rolling_gate.rolling_gate.rule.simulation_distance": "Simulation Distance",
"rolling_gate.rolling_gate.rule.simulation_distance.desc": "Set the default simulation distance for server",

"rolling_gate.command.root.version": "Version: %s",
"rolling_gate.command.reload.success": "Reload Success!",
"rolling_gate.command.rule.select.hover": "Click to select the value",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/rolling_gate/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"rolling_gate.rolling_gate.rule.view_distance": "视距",
"rolling_gate.rolling_gate.rule.view_distance.desc": "设置服务器的默认视距",

"rolling_gate.rolling_gate.rule.simulation_distance": "模拟距离",
"rolling_gate.rolling_gate.rule.simulation_distance.desc": "设置服务器的模拟距离",

"rolling_gate.command.root.version": "版本: %s",
"rolling_gate.command.reload.success": "重载成功!",
"rolling_gate.command.rule.select.hover": "点击选择该值",
Expand Down

0 comments on commit 8ae9edc

Please sign in to comment.