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
e693612e
Commit
e693612e
authored
May 05, 2022
by
Melledy
Browse files
Fix clear command causing a concurrency error
parent
3ee619a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/ClearCommand.java
View file @
e693612e
...
@@ -3,6 +3,7 @@ package emu.grasscutter.command.commands;
...
@@ -3,6 +3,7 @@ package emu.grasscutter.command.commands;
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
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.Inventory
;
import
emu.grasscutter.game.inventory.Inventory
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
...
@@ -26,65 +27,71 @@ public final class ClearCommand implements CommandHandler {
...
@@ -26,65 +27,71 @@ public final class ClearCommand implements CommandHandler {
return
;
return
;
}
}
Inventory
playerInventory
=
targetPlayer
.
getInventory
();
Inventory
playerInventory
=
targetPlayer
.
getInventory
();
List
<
GameItem
>
toDelete
=
null
;
switch
(
args
.
get
(
0
))
{
switch
(
args
.
get
(
0
))
{
case
"wp"
->
{
case
"wp"
->
{
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
forEach
(
item
->
playerInventory
.
removeItem
(
item
,
item
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_weapons
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_weapons
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
}
}
case
"art"
->
{
case
"art"
->
{
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
)
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
)
.
filter
(
item
->
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
)
.
filter
(
item
->
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
)
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
forEach
(
item
->
playerInventory
.
removeItem
(
item
,
item
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
}
}
case
"mat"
->
{
case
"mat"
->
{
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_MATERIAL
)
.
filter
(
item
->
item
.
getItemType
()
==
ItemType
.
ITEM_MATERIAL
)
.
filter
(
item
->
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
)
.
filter
(
item
->
item
.
getLevel
()
==
1
&&
item
.
getExp
()
==
0
)
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
filter
(
item
->
!
item
.
isLocked
()
&&
!
item
.
isEquipped
())
.
forEach
(
item
->
playerInventory
.
removeItem
(
item
,
item
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
}
}
case
"all"
->
{
case
"all"
->
{
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item1
->
item1
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
)
.
filter
(
item1
->
item1
.
getItemType
()
==
ItemType
.
ITEM_RELIQUARY
)
.
filter
(
item1
->
item1
.
getLevel
()
==
1
&&
item1
.
getExp
()
==
0
)
.
filter
(
item1
->
item1
.
getLevel
()
==
1
&&
item1
.
getExp
()
==
0
)
.
filter
(
item1
->
!
item1
.
isLocked
()
&&
!
item1
.
isEquipped
())
.
filter
(
item1
->
!
item1
.
isLocked
()
&&
!
item1
.
isEquipped
())
.
forEach
(
item1
->
playerInventory
.
removeItem
(
item1
,
item1
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item2
->
item2
.
getItemType
()
==
ItemType
.
ITEM_MATERIAL
)
.
filter
(
item2
->
item2
.
getItemType
()
==
ItemType
.
ITEM_MATERIAL
)
.
filter
(
item2
->
!
item2
.
isLocked
()
&&
!
item2
.
isEquipped
())
.
filter
(
item2
->
!
item2
.
isLocked
()
&&
!
item2
.
isEquipped
())
.
forEach
(
item2
->
playerInventory
.
removeItem
(
item2
,
item2
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item3
->
item3
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
.
filter
(
item3
->
item3
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
.
filter
(
item3
->
item3
.
getLevel
()
==
1
&&
item3
.
getExp
()
==
0
)
.
filter
(
item3
->
item3
.
getLevel
()
==
1
&&
item3
.
getExp
()
==
0
)
.
filter
(
item3
->
!
item3
.
isLocked
()
&&
!
item3
.
isEquipped
())
.
filter
(
item3
->
!
item3
.
isLocked
()
&&
!
item3
.
isEquipped
())
.
forEach
(
item3
->
playerInventory
.
removeItem
(
item3
,
item3
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_artifacts
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item4
->
item4
.
getItemType
()
==
ItemType
.
ITEM_FURNITURE
)
.
filter
(
item4
->
item4
.
getItemType
()
==
ItemType
.
ITEM_FURNITURE
)
.
filter
(
item4
->
!
item4
.
isLocked
()
&&
!
item4
.
isEquipped
())
.
filter
(
item4
->
!
item4
.
isLocked
()
&&
!
item4
.
isEquipped
())
.
forEach
(
item4
->
playerInventory
.
removeItem
(
item4
,
item4
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_furniture
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_furniture
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item5
->
item5
.
getItemType
()
==
ItemType
.
ITEM_DISPLAY
)
.
filter
(
item5
->
item5
.
getItemType
()
==
ItemType
.
ITEM_DISPLAY
)
.
filter
(
item5
->
!
item5
.
isLocked
()
&&
!
item5
.
isEquipped
())
.
filter
(
item5
->
!
item5
.
isLocked
()
&&
!
item5
.
isEquipped
())
.
forEach
(
item5
->
playerInventory
.
removeItem
(
item5
,
item5
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_displays
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_displays
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
playerInventory
.
getItems
().
values
().
stream
()
toDelete
=
playerInventory
.
getItems
().
values
().
stream
()
.
filter
(
item6
->
item6
.
getItemType
()
==
ItemType
.
ITEM_VIRTUAL
)
.
filter
(
item6
->
item6
.
getItemType
()
==
ItemType
.
ITEM_VIRTUAL
)
.
filter
(
item6
->
!
item6
.
isLocked
()
&&
!
item6
.
isEquipped
())
.
filter
(
item6
->
!
item6
.
isLocked
()
&&
!
item6
.
isEquipped
())
.
forEach
(
item6
->
playerInventory
.
removeItem
(
item6
,
item6
.
getCount
())
);
.
toList
(
);
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_virtuals
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_virtuals
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_everything
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
CommandHandler
.
sendMessage
(
sender
,
Grasscutter
.
getLanguage
().
Clear_everything
.
replace
(
"{name}"
,
targetPlayer
.
getNickname
()));
}
}
}
}
if
(
toDelete
!=
null
)
{
playerInventory
.
removeItems
(
toDelete
);
}
}
}
}
}
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