Skip to content

Commit b42f420

Browse files
committed
Fixed the ECS
1 parent f838a00 commit b42f420

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

OnsetJava-API/src/main/java/net/onfirenetwork/onsetjava/component/EntityComponentSystem.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.onfirenetwork.onsetjava.plugin.event.vehicle.VehicleDamageEvent;
99
import net.onfirenetwork.onsetjava.plugin.event.vehicle.VehicleRespawnEvent;
1010

11+
import java.util.List;
1112
import java.util.function.Consumer;
1213

1314
public class EntityComponentSystem {
@@ -22,11 +23,15 @@ public static void init(){
2223
}
2324

2425
private static void applyEvents(Player player, Consumer<PlayerComponent> consumer){
25-
player.getComponents().forEach(consumer);
26+
List<PlayerComponent> components = player.getComponents();
27+
components.forEach(c -> c.setEntity(player));
28+
components.forEach(consumer);
2629
}
2730

2831
private static void applyEvents(Vehicle vehicle, Consumer<VehicleComponent> consumer){
29-
vehicle.getComponents().forEach(consumer);
32+
List<VehicleComponent> components = vehicle.getComponents();
33+
components.forEach(c -> c.setEntity(vehicle));
34+
components.forEach(consumer);
3035
}
3136

3237
@EventHandler

OnsetJava-API/src/main/java/net/onfirenetwork/onsetjava/entity/AttributeEntity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ default <T> T getAttribute(String key){
1616
return value == null ? null : (T) value;
1717
}
1818
default <T> T getAttribute(String key, T defaultValue){
19-
return (T) getAttributes().getOrDefault(key, defaultValue);
19+
T value = getAttribute(key);
20+
if(value == null){
21+
value = defaultValue;
22+
setAttribute(key, value);
23+
}
24+
return value;
2025
}
2126

2227
}

OnsetJava-JNI/src/main/java/net/onfirenetwork/onsetjava/jni/AttributeSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public class AttributeSystem {
1717
private static Map<Integer, Map<String, Object>> text3DAttributes = new HashMap<>();
1818

1919
public static Map<String, Object> getPlayerAttributes(int id){
20-
if(!playerAttributes.containsKey(id))
20+
if(!playerAttributes.containsKey(id)){
2121
playerAttributes.put(id, new HashMap<>());
22+
}
2223
return playerAttributes.get(id);
2324
}
2425

0 commit comments

Comments
 (0)