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

Commit

Permalink
Cast and Remove commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Apr 2, 2017
1 parent 68505b9 commit f600eae
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 1 deletion.
Expand Up @@ -117,11 +117,13 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.getImplementation().getAddonsFolder().mkdirs();
Denizen2Core.getImplementation().getScriptDataFolder().mkdirs();
// Commands: Entity
Denizen2Core.register(new CastCommand());
Denizen2Core.register(new EditEntityCommand());
Denizen2Core.register(new EquipCommand());
Denizen2Core.register(new FlagCommand());
Denizen2Core.register(new HurtCommand());
Denizen2Core.register(new MountCommand());
Denizen2Core.register(new RemoveCommand());
Denizen2Core.register(new SpawnCommand());
Denizen2Core.register(new TeleportCommand());
Denizen2Core.register(new UnflagCommand());
Expand Down
@@ -0,0 +1,110 @@
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.IntegerTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.manipulator.mutable.PotionEffectData;
import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.effect.potion.PotionEffectType;

import java.util.Optional;

public class CastCommand extends AbstractCommand {

// <--[explanation]
// @Name Potion Effect Types
// @Group Useful Lists
// @Description
// A list of all default potion effect types can be found here:
// <@link url https://jd.spongepowered.org/6.0.0-SNAPSHOT/org/spongepowered/api/effect/potion/PotionEffectTypes.html>potion effect types list<@/link>
// These can be used with the cast command.
// -->

// <--[command]
// @Name cast
// @Arguments <entity> <effect> <duration>
// @Short casts a potion effect on an entity.
// @Updated 2017/04/01
// @Group Entities
// @Minimum 3
// @Maximum 3
// @Named amplifier (IntegerTag) Sets the potion effect amplifier.
// @Named ambient (BooleanTag) Sets whether the effect will be ambient or not.
// @Named particles (BooleanTag) Sets whether the effect will show particles or not.
// @Description
// Casts a potion effect on an entity for the specified duration.
// Particles are set to true by default, and ambient to false.
// @Example
// # This example casts 'poison' on the player for 5 seconds
// - cast <player> poison 5s
// -->

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

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

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

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

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
String name = entry.getArgumentObject(queue, 1).toString().toLowerCase();
if (!ent.getInternal().supports(PotionEffectData.class)) {
queue.handleError(entry, "This entity type does not support potion effects!");
return;
}
PotionEffectData data = ent.getInternal().getOrCreate(PotionEffectData.class).get();
Optional<PotionEffectType> type = Sponge.getRegistry().getType(PotionEffectType.class, name);
if (!type.isPresent()) {
queue.handleError(entry, "Invalid potion effect name: '" + name + "'!");
return;
}
DurationTag dur = DurationTag.getFor(queue.error, entry.getArgumentObject(queue, 2));
PotionEffect.Builder build = PotionEffect.builder().potionType(type.get()).duration((int) dur.getInternal() * 20);
if (entry.namedArgs.containsKey("amplifier")) {
IntegerTag amp = IntegerTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "amplifier"));
build.amplifier((int) amp.getInternal() - 1);
}
if (entry.namedArgs.containsKey("ambient")) {
BooleanTag amb = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "ambient"));
build.ambience(amb.getInternal());
}
else {
build.particles(false);
}
if (entry.namedArgs.containsKey("particles")) {
BooleanTag part = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "particles"));
build.particles(part.getInternal());
}
else {
build.particles(true);
}
if (queue.shouldShowGood()) {
queue.outGood("Casting " + ColorSet.emphasis + name + ColorSet.good
+ " on " + ColorSet.emphasis + ent.debug() + ColorSet.good
+ " for " + ColorSet.emphasis + dur.debug() + ColorSet.good + " seconds!");
}
data.addElement(build.build());
ent.getInternal().offer(data);
}
}
Expand Up @@ -90,7 +90,7 @@ public void execute(CommandQueue queue, CommandEntry entry) {
build.type(DamageTypes.GENERIC);
}
if (queue.shouldShowGood()) {
queue.outGood("hurting " + ColorSet.emphasis + ent.debug() + ColorSet.good
queue.outGood("Hurting " + ColorSet.emphasis + ent.debug() + ColorSet.good
+ " for " + ColorSet.emphasis + dam.debug() + ColorSet.good + " points of damage!");
}
ent.getInternal().damage(dam.getInternal(), build.build(), Denizen2Sponge.getGenericCause());
Expand Down
@@ -0,0 +1,59 @@
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.AbstractTagObject;
import com.denizenscript.denizen2core.tags.objects.ListTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;

public class RemoveCommand extends AbstractCommand {

// <--[command]
// @Name remove
// @Arguments <entity list>
// @Short removes a list of entities.
// @Updated 2017/04/02
// @Group Entities
// @Minimum 1
// @Maximum 1
// @Description
// Removes a list of entities from the world.
// @Example
// # This example removes all zombies within a 3 block range of the player
// - remove <player.location.nearby_entities[type:zombie|range:3]>
// -->

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

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

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

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

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
ListTag list = ListTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
for (AbstractTagObject ato : list.getInternal()) {
EntityTag ent = EntityTag.getFor(queue.error, ato);
ent.getInternal().remove();
}
if (queue.shouldShowGood()) {
queue.outGood("Removing entities: " + ColorSet.emphasis + list.debug() + ColorSet.good + "!");
}
}
}

0 comments on commit f600eae

Please sign in to comment.