move final HashSets, ArrayList, HashMap, ... initialisation from constructor to class

This commit is contained in:
Bixilon 2020-08-25 18:16:32 +02:00
parent 0f4734e84f
commit d7b9c2efc6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 17 additions and 32 deletions

View File

@ -19,15 +19,15 @@ import de.bixilon.minosoft.game.datatypes.inventory.Slot;
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffect;
import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Entities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
public abstract class Entity implements EntityInterface {
final int entityId;
final UUID uuid;
final HashMap<InventorySlots.EntityInventorySlots, Slot> equipment;
final ArrayList<StatusEffect> effectList;
final HashMap<InventorySlots.EntityInventorySlots, Slot> equipment = new HashMap<>();
final HashSet<StatusEffect> effectList = new HashSet<>();
Location location;
int yaw;
int pitch;
@ -53,8 +53,6 @@ public abstract class Entity implements EntityInterface {
this.location = location;
this.yaw = yaw;
this.pitch = pitch;
this.equipment = new HashMap<>();
this.effectList = new ArrayList<>();
}
public int getEntityId() {
@ -114,7 +112,7 @@ public abstract class Entity implements EntityInterface {
return EntityMetaData.class;
}
public ArrayList<StatusEffect> getEffectList() {
public HashSet<StatusEffect> getEffectList() {
return effectList;
}

View File

@ -16,13 +16,9 @@ package de.bixilon.minosoft.game.datatypes.scoreboard;
import java.util.HashMap;
public class ScoreboardManager {
final HashMap<String, Team> teams;
final HashMap<String, ScoreboardObjective> objectives;
final HashMap<String, Team> teams = new HashMap<>();
final HashMap<String, ScoreboardObjective> objectives = new HashMap<>();
public ScoreboardManager() {
teams = new HashMap<>();
objectives = new HashMap<>();
}
public void addTeam(Team team) {
teams.put(team.getName(), team);

View File

@ -19,13 +19,12 @@ import java.util.HashMap;
public class ScoreboardObjective {
final String objectiveName;
final HashMap<String, ScoreboardScore> scores;
final HashMap<String, ScoreboardScore> scores = new HashMap<>();
TextComponent objectiveValue;
public ScoreboardObjective(String objectiveName, TextComponent objectiveValue) {
this.objectiveName = objectiveName;
this.objectiveValue = objectiveValue;
this.scores = new HashMap<>();
}
public String getObjectiveName() {

View File

@ -26,19 +26,16 @@ import java.util.Map;
* Collection of ChunkColumns
*/
public class World {
final HashMap<ChunkLocation, Chunk> chunks;
final HashMap<Integer, Entity> entities;
final HashMap<ChunkLocation, Chunk> chunks = new HashMap<>();
final HashMap<Integer, Entity> entities = new HashMap<>();
final String name;
final HashMap<BlockPosition, CompoundTag> blockEntityMeta;
final HashMap<BlockPosition, CompoundTag> blockEntityMeta = new HashMap<>();
boolean hardcore;
boolean raining;
Dimension dimension; // used for sky color, etc
public World(String name) {
this.name = name;
chunks = new HashMap<>();
entities = new HashMap<>();
blockEntityMeta = new HashMap<>();
}
public String getName() {

View File

@ -40,10 +40,10 @@ import java.util.ArrayList;
public class Connection {
final ArrayList<ServerAddress> addresses;
final Network network;
final PacketHandler handler;
final PacketSender sender;
final ArrayList<ClientboundPacket> handlingQueue;
final Network network = new Network(this);
final PacketHandler handler = new PacketHandler(this);
final PacketSender sender = new PacketSender(this);
final ArrayList<ClientboundPacket> handlingQueue = new ArrayList<>();
final VelocityHandler velocityHandler = new VelocityHandler(this);
final int connectionId;
ServerAddress address;
@ -66,10 +66,6 @@ public class Connection {
e.printStackTrace();
throw new RuntimeException(e);
}
network = new Network(this);
handlingQueue = new ArrayList<>();
handler = new PacketHandler(this);
sender = new PacketSender(this);
}
/**

View File

@ -38,7 +38,7 @@ import java.util.ArrayList;
public class Network {
final Connection connection;
final ArrayList<ServerboundPacket> queue;
final ArrayList<ServerboundPacket> queue = new ArrayList<>();
Thread socketThread;
int compressionThreshold = -1;
Socket socket;
@ -49,9 +49,8 @@ public class Network {
SecretKey secretKey;
boolean connected;
public Network(Connection c) {
this.connection = c;
this.queue = new ArrayList<>();
public Network(Connection connection) {
this.connection = connection;
}
public void connect(ServerAddress address) {