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

Commit

Permalink
Air command and tags (#16)
Browse files Browse the repository at this point in the history
* Air command and tags

* Fixes

* Missing line .-.
  • Loading branch information
Xenmai authored and mcmonkey4eva committed Apr 17, 2017
1 parent 0228a56 commit a16a574
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 5 deletions.
Expand Up @@ -119,6 +119,7 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.getImplementation().getAddonsFolder().mkdirs();
Denizen2Core.getImplementation().getScriptDataFolder().mkdirs();
// Commands: Entity
Denizen2Core.register(new AirCommand());
Denizen2Core.register(new CastCommand());
Denizen2Core.register(new EditEntityCommand());
Denizen2Core.register(new EquipCommand());
Expand Down
@@ -0,0 +1,93 @@
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.tags.objects.BooleanTag;
import com.denizenscript.denizen2core.tags.objects.DurationTag;
import com.denizenscript.denizen2core.tags.objects.NumberTag;
import com.denizenscript.denizen2core.utilities.CoreUtilities;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.event.cause.entity.damage.DamageType;
import org.spongepowered.api.event.cause.entity.damage.DamageTypes;
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;

import java.util.Optional;

public class AirCommand extends AbstractCommand {

// <--[command]
// @Name air
// @Arguments <entity> <duration>
// @Short sets the air level of the entity.
// @Updated 2017/04/17
// @Group Entities
// @Minimum 2
// @Maximum 2
// @Named type (TextTag) Sets of what type the air level will be.
// @Description
// Sets the air level of the entity. Optionally specify a type ('remaining' or 'maximum')
// to adjust the specified air level type. Defaults to 'remaining'.
// @Example
// # This example completely fills the air bar of the player
// - air <player> <player.max_air>
// -->

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

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

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

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

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
DurationTag dur = DurationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
if (!ent.getInternal().supports(Keys.MAX_AIR)) {
queue.handleError(entry, "This entity does not support air levels!");
return;
}
String type;
if (entry.namedArgs.containsKey("type")) {
type = entry.getNamedArgumentObject(queue, "type").toString();
switch (type) {
case "remaining":
ent.getInternal().offer(Keys.REMAINING_AIR, (int) (dur.getInternal() * 20));
break;
case "maximum":
ent.getInternal().offer(Keys.MAX_AIR, (int) (dur.getInternal() * 20));
break;
default:
queue.handleError(entry, "Invalid air level type: '" + type + "'!");
return;
}
}
else {
type = "remaining";
ent.getInternal().offer(Keys.REMAINING_AIR, (int) (dur.getInternal() * 20));
}
if (queue.shouldShowGood()) {
queue.outGood("Setting the " + ColorSet.emphasis + type + ColorSet.good + " air level of "
+ ColorSet.emphasis + ent.debug() + ColorSet.good + " to "
+ ColorSet.emphasis + dur.debug() + ColorSet.good + " seconds!");
}
}
}
Expand Up @@ -18,7 +18,7 @@ public class SetBlockCommand extends AbstractCommand {
// @Name setblock
// @Arguments <list of locations> <blocktype>
// @Short sets a block's type.
// @Updated 2016/11/24
// @Updated 2017/04/03
// @Group World
// @Minimum 2
// @Maximum 2
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.denizenscript.denizen2sponge.utilities.flags.FlagMap;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.property.entity.EyeHeightProperty;
import org.spongepowered.api.data.property.entity.EyeLocationProperty;
import org.spongepowered.api.data.type.HandTypes;
Expand Down Expand Up @@ -361,6 +362,29 @@ public String friendlyName() {
Entity ent = ((EntityTag) obj).internal;
return new CuboidTag(ent.getBoundingBox().get(), ent.getWorld());
});
// <--[tag]
// @Name EntityTag.max_air
// @Updated 2017/04/17
// @Group Current Information
// @ReturnType DurationTag
// @Returns the maximum air level this entity can have.
// -->
handlers.put("max_air", (dat, obj) -> new DurationTag(((EntityTag) obj).internal.get(Keys.MAX_AIR).get() / 20.0));
// <--[tag]
// @Name EntityTag.remaining_air
// @Updated 2017/04/17
// @Group Current Information
// @ReturnType DurationTag
// @Returns the remaining air level this entity can have.
// -->
handlers.put("remaining_air", (dat, obj) -> {
Entity ent = ((EntityTag) obj).internal;
Optional<Integer> opt = ent.get(Keys.REMAINING_AIR);
if (!opt.isPresent()) {
return new DurationTag(ent.get(Keys.MAX_AIR).get() / 20.0);
}
return new DurationTag(opt.get() / 20.0);
});
}

public static EntityTag getFor(Action<String> error, String text) {
Expand Down
Expand Up @@ -44,23 +44,23 @@ public ItemStack getInternal() {
// @ReturnType ItemTypeTag
// @Returns the type of the item.
// -->
handlers.put("item_type", (dat, obj) -> new ItemTypeTag((((ItemTag) obj).internal.getItem())));
handlers.put("item_type", (dat, obj) -> new ItemTypeTag(((ItemTag) obj).internal.getItem()));
// <--[tag]
// @Name ItemTag.quantity
// @Updated 2017/04/04
// @Group Identification
// @ReturnType IntegerTag
// @Returns the amount of items in this stack.
// -->
handlers.put("quantity", (dat, obj) -> new IntegerTag((((ItemTag) obj).internal.getQuantity())));
handlers.put("quantity", (dat, obj) -> new IntegerTag(((ItemTag) obj).internal.getQuantity()));
// <--[tag]
// @Name ItemTag.max_stack_quantity
// @Updated 2017/04/04
// @Group Identification
// @ReturnType IntegerTag
// @Returns the maximum amount of items of this type in a stack.
// -->
handlers.put("max_stack_quantity", (dat, obj) -> new IntegerTag((((ItemTag) obj).internal.getMaxStackQuantity())));
handlers.put("max_stack_quantity", (dat, obj) -> new IntegerTag(((ItemTag) obj).internal.getMaxStackQuantity()));
// <--[tag]
// @Name ItemTag.data
// @Updated 2016/11/24
Expand Down Expand Up @@ -201,7 +201,7 @@ public ItemStack getInternal() {
AbstractTagObject ato = flags.getInternal().get(flagName);
if (ato == null) {
if (!dat.hasFallback()) {
dat.error.run("Invalid flag specified, not present on this entity!");
dat.error.run("Invalid flag specified, not present on this item!");
}
return new NullTag();
}
Expand Down
Expand Up @@ -143,6 +143,14 @@ public Player getInternal() {
// @Returns the current IP of the player.
// -->
handlers.put("ip", (dat, obj) -> new TextTag(((PlayerTag) obj).internal.getConnection().getAddress().getAddress().getHostName()));
// <--[tag]
// @Name PlayerTag.latency
// @Updated 2017/04/17
// @Group Properties
// @ReturnType IntegerTag
// @Returns the current latency of the player, in milliseconds.
// -->
handlers.put("latency", (dat, obj) -> new IntegerTag(((PlayerTag) obj).internal.getConnection().getLatency()));
}

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

0 comments on commit a16a574

Please sign in to comment.