Skip to content

Commit

Permalink
expand entity.detonate to include creepers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 3, 2020
1 parent a147846 commit 768e9ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
Expand Up @@ -3169,6 +3169,25 @@ public void adjust(Mechanism mechanism) {
getLivingEntity().setSwimming(mechanism.getValue().asBoolean());
}

// <--[mechanism]
// @object EntityTag
// @name detonate
// @input None
// @description
// If the entity is a firework or a creeper, detonates it.
// -->
if (mechanism.matches("detonate")) {
if (getBukkitEntity() instanceof Firework) {
((Firework) getBukkitEntity()).detonate();
}
else if (getBukkitEntity() instanceof Creeper) {
((Creeper) getBukkitEntity()).explode();
}
else {
Debug.echoError("Cannot detonate entity of type '" + getBukkitEntityType().name() + "'.");
}
}

CoreUtilities.autoPropertyMechanism(this, mechanism);
}
}
Expand Up @@ -33,7 +33,7 @@ public static EntityFirework getFrom(ObjectTag entity) {
};

public static final String[] handledMechs = new String[] {
"firework_item", "detonate"
"firework_item"
};

private EntityFirework(EntityTag entity) {
Expand Down Expand Up @@ -99,18 +99,5 @@ public void adjust(Mechanism mechanism) {
Debug.echoError("'" + mechanism.getValue().asString() + "' is not a valid firework item.");
}
}

// <--[mechanism]
// @object EntityTag
// @name detonate
// @input None
// @description
// If the entity is a firework, detonates it.
// @tags
// <EntityTag.firework_item>
// -->
if (mechanism.matches("detonate")) {
((Firework) firework.getBukkitEntity()).detonate();
}
}
}
Expand Up @@ -58,64 +58,50 @@ public ExplodeCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(LocationTag.class)) {

scriptEntry.addObject("location", arg.asType(LocationTag.class));
}
else if (!scriptEntry.hasObject("power")
&& arg.matchesFloat()
&& arg.matchesPrefix("power", "p")) {

scriptEntry.addObject("power", arg.asElement());
}
else if (!scriptEntry.hasObject("breakblocks")
&& arg.matches("breakblocks")) {

scriptEntry.addObject("breakblocks", "");
}
else if (!scriptEntry.hasObject("fire")
&& arg.matches("fire")) {

scriptEntry.addObject("fire", "");
}
else {
arg.reportUnhandled();
}
}

// Use default values if necessary
scriptEntry.defaultObject("power", new ElementTag(1.0));
scriptEntry.defaultObject("location",
Utilities.entryHasNPC(scriptEntry) ? Utilities.getEntryNPC(scriptEntry).getLocation() : null,
Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getLocation() : null);

if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
}

@Override
public void execute(final ScriptEntry scriptEntry) {

final LocationTag location = scriptEntry.getObjectTag("location");
ElementTag power = scriptEntry.getElement("power");
boolean breakblocks = scriptEntry.hasObject("breakblocks");
boolean fire = scriptEntry.hasObject("fire");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
(ArgumentHelper.debugObj("location", location.toString()) +
ArgumentHelper.debugObj("power", power) +
ArgumentHelper.debugObj("breakblocks", breakblocks) +
ArgumentHelper.debugObj("fire", fire)));
}

location.getWorld().createExplosion
(location.getX(), location.getY(), location.getZ(),
power.asFloat(), fire, breakblocks);
location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), power.asFloat(), fire, breakblocks);
}
}

0 comments on commit 768e9ad

Please sign in to comment.