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
07969577
Commit
07969577
authored
Apr 24, 2022
by
BaiSugar
Browse files
Added command to get all items
parent
02ef9d84
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/Command.java
View file @
07969577
...
@@ -14,4 +14,6 @@ public @interface Command {
...
@@ -14,4 +14,6 @@ public @interface Command {
String
[]
aliases
()
default
{};
String
[]
aliases
()
default
{};
String
permission
()
default
""
;
String
permission
()
default
""
;
boolean
threading
()
default
false
;
}
}
src/main/java/emu/grasscutter/command/CommandMap.java
View file @
07969577
...
@@ -11,7 +11,6 @@ import java.util.*;
...
@@ -11,7 +11,6 @@ import java.util.*;
public
final
class
CommandMap
{
public
final
class
CommandMap
{
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
HashMap
<>();
private
final
Map
<
String
,
CommandHandler
>
commands
=
new
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
HashMap
<>();
private
final
Map
<
String
,
Command
>
annotations
=
new
HashMap
<>();
public
CommandMap
()
{
public
CommandMap
()
{
this
(
false
);
this
(
false
);
}
}
...
@@ -106,8 +105,9 @@ public final class CommandMap {
...
@@ -106,8 +105,9 @@ public final class CommandMap {
*/
*/
public
void
invoke
(
GenshinPlayer
player
,
String
rawMessage
)
{
public
void
invoke
(
GenshinPlayer
player
,
String
rawMessage
)
{
rawMessage
=
rawMessage
.
trim
();
rawMessage
=
rawMessage
.
trim
();
if
(
rawMessage
.
length
()
==
0
)
{
if
(
rawMessage
.
length
()
==
0
)
{
CommandHandler
.
sendMessage
(
player
,
"No command specified."
);
return
;
CommandHandler
.
sendMessage
(
player
,
"No command specified."
);
return
;
}
}
// Remove prefix if present.
// Remove prefix if present.
...
@@ -118,7 +118,6 @@ public final class CommandMap {
...
@@ -118,7 +118,6 @@ public final class CommandMap {
String
[]
split
=
rawMessage
.
split
(
" "
);
String
[]
split
=
rawMessage
.
split
(
" "
);
List
<
String
>
args
=
new
LinkedList
<>(
Arrays
.
asList
(
split
));
List
<
String
>
args
=
new
LinkedList
<>(
Arrays
.
asList
(
split
));
String
label
=
args
.
remove
(
0
);
String
label
=
args
.
remove
(
0
);
// Get command handler.
// Get command handler.
CommandHandler
handler
=
this
.
commands
.
get
(
label
);
CommandHandler
handler
=
this
.
commands
.
get
(
label
);
if
(
handler
==
null
)
{
if
(
handler
==
null
)
{
...
@@ -130,14 +129,22 @@ public final class CommandMap {
...
@@ -130,14 +129,22 @@ public final class CommandMap {
if
(
player
!=
null
)
{
if
(
player
!=
null
)
{
String
permissionNode
=
this
.
annotations
.
get
(
label
).
permission
();
String
permissionNode
=
this
.
annotations
.
get
(
label
).
permission
();
Account
account
=
player
.
getAccount
();
Account
account
=
player
.
getAccount
();
if
(!
permissionNode
.
isEmpty
()
&&
!
account
.
hasPermission
(
permissionNode
))
{
if
(!
permissionNode
.
isEmpty
()
&&
!
account
.
hasPermission
(
permissionNode
))
{
CommandHandler
.
sendMessage
(
player
,
"You do not have permission to run this command."
);
CommandHandler
.
sendMessage
(
player
,
"You do not have permission to run this command."
);
return
;
return
;
}
}
}
}
// Invoke execute method for handler.
// Invoke execute method for handler.
handler
.
execute
(
player
,
args
);
boolean
threading
=
this
.
annotations
.
get
(
label
).
threading
();
Runnable
runnable
=
()
->
handler
.
execute
(
player
,
args
);
if
(
threading
)
{
Thread
command
=
new
Thread
(
runnable
);
command
.
start
();
}
else
{
runnable
.
run
();
}
}
}
/**
/**
...
...
src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java
View file @
07969577
package
emu.grasscutter.command.commands
;
package
emu.grasscutter.command.commands
;
import
com.thoughtworks.proxy.toys.nullobject.Null
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.command.CommandHandler
;
...
@@ -9,14 +10,11 @@ import emu.grasscutter.data.def.ItemData;
...
@@ -9,14 +10,11 @@ import emu.grasscutter.data.def.ItemData;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
java.util.LinkedList
;
import
java.util.*
;
import
java.util.List
;
@Command
(
label
=
"giveall"
,
usage
=
"giveall [player] <amount>"
,
@Command
(
label
=
"giveall"
,
usage
=
"giveall [player] <amount>"
,
description
=
"Gives
A
ll item
to you or the specified player
"
,
aliases
=
{
"givea"
},
permission
=
"player.giveall"
)
description
=
"Gives
a
ll item
s
"
,
aliases
=
{
"givea"
},
permission
=
"player.giveall"
,
threading
=
true
)
public
class
GiveAllCommand
implements
CommandHandler
{
public
class
GiveAllCommand
implements
CommandHandler
{
@Override
@Override
...
@@ -25,7 +23,12 @@ public class GiveAllCommand implements CommandHandler {
...
@@ -25,7 +23,12 @@ public class GiveAllCommand implements CommandHandler {
switch
(
args
.
size
())
{
switch
(
args
.
size
())
{
default
:
// giveall *no args*
default
:
// giveall *no args*
try
{
target
=
sender
.
getUid
();
target
=
sender
.
getUid
();
}
catch
(
NullPointerException
ignored
){
CommandHandler
.
sendMessage
(
sender
,
"Player not found."
);
return
;
}
break
;
break
;
case
1
:
//[player]
case
1
:
//[player]
try
{
try
{
...
@@ -62,27 +65,27 @@ public class GiveAllCommand implements CommandHandler {
...
@@ -62,27 +65,27 @@ public class GiveAllCommand implements CommandHandler {
}
}
this
.
GetAllItem
(
targetPlayer
,
amount
);
this
.
GetAllItem
(
targetPlayer
,
amount
);
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Get A
ll
I
tems
D
one
."
)
);
CommandHandler
.
sendMessage
(
sender
,
"Done! or Getting a
ll
i
tems
d
one
"
);
}
}
public
void
GetAllItem
(
GenshinPlayer
player
,
int
amount
){
public
void
GetAllItem
(
GenshinPlayer
player
,
int
amount
){
CommandHandler
.
sendMessage
(
player
,
"Get All Items..."
);
CommandHandler
.
sendMessage
(
player
,
"Getting all items…"
);
Collection
<
GenshinItem
>
genshinItemList
=
new
LinkedList
<>();
for
(
ItemData
itemdata:
GenshinData
.
getItemDataMap
().
values
())
{
for
(
ItemData
itemdata:
GenshinData
.
getItemDataMap
().
values
())
{
if
(
itemdata
.
getId
()
>
1000
&&
itemdata
.
getId
()
<=
2000
)
continue
;
//is avatar
if
(
itemdata
.
getId
()
>
1000
&&
itemdata
.
getId
()
<=
1099
)
continue
;
//is avatar
if
(
itemdata
.
isEquip
())
{
if
(
itemdata
.
isEquip
())
{
List
<
GenshinItem
>
items
=
new
LinkedList
<>();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
items
.
add
(
new
GenshinItem
(
itemdata
));
genshinItemList
.
add
(
new
GenshinItem
(
itemdata
));
}
}
player
.
getInventory
().
addItems
(
items
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
SubfieldDrop
));
}
else
{
}
else
{
GenshinItem
genshinItem
=
new
GenshinItem
(
itemdata
);
GenshinItem
genshinItem
=
new
GenshinItem
(
itemdata
);
genshinItem
.
setCount
(
amount
);
genshinItem
.
setCount
(
amount
);
player
.
getInventory
().
addItem
(
genshinItem
);
genshinItemList
.
add
(
genshinItem
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
SubfieldDrop
));
}
}
}
}
player
.
getInventory
().
addItems
(
genshinItemList
);
for
(
AvatarData
avatarData:
GenshinData
.
getAvatarDataMap
().
values
())
for
(
AvatarData
avatarData:
GenshinData
.
getAvatarDataMap
().
values
())
{
{
int
ascension
;
int
ascension
;
...
...
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