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
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/commands/PlayerCommands.java
View file @
b35ee455
package
emu.grasscutter.commands
;
package
emu.grasscutter.commands
;
import
java.lang.reflect.Modifier
;
import
emu.grasscutter.Grasscutter
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.World
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityItem
;
import
emu.grasscutter.game.entity.EntityItem
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.entity.GenshinEntity
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.inventory.Inventory
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.game.props.FightProperty
;
...
@@ -23,306 +19,302 @@ import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
...
@@ -23,306 +19,302 @@ import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
public
class
PlayerCommands
{
import
java.util.LinkedList
;
private
static
HashMap
<
String
,
PlayerCommand
>
commandList
=
new
HashMap
<
String
,
PlayerCommand
>();
import
java.util.List
;
private
static
HashMap
<
String
,
PlayerCommand
>
commandAliasList
=
new
HashMap
<
String
,
PlayerCommand
>();
static
{
try
{
// Look for classes
for
(
Class
<?>
cls
:
PlayerCommands
.
class
.
getDeclaredClasses
())
{
// Get non abstract classes
if
(!
Modifier
.
isAbstract
(
cls
.
getModifiers
()))
{
Command
commandAnnotation
=
cls
.
getAnnotation
(
Command
.
class
);
PlayerCommand
command
=
(
PlayerCommand
)
cls
.
newInstance
();
if
(
commandAnnotation
!=
null
)
{
command
.
setLevel
(
commandAnnotation
.
gmLevel
());
command
.
setHelpText
(
commandAnnotation
.
helpText
());
for
(
String
alias
:
commandAnnotation
.
aliases
())
{
if
(
alias
.
length
()
==
0
)
{
continue
;
}
String
commandName
=
alias
;
commandAliasList
.
put
(
commandName
,
command
);
}
}
String
commandName
=
cls
.
getSimpleName
().
toLowerCase
();
/**
commandList
.
put
(
commandName
,
command
);
* A container for player-related commands.
}
*/
public
final
class
PlayerCommands
{
@Command
(
label
=
"give"
,
aliases
=
{
"g"
,
"item"
,
"giveitem"
},
usage
=
"Usage: give [player] <itemId|itemName> [amount]"
)
public
static
class
GiveCommand
implements
CommandHandler
{
}
@Override
}
catch
(
Exception
e
)
{
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
int
target
,
item
,
amount
=
1
;
switch
(
args
.
size
())
{
default
:
CommandHandler
.
sendMessage
(
player
,
"Usage: give <player> <itemId|itemName> [amount]"
);
return
;
case
1
:
try
{
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
target
=
player
.
getId
();
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from item name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid item id."
);
return
;
}
}
break
;
case
2
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
target
=
player
.
getId
();
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
else
{
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
}
}
catch
(
NumberFormatException
ignored
)
{
public
static
void
handle
(
GenshinPlayer
player
,
String
msg
)
{
// TODO: Parse from item name using GM Handbook.
String
[]
split
=
msg
.
split
(
" "
);
CommandHandler
.
sendMessage
(
player
,
"Invalid item or player ID."
);
// End if invalid
if
(
split
.
length
==
0
)
{
return
;
return
;
}
}
break
;
case
3
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Invalid player ID."
);
return
;
}
String
first
=
split
[
0
].
toLowerCase
().
substring
(
1
);
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
PlayerCommand
c
=
PlayerCommands
.
commandList
.
get
(
first
);
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
PlayerCommand
a
=
PlayerCommands
.
commandAliasList
.
get
(
first
);
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from item name using GM Handbook.
if
(
c
!=
null
||
a
!=
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Invalid item or player ID."
);
PlayerCommand
cmd
=
c
!=
null
?
c
:
a
;
// Level check
if
(
player
.
getGmLevel
()
<
cmd
.
getLevel
())
{
return
;
return
;
}
}
// Execute
break
;
int
len
=
Math
.
min
(
split
[
0
].
length
()
+
1
,
msg
.
length
());
cmd
.
execute
(
player
,
msg
.
substring
(
len
));
}
}
}
public
static
abstract
class
PlayerCommand
{
// GM level required to use this command
private
int
level
;
private
String
helpText
;
protected
int
getLevel
()
{
return
this
.
level
;
}
protected
void
setLevel
(
int
minLevel
)
{
this
.
level
=
minLevel
;
}
protected
String
getHelpText
()
{
return
this
.
helpText
;
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
protected
void
setHelpText
(
String
helpText
)
{
this
.
helpText
=
helpText
;
}
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Player not found."
);
return
;
// Main
public
abstract
void
execute
(
GenshinPlayer
player
,
String
raw
);
}
}
// ================ Commands ================
ItemData
itemData
=
GenshinData
.
getItemDataMap
().
get
(
item
);
if
(
itemData
==
null
)
{
@Command
(
aliases
=
{
"h"
},
helpText
=
"Shows this command"
)
CommandHandler
.
sendMessage
(
player
,
"Invalid item id."
);
return
;
public
static
class
Help
extends
PlayerCommand
{
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
String
helpMessage
=
"Grasscutter Commands: "
;
for
(
Map
.
Entry
<
String
,
PlayerCommand
>
cmd
:
commandList
.
entrySet
())
{
helpMessage
+=
"\n"
+
cmd
.
getKey
()
+
" - "
+
cmd
.
getValue
().
helpText
;
}
}
player
.
dropMessage
(
helpMessage
);
this
.
item
(
targetPlayer
,
itemData
,
amount
);
}
}
}
@Command
(
aliases
=
{
"g"
,
"item"
,
"additem"
},
helpText
=
"/give [item id] [count] - Gives {count} amount of {item id}"
)
/**
public
static
class
Give
extends
PlayerCommand
{
* give [player] [itemId|itemName] [amount]
@Override
*/
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
@Override
public
void
execute
(
List
<
String
>
args
)
{
String
[]
split
=
raw
.
split
(
" "
);
if
(
args
.
size
()
<
2
)
{
int
itemId
=
0
,
count
=
1
;
CommandHandler
.
sendMessage
(
null
,
"Usage: give <player> <itemId|itemName> [amount]"
);
return
;
try
{
itemId
=
Integer
.
parseInt
(
split
[
0
]);
}
catch
(
Exception
e
)
{
itemId
=
0
;
}
}
try
{
try
{
count
=
Math
.
max
(
Math
.
min
(
Integer
.
parseInt
(
split
[
1
]),
Integer
.
MAX_VALUE
),
1
);
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
catch
(
Exception
e
)
{
int
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
count
=
1
;
int
amount
=
1
;
if
(
args
.
size
()
>
2
)
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
}
// Give
ItemData
itemData
=
GenshinData
.
getItemDataMap
().
get
(
item
);
ItemData
itemData
=
GenshinData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
==
null
)
{
GenshinItem
item
;
CommandHandler
.
sendMessage
(
null
,
"Invalid item id."
);
return
;
}
if
(
itemData
==
null
)
{
this
.
item
(
targetPlayer
,
itemData
,
amount
);
player
.
dropMessage
(
"Error: Item data not found"
);
}
catch
(
NumberFormatException
ignored
)
{
return
;
CommandHandler
.
sendMessage
(
null
,
"Invalid item or player ID."
);
}
}
}
if
(
itemData
.
isEquip
())
{
private
void
item
(
GenshinPlayer
player
,
ItemData
itemData
,
int
amount
)
{
GenshinItem
genshinItem
=
new
GenshinItem
(
itemData
);
if
(
itemData
.
isEquip
())
{
List
<
GenshinItem
>
items
=
new
LinkedList
<>();
List
<
GenshinItem
>
items
=
new
LinkedList
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
item
=
new
GenshinItem
(
itemData
);
items
.
add
(
genshinItem
);
items
.
add
(
item
);
}
player
.
getInventory
().
addItems
(
items
);
}
player
.
getInventory
().
addItems
(
items
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
SubfieldDrop
));
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
SubfieldDrop
));
}
else
{
}
else
{
item
=
new
GenshinItem
(
itemData
,
c
ount
);
genshinItem
.
setCount
(
am
ount
);
player
.
getInventory
().
addItem
(
i
tem
);
player
.
getInventory
().
addItem
(
genshinI
tem
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
i
tem
,
ActionReason
.
SubfieldDrop
));
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinI
tem
,
ActionReason
.
SubfieldDrop
));
}
}
}
}
}
}
@Command
(
aliases
=
{
"d"
},
helpText
=
"/drop [item id] [count] - Drops {count} amount of {item id}"
)
@Command
(
label
=
"drop"
,
aliases
=
{
"d"
,
"dropitem"
},
public
static
class
Drop
extends
PlayerCommand
{
usage
=
"Usage: drop <itemId|itemName> [amount]"
,
@Override
execution
=
Command
.
Execution
.
PLAYER
)
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
public
static
class
DropCommand
implements
CommandHandler
{
String
[]
split
=
raw
.
split
(
" "
);
int
itemId
=
0
,
count
=
1
;
try
{
@Override
itemId
=
Integer
.
parseInt
(
split
[
0
]);
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
}
catch
(
Exception
e
)
{
if
(
args
.
size
()
<
1
)
{
itemId
=
0
;
CommandHandler
.
sendMessage
(
null
,
"Usage: drop <itemId|itemName> [amount]"
);
return
;
}
}
try
{
try
{
count
=
Math
.
max
(
Math
.
min
(
Integer
.
parseInt
(
split
[
1
]),
Integer
.
MAX_VALUE
),
1
);
int
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
catch
(
Exception
e
)
{
int
amount
=
1
;
if
(
args
.
size
()
>
1
)
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
count
=
1
;
}
// Give
ItemData
itemData
=
GenshinData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
==
null
)
{
ItemData
itemData
=
GenshinData
.
getItemDataMap
().
get
(
item
);
player
.
dropMessage
(
"Error: I
tem
d
ata
not found"
);
if
(
i
tem
D
ata
==
null
)
{
return
;
CommandHandler
.
sendMessage
(
null
,
"Invalid item id."
);
return
;
}
}
if
(
itemData
.
isEquip
())
{
if
(
itemData
.
isEquip
())
{
float
range
=
(
5
f
+
(.
1
f
*
c
ount
));
float
range
=
(
5
f
+
(.
1
f
*
am
ount
));
for
(
int
i
=
0
;
i
<
c
ount
;
i
++)
{
for
(
int
i
=
0
;
i
<
am
ount
;
i
++)
{
Position
pos
=
player
.
getPos
().
clone
().
addX
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
)).
addY
(
3
f
).
addZ
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
));
Position
pos
=
player
.
getPos
().
clone
().
addX
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
)).
addY
(
3
f
).
addZ
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
));
EntityItem
entity
=
new
EntityItem
(
player
.
getWorld
(),
player
,
itemData
,
pos
,
1
);
EntityItem
entity
=
new
EntityItem
(
player
.
getWorld
(),
player
,
itemData
,
pos
,
1
);
player
.
getWorld
().
addEntity
(
entity
);
player
.
getWorld
().
addEntity
(
entity
);
}
}
}
else
{
}
else
{
EntityItem
entity
=
new
EntityItem
(
player
.
getWorld
(),
player
,
itemData
,
player
.
getPos
().
clone
().
addY
(
3
f
),
c
ount
);
EntityItem
entity
=
new
EntityItem
(
player
.
getWorld
(),
player
,
itemData
,
player
.
getPos
().
clone
().
addY
(
3
f
),
am
ount
);
player
.
getWorld
().
addEntity
(
entity
);
player
.
getWorld
().
addEntity
(
entity
);
}
}
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid item or player ID."
);
}
}
}
}
@Command
(
helpText
=
"/spawn [monster id] [count] - Creates {count} amount of {item id}"
)
public
static
class
Spawn
extends
PlayerCommand
{
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
String
[]
split
=
raw
.
split
(
" "
);
int
monsterId
=
0
,
count
=
1
,
level
=
1
;
try
{
monsterId
=
Integer
.
parseInt
(
split
[
0
]);
}
catch
(
Exception
e
)
{
monsterId
=
0
;
}
}
try
{
@Command
(
label
=
"spawn"
,
execution
=
Command
.
Execution
.
PLAYER
,
level
=
Math
.
max
(
Math
.
min
(
Integer
.
parseInt
(
split
[
1
]),
200
),
1
);
usage
=
"Usage: spawn <entityId|entityName> [level] [amount]"
)
}
catch
(
Exception
e
)
{
public
static
class
SpawnCommand
implements
CommandHandler
{
level
=
1
;
}
try
{
@Override
count
=
Math
.
max
(
Math
.
min
(
Integer
.
parseInt
(
split
[
2
]),
1000
),
1
);
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
}
catch
(
Exception
e
)
{
if
(
args
.
size
()
<
1
)
{
count
=
1
;
CommandHandler
.
sendMessage
(
null
,
"Usage: spawn <entityId|entityName> [amount]"
);
return
;
}
}
// Give
try
{
MonsterData
monsterData
=
GenshinData
.
getMonsterDataMap
().
get
(
monsterId
);
int
entity
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
level
=
1
;
if
(
args
.
size
()
>
1
)
level
=
Integer
.
parseInt
(
args
.
get
(
1
));
int
amount
=
1
;
if
(
args
.
size
()
>
2
)
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
if
(
monsterData
==
null
)
{
MonsterData
entityData
=
GenshinData
.
getMonsterDataMap
().
get
(
entity
);
player
.
dropMessage
(
"Error: Monster data not found"
);
if
(
entityData
==
null
)
{
return
;
CommandHandler
.
sendMessage
(
null
,
"Invalid entity id."
);
return
;
}
}
float
range
=
(
5
f
+
(.
1
f
*
c
ount
));
float
range
=
(
5
f
+
(.
1
f
*
am
ount
));
for
(
int
i
=
0
;
i
<
c
ount
;
i
++)
{
for
(
int
i
=
0
;
i
<
am
ount
;
i
++)
{
Position
pos
=
player
.
getPos
().
clone
().
addX
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
)).
addY
(
3
f
).
addZ
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
));
Position
pos
=
player
.
getPos
().
clone
().
addX
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
)).
addY
(
3
f
).
addZ
((
float
)
(
Math
.
random
()
*
range
)
-
(
range
/
2
));
EntityMonster
entity
=
new
EntityMonster
(
player
.
getWorld
(),
monster
Data
,
pos
,
level
);
EntityMonster
monster
=
new
EntityMonster
(
player
.
getWorld
(),
entity
Data
,
pos
,
level
);
player
.
getWorld
().
addEntity
(
entity
);
player
.
getWorld
().
addEntity
(
monster
);
}
}
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid item or player ID."
);
}
}
}
}
}
@Command
(
label
=
"killall"
,
usage
=
"Usage: killall [sceneId]"
)
public
static
class
KillAllCommand
implements
CommandHandler
{
@Command
(
helpText
=
"/killall"
)
public
static
class
KillAll
extends
PlayerCommand
{
@Override
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
List
<
GenshinEntity
>
toRemove
=
new
LinkedList
<>
();
World
world
=
player
.
getWorld
();
for
(
GenshinEntity
entity
:
player
.
getW
orld
()
.
getEntities
().
values
()
)
{
w
orld
.
getEntities
().
values
()
.
stream
()
if
(
entity
instanceof
EntityMonster
)
{
.
filter
(
entity
->
entity
instanceof
EntityMonster
)
toRemove
.
add
(
entity
);
.
forEach
(
entity
->
world
.
killEntity
(
entity
,
0
)
);
}
}
@Override
public
void
execute
(
List
<
String
>
args
)
{
if
(
args
.
size
()
<
1
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: killall [sceneId]"
);
return
;
}
try
{
int
sceneId
=
Integer
.
parseInt
(
args
.
get
(
0
));
CommandHandler
.
sendMessage
(
null
,
"Killing all monsters in scene "
+
sceneId
);
// TODO: Implement getting worlds by scene ID.
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid scene id."
);
}
}
toRemove
.
forEach
(
e
->
player
.
getWorld
().
killEntity
(
e
,
0
));
}
}
}
}
@Command
(
helpText
=
"/resetconst - Resets all constellations for the currently active character"
)
@Command
(
label
=
"resetconst"
,
aliases
=
{
"resetconstellation"
},
public
static
class
ResetConst
extends
PlayerCommand
{
usage
=
"Usage: resetconst [all]"
,
execution
=
Command
.
Execution
.
PLAYER
)
public
static
class
ResetConstellationCommand
implements
CommandHandler
{
@Override
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
if
(
args
.
size
()
>
0
&&
args
.
get
(
0
).
equalsIgnoreCase
(
"all"
))
{
player
.
getAvatars
().
forEach
(
this
::
resetConstellation
);
player
.
dropMessage
(
"Reset all avatars' constellations."
);
}
else
{
EntityAvatar
entity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
EntityAvatar
entity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
if
(
entity
==
null
)
if
(
entity
==
null
)
{
return
;
return
;
}
GenshinAvatar
avatar
=
entity
.
getAvatar
();
GenshinAvatar
avatar
=
entity
.
getAvatar
();
this
.
resetConstellation
(
avatar
);
player
.
dropMessage
(
"Constellations for "
+
avatar
.
getAvatarData
().
getName
()
+
" have been reset. Please relog to see changes."
);
}
}
private
void
resetConstellation
(
GenshinAvatar
avatar
)
{
avatar
.
getTalentIdList
().
clear
();
avatar
.
getTalentIdList
().
clear
();
avatar
.
setCoreProudSkillLevel
(
0
);
avatar
.
setCoreProudSkillLevel
(
0
);
avatar
.
recalcStats
();
avatar
.
recalcStats
();
avatar
.
save
();
avatar
.
save
();
player
.
dropMessage
(
"Constellations for "
+
entity
.
getAvatar
().
getAvatarData
().
getName
()
+
" have been reset. Please relogin to see changes."
);
}
}
}
}
@Command
(
helpText
=
"/godmode - Prevents you from taking damage"
)
@Command
(
label
=
"godmode"
,
public
static
class
Godmode
extends
PlayerCommand
{
usage
=
"Usage: godmode"
,
execution
=
Command
.
Execution
.
PLAYER
)
public
static
class
GodModeCommand
implements
CommandHandler
{
@Override
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
player
.
setGodmode
(!
player
.
has
Godmode
());
player
.
setGodmode
(!
player
.
in
Godmode
());
player
.
dropMessage
(
"Godmode is now "
+
(
player
.
has
Godmode
()
?
"
ON"
:
"OFF"
)
);
player
.
dropMessage
(
"Godmode is now "
+
(
player
.
in
Godmode
()
?
"
enabled"
:
"disabled"
)
+
"."
);
}
}
}
}
@Command
(
helpText
=
"/sethp [hp]"
)
@Command
(
label
=
"sethealth"
,
aliases
=
{
"sethp"
},
public
static
class
Sethp
extends
PlayerCommand
{
usage
=
"Usage: sethealth <hp>"
,
execution
=
Command
.
Execution
.
PLAYER
)
@Override
public
static
class
SetHealthCommand
implements
CommandHandler
{
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
String
[]
split
=
raw
.
split
(
" "
);
int
hp
=
0
;
try
{
@Override
hp
=
Math
.
max
(
Integer
.
parseInt
(
split
[
0
]),
1
);
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
}
catch
(
Exception
e
)
{
if
(
args
.
size
()
<
1
)
{
hp
=
1
;
CommandHandler
.
sendMessage
(
null
,
"Usage: sethealth <hp>"
);
return
;
}
}
try
{
int
health
=
Integer
.
parseInt
(
args
.
get
(
0
));
EntityAvatar
entity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
EntityAvatar
entity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
if
(
entity
==
null
)
if
(
entity
==
null
)
{
return
;
return
;
}
entity
.
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
h
p
);
entity
.
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
h
ealth
);
entity
.
getWorld
().
broadcastPacket
(
new
PacketEntityFightPropUpdateNotify
(
entity
,
FightProperty
.
FIGHT_PROP_CUR_HP
));
entity
.
getWorld
().
broadcastPacket
(
new
PacketEntityFightPropUpdateNotify
(
entity
,
FightProperty
.
FIGHT_PROP_CUR_HP
));
player
.
dropMessage
(
"Health set to "
+
health
+
"."
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid health value."
);
}
}
}
}
@Command
(
aliases
=
{
"clearart"
},
helpText
=
"/clearartifacts"
)
public
static
class
ClearArtifacts
extends
PlayerCommand
{
@Override
public
void
execute
(
GenshinPlayer
player
,
String
raw
)
{
List
<
GenshinItem
>
toRemove
=
new
LinkedList
<>();
for
(
GenshinItem
item
:
player
.
getInventory
().
getItems
().
values
())
{
if
(
item
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
&&
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
&&
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
{
toRemove
.
add
(
item
);
}
}
}
player
.
getInventory
().
removeItems
(
toRemove
);
@Command
(
label
=
"clearartifacts"
,
aliases
=
{
"clearart"
},
usage
=
"Usage: clearartifacts"
,
execution
=
Command
.
Execution
.
PLAYER
)
public
static
class
ClearArtifactsCommand
implements
CommandHandler
{
@Override
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
Inventory
playerInventory
=
player
.
getInventory
();
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
)
.
filter
(
item
->
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
)
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
forEach
(
item
->
playerInventory
.
removeItem
(
item
,
item
.
getCount
()));
}
}
}
}
}
}
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 {
...
@@ -485,7 +485,7 @@ public class GenshinPlayer {
this
.
regionId
=
regionId
;
this
.
regionId
=
regionId
;
}
}
public
boolean
has
Godmode
()
{
public
boolean
in
Godmode
()
{
return
godmode
;
return
godmode
;
}
}
...
@@ -559,6 +559,15 @@ public class GenshinPlayer {
...
@@ -559,6 +559,15 @@ public class GenshinPlayer {
this
.
sendPacket
(
new
PacketPrivateChatNotify
(
GenshinConstants
.
SERVER_CONSOLE_UID
,
getId
(),
message
.
toString
()));
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
)
{
public
void
interactWith
(
int
gadgetEntityId
)
{
GenshinEntity
entity
=
getWorld
().
getEntityById
(
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> {
...
@@ -344,7 +344,7 @@ public class World implements Iterable<GenshinPlayer> {
// Godmode check
// Godmode check
if
(
target
instanceof
EntityAvatar
)
{
if
(
target
instanceof
EntityAvatar
)
{
if
(((
EntityAvatar
)
target
).
getPlayer
().
has
Godmode
())
{
if
(((
EntityAvatar
)
target
).
getPlayer
().
in
Godmode
())
{
return
;
return
;
}
}
}
}
...
...
src/main/java/emu/grasscutter/utils/Utils.java
View file @
b35ee455
...
@@ -118,6 +118,16 @@ public final class Utils {
...
@@ -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.
* 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