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
2e01c7d5
Commit
2e01c7d5
authored
Apr 18, 2022
by
KingRainbow44
Browse files
Find by player's UID not IID
parent
a4932c75
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/commands/PlayerCommands.java
View file @
2e01c7d5
...
@@ -51,7 +51,7 @@ public final class PlayerCommands {
...
@@ -51,7 +51,7 @@ public final class PlayerCommands {
case
2
:
case
2
:
try
{
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
)
==
null
)
{
if
(
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
)
==
null
)
{
target
=
player
.
getId
();
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
target
=
player
.
getId
();
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
else
{
}
else
{
...
@@ -66,7 +66,7 @@ public final class PlayerCommands {
...
@@ -66,7 +66,7 @@ public final class PlayerCommands {
case
3
:
case
3
:
try
{
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
)
==
null
)
{
if
(
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
)
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Invalid player ID."
);
return
;
CommandHandler
.
sendMessage
(
player
,
"Invalid player ID."
);
return
;
}
}
...
@@ -80,7 +80,7 @@ public final class PlayerCommands {
...
@@ -80,7 +80,7 @@ public final class PlayerCommands {
break
;
break
;
}
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
);
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
);
if
(
targetPlayer
==
null
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Player not found."
);
return
;
CommandHandler
.
sendMessage
(
player
,
"Player not found."
);
return
;
}
}
...
@@ -107,7 +107,7 @@ public final class PlayerCommands {
...
@@ -107,7 +107,7 @@ public final class PlayerCommands {
int
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
int
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
int
amount
=
1
;
if
(
args
.
size
()
>
2
)
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
int
amount
=
1
;
if
(
args
.
size
()
>
2
)
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
);
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
);
if
(
targetPlayer
==
null
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
}
...
...
src/main/java/emu/grasscutter/commands/ServerCommands.java
View file @
2e01c7d5
...
@@ -42,7 +42,7 @@ public final class ServerCommands {
...
@@ -42,7 +42,7 @@ public final class ServerCommands {
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
);
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
);
if
(
targetPlayer
==
null
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
}
...
@@ -64,7 +64,7 @@ public final class ServerCommands {
...
@@ -64,7 +64,7 @@ public final class ServerCommands {
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
String
message
=
String
.
join
(
" "
,
args
.
subList
(
1
,
args
.
size
()));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
I
d
(
target
);
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerBy
Ui
d
(
target
);
if
(
targetPlayer
==
null
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
}
...
@@ -108,7 +108,7 @@ public final class ServerCommands {
...
@@ -108,7 +108,7 @@ public final class ServerCommands {
Account
account
=
DatabaseHelper
.
createAccountWithId
(
username
,
uid
);
Account
account
=
DatabaseHelper
.
createAccountWithId
(
username
,
uid
);
if
(
account
==
null
)
{
if
(
account
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Account already exists."
);
return
;
CommandHandler
.
sendMessage
(
null
,
"Account already exists."
);
return
;
}
else
CommandHandler
.
sendMessage
(
null
,
"Account created with UID "
+
account
.
getId
()
+
"."
);
}
else
CommandHandler
.
sendMessage
(
null
,
"Account created with UID "
+
account
.
get
Player
Id
()
+
"."
);
return
;
return
;
case
"delete"
:
case
"delete"
:
if
(
DatabaseHelper
.
deleteAccount
(
username
))
{
if
(
DatabaseHelper
.
deleteAccount
(
username
))
{
...
...
src/main/java/emu/grasscutter/database/DatabaseHelper.java
View file @
2e01c7d5
...
@@ -36,6 +36,7 @@ public class DatabaseHelper {
...
@@ -36,6 +36,7 @@ public class DatabaseHelper {
if
(
reservedId
==
GenshinConstants
.
SERVER_CONSOLE_UID
)
{
if
(
reservedId
==
GenshinConstants
.
SERVER_CONSOLE_UID
)
{
return
null
;
return
null
;
}
}
exists
=
DatabaseHelper
.
getAccountByPlayerId
(
reservedId
);
exists
=
DatabaseHelper
.
getAccountByPlayerId
(
reservedId
);
if
(
exists
!=
null
)
{
if
(
exists
!=
null
)
{
return
null
;
return
null
;
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
2e01c7d5
package
emu.grasscutter.server.game
;
package
emu.grasscutter.server.game
;
import
java.net.InetSocketAddress
;
import
java.net.InetSocketAddress
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
emu.grasscutter.GenshinConstants
;
import
emu.grasscutter.GenshinConstants
;
...
@@ -115,6 +110,12 @@ public final class GameServer extends MihoyoKcpServer {
...
@@ -115,6 +110,12 @@ public final class GameServer extends MihoyoKcpServer {
return
this
.
getPlayers
().
get
(
id
);
return
this
.
getPlayers
().
get
(
id
);
}
}
public
GenshinPlayer
getPlayerByUid
(
int
uid
)
{
return
this
.
getPlayers
().
values
().
stream
()
.
filter
(
player
->
player
.
getAccount
().
getPlayerId
()
==
uid
)
.
findFirst
().
orElse
(
this
.
getPlayerById
(
uid
));
}
public
GenshinPlayer
forceGetPlayerById
(
int
id
)
{
public
GenshinPlayer
forceGetPlayerById
(
int
id
)
{
// Console check
// Console check
if
(
id
==
GenshinConstants
.
SERVER_CONSOLE_UID
)
{
if
(
id
==
GenshinConstants
.
SERVER_CONSOLE_UID
)
{
...
...
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