This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...va/com/denizenscript/denizen2sponge/events/entity/EntityCollidesWithBlockScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.denizenscript.denizen2sponge.events.entity; | ||
|
||
import com.denizenscript.denizen2core.events.ScriptEvent; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper; | ||
import com.denizenscript.denizen2sponge.tags.objects.BlockTypeTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.LocationTag; | ||
import com.denizenscript.denizen2sponge.utilities.Utilities; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.entity.Entity; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.block.CollideBlockEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class EntityCollidesWithBlockScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Since 0.3.2 | ||
// @Events | ||
// entity collides with block | ||
// | ||
// @Updated 2017/10/27 | ||
// | ||
// @Group Entity | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity collides with a block. Note: this event may fire very rapidly. | ||
// | ||
// @Switch entity_type (EntityTypeTag) checks the entity type. | ||
// @Switch block_type (BlockTypeTag) checks the block type. | ||
// @Switch world (WorldTag) checks the world. | ||
// @Switch cuboid (CuboidTag) checks the cuboid area. | ||
// @Switch weather (TextTag) checks the weather. | ||
// | ||
// @Context | ||
// entity (EntityTag) returns the entity that collided with the block. | ||
// location (LocationTag) returns the location of the colliding block. | ||
// impact_normal (LocationTag) returns the impact normal of the collision. | ||
// | ||
// @Determinations | ||
// None. | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityCollidesWithBlock"; | ||
} | ||
|
||
@Override | ||
public boolean couldMatch(ScriptEventData data) { | ||
return data.eventPath.startsWith("entity collides with block"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptEventData data) { | ||
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error, "entity_type") | ||
&& D2SpongeEventHelper.checkBlockType(material.getInternal(), data, this::error, "block_type") | ||
&& D2SpongeEventHelper.checkWorld(location.getInternal().world, data, this::error) | ||
&& D2SpongeEventHelper.checkCuboid(location.getInternal(), data, this::error) | ||
&& D2SpongeEventHelper.checkWeather(Utilities.getIdWithoutDefaultPrefix( | ||
location.getInternal().world.getWeather().getId()), data, this::error); | ||
} | ||
|
||
public EntityTag entity; | ||
|
||
public BlockTypeTag material; | ||
|
||
public LocationTag location; | ||
|
||
public LocationTag impact_normal; | ||
|
||
public CollideBlockEvent internal; | ||
|
||
@Override | ||
public void enable() { | ||
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
Sponge.getEventManager().unregisterListeners(this); | ||
} | ||
|
||
@Override | ||
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) { | ||
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data); | ||
defs.put("entity", entity); | ||
defs.put("location", location); | ||
defs.put("impact_normal", impact_normal); | ||
return defs; | ||
} | ||
|
||
@Listener | ||
public void onEntityCollidesWithBlock(CollideBlockEvent evt) { | ||
EntityCollidesWithBlockScriptEvent event = (EntityCollidesWithBlockScriptEvent) clone(); | ||
event.internal = evt; | ||
event.entity = new EntityTag((Entity) evt.getSource()); | ||
event.material = new BlockTypeTag(evt.getTargetBlock().getType()); | ||
event.location = new LocationTag(evt.getTargetLocation()); | ||
event.impact_normal = new LocationTag(evt.getTargetSide().asOffset()); | ||
event.cancelled = evt.isCancelled(); | ||
event.run(); | ||
evt.setCancelled(event.cancelled); | ||
} | ||
|
||
@Override | ||
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) { | ||
super.applyDetermination(errors, determination, value); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...a/com/denizenscript/denizen2sponge/events/entity/EntityCollidesWithEntityScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.denizenscript.denizen2sponge.events.entity; | ||
|
||
import com.denizenscript.denizen2core.events.ScriptEvent; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.ListTag; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.LocationTag; | ||
import com.denizenscript.denizen2sponge.utilities.Utilities; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.entity.Entity; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.entity.CollideEntityEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class EntityCollidesWithEntityScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Since 0.3.2 | ||
// @Events | ||
// entity collides with entity | ||
// | ||
// @Updated 2017/11/03 | ||
// | ||
// @Group Entity | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity collides with another entity. Note: this event may fire very rapidly. | ||
// | ||
// @Switch type (EntityTypeTag) checks the first entity type. | ||
// @Switch world (WorldTag) checks the world. | ||
// @Switch cuboid (CuboidTag) checks the cuboid area. | ||
// @Switch weather (TextTag) checks the weather. | ||
// | ||
// @Context | ||
// entities (EntityTag) returns the entities that collided. | ||
// | ||
// @Determinations | ||
// None. | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityCollidesWithEntity"; | ||
} | ||
|
||
@Override | ||
public boolean couldMatch(ScriptEventData data) { | ||
return data.eventPath.startsWith("entity collides with entity"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptEventData data) { | ||
return D2SpongeEventHelper.checkEntityType(((EntityTag) entities.getInternal().get(0)).getInternal().getType(), data, this::error, "type") | ||
&& D2SpongeEventHelper.checkWorld(((EntityTag) entities.getInternal().get(0)).getInternal().getLocation().getExtent(), data, this::error) | ||
&& D2SpongeEventHelper.checkCuboid(new LocationTag(((EntityTag) entities.getInternal().get(0)).getInternal().getLocation()).getInternal(), data, this::error) | ||
&& D2SpongeEventHelper.checkWeather(Utilities.getIdWithoutDefaultPrefix( | ||
((EntityTag) entities.getInternal().get(0)).getInternal().getLocation().getExtent().getWeather().getId()), data, this::error); | ||
} | ||
|
||
public ListTag entities; | ||
|
||
public CollideEntityEvent internal; | ||
|
||
@Override | ||
public void enable() { | ||
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
Sponge.getEventManager().unregisterListeners(this); | ||
} | ||
|
||
@Override | ||
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) { | ||
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data); | ||
defs.put("entities", entities); | ||
return defs; | ||
} | ||
|
||
@Listener | ||
public void onEntityCollidesWithEntity(CollideEntityEvent evt) { | ||
EntityCollidesWithEntityScriptEvent event = (EntityCollidesWithEntityScriptEvent) clone(); | ||
event.internal = evt; | ||
ListTag list = new ListTag(); | ||
for (Entity ent : evt.getEntities()) { | ||
list.getInternal().add(new EntityTag(ent)); | ||
} | ||
event.entities = list; | ||
event.cancelled = evt.isCancelled(); | ||
event.run(); | ||
evt.setCancelled(event.cancelled); | ||
} | ||
|
||
@Override | ||
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) { | ||
super.applyDetermination(errors, determination, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters