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
1ceda2a4
Commit
1ceda2a4
authored
Nov 05, 2022
by
AnimeGitB
Browse files
Remove LinkedList usage
https://twitter.com/joshbloch/status/583813919019573248
parent
09f392bb
Changes
7
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/CommandMap.java
View file @
1ceda2a4
...
@@ -89,7 +89,7 @@ public final class CommandMap {
...
@@ -89,7 +89,7 @@ public final class CommandMap {
}
}
public
List
<
Command
>
getAnnotationsAsList
()
{
public
List
<
Command
>
getAnnotationsAsList
()
{
return
new
Linked
List
<>(
this
.
annotations
.
values
());
return
new
Array
List
<>(
this
.
annotations
.
values
());
}
}
public
Map
<
String
,
Command
>
getAnnotations
()
{
public
Map
<
String
,
Command
>
getAnnotations
()
{
...
@@ -102,7 +102,7 @@ public final class CommandMap {
...
@@ -102,7 +102,7 @@ public final class CommandMap {
* @return All command handlers as a list.
* @return All command handlers as a list.
*/
*/
public
List
<
CommandHandler
>
getHandlersAsList
()
{
public
List
<
CommandHandler
>
getHandlersAsList
()
{
return
new
Linked
List
<>(
this
.
commands
.
values
());
return
new
Array
List
<>(
this
.
commands
.
values
());
}
}
public
Map
<
String
,
CommandHandler
>
getHandlers
()
{
public
Map
<
String
,
CommandHandler
>
getHandlers
()
{
...
@@ -234,8 +234,8 @@ public final class CommandMap {
...
@@ -234,8 +234,8 @@ public final class CommandMap {
// Parse message.
// Parse message.
String
[]
split
=
rawMessage
.
split
(
" "
);
String
[]
split
=
rawMessage
.
split
(
" "
);
List
<
String
>
args
=
new
LinkedList
<>(
Arrays
.
asList
(
split
)
);
String
label
=
split
[
0
].
toLowerCase
(
);
String
label
=
args
.
remove
(
0
).
toLowerCase
(
);
List
<
String
>
args
=
new
ArrayList
<>(
Arrays
.
asList
(
split
).
subList
(
1
,
split
.
length
)
);
String
playerId
=
(
player
==
null
)
?
consoleId
:
player
.
getAccount
().
getId
();
String
playerId
=
(
player
==
null
)
?
consoleId
:
player
.
getAccount
().
getId
();
// Check for special cases - currently only target command.
// Check for special cases - currently only target command.
...
...
src/main/java/emu/grasscutter/game/player/PlayerBuffManager.java
View file @
1ceda2a4
package
emu.grasscutter.game.player
;
package
emu.grasscutter.game.player
;
import
java.util.
Linked
List
;
import
java.util.
Array
List
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -15,11 +15,8 @@ import emu.grasscutter.server.packet.send.PacketServerBuffChangeNotify;
...
@@ -15,11 +15,8 @@ import emu.grasscutter.server.packet.send.PacketServerBuffChangeNotify;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
lombok.AccessLevel
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.val
;
@Getter
(
AccessLevel
.
PRIVATE
)
public
class
PlayerBuffManager
extends
BasePlayerManager
{
public
class
PlayerBuffManager
extends
BasePlayerManager
{
private
int
nextBuffUid
;
private
int
nextBuffUid
;
...
@@ -29,7 +26,7 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -29,7 +26,7 @@ public class PlayerBuffManager extends BasePlayerManager {
public
PlayerBuffManager
(
Player
player
)
{
public
PlayerBuffManager
(
Player
player
)
{
super
(
player
);
super
(
player
);
this
.
buffs
=
new
Int2ObjectOpenHashMap
<>();
this
.
buffs
=
new
Int2ObjectOpenHashMap
<>();
this
.
pendingBuffs
=
new
Linked
List
<>();
this
.
pendingBuffs
=
new
Array
List
<>();
}
}
/**
/**
...
@@ -46,7 +43,7 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -46,7 +43,7 @@ public class PlayerBuffManager extends BasePlayerManager {
* @return True if a buff with this group id exists
* @return True if a buff with this group id exists
*/
*/
public
synchronized
boolean
hasBuff
(
int
groupId
)
{
public
synchronized
boolean
hasBuff
(
int
groupId
)
{
return
this
.
getB
uffs
()
.
containsKey
(
groupId
);
return
this
.
b
uffs
.
containsKey
(
groupId
);
}
}
/**
/**
...
@@ -55,11 +52,11 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -55,11 +52,11 @@ public class PlayerBuffManager extends BasePlayerManager {
public
synchronized
void
clearBuffs
()
{
public
synchronized
void
clearBuffs
()
{
// Remove from player
// Remove from player
getPlayer
().
sendPacket
(
getPlayer
().
sendPacket
(
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_DEL_SERVER_BUFF
,
getB
uffs
()
.
values
())
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_DEL_SERVER_BUFF
,
this
.
b
uffs
.
values
())
);
);
// Clear
// Clear
getB
uffs
()
.
clear
();
this
.
b
uffs
.
clear
();
}
}
/**
/**
...
@@ -139,7 +136,7 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -139,7 +136,7 @@ public class PlayerBuffManager extends BasePlayerManager {
// Create and store buff
// Create and store buff
PlayerBuff
buff
=
new
PlayerBuff
(
getNextBuffUid
(),
buffData
,
duration
);
PlayerBuff
buff
=
new
PlayerBuff
(
getNextBuffUid
(),
buffData
,
duration
);
getB
uffs
()
.
put
(
buff
.
getGroupId
(),
buff
);
this
.
b
uffs
.
put
(
buff
.
getGroupId
(),
buff
);
// Packet
// Packet
getPlayer
().
sendPacket
(
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_ADD_SERVER_BUFF
,
buff
));
getPlayer
().
sendPacket
(
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_ADD_SERVER_BUFF
,
buff
));
...
@@ -153,7 +150,7 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -153,7 +150,7 @@ public class PlayerBuffManager extends BasePlayerManager {
* @return True if a buff was remove
* @return True if a buff was remove
*/
*/
public
synchronized
boolean
removeBuff
(
int
buffGroupId
)
{
public
synchronized
boolean
removeBuff
(
int
buffGroupId
)
{
PlayerBuff
buff
=
this
.
getB
uffs
()
.
get
(
buffGroupId
);
PlayerBuff
buff
=
this
.
b
uffs
.
get
(
buffGroupId
);
if
(
buff
!=
null
)
{
if
(
buff
!=
null
)
{
getPlayer
().
sendPacket
(
getPlayer
().
sendPacket
(
...
@@ -167,28 +164,24 @@ public class PlayerBuffManager extends BasePlayerManager {
...
@@ -167,28 +164,24 @@ public class PlayerBuffManager extends BasePlayerManager {
public
synchronized
void
onTick
()
{
public
synchronized
void
onTick
()
{
// Skip if no buffs
// Skip if no buffs
if
(
getBuffs
().
size
()
==
0
)
return
;
if
(
this
.
buffs
.
isEmpty
()
)
return
;
long
currentTime
=
System
.
currentTimeMillis
();
long
currentTime
=
System
.
currentTimeMillis
();
// Add to pending buffs to remove if buff has expired
// Add to pending buffs to remove if buff has expired
for
(
PlayerBuff
buff
:
getBuffs
().
values
())
{
this
.
buffs
.
values
().
removeIf
(
buff
->
{
if
(
currentTime
>
buff
.
getEndTime
())
{
if
(
currentTime
<=
buff
.
getEndTime
())
this
.
getPendingBuffs
().
add
(
buff
);
return
false
;
}
this
.
pendingBuffs
.
add
(
buff
);
}
return
true
;
});
if
(
this
.
getP
endingBuffs
()
.
size
()
>
0
)
{
if
(
this
.
p
endingBuffs
.
size
()
>
0
)
{
// Send packet
// Send packet
getPlayer
().
sendPacket
(
getPlayer
().
sendPacket
(
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_DEL_SERVER_BUFF
,
this
.
pendingBuffs
)
new
PacketServerBuffChangeNotify
(
getPlayer
(),
ServerBuffChangeType
.
SERVER_BUFF_CHANGE_TYPE_DEL_SERVER_BUFF
,
this
.
pendingBuffs
)
);
);
this
.
pendingBuffs
.
clear
();
// Remove buff from player buff map
for
(
PlayerBuff
buff
:
this
.
getPendingBuffs
())
{
getBuffs
().
remove
(
buff
.
getGroupId
());
}
this
.
getPendingBuffs
().
clear
();
}
}
}
}
...
...
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
1ceda2a4
...
@@ -274,15 +274,8 @@ public class Scene {
...
@@ -274,15 +274,8 @@ public class Scene {
}
}
public
void
showOtherEntities
(
Player
player
)
{
public
void
showOtherEntities
(
Player
player
)
{
List
<
GameEntity
>
entities
=
new
LinkedList
<>();
GameEntity
currentEntity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
GameEntity
currentEntity
=
player
.
getTeamManager
().
getCurrentAvatarEntity
();
List
<
GameEntity
>
entities
=
this
.
getEntities
().
values
().
stream
().
filter
(
entity
->
entity
!=
currentEntity
).
toList
();
for
(
GameEntity
entity
:
this
.
getEntities
().
values
())
{
if
(
entity
==
currentEntity
)
{
continue
;
}
entities
.
add
(
entity
);
}
player
.
sendPacket
(
new
PacketSceneEntityAppearNotify
(
entities
,
VisionType
.
VISION_TYPE_MEET
));
player
.
sendPacket
(
new
PacketSceneEntityAppearNotify
(
entities
,
VisionType
.
VISION_TYPE_MEET
));
}
}
...
@@ -422,8 +415,8 @@ public class Scene {
...
@@ -422,8 +415,8 @@ public class Scene {
}
}
// Todo
// Todo
List
<
GameEntity
>
toAdd
=
new
Linked
List
<>();
List
<
GameEntity
>
toAdd
=
new
Array
List
<>();
List
<
GameEntity
>
toRemove
=
new
Linked
List
<>();
List
<
GameEntity
>
toRemove
=
new
Array
List
<>();
var
spawnedEntities
=
this
.
getSpawnedEntities
();
var
spawnedEntities
=
this
.
getSpawnedEntities
();
for
(
SpawnDataEntry
entry
:
visible
)
{
for
(
SpawnDataEntry
entry
:
visible
)
{
// If spawn entry is in our view and hasnt been spawned/killed yet, we should spawn it
// If spawn entry is in our view and hasnt been spawned/killed yet, we should spawn it
...
...
src/main/java/emu/grasscutter/plugin/PluginManager.java
View file @
1ceda2a4
...
@@ -181,7 +181,7 @@ public final class PluginManager {
...
@@ -181,7 +181,7 @@ public final class PluginManager {
// Add the plugin to the list of loaded plugins.
// Add the plugin to the list of loaded plugins.
this
.
plugins
.
put
(
identifier
.
name
,
plugin
);
this
.
plugins
.
put
(
identifier
.
name
,
plugin
);
// Create a collection for the plugin's listeners.
// Create a collection for the plugin's listeners.
this
.
listeners
.
put
(
plugin
,
new
Linked
List
<>());
this
.
listeners
.
put
(
plugin
,
new
Array
List
<>());
// Call the plugin's onLoad method.
// Call the plugin's onLoad method.
try
{
try
{
...
@@ -242,18 +242,14 @@ public final class PluginManager {
...
@@ -242,18 +242,14 @@ public final class PluginManager {
* @param priority The priority to call for.
* @param priority The priority to call for.
*/
*/
private
void
checkAndFilter
(
Event
event
,
HandlerPriority
priority
)
{
private
void
checkAndFilter
(
Event
event
,
HandlerPriority
priority
)
{
// Create a collection of listeners.
List
<
EventHandler
<?
extends
Event
>>
listeners
=
new
LinkedList
<>();
// Add all listeners from every plugin.
// Add all listeners from every plugin.
this
.
listeners
.
values
().
forEach
(
listeners:
:
addAll
);
this
.
listeners
.
values
().
stream
()
.
flatMap
(
Collection:
:
stream
)
listeners
.
stream
()
// Filter the listeners by priority.
// Filter the listeners by priority.
.
filter
(
handler
->
handler
.
handles
().
isInstance
(
event
))
.
filter
(
handler
->
handler
.
handles
().
isInstance
(
event
))
.
filter
(
handler
->
handler
.
getPriority
()
==
priority
)
.
filter
(
handler
->
handler
.
getPriority
()
==
priority
)
// Invoke the event.
// Invoke the event.
.
toList
()
.
forEach
(
handler
->
this
.
invokeHandler
(
event
,
handler
));
.
forEach
(
handler
->
this
.
invokeHandler
(
event
,
handler
));
}
}
/**
/**
...
...
src/main/java/emu/grasscutter/plugin/api/ServerHook.java
View file @
1ceda2a4
...
@@ -11,8 +11,9 @@ import emu.grasscutter.server.game.GameServer;
...
@@ -11,8 +11,9 @@ import emu.grasscutter.server.game.GameServer;
import
emu.grasscutter.server.http.HttpServer
;
import
emu.grasscutter.server.http.HttpServer
;
import
emu.grasscutter.server.http.Router
;
import
emu.grasscutter.server.http.Router
;
import
java.util.
Linked
List
;
import
java.util.
Array
List
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Stream
;
/**
/**
* Hooks into the {@link GameServer} class, adding convenient ways to do certain things.
* Hooks into the {@link GameServer} class, adding convenient ways to do certain things.
...
@@ -60,8 +61,17 @@ public final class ServerHook {
...
@@ -60,8 +61,17 @@ public final class ServerHook {
* Gets all online players.
* Gets all online players.
* @return Players connected to the server.
* @return Players connected to the server.
*/
*/
@Deprecated
(
forRemoval
=
true
)
public
List
<
Player
>
getOnlinePlayers
()
{
public
List
<
Player
>
getOnlinePlayers
()
{
return
new
LinkedList
<>(
this
.
gameServer
.
getPlayers
().
values
());
return
new
ArrayList
<>(
this
.
gameServer
.
getPlayers
().
values
());
}
/**
* Gets all online players.
* @return Players connected to the server.
*/
public
Stream
<
Player
>
getOnlinePlayersStream
()
{
return
this
.
gameServer
.
getPlayers
().
values
().
stream
();
}
}
/**
/**
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketServerBuffChangeNotify.java
View file @
1ceda2a4
package
emu.grasscutter.server.packet.send
;
package
emu.grasscutter.server.packet.send
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.stream.Stream
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.PlayerBuffManager.PlayerBuff
;
import
emu.grasscutter.game.player.PlayerBuffManager.PlayerBuff
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.BasePacket
;
...
@@ -13,31 +13,25 @@ import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChan
...
@@ -13,31 +13,25 @@ import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChan
public
class
PacketServerBuffChangeNotify
extends
BasePacket
{
public
class
PacketServerBuffChangeNotify
extends
BasePacket
{
public
PacketServerBuffChangeNotify
(
Player
player
,
ServerBuffChangeType
changeType
,
PlayerBuff
buff
)
{
public
PacketServerBuffChangeNotify
(
Player
player
,
ServerBuffChangeType
changeType
,
PlayerBuff
buff
)
{
super
(
PacketOpcodes
.
ServerBuffChangeNotify
);
this
(
player
,
changeType
,
Stream
.
of
(
buff
));
var
proto
=
ServerBuffChangeNotify
.
newBuilder
();
for
(
EntityAvatar
entity
:
player
.
getTeamManager
().
getActiveTeam
())
{
proto
.
addAvatarGuidList
(
entity
.
getAvatar
().
getGuid
());
}
}
proto
.
setServerBuffChangeType
(
changeType
);
public
PacketServerBuffChangeNotify
(
Player
player
,
ServerBuffChangeType
changeType
,
Collection
<
PlayerBuff
>
buffs
)
{
proto
.
addServerBuffList
(
buff
.
toProto
());
this
(
player
,
changeType
,
buffs
.
stream
());
this
.
setData
(
proto
);
}
}
public
PacketServerBuffChangeNotify
(
Player
player
,
ServerBuffChangeType
changeType
,
Collection
<
PlayerBuff
>
buffs
)
{
public
PacketServerBuffChangeNotify
(
Player
player
,
ServerBuffChangeType
changeType
,
Stream
<
PlayerBuff
>
buffs
)
{
super
(
PacketOpcodes
.
ServerBuffChangeNotify
);
super
(
PacketOpcodes
.
ServerBuffChangeNotify
);
var
proto
=
ServerBuffChangeNotify
.
newBuilder
();
var
proto
=
ServerBuffChangeNotify
.
newBuilder
();
for
(
EntityAvatar
entity
:
player
.
getTeamManager
().
getActiveTeam
()
)
{
player
.
getTeamManager
().
getActiveTeam
()
.
stream
()
proto
.
addAvatarGuidList
(
entity
.
getAvatar
().
getGuid
())
;
.
mapToLong
(
entity
->
entity
.
getAvatar
().
getGuid
())
}
.
forEach
(
proto:
:
addAvatarGuidList
);
proto
.
setServerBuffChangeType
(
changeType
);
proto
.
setServerBuffChangeType
(
changeType
);
proto
.
addAllServerBuffList
(
buffs
.
stream
().
map
(
PlayerBuff:
:
toProto
).
toList
());
buffs
.
map
(
PlayerBuff:
:
toProto
)
.
forEach
(
proto:
:
addServerBuffList
);
this
.
setData
(
proto
);
this
.
setData
(
proto
);
}
}
...
...
src/main/java/emu/grasscutter/task/TaskMap.java
View file @
1ceda2a4
...
@@ -133,7 +133,7 @@ public final class TaskMap {
...
@@ -133,7 +133,7 @@ public final class TaskMap {
}
}
public
List
<
TaskHandler
>
getHandlersAsList
()
{
public
List
<
TaskHandler
>
getHandlersAsList
()
{
return
new
Linked
List
<>(
this
.
tasks
.
values
());
return
new
Array
List
<>(
this
.
tasks
.
values
());
}
}
public
HashMap
<
String
,
TaskHandler
>
getHandlers
()
{
public
HashMap
<
String
,
TaskHandler
>
getHandlers
()
{
...
...
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