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