Skip to content

Commit

Permalink
improvements to the hurt command, for #1917
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 19, 2019
1 parent 7aa27d1 commit 32f4a70
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class HurtCommand extends AbstractCommand {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

boolean specified_targets = false;

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("amount")
Expand All @@ -38,16 +36,8 @@ else if (!scriptEntry.hasObject("source")
scriptEntry.addObject("source", arg.asType(dEntity.class));
}
else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentType(dList.class)) {
// Entity arg
&& arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class, scriptEntry));
specified_targets = true;
}
else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentType(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
specified_targets = true;
}
else if (!scriptEntry.hasObject("cause")
&& arg.matchesEnum(EntityDamageEvent.DamageCause.values())) {
Expand All @@ -62,7 +52,7 @@ else if (!scriptEntry.hasObject("cause")
scriptEntry.addObject("amount", new Element(1.0d));
}

if (!specified_targets) {
if (!scriptEntry.hasObject("entities")) {
List<dEntity> entities = new ArrayList<dEntity>();
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
Expand Down Expand Up @@ -111,18 +101,19 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}
}
else {
EntityDamageEvent ede = source == null ? new EntityDamageEvent(entity.getBukkitEntity(),
EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount) :
new EntityDamageByEntityEvent(source.getBukkitEntity(),
entity.getBukkitEntity(), EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount);
EntityDamageEvent.DamageCause causeEnum = EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase());
EntityDamageEvent ede = source == null ? new EntityDamageEvent(entity.getBukkitEntity(), causeEnum, amount) :
new EntityDamageByEntityEvent(source.getBukkitEntity(), entity.getBukkitEntity(), causeEnum, amount);
Bukkit.getPluginManager().callEvent(ede);
if (!ede.isCancelled()) {
entity.getLivingEntity().setLastDamageCause(ede);
if (source == null) {
entity.getLivingEntity().damage(ede.getFinalDamage());
}
else {
entity.getLivingEntity().damage(ede.getFinalDamage(), source.getBukkitEntity());
}
entity.getLivingEntity().setLastDamageCause(ede);
}
}
}
Expand Down

0 comments on commit 32f4a70

Please sign in to comment.