Skip to content

Commit 47bb286

Browse files
committed
fix: whole checks & fixes
1 parent 54bc47d commit 47bb286

20 files changed

Lines changed: 206 additions & 120 deletions

File tree

README-en.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ If `blockUpdate` is not needed, **disabling this is highly recommended**.
346346

347347
**just in >=1.20**
348348

349+
**removed after v2.0.0**
350+
349351
If you want to use note block update suppression in 1.20, this may help you.
350352

351353
- Default value: `false`

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ DispenserBlockEntity dispenserBlockEntity = (DispenserBlockEntity)blockPointerIm
347347

348348
**仅限`1.20`版本及以上**
349349

350+
**在v2.0.0以上版本已被移除**
351+
350352
如果你想在`1.20`使用音符盒极简抑制器,这可能能帮助你
351353

352354
- Default value: `false`

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ plugins {
99

1010
val minecraftVer = stonecutter.current.version
1111
val modver = "${property("mod_version")}"
12-
val mod = "${modver}+${minecraftVer}+build.${SimpleDateFormat("yyMMddHHmm").format(Date())}"
12+
13+
val modBuildNameSuffix = "v${modver}+build.${SimpleDateFormat("yyMMddHHmm").format(Date())}-${minecraftVer}"
1314
val archivesBaseName = project.findProperty("archives_base_name")
1415

1516
base {
16-
archivesName.set("${archivesBaseName}+${mod}")
17+
archivesName.set("${archivesBaseName}+${modBuildNameSuffix}")
1718
}
1819

1920
repositories {
@@ -65,7 +66,7 @@ tasks.processResources {
6566

6667
filesMatching("fabric.mod.json") {
6768
val valueMap = mapOf(
68-
"version" to modver,
69+
"version" to modver,
6970
"minecraft_requirement_version" to minecraftVer,
7071
)
7172
expand(valueMap)
@@ -90,3 +91,5 @@ tasks.jar {
9091
}
9192
}
9293
}
94+
95+
println(stonecutter.tree.versions.toString())

src/main/java/io/github/optijava/opt_carpet_addition/OptCarpetSettings.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class OptCarpetSettings {
1616
public static final String OCA = "OCA";
1717
public static final String FALSE = "false";
18+
public static final String TRUE = "true";
1819
public static Path configDirectory = FabricLoader.getInstance().getConfigDir().resolve("opt-carpet-addition");
1920

2021
// Tp command rules =======================================================================
@@ -116,12 +117,13 @@ public class OptCarpetSettings {
116117
)
117118
public static boolean commandLogger = false;
118119

119-
//#if MC < 12110
120-
@Rule(
120+
//? if < 1.21.10 {
121+
/*@Rule(
121122
categories = {RuleCategory.OPTIMIZATION,OCA}
122123
)
123124
public static boolean optimizeFakePlayerSpawn = false;
124-
//#endif
125+
*///?}
126+
125127

126128
@Rule(
127129
categories = {RuleCategory.FEATURE,OCA}
@@ -173,13 +175,16 @@ public class OptCarpetSettings {
173175
public static boolean allowSpectatorTpToAnyPlayer = false;
174176

175177
@Rule(
176-
categories = {RuleCategory.COMMAND , OCA}
178+
categories = {RuleCategory.COMMAND , OCA},
179+
options = {"true", "false", "1", "2", "3", "4"},
180+
strict = true
177181
)
178-
public static boolean enableLoggerCommand = true;
182+
public static String enableLoggerCommand = TRUE;
179183

180184
@Rule(
181185
categories = {RuleCategory.COMMAND , OCA},
182-
options = {"true", "false", "1", "2", "3", "4"}
186+
options = {"true", "false", "1", "2", "3", "4"},
187+
strict = true
183188
)
184189
public static String enableCrashCommand = FALSE;
185190

src/main/java/io/github/optijava/opt_carpet_addition/commands/CommandLoggerCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class CommandLoggerCommand {
1313
public static void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher) {
1414
LiteralArgumentBuilder<CommandSourceStack> argumentBuilder = Commands.literal("commandlogger").
15-
requires((player) -> carpet.utils.CommandHelper.canUseCommand(player, enableLoggerCommand))
15+
requires((player) -> (carpet.utils.CommandHelper.canUseCommand(player, enableLoggerCommand)))
1616
.then(
1717
Commands.literal("reload")
1818
.executes(CommandLoggerCommand::reload)

src/main/java/io/github/optijava/opt_carpet_addition/commands/CrashCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public static int confirm(CommandContext<CommandSourceStack> context) {
4545
return 0;
4646
}
4747
OptCarpetAddition.LOGGER.fatal("[OCA Crash Command] Confirm Crash!");
48-
// Runtime.getRuntime().halt(1);
4948
throw new Error("[OCA Crash Command] Confirm Crash!");
5049
}
5150

src/main/java/io/github/optijava/opt_carpet_addition/commands/ListAdvanceCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private static int listAdvance(CommandContext<CommandSourceStack> context) {
3030
//?} else if >= 1.21.5 {
3131
/*sb.append(s.getName().getString()).append(" ").append(s.gameMode).append(" ").append(s.connection.latency()).append("ms ").append(s.getIpAddress()).append(" ").append(s.getGameProfile().getId().toString()).append("\n");
3232
*///?}
33+
// TODO: 加回来1.21版本
3334
});
3435
Messenger.m(context.getSource(), sb.toString());
3536
} catch (Exception e) {

src/main/java/io/github/optijava/opt_carpet_addition/commands/PlayerTpCommand.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
import java.util.Map;
2222
import java.util.Objects;
2323

24+
import static io.github.optijava.opt_carpet_addition.utils.McUtils.MINECRAFT_SERVER;
25+
2426

2527
public class PlayerTpCommand {
2628

2729
/* permit 1 request per 2 seconds < == > permit 0.5 request per 1 second */
2830
public static Map<ServerPlayer, RateLimiter> rateLimiterMap = new HashMap<>();
2931

30-
private PlayerTpCommand() {}
31-
3232
private static final String COMMAND_PREFIX = "player";
33-
private static final MinecraftServer server = CarpetServer.minecraft_server;
3433

3534
public static void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher) {
3635
LiteralArgumentBuilder<CommandSourceStack> argumentBuilder = Commands.literal(COMMAND_PREFIX)
@@ -64,17 +63,17 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
6463

6564
String target = StringArgumentType.getString(context, COMMAND_PREFIX);
6665

67-
if (CarpetServer.minecraft_server.getPlayerList().getPlayerByName(target) == null) {
66+
if (MINECRAFT_SERVER.getPlayerList().getPlayerByName(target) == null) {
6867
Messenger.m(context.getSource(), "r No such player");
6968
return 0;
7069
}
7170

72-
if (context.getSource().equals(server.createCommandSourceStack())) {
71+
if (context.getSource().equals(MINECRAFT_SERVER.createCommandSourceStack())) {
7372
Messenger.m(context.getSource(), "r Console can't tp to player.");
7473
OptCarpetAddition.LOGGER.warn("Console can't tp to player");
7574
return 0;
7675
}
77-
if (StringArgumentType.getString(context, COMMAND_PREFIX).isEmpty() || target == null) {
76+
if (StringArgumentType.getString(context, COMMAND_PREFIX).isEmpty()) {
7877
Messenger.m(context.getSource(), "r Invalid player name.");
7978
return 0;
8079
}
@@ -86,18 +85,18 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
8685
/*final String commandSourcePlayerName = Objects.requireNonNull(context.getSource().getPlayer()).getGameProfile().getName();
8786
*///?}
8887

89-
if (server.getPlayerList().getPlayerByName(target) instanceof EntityPlayerMPFake) {
88+
if (MINECRAFT_SERVER.getPlayerList().getPlayerByName(target) instanceof EntityPlayerMPFake) {
9089

9190
switch (OptCarpetSettings.commandTpToFakePlayer) {
92-
case "true" -> executeTp(commandSourcePlayerName, context);
91+
case OptCarpetSettings.TRUE -> executeTp(commandSourcePlayerName, context);
9392
case "ops" -> {
9493
if (McUtils.isOp(context.getSource().getPlayer().getGameProfile())) {
9594
executeTp(commandSourcePlayerName, context);
9695
} else {
9796
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().gameMode.getGameModeForPlayer().equals(GameType.SPECTATOR)){
9897
executeTp(commandSourcePlayerName, context);
9998
} else {
100-
Messenger.m(context.getSource(), "r You have no permission to teleport to fake player.You aren't op.");
99+
Messenger.m(context.getSource(), "r You have no permission to teleport to fake player. You aren't op.");
101100
}
102101
}
103102
}
@@ -111,17 +110,17 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
111110
}
112111

113112
} else {
114-
113+
// TODO: "true"改为OCS.TRUE
115114
switch (OptCarpetSettings.allowTpToRealPlayer) {
116-
case "true" -> tp(commandSourcePlayerName, target);
115+
case OptCarpetSettings.TRUE -> tp(commandSourcePlayerName, target);
117116
case "ops" -> {
118117
if (McUtils.isOp(context.getSource().getPlayer().getGameProfile())) {
119118
tp(commandSourcePlayerName, target);
120119
} else {
121120
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().gameMode.getGameModeForPlayer().equals(GameType.SPECTATOR)) {
122121
executeTp(commandSourcePlayerName, context);
123122
} else {
124-
Messenger.m(context.getSource(), "r You have no permission to teleport to real player.You aren't op.");
123+
Messenger.m(context.getSource(), "r You have no permission to teleport to real player. You aren't op.");
125124
}
126125
}
127126
}
@@ -150,18 +149,18 @@ private static int teleportHere(CommandContext<CommandSourceStack> context) {
150149

151150
String target = StringArgumentType.getString(context, COMMAND_PREFIX);
152151

153-
if (server.getPlayerList().getPlayerByName(target) == null) {
152+
if (MINECRAFT_SERVER.getPlayerList().getPlayerByName(target) == null) {
154153
Messenger.m(context.getSource(), "r No such player");
155154
return 0;
156155
}
157156

158-
if (context.getSource().equals(server.createCommandSourceStack())) {
157+
if (context.getSource().equals(MINECRAFT_SERVER.createCommandSourceStack())) {
159158
Messenger.m(context.getSource(), "r Console can't tp here player.");
160159
OptCarpetAddition.LOGGER.warn("Console can't tp here player");
161160
return 0;
162161
}
163162

164-
if (StringArgumentType.getString(context, COMMAND_PREFIX).isEmpty() || target == null) {
163+
if (StringArgumentType.getString(context, COMMAND_PREFIX).isEmpty()) {
165164
Messenger.m(context.getSource(), "r Invalid player name.");
166165
return 0;
167166
}
@@ -173,32 +172,32 @@ private static int teleportHere(CommandContext<CommandSourceStack> context) {
173172
/*final String commandSourcePlayerName = Objects.requireNonNull(context.getSource().getPlayer()).getGameProfile().getName();
174173
*///?}
175174

176-
if (server.getPlayerList().getPlayerByName(target) instanceof EntityPlayerMPFake) {
175+
if (MINECRAFT_SERVER.getPlayerList().getPlayerByName(target) instanceof EntityPlayerMPFake) {
177176

178177
switch (OptCarpetSettings.commandTpHereFakePlayer) {
179-
case "true" -> executeTpHere(commandSourcePlayerName, context);
178+
case OptCarpetSettings.TRUE -> executeTpHere(commandSourcePlayerName, context);
180179
case "ops" -> {
181180
if (McUtils.isOp(context.getSource().getPlayer().getGameProfile())) {
182181
executeTpHere(commandSourcePlayerName, context);
183182
} else {
184-
Messenger.m(context.getSource(), "r You have no permission to teleport here fake player.You aren't op.");
183+
Messenger.m(context.getSource(), "r You have no permission to teleport here fake player. You aren't op.");
185184
}
186185
}
187-
case "false" -> Messenger.m(context.getSource(), "r Anybody can't teleport here fake player.");
186+
case OptCarpetSettings.FALSE -> Messenger.m(context.getSource(), "r Anybody can't teleport here fake player.");
188187
}
189188

190189
} else {
191190

192191
switch (OptCarpetSettings.allowTpHereRealPlayer) {
193-
case "true" -> tp(target, commandSourcePlayerName);
192+
case OptCarpetSettings.TRUE -> tp(target, commandSourcePlayerName);
194193
case "ops" -> {
195194
if (McUtils.isOp(context.getSource().getPlayer().getGameProfile())) {
196195
tp(target, commandSourcePlayerName);
197196
} else {
198-
Messenger.m(context.getSource(), "r You have no permission to teleport here real player.You aren't op.");
197+
Messenger.m(context.getSource(), "r You have no permission to teleport here real player. You aren't op.");
199198
}
200199
}
201-
case "false" -> Messenger.m(context.getSource(), "r Anybody can't teleport here real player.");
200+
case OptCarpetSettings.FALSE -> Messenger.m(context.getSource(), "r Anybody can't teleport here real player.");
202201
}
203202

204203
}
@@ -266,7 +265,7 @@ private static boolean checkTpHereWhitelist(String name) {
266265
}
267266

268267
private static void tp(String target, String commandSourcePlayerName) throws CommandSyntaxException {
269-
Commands commands = server.getCommands();
270-
commands.getDispatcher().execute(commands.getDispatcher().parse("tp " + target + " " + commandSourcePlayerName, server.createCommandSourceStack()));
268+
Commands commands = MINECRAFT_SERVER.getCommands();
269+
commands.getDispatcher().execute(commands.getDispatcher().parse("tp " + target + " " + commandSourcePlayerName, MINECRAFT_SERVER.createCommandSourceStack()));
271270
}
272271
}

src/main/java/io/github/optijava/opt_carpet_addition/commands/TpLimitCommand.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515

1616
public class TpLimitCommand {
1717

18-
private TpLimitCommand() {
19-
20-
}
21-
2218
public static void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher) {
23-
2419

2520
LiteralArgumentBuilder<CommandSourceStack> argument = Commands.literal("tpmanager")
2621
.requires((player) -> carpet.utils.CommandHelper.canUseCommand(player, enableTpmanagerCommand))

src/main/java/io/github/optijava/opt_carpet_addition/events/fixExperienceBug/FixExperienceBug.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public void afterChangeLevel(ServerPlayer player, ServerLevel origin, ServerLeve
2020
}
2121
}
2222
//?} else {
23-
//public class FixExperienceBug implements ServerEntityWorldChangeEvents.AfterPlayerChange {
24-
// @Override
25-
// public void afterChangeWorld(ServerPlayer player, ServerLevel origin, ServerLevel destination) {
26-
// if (OptCarpetSettings.fixXpLevelBug) {
27-
// // refresh player's experience bar
28-
// player.giveExperiencePoints(0);
29-
// }
30-
// }
31-
//}
32-
//?}
23+
/*public class FixExperienceBug implements ServerEntityWorldChangeEvents.AfterPlayerChange {
24+
@Override
25+
public void afterChangeWorld(ServerPlayer player, ServerLevel origin, ServerLevel destination) {
26+
if (OptCarpetSettings.fixXpLevelBug) {
27+
// refresh player's experience bar
28+
player.giveExperiencePoints(0);
29+
}
30+
}
31+
}
32+
*///?}

0 commit comments

Comments
 (0)