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

View File

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

View File

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

View File

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

View File

@ -40,10 +40,10 @@ import java.util.ArrayList;
public class Connection { public class Connection {
final ArrayList<ServerAddress> addresses; final ArrayList<ServerAddress> addresses;
final Network network; final Network network = new Network(this);
final PacketHandler handler; final PacketHandler handler = new PacketHandler(this);
final PacketSender sender; final PacketSender sender = new PacketSender(this);
final ArrayList<ClientboundPacket> handlingQueue; final ArrayList<ClientboundPacket> handlingQueue = new ArrayList<>();
final VelocityHandler velocityHandler = new VelocityHandler(this); final VelocityHandler velocityHandler = new VelocityHandler(this);
final int connectionId; final int connectionId;
ServerAddress address; ServerAddress address;
@ -66,10 +66,6 @@ public class Connection {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); 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 { public class Network {
final Connection connection; final Connection connection;
final ArrayList<ServerboundPacket> queue; final ArrayList<ServerboundPacket> queue = new ArrayList<>();
Thread socketThread; Thread socketThread;
int compressionThreshold = -1; int compressionThreshold = -1;
Socket socket; Socket socket;
@ -49,9 +49,8 @@ public class Network {
SecretKey secretKey; SecretKey secretKey;
boolean connected; boolean connected;
public Network(Connection c) { public Network(Connection connection) {
this.connection = c; this.connection = connection;
this.queue = new ArrayList<>();
} }
public void connect(ServerAddress address) { public void connect(ServerAddress address) {