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
b35ee455
Commit
b35ee455
authored
Apr 18, 2022
by
KingRainbow44
Browse files
Add existing commands
parent
61c0ff36
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/commands/PlayerCommands.java
View file @
b35ee455
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/commands/ServerCommands.java
0 → 100644
View file @
b35ee455
package
emu.grasscutter.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.Account
;
import
emu.grasscutter.game.GenshinPlayer
;
import
java.util.List
;
/**
* A container for server-related commands.
*/
public
final
class
ServerCommands
{
@Command
(
label
=
"reload"
,
usage
=
"Usage: reload"
)
public
static
class
ReloadCommand
implements
CommandHandler
{
@Override
public
void
execute
(
List
<
String
>
args
)
{
Grasscutter
.
getLogger
().
info
(
"Reloading config."
);
Grasscutter
.
loadConfig
();
Grasscutter
.
getDispatchServer
().
loadQueries
();
Grasscutter
.
getLogger
().
info
(
"Reload complete."
);
}
@Override
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
this
.
execute
(
args
);
}
}
@Command
(
label
=
"sendmessage"
,
aliases
=
{
"sendmsg"
,
"msg"
},
usage
=
"Usage: sendmessage <player> <message>"
)
public
static
class
SendMessageCommand
implements
CommandHandler
{
@Override
public
void
execute
(
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: sendmessage <player> <message>"
);
return
;
}
try
{
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
targetPlayer
.
dropMessage
(
message
);
CommandHandler
.
sendMessage
(
null
,
"Message sent."
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid player ID."
);
}
}
@Override
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: sendmessage <player> <message>"
);
return
;
}
try
{
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
targetPlayer
.
sendMessage
(
player
,
message
);
CommandHandler
.
sendMessage
(
null
,
"Message sent."
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid player ID."
);
}
}
}
@Command
(
label
=
"account"
,
usage
=
"Usage: account <create|delete> <username> [uid]"
,
execution
=
Command
.
Execution
.
CONSOLE
)
public
static
class
AccountCommand
implements
CommandHandler
{
@Override
public
void
execute
(
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: account <create|delete> <username> [uid]"
);
return
;
}
String
action
=
args
.
get
(
0
);
String
username
=
args
.
get
(
1
);
switch
(
action
)
{
default
:
CommandHandler
.
sendMessage
(
null
,
"Usage: account <create|delete> <username> [uid]"
);
return
;
case
"create"
:
int
uid
=
0
;
if
(
args
.
size
()
>
2
)
{
try
{
uid
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid UID."
);
return
;
}
}
Account
account
=
DatabaseHelper
.
createAccountWithId
(
username
,
uid
);
if
(
account
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Account already exists."
);
return
;
}
else
CommandHandler
.
sendMessage
(
null
,
"Account created with UID "
+
account
.
getId
()
+
"."
);
return
;
case
"delete"
:
if
(
DatabaseHelper
.
deleteAccount
(
username
))
{
CommandHandler
.
sendMessage
(
null
,
"Account deleted."
);
return
;
}
else
CommandHandler
.
sendMessage
(
null
,
"Account not found."
);
return
;
}
}
}
}
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
b35ee455
...
...
@@ -485,7 +485,7 @@ public class GenshinPlayer {
this
.
regionId
=
regionId
;
}
public
boolean
has
Godmode
()
{
public
boolean
in
Godmode
()
{
return
godmode
;
}
...
...
@@ -558,6 +558,15 @@ public class GenshinPlayer {
public
void
dropMessage
(
Object
message
)
{
this
.
sendPacket
(
new
PacketPrivateChatNotify
(
GenshinConstants
.
SERVER_CONSOLE_UID
,
getId
(),
message
.
toString
()));
}
/**
* Sends a message to another player.
* @param sender The sender of the message.
* @param message The message to send.
*/
public
void
sendMessage
(
GenshinPlayer
sender
,
Object
message
)
{
this
.
sendPacket
(
new
PacketPrivateChatNotify
(
sender
.
getId
(),
this
.
getId
(),
message
.
toString
()));
}
public
void
interactWith
(
int
gadgetEntityId
)
{
GenshinEntity
entity
=
getWorld
().
getEntityById
(
gadgetEntityId
);
...
...
src/main/java/emu/grasscutter/game/World.java
View file @
b35ee455
...
...
@@ -344,7 +344,7 @@ public class World implements Iterable<GenshinPlayer> {
// Godmode check
if
(
target
instanceof
EntityAvatar
)
{
if
(((
EntityAvatar
)
target
).
getPlayer
().
has
Godmode
())
{
if
(((
EntityAvatar
)
target
).
getPlayer
().
in
Godmode
())
{
return
;
}
}
...
...
src/main/java/emu/grasscutter/utils/Utils.java
View file @
b35ee455
...
...
@@ -118,6 +118,16 @@ public final class Utils {
}
}
/**
* Get object with null fallback.
* @param nonNull The object to return if not null.
* @param fallback The object to return if null.
* @return One of the two provided objects.
*/
public
static
<
T
>
T
requireNonNullElseGet
(
T
nonNull
,
T
fallback
)
{
return
nonNull
!=
null
?
nonNull
:
fallback
;
}
/**
* Checks for required files and folders before startup.
*/
...
...
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