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

Commit

Permalink
Vanish and Invisible commands
Browse files Browse the repository at this point in the history
Also fixed Drop command definition
  • Loading branch information
Xenmai committed Feb 11, 2018
1 parent 0c2eea3 commit 8222a24
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 2 deletions.
Expand Up @@ -134,6 +134,7 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.register(new FlagCommand());
Denizen2Core.register(new HealCommand());
Denizen2Core.register(new HurtCommand());
Denizen2Core.register(new InvisibleCommand());
Denizen2Core.register(new LookAtCommand());
Denizen2Core.register(new MountCommand());
Denizen2Core.register(new PrimeCommand());
Expand All @@ -143,6 +144,7 @@ public void onServerStart(GamePreInitializationEvent event) {
Denizen2Core.register(new TargetCommand());
Denizen2Core.register(new TeleportCommand());
Denizen2Core.register(new UnflagCommand());
Denizen2Core.register(new VanishCommand());
// Commands: Item
Denizen2Core.register(new CreateInventoryCommand());
Denizen2Core.register(new ForgetInventoryCommand());
Expand Down Expand Up @@ -277,7 +279,7 @@ public void onServerStart(GamePreInitializationEvent event) {
Sponge.getEventManager().post(new Denizen2SpongeLoadingEvent(getGenericCause()));
// Load Denizen2
Denizen2Core.start();
// Build loaded advamcements
// Build loaded advancements
AdvancementScript.buildAll();
// Central loop
Sponge.getScheduler().createTaskBuilder().intervalTicks(1).execute(() -> Denizen2Core.tick(0.05)).submit(this);
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import com.denizenscript.denizen2sponge.tags.objects.ItemTag;
import com.denizenscript.denizen2sponge.tags.objects.LocationTag;
import com.denizenscript.denizen2sponge.utilities.UtilLocation;
Expand Down Expand Up @@ -57,12 +58,13 @@ public void execute(CommandQueue queue, CommandEntry entry) {
LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
UtilLocation location = locationTag.getInternal();
if (location.world == null) {
queue.handleError(entry, "Invalid location with no world in Spawn command!");
queue.handleError(entry, "Invalid location with no world in Drop command!");
return;
}
Entity entity = location.world.createEntity(EntityTypes.ITEM, location.toVector3d());
entity.offer(Keys.REPRESENTED_ITEM, item.getInternal().createSnapshot());
location.world.spawnEntity(entity);
queue.commandStack.peek().setDefinition("drop_entity", new EntityTag(entity));
if (queue.shouldShowGood()) {
queue.outGood("Dropped item " + ColorSet.emphasis + item.debug() + ColorSet.good
+ " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "!");
Expand Down
@@ -0,0 +1,61 @@
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.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.data.key.Keys;

public class InvisibleCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name invisible
// @Arguments <entity> <state>
// @Short changes the invisibility state of an entity.
// @Updated 2018/02/11
// @Group Entity
// @Minimum 2
// @Maximum 2
// @Description
// Changes the invisibility state of an entity. Invisible entities can't be seen,
// but update packets are still sent to the server and clients.
// Related commands: <@link command vanish>vanish<@/link>.
// @Example
// # Makes the player invisible.
// - invisible <player> true
// -->

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

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

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

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

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entity = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
BooleanTag state = BooleanTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
entity.getInternal().offer(Keys.INVISIBLE, state.getInternal());
if (queue.shouldShowGood()) {
queue.outGood("Setting invisible state of entity '" + ColorSet.emphasis + entity.debug()
+ ColorSet.good + "' to '" + ColorSet.emphasis + state.debug() + ColorSet.good + "'!");
}
}
}
@@ -0,0 +1,75 @@
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.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.EntityTag;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;

public class VanishCommand extends AbstractCommand {

// <--[command]
// @Since 0.4.0
// @Name vanish
// @Arguments <entity> <state>
// @Short changes the vanish state of an entity.
// @Updated 2018/02/11
// @Group Entity
// @Minimum 2
// @Maximum 2
// @Named ignore_collisions (BooleanTag) Sets whether this vanished entity can collide with other entities.
// @Named untargeteable (BooleanTag) Sets whether this vanished entity can be selected as a target.
// @Description
// Changes the vanish state of an entity. Vanished entities don't send packets to clients,
// but they can still affect collisions or target selection server-side. This can be adjusted
// with the "ignore_collisions" and "untargeteable" named arguments.
// but update packets are still sent to the server and clients.
// Related commands: <@link command invisible>invisible<@/link>.
// @Example
// # Vanishes the player and makes it untargeteable and uncollidable.
// - vanish <player> true --ignore_collisions true --untargeteable true
// -->

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

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

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

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

@Override
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag entityTag = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
BooleanTag state = BooleanTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
Entity entity = entityTag.getInternal();
entity.offer(Keys.VANISH, state.getInternal());
if (entry.namedArgs.containsKey("ignore_collisions")) {
BooleanTag bt = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "ignore_collisions"));
entity.offer(Keys.VANISH_IGNORES_COLLISION, bt.getInternal());
}
if (entry.namedArgs.containsKey("untargeteable")) {
BooleanTag bt = BooleanTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "untargeteable"));
entity.offer(Keys.VANISH_PREVENTS_TARGETING, bt.getInternal());
}
if (queue.shouldShowGood()) {
queue.outGood("Setting vanish state of entity '" + ColorSet.emphasis + entityTag.debug()
+ ColorSet.good + "' to '" + ColorSet.emphasis + state.debug() + ColorSet.good + "'!");
}
}
}

0 comments on commit 8222a24

Please sign in to comment.