Skip to content

Commit

Permalink
Fetching unit by type, build without type, and fixing a nullpointer c…
Browse files Browse the repository at this point in the history
…rash (#9703)

* Pluh

* Pluh

* Update LExecutor.java

* fixed the null

* Update LExecutor.java

* I will point your null exception

* is it null or nah

* it is nah

* Update LExecutor.java

* Update LExecutor.java

* null zero
  • Loading branch information
BlueTheCube authored Apr 2, 2024
1 parent e177035 commit d3a78a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions core/src/mindustry/logic/LExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1363,13 +1363,21 @@ public void run(LExecutor exec){
TeamData data = t.data();

switch(type){
case unit -> exec.setobj(result, i < 0 || i >= data.units.size ? null : data.units.get(i));
case unit -> {
UnitType type = exec.obj(extra) instanceof UnitType u ? u : null;
if(type == null){
exec.setobj(result, i < 0 || i >= data.units.size ? null : data.units.get(i));
}else{
var units = data.unitCache(type);
exec.setobj(result, units == null || i < 0 || i >= units.size ? null : units.get(i));
}
}
case player -> exec.setobj(result, i < 0 || i >= data.players.size || data.players.get(i).unit().isNull() ? null : data.players.get(i).unit());
case core -> exec.setobj(result, i < 0 || i >= data.cores.size ? null : data.cores.get(i));
case build -> {
Block block = exec.obj(extra) instanceof Block b ? b : null;
if(block == null){
exec.setobj(result, null);
exec.setobj(result, i < 0 || i >= data.buildings.size ? null : data.buildings.get(i));
}else{
var builds = data.getBuildings(block);
exec.setobj(result, i < 0 || i >= builds.size ? null : builds.get(i));
Expand All @@ -1380,7 +1388,7 @@ public void run(LExecutor exec){
if(type == null){
exec.setnum(result, data.units.size);
}else{
exec.setnum(result, data.unitsByType[type.id].size);
exec.setnum(result, data.unitCache(type) == null ? 0 : data.unitCache(type).size);
}
}
case coreCount -> exec.setnum(result, data.cores.size);
Expand Down
8 changes: 7 additions & 1 deletion core/src/mindustry/logic/LStatements.java
Original file line number Diff line number Diff line change
Expand Up @@ -1856,11 +1856,17 @@ void rebuild(Table table){
fields(table, index, i -> index = i);
}

if(type == FetchType.buildCount || type == FetchType.build || type == FetchType.unitCount){
if(type == FetchType.buildCount || type == FetchType.build){
row(table);

fields(table, "block", extra, i -> extra = i);
}

if(type == FetchType.unitCount || type == FetchType.unit){
row(table);

fields(table, "unit", extra, i -> extra = i);
}
}

@Override
Expand Down

0 comments on commit d3a78a9

Please sign in to comment.