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.
Added some missing documentation as well as damage determination.
- Loading branch information
Showing
6 changed files
with
233 additions
and
6 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
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
110 changes: 110 additions & 0 deletions
110
src/main/java/com/denizenscript/denizen2sponge/events/entity/EntityDiesScriptEvent.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,110 @@ | ||
package com.denizenscript.denizen2sponge.events.entity; | ||
|
||
import com.denizenscript.denizen2core.events.ScriptEvent; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.BooleanTag; | ||
import com.denizenscript.denizen2core.tags.objects.NumberTag; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.cause.entity.damage.DamageModifier; | ||
import org.spongepowered.api.event.entity.DamageEntityEvent; | ||
import org.spongepowered.api.event.entity.DestructEntityEvent; | ||
import org.spongepowered.api.util.Tuple; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Function; | ||
|
||
public class EntityDiesScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity dies | ||
// | ||
// @Updated 2017/03/24 | ||
// | ||
// @Group Entity | ||
// | ||
// @Cancellable false | ||
// | ||
// @Triggers when an entity dies. | ||
// | ||
// @Switch type (EntityTypeTag) checks the entity type. | ||
// | ||
// @Context | ||
// entity (EntityTag) returns the entity that died. | ||
// message (FormattedTextTag) returns the message that will be broadcast to the server. | ||
// | ||
// @Determinations | ||
// message (FormattedTextTag) to set the message displayed when the entity dies. | ||
// cancel_message (BooleanTag) to set whether the death message is cancelled. | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityDies"; | ||
} | ||
|
||
@Override | ||
public boolean couldMatch(ScriptEventData data) { | ||
return data.eventPath.startsWith("entity dies"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptEventData data) { | ||
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error); | ||
} | ||
|
||
public EntityTag entity; | ||
|
||
public FormattedTextTag message; | ||
|
||
public DestructEntityEvent.Death internal; | ||
|
||
@Override | ||
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) { | ||
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data); | ||
defs.put("entity", entity); | ||
defs.put("message", message); | ||
return defs; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
Sponge.getEventManager().unregisterListeners(this); | ||
} | ||
|
||
@Listener | ||
public void onEntityDies(DestructEntityEvent.Death evt) { | ||
EntityDiesScriptEvent event = (EntityDiesScriptEvent) clone(); | ||
event.internal = evt; | ||
event.entity = new EntityTag(evt.getTargetEntity()); | ||
event.message = new FormattedTextTag(evt.getMessage()); | ||
event.run(); | ||
} | ||
|
||
@Override | ||
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) { | ||
if (determination.equals("message")) { | ||
FormattedTextTag ftt = FormattedTextTag.getFor(this::error, value); | ||
message = ftt; | ||
internal.setMessage(ftt.getInternal()); | ||
} | ||
else if (determination.equals("cancel_message")) { | ||
// TODO: Context for this? | ||
BooleanTag bt = BooleanTag.getFor(this::error, value); | ||
internal.setMessageCancelled(bt.getInternal()); | ||
} | ||
else { | ||
super.applyDetermination(errors, determination, value); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/com/denizenscript/denizen2sponge/events/entity/EntityKilledScriptEvent.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,100 @@ | ||
package com.denizenscript.denizen2sponge.events.entity; | ||
|
||
import com.denizenscript.denizen2core.events.ScriptEvent; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.NumberTag; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.events.D2SpongeEventHelper; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.cause.entity.damage.DamageModifier; | ||
import org.spongepowered.api.event.entity.DamageEntityEvent; | ||
import org.spongepowered.api.util.Tuple; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Function; | ||
|
||
public class EntityKilledScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity killed | ||
// | ||
// @Updated 2017/03/24 | ||
// | ||
// @Group Entity | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity is killed. | ||
// | ||
// @Switch type (EntityTypeTag) checks the entity type. | ||
// | ||
// @Context | ||
// entity (EntityTag) returns the entity that was killed. | ||
// damage (NumberTag) returns the amount of damage applied. | ||
// | ||
// @Determinations | ||
// None. | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityKilled"; | ||
} | ||
|
||
@Override | ||
public boolean couldMatch(ScriptEventData data) { | ||
return data.eventPath.startsWith("entity killed"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptEventData data) { | ||
return D2SpongeEventHelper.checkEntityType(entity.getInternal().getType(), data, this::error); | ||
} | ||
|
||
public EntityTag entity; | ||
|
||
public NumberTag damage; | ||
|
||
public DamageEntityEvent internal; | ||
|
||
@Override | ||
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) { | ||
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data); | ||
defs.put("entity", entity); | ||
defs.put("damage", damage); | ||
return defs; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
Sponge.getEventManager().unregisterListeners(this); | ||
} | ||
|
||
@Listener | ||
public void onEntityKilled(DamageEntityEvent evt) { | ||
EntityKilledScriptEvent event = (EntityKilledScriptEvent) clone(); | ||
event.internal = evt; | ||
if (!evt.willCauseDeath()) { | ||
return; | ||
} | ||
event.entity = new EntityTag(evt.getTargetEntity()); | ||
event.damage = new NumberTag(evt.getFinalDamage()); | ||
event.cancelled = evt.isCancelled(); | ||
// TODO: Cause viewing | ||
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