1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
--- a/net/minecraft/server/commands/SetSpawnCommand.java
+++ b/net/minecraft/server/commands/SetSpawnCommand.java
@@ -1,11 +1,12 @@
package net.minecraft.server.commands;
import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.AngleArgument;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
@@ -16,73 +17,43 @@
import net.minecraft.world.level.Level;
public class SetSpawnCommand {
+
+ public SetSpawnCommand() {}
+
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
- dispatcher.register(
- Commands.literal("spawnpoint")
- .requires(source -> source.hasPermission(2))
- .executes(
- context -> setSpawn(
- context.getSource(),
- Collections.singleton(context.getSource().getPlayerOrException()),
- BlockPos.containing(context.getSource().getPosition()),
- 0.0F
- )
- )
- .then(
- Commands.argument("targets", EntityArgument.players())
- .executes(
- context -> setSpawn(
- context.getSource(),
- EntityArgument.getPlayers(context, "targets"),
- BlockPos.containing(context.getSource().getPosition()),
- 0.0F
- )
- )
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context -> setSpawn(
- context.getSource(),
- EntityArgument.getPlayers(context, "targets"),
- BlockPosArgument.getSpawnablePos(context, "pos"),
- 0.0F
- )
- )
- .then(
- Commands.argument("angle", AngleArgument.angle())
- .executes(
- context -> setSpawn(
- context.getSource(),
- EntityArgument.getPlayers(context, "targets"),
- BlockPosArgument.getSpawnablePos(context, "pos"),
- AngleArgument.getAngle(context, "angle")
- )
- )
- )
- )
- )
- );
+ dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("spawnpoint").requires((commandlistenerwrapper) -> {
+ return commandlistenerwrapper.hasPermission(2);
+ })).executes((commandcontext) -> {
+ return setSpawn((CommandSourceStack) commandcontext.getSource(), Collections.singleton(((CommandSourceStack) commandcontext.getSource()).getPlayerOrException()), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()), 0.0F);
+ })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("targets", EntityArgument.players()).executes((commandcontext) -> {
+ return setSpawn((CommandSourceStack) commandcontext.getSource(), EntityArgument.getPlayers(commandcontext, "targets"), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()), 0.0F);
+ })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+ return setSpawn((CommandSourceStack) commandcontext.getSource(), EntityArgument.getPlayers(commandcontext, "targets"), BlockPosArgument.getSpawnablePos(commandcontext, "pos"), 0.0F);
+ })).then(net.minecraft.commands.Commands.argument("angle", AngleArgument.angle()).executes((commandcontext) -> {
+ return setSpawn((CommandSourceStack) commandcontext.getSource(), EntityArgument.getPlayers(commandcontext, "targets"), BlockPosArgument.getSpawnablePos(commandcontext, "pos"), AngleArgument.getAngle(commandcontext, "angle"));
+ })))));
}
private static int setSpawn(CommandSourceStack source, Collection<ServerPlayer> targets, BlockPos pos, float angle) {
- ResourceKey<Level> resourceKey = source.getLevel().dimension();
+ ResourceKey<Level> resourcekey = source.getLevel().dimension();
+ Iterator iterator = targets.iterator();
- for (ServerPlayer serverPlayer : targets) {
- serverPlayer.setRespawnPosition(resourceKey, pos, angle, true, false);
+ while (iterator.hasNext()) {
+ ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+
+ entityplayer.setRespawnPosition(resourcekey, pos, angle, true, false, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.COMMAND); // CraftBukkit
}
- String string = resourceKey.location().toString();
+ String s = resourcekey.location().toString();
+
if (targets.size() == 1) {
- source.sendSuccess(
- () -> Component.translatable(
- "commands.spawnpoint.success.single", pos.getX(), pos.getY(), pos.getZ(), angle, string, targets.iterator().next().getDisplayName()
- ),
- true
- );
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.spawnpoint.success.single", pos.getX(), pos.getY(), pos.getZ(), angle, s, ((ServerPlayer) targets.iterator().next()).getDisplayName());
+ }, true);
} else {
- source.sendSuccess(
- () -> Component.translatable("commands.spawnpoint.success.multiple", pos.getX(), pos.getY(), pos.getZ(), angle, string, targets.size()), true
- );
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.spawnpoint.success.multiple", pos.getX(), pos.getY(), pos.getZ(), angle, s, targets.size());
+ }, true);
}
return targets.size();
|