Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Explosive Commands and Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Jan 10, 2018
1 parent b430fbd commit faeb4fb
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 5 deletions.
Expand Up @@ -124,6 +124,8 @@ public void onServerStart(GamePreInitializationEvent event) {
// Commands: Entity
Denizen2Core.register(new AirCommand());
Denizen2Core.register(new CastCommand());
Denizen2Core.register(new DefuseCommand());
Denizen2Core.register(new DetonateCommand());
Denizen2Core.register(new DropCommand());
Denizen2Core.register(new EditEntityCommand());
Denizen2Core.register(new EquipCommand());
Expand All @@ -132,6 +134,7 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.register(new HurtCommand());
Denizen2Core.register(new LookAtCommand());
Denizen2Core.register(new MountCommand());
Denizen2Core.register(new PrimeCommand());
Denizen2Core.register(new RemoveCommand());
Denizen2Core.register(new SpawnCommand());
Denizen2Core.register(new TeleportCommand());
Expand Down
@@ -0,0 +1,64 @@
package com.denizenscript.denizen2sponge.commands.entity;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.entity.explosive.FusedExplosive;

public class DefuseCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name defuse
// @Arguments <entity>
// @Short defuses an explosive entity.
// @Updated 2018/01/10
// @Group Entity
// @Minimum 1
// @Maximum 1
// @Description
// Defuses an explosive entity. Inverse of <@link command prime>prime<@/link>.
// @Example
// # This example defuses the creeper the player is looking at.
// - defuse <player.target_entities[type:creeper].get[1]>
// -->

@Override
public String getName() {
return "defuse";
}

@Override
public String getArguments() {
return "<entity>";
}

@Override
public int getMinimumArguments() {
return 1;
}

@Override
public int getMaximumArguments() {
return 1;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
try {
((FusedExplosive) ent.getInternal()).defuse();
if (queue.shouldShowGood()) {
queue.outGood("Defusing entity: " + ColorSet.emphasis + ent.debug() + ColorSet.good + "!");
}
}
catch (ClassCastException e) {
queue.handleError("This entity is not an explosive, so it can't be defused!");
}
catch (IllegalStateException e) {
queue.handleError("This explosive entity is not primed!");
}
}
}
@@ -0,0 +1,61 @@
package com.denizenscript.denizen2sponge.commands.entity;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.entity.explosive.Explosive;

public class DetonateCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name detonate
// @Arguments <entity>
// @Short instantly detonates an explosive entity.
// @Updated 2018/01/10
// @Group Entity
// @Minimum 1
// @Maximum 1
// @Description
// Instantly detonates an explosive entity.
// @Example
// # This example detonates the creeper the player is looking at.
// - detonate <player.target_entities[type:creeper].get[1]>
// -->

@Override
public String getName() {
return "detonate";
}

@Override
public String getArguments() {
return "<entity>";
}

@Override
public int getMinimumArguments() {
return 1;
}

@Override
public int getMaximumArguments() {
return 1;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
try {
((Explosive) ent.getInternal()).detonate();
if (queue.shouldShowGood()) {
queue.outGood("Detonating entity: " + ColorSet.emphasis + ent.debug() + ColorSet.good + "!");
}
}
catch (ClassCastException e) {
queue.handleError("This entity is not an explosive, so it can't be detonated!");
}
}
}
@@ -0,0 +1,64 @@
package com.denizenscript.denizen2sponge.commands.entity;

import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.entity.explosive.FusedExplosive;

public class PrimeCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name prime
// @Arguments <entity>
// @Short primes an explosive entity.
// @Updated 2018/01/10
// @Group Entity
// @Minimum 1
// @Maximum 1
// @Description
// Primes an explosive entity. Inverse of <@link command defuse>defuse<@/link>.
// @Example
// # This example primes the creeper the player is looking at.
// - prime <player.target_entities[type:creeper].get[1]>
// -->

@Override
public String getName() {
return "prime";
}

@Override
public String getArguments() {
return "<entity>";
}

@Override
public int getMinimumArguments() {
return 1;
}

@Override
public int getMaximumArguments() {
return 1;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
try {
((FusedExplosive) ent.getInternal()).prime();
if (queue.shouldShowGood()) {
queue.outGood("Priming entity: " + ColorSet.emphasis + ent.debug() + ColorSet.good + "!");
}
}
catch (ClassCastException e) {
queue.handleError("This entity is not an explosive, so it can't be primed!");
}
catch (IllegalStateException e) {
queue.handleError("This explosive entity is already primed!");
}
}
}
Expand Up @@ -13,7 +13,6 @@
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.living.humanoid.player.CooldownEvent;
import org.spongepowered.api.event.filter.Getter;
import org.spongepowered.api.event.filter.cause.Root;

import java.util.HashMap;
Expand All @@ -33,8 +32,6 @@ public class ItemCooldownStartsScriptEvent extends ScriptEvent {
//
// @Triggers when a item type's cooldown starts for a player.
//
// @Warning This event does not trigger in Sponge during last testing.
//
// @Switch type (ItemTypeTag) checks the item type.
// @Switch world (WorldTag) checks the world.
// @Switch cuboid (CuboidTag) checks the cuboid area.
Expand Down Expand Up @@ -101,7 +98,7 @@ public void disable() {
}

@Listener
public void onItemCooldownStarts(CooldownEvent.Set evt, @Getter("getTargetEntity") Player player) {
public void onItemCooldownStarts(CooldownEvent.Set evt, @Root Player player) {
ItemCooldownStartsScriptEvent event = (ItemCooldownStartsScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.*;
import org.spongepowered.api.entity.explosive.Explosive;
import org.spongepowered.api.entity.explosive.FusedExplosive;
import org.spongepowered.api.entity.hanging.Hanging;
import org.spongepowered.api.entity.hanging.LeashHitch;
import org.spongepowered.api.entity.hanging.Painting;
Expand Down Expand Up @@ -481,7 +482,7 @@ public String friendlyName() {
// @Since 0.3.0
// @Name EntityTag.explosion_radius
// @Updated 2017/09/28
// @Group Current Information
// @Group Explosive Entities
// @ReturnType IntegerTag
// @Returns the radius in blocks that the explosion will affect. Explosive entities only.
// -->
Expand Down Expand Up @@ -877,6 +878,33 @@ else if (ent instanceof Ageable) {
}
return list;
});
// <--[tag]
// @Since 0.4.0
// @Name EntityTag.fuse_duration
// @Updated 2018/01/10
// @Group Explosive Entities
// @ReturnType DurationTag
// @Returns the duration before an explosive entity detonates when primed.
// -->
handlers.put("fuse_duration", (dat, obj) -> new DurationTag(((FusedExplosive) ((EntityTag) obj).internal).getFuseData().fuseDuration().get() * (1.0 / 20.0)));
// <--[tag]
// @Since 0.4.0
// @Name EntityTag.remaining_fuse_duration
// @Updated 2018/01/10
// @Group Explosive Entities
// @ReturnType DurationTag
// @Returns the remaining duration before a primed explosive entity detonates.
// -->
handlers.put("remaining_fuse_duration", (dat, obj) -> new DurationTag(((FusedExplosive) ((EntityTag) obj).internal).getFuseData().ticksRemaining().get() * (1.0 / 20.0)));
// <--[tag]
// @Since 0.4.0
// @Name EntityTag.is_primed
// @Updated 2018/01/10
// @Group Explosive Entities
// @ReturnType BooleanTag
// @Returns whether an explosive entity is primed.
// -->
handlers.put("is_primed", (dat, obj) -> new BooleanTag(((FusedExplosive) ((EntityTag) obj).internal).isPrimed()));
}

public static EntityTag getFor(Action<String> error, String text) {
Expand Down

0 comments on commit faeb4fb

Please sign in to comment.