Skip to content

Commit

Permalink
Optimize vehicle collision events more
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Oct 6, 2023
1 parent 8dc6461 commit 1c128b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ public class BukkitVehicleEvents {
public static class BukkitMCVehicleEntityCollideEvent extends BukkitMCVehicleEvent
implements MCVehicleEntityCollideEvent {

VehicleEntityCollisionEvent vec;
private final VehicleEntityCollisionEvent vec;
private MCEntity entity;

public BukkitMCVehicleEntityCollideEvent(VehicleCollisionEvent event) {
public BukkitMCVehicleEntityCollideEvent(VehicleEntityCollisionEvent event) {
super(event);
vec = (VehicleEntityCollisionEvent) event;
vec = event;
}

@Override
public MCEntity getEntity() {
return BukkitConvertor.BukkitGetCorrectEntity(vec.getEntity());
if(entity == null) {
entity = BukkitConvertor.BukkitGetCorrectEntity(vec.getEntity());
}
return entity;
}

@Override
Expand Down Expand Up @@ -185,15 +189,19 @@ public MCEntity getAttacker() {

public static class BukkitMCVehicleEvent implements MCVehicleEvent {

VehicleEvent ve;
private final VehicleEvent ve;
private MCEntity vehicle;

public BukkitMCVehicleEvent(VehicleEvent event) {
ve = event;
}

@Override
public MCEntity getVehicle() {
return BukkitConvertor.BukkitGetCorrectEntity(ve.getVehicle());
if(vehicle == null) {
vehicle = BukkitConvertor.BukkitGetCorrectEntity(ve.getVehicle());
}
return vehicle;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,23 @@ public void bind(BoundEvent event) {

@Override
public boolean matches(Map<String, Mixed> prefilter, BindableEvent e) throws PrefilterNonMatchException {
if(e instanceof MCVehicleCollideEvent) {
MCVehicleCollideEvent event = (MCVehicleCollideEvent) e;
Prefilters.match(prefilter, "type", event.getVehicle().getType().name(), PrefilterType.MACRO);
if(e instanceof MCVehicleCollideEvent event) {
if(prefilter.isEmpty()) {
return true;
}
if(prefilter.containsKey("collisiontype")) {
if(!event.getCollisionType().name().equals(prefilter.get("collisiontype").val())) {
return false;
}
}
switch(event.getCollisionType()) {
case BLOCK:
Prefilters.match(prefilter, "hittype",
((MCVehicleBlockCollideEvent) event).getBlock().getType().getName(),
PrefilterType.STRING_MATCH);
if(prefilter.containsKey("hittype")) {
if(!((MCVehicleBlockCollideEvent) event).getBlock().getType().name()
.equals(prefilter.get("hittype").val())) {
return false;
}
}
break;
case ENTITY:
Prefilters.match(prefilter, "hittype", ((MCVehicleEntityCollideEvent) event)
Expand All @@ -263,6 +267,7 @@ public boolean matches(Map<String, Mixed> prefilter, BindableEvent e) throws Pre
+ " Minecraft has reached the point where vehicles can hit things that are neither"
+ " a block nor an entity. Please report this error to developers.", Target.UNKNOWN);
}
Prefilters.match(prefilter, "type", event.getVehicle().getType().name(), PrefilterType.MACRO);
return true;
}
return false;
Expand Down

0 comments on commit 1c128b8

Please sign in to comment.