Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
74ad6357
Commit
74ad6357
authored
Apr 29, 2022
by
xtaodada
Browse files
Support Teleport from console
parent
d1e5fad9
Changes
3
Show whitespace changes
Inline
Side-by-side
README.md
View file @
74ad6357
...
...
@@ -134,7 +134,7 @@ There is a dummy user named "Server" in every player's friends list that you can
| spawn | spanw
<entityID
\|
entityName
>
[level] [amount] | server.spawn | Client only | Spawns an entity near you | |
| stop | stop | server.stop | Both side | Stops the server | |
| talent | talent
<talentID>
<value>
| player.settalent | Client only | Sets talent level for your currently selected character | |
| teleport | teleport
<x>
<y>
<z>
| player.teleport |
Client only
| Change the player's position. | tp |
| teleport | teleport
[@player id]
<x>
<y>
<z>
[scene id]
| player.teleport |
Both side
| Change the player's position. | tp |
| tpall | | player.tpall | Client only | Teleports all players in your world to your position | |
| weather | weather
<weatherID>
<climateID>
| player.weather | Client only | Changes the weather | w |
...
...
README_zh-CN.md
View file @
74ad6357
...
...
@@ -135,7 +135,7 @@ chmod +x gradlew
| spawn | spanw
<实体ID
\|
实体名称
>
[等级] [数量] | server.spawn | 仅客户端 | 在你周围生成实体 | |
| stop | stop | server.stop | 均可使用 | 停止服务器 | |
| talent | talent
<天赋ID>
<等级>
| player.settalent | 仅客户端 | 设置当前角色的天赋等级 | |
| teleport | teleport
<x>
<y>
<z>
| player.teleport |
仅客户端
| 传送玩家到指定坐标 | tp |
| teleport | teleport
[@player id]
<x>
<y>
<z>
[scene id]
| player.teleport |
均可使用
| 传送玩家到指定坐标 | tp |
| tpall | | player.tpall | 仅客户端 | 传送多人世界中所有的玩家到自身地点 | |
| weather | weather
<天气ID>
<气候ID>
| player.weather | 仅客户端 | 改变天气 | w |
...
...
src/main/java/emu/grasscutter/command/commands/TeleportCommand.java
View file @
74ad6357
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
...
...
@@ -7,21 +8,39 @@ import emu.grasscutter.utils.Position;
import
java.util.List
;
@Command
(
label
=
"teleport"
,
usage
=
"teleport
<x> <y> <z>
"
,
aliases
=
{
"tp"
},
@Command
(
label
=
"teleport"
,
usage
=
"teleport
[@player id] <x> <y> <z> [scene id]
"
,
aliases
=
{
"tp"
},
description
=
"Change the player's position."
,
permission
=
"player.teleport"
)
public
final
class
TeleportCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
List
<
String
>
args
)
{
int
target
;
if
(
args
.
size
()
<
(
sender
==
null
?
4
:
3
))
{
CommandHandler
.
sendMessage
(
sender
,
sender
==
null
?
"Usage: /tp @<player id> <x> <y> <z> [scene id]"
:
"Usage: /tp [@<player id>] <x> <y> <z> [scene id]"
);
return
;
}
if
(
args
.
get
(
0
).
startsWith
(
"@"
))
{
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
).
substring
(
1
));
}
catch
(
NumberFormatException
e
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid player id."
);
return
;
}
}
else
{
if
(
sender
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"
Run this command in-game
."
);
CommandHandler
.
sendMessage
(
null
,
"
You must specify a player id
."
);
return
;
}
target
=
sender
.
getUid
();
}
if
(
args
.
size
()
<
3
){
CommandHandler
.
sendMessage
(
sender
,
"Usage: /tp <x> <y> <z> [scene id]"
);
Player
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
"Player not found or offline."
);
return
;
}
args
=
args
.
subList
(
args
.
get
(
0
).
startsWith
(
"@"
)
?
1
:
0
,
args
.
size
());
try
{
float
x
=
0
f
;
...
...
@@ -29,39 +48,41 @@ public final class TeleportCommand implements CommandHandler {
float
z
=
0
f
;
if
(
args
.
get
(
0
).
contains
(
"~"
))
{
if
(
args
.
get
(
0
).
equals
(
"~"
))
{
x
=
send
er
.
getPos
().
getX
();
x
=
targetPlay
er
.
getPos
().
getX
();
}
else
{
x
=
Float
.
parseFloat
(
args
.
get
(
0
).
replace
(
"~"
,
""
))
+
send
er
.
getPos
().
getX
();
x
=
Float
.
parseFloat
(
args
.
get
(
0
).
replace
(
"~"
,
""
))
+
targetPlay
er
.
getPos
().
getX
();
}
}
else
{
x
=
Float
.
parseFloat
(
args
.
get
(
0
));
}
if
(
args
.
get
(
1
).
contains
(
"~"
))
{
if
(
args
.
get
(
1
).
equals
(
"~"
))
{
y
=
send
er
.
getPos
().
getY
();
y
=
targetPlay
er
.
getPos
().
getY
();
}
else
{
y
=
Float
.
parseFloat
(
args
.
get
(
1
).
replace
(
"~"
,
""
))
+
send
er
.
getPos
().
getY
();
y
=
Float
.
parseFloat
(
args
.
get
(
1
).
replace
(
"~"
,
""
))
+
targetPlay
er
.
getPos
().
getY
();
}
}
else
{
y
=
Float
.
parseFloat
(
args
.
get
(
1
));
}
if
(
args
.
get
(
2
).
contains
(
"~"
))
{
if
(
args
.
get
(
2
).
equals
(
"~"
))
{
z
=
send
er
.
getPos
().
getZ
();
z
=
targetPlay
er
.
getPos
().
getZ
();
}
else
{
z
=
Float
.
parseFloat
(
args
.
get
(
2
).
replace
(
"~"
,
""
))
+
send
er
.
getPos
().
getZ
();
z
=
Float
.
parseFloat
(
args
.
get
(
2
).
replace
(
"~"
,
""
))
+
targetPlay
er
.
getPos
().
getZ
();
}
}
else
{
z
=
Float
.
parseFloat
(
args
.
get
(
2
));
}
int
sceneId
=
send
er
.
getSceneId
();
int
sceneId
=
targetPlay
er
.
getSceneId
();
if
(
args
.
size
()
==
4
){
sceneId
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
Position
target
=
new
Position
(
x
,
y
,
z
);
boolean
result
=
send
er
.
getWorld
().
transferPlayerToScene
(
send
er
,
sceneId
,
target
);
Position
target
_pos
=
new
Position
(
x
,
y
,
z
);
boolean
result
=
targetPlay
er
.
getWorld
().
transferPlayerToScene
(
targetPlay
er
,
sceneId
,
target
_pos
);
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid position."
);
}
else
{
CommandHandler
.
sendMessage
(
sender
,
"Teleported "
+
targetPlayer
.
getNickname
()
+
" to "
+
x
+
","
+
y
+
","
+
z
+
" in scene "
+
sceneId
);
}
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid position."
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment