Skip to content

Commit

Permalink
Inject Entity in spawner_spawn event
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jun 26, 2018
1 parent 9df39df commit a41cacd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/me/pseudoknight/chspigot/Events.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.pseudoknight.chspigot;

import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.annotations.api;
import com.laytonsmith.core.CHVersion;
import com.laytonsmith.core.ObjectGenerator;
Expand All @@ -10,8 +11,10 @@
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.events.AbstractEvent;
import com.laytonsmith.core.events.BindableEvent;
import com.laytonsmith.core.events.BoundEvent;
import com.laytonsmith.core.events.Driver;
import com.laytonsmith.core.events.Prefilters;
import com.laytonsmith.core.exceptions.EventException;
Expand Down Expand Up @@ -321,6 +324,23 @@ public Version since() {
public boolean modifyEvent(String key, Construct value, BindableEvent e) {
return false;
}

@Override
public void preExecution(Environment env, BoundEvent.ActiveEvent activeEvent) {
if(activeEvent.getUnderlyingEvent() instanceof MCSpawnerSpawnEvent) {
// Entity object isn't in the world yet, so we need to inject it to make it accessible to functions
MCEntity entity = ((MCSpawnerSpawnEvent) activeEvent.getUnderlyingEvent()).getEntity();
Static.InjectEntity(entity);
}
}

@Override
public void postExecution(Environment env, BoundEvent.ActiveEvent activeEvent) {
if(activeEvent.getUnderlyingEvent() instanceof MCSpawnerSpawnEvent) {
MCEntity entity = ((MCSpawnerSpawnEvent) activeEvent.getUnderlyingEvent()).getEntity();
Static.UninjectEntity(entity);
}
}
}

}

0 comments on commit a41cacd

Please sign in to comment.