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

Commit

Permalink
Named Arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Apr 2, 2017
1 parent babc7d9 commit 68505b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
Expand Up @@ -28,14 +28,16 @@ public class HurtCommand extends AbstractCommand {

// <--[command]
// @Name hurt
// @Arguments <entity> <amount> [absolute? boolean] [type]
// @Arguments <entity> <amount>
// @Short damages the entity for the specified amount.
// @Updated 2017/03/31
// @Updated 2017/04/01
// @Group Entities
// @Minimum 2
// @Maximum 4
// @Maximum 2
// @Named absolute (BooleanTag) Sets whether the damage is absolute or not.
// @Named type (TextTag) Sets of what type the damage will be.
// @Description
// Damages the entity for the specified amount. If no boolean is specified, the damage will be absolute by default.
// Damages the entity for the specified amount. This damage is absolute by default.
// @Example
// # This example hurts the player for 4 points (2 hearts) of damage
// - hurt <player> 4
Expand All @@ -48,7 +50,7 @@ public String getName() {

@Override
public String getArguments() {
return "<entity> <amount> [absolute? boolean] [type]";
return "<entity> <amount>";
}

@Override
Expand All @@ -58,25 +60,25 @@ public int getMinimumArguments() {

@Override
public int getMaximumArguments() {
return 4;
return 2;
}

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
NumberTag dam = NumberTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
DamageSource.Builder build = DamageSource.builder();
if (entry.arguments.size() > 2) {
BooleanTag abs = BooleanTag.getFor(queue.error, entry.getArgumentObject(queue, 2));
if (entry.namedArgs.containsKey("absolute")) {
BooleanTag abs = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "absolute"));
if (abs.getInternal()) {
build.absolute();
}
}
else {
build.absolute();
}
if (entry.arguments.size() > 3) {
String typeName = entry.getArgumentObject(queue, 3).toString().toLowerCase();
if (entry.namedArgs.containsKey("type")) {
String typeName = entry.getNamedArgumentObject(queue, "type").toString().toLowerCase();
Optional<DamageType> type = Sponge.getRegistry().getType(DamageType.class, typeName);
if (!type.isPresent()) {
queue.handleError(entry, "Invalid damage type: '" + typeName + "'!");
Expand Down
Expand Up @@ -24,18 +24,22 @@ public class PlayEffectCommand extends AbstractCommand {

// <--[command]
// @Name playeffect
// @Arguments <location> <effect> [count] [offset] [motion] [visibility]
// @Arguments <location> <effect>
// @Short plays an effect.
// @Updated 2017/03/31
// @Updated 2017/04/01
// @Group World
// @Minimum 2
// @Maximum 6
// @Maximum 2
// @Named count (IntegerTag) Sets how many particles will be played.
// @Named offset (LocationTag) Sets the offset of the particles.
// @Named motion (LocationTag) Sets the motion of the particles.
// @Named visibility (IntegerTag) Sets the visibility radius of the effect.
// @Description
// Plays an effect at certain location. Optionally specify a particle count, offset, velocity and visibility radius.
// TODO: Explain more!
// @Example
// # This example plays the 'heart' effect around the player.
// - playeffect <player.location> heart 50 1,1,1 0,0,0
// - playeffect <player.location> heart --count 50 --offset 1,1,1
// -->

@Override
Expand All @@ -45,7 +49,7 @@ public String getName() {

@Override
public String getArguments() {
return "<location> <effect> [offset] [motion]";
return "<location> <effect>";
}

@Override
Expand All @@ -55,7 +59,7 @@ public int getMinimumArguments() {

@Override
public int getMaximumArguments() {
return 6;
return 2;
}

@Override
Expand All @@ -69,20 +73,20 @@ public void execute(CommandQueue queue, CommandEntry entry) {
return;
}
build.type(type.get());
if (entry.arguments.size() > 2) {
IntegerTag integer = IntegerTag.getFor(queue.error, entry.getArgumentObject(queue, 2));
if (entry.namedArgs.containsKey("count")) {
IntegerTag integer = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "count"));
build.quantity((int) integer.getInternal());
}
if (entry.arguments.size() > 3) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 3));
if (entry.namedArgs.containsKey("offset")) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "offset"));
build.offset(offset.getInternal().toVector3d());
}
if (entry.arguments.size() > 4) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 4));
if (entry.namedArgs.containsKey("motion")) {
LocationTag offset = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "motion"));
build.velocity(offset.getInternal().toVector3d());
}
if (entry.arguments.size() > 5) {
IntegerTag visibility = IntegerTag.getFor(queue.error, entry.getArgumentObject(queue, 5));
if (entry.namedArgs.containsKey("visibility")) {
IntegerTag visibility = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "visibility"));
loc.getInternal().world.spawnParticles(build.build(), loc.getInternal().toVector3d(), (int) visibility.getInternal());
}
else {
Expand Down

0 comments on commit 68505b9

Please sign in to comment.