This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Xenmai/master
Explosion event, LookAt command, Entity tags
- Loading branch information
Showing
6 changed files
with
547 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/denizenscript/denizen2sponge/commands/entity/LookAtCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.utilities.debugging.ColorSet; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.LocationTag; | ||
import com.flowpowered.math.vector.Vector3d; | ||
import org.spongepowered.api.entity.living.Living; | ||
|
||
public class LookAtCommand extends AbstractCommand { | ||
|
||
// <--[command] | ||
// @Name lookat | ||
// @Arguments <entity> <location> | ||
// @Short makes an entity look at a location. | ||
// @Updated 2017/10/02 | ||
// @Group Entity | ||
// @Minimum 2 | ||
// @Maximum 2 | ||
// @Description | ||
// Makes a living entity look at a location. This will rotate the entity's head, but not its body. | ||
// @Example | ||
// # This example makes the target entity of the player look at him in the eye | ||
// - lookat <player.entities_on_cursor.get[1]> <player.eye_location> | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "lookat"; | ||
} | ||
|
||
@Override | ||
public String getArguments() { | ||
return "<entity> <location>"; | ||
} | ||
|
||
@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)); | ||
Living ent = (Living) entityTag.getInternal(); | ||
LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1)); | ||
Vector3d loc = locationTag.getInternal().toVector3d(); | ||
ent.lookAt(loc); | ||
if (queue.shouldShowGood()) { | ||
queue.outGood("Entity " + ColorSet.emphasis + entityTag.debug() + ColorSet.good + " is now looking at " | ||
+ ColorSet.emphasis + locationTag.debug() + ColorSet.good + "!"); | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
src/main/java/com/denizenscript/denizen2sponge/events/server/CommandSentScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package com.denizenscript.denizen2sponge.events.server; | ||
|
||
import com.denizenscript.denizen2core.events.ScriptEvent; | ||
import com.denizenscript.denizen2core.tags.AbstractTagObject; | ||
import com.denizenscript.denizen2core.tags.objects.ListTag; | ||
import com.denizenscript.denizen2core.tags.objects.TextTag; | ||
import com.denizenscript.denizen2sponge.Denizen2Sponge; | ||
import com.denizenscript.denizen2sponge.tags.objects.EntityTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.LocationTag; | ||
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.block.tileentity.CommandBlock; | ||
import org.spongepowered.api.command.CommandSource; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
import org.spongepowered.api.entity.vehicle.minecart.CommandBlockMinecart; | ||
import org.spongepowered.api.event.Listener; | ||
import org.spongepowered.api.event.command.SendCommandEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class CommandSentScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Events | ||
// command sent | ||
// | ||
// @Updated 2017/10/04 | ||
// | ||
// @Cancellable true | ||
// | ||
// @Group Server | ||
// | ||
// @Triggers when a command is used by any source. | ||
// | ||
// @Context | ||
// command (TextTag) returns the main command that was used. | ||
// args (ListTag<TextTag>) returns a list of the arguments used. | ||
// raw_args (TextTag) returns the arguments as a single text tag. | ||
// source (TextTag) returns whether the command was sent by the console, a player or a command block. | ||
// player (PlayerTag) returns the player that sent the command, if the source was in fact one. | ||
// location (LocationTag) returns the location of the command block that sent the command, if the source is in fact one. | ||
// entity (EntityTag) returns the command block minecart that sent the command, if the source is in fact one. | ||
// | ||
// @Determinations | ||
// command (TextTag) to set the main command that will be used. | ||
// args (ListTag<TextTag>) to set a list of the arguments that will be used. | ||
// raw_args (TextTag) to set the arguments as a single text tag. | ||
// --> | ||
|
||
@Override | ||
public String getName() { | ||
return "CommandSent"; | ||
} | ||
|
||
@Override | ||
public boolean couldMatch(ScriptEventData data) { | ||
return data.eventPath.startsWith("command sent"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptEventData data) { | ||
return true; | ||
} | ||
|
||
public TextTag command; | ||
|
||
public ListTag args; | ||
|
||
public TextTag raw_args; | ||
|
||
public TextTag source; | ||
|
||
public PlayerTag player; | ||
|
||
public LocationTag location; | ||
|
||
public EntityTag entity; | ||
|
||
public SendCommandEvent internal; | ||
|
||
// TODO: Thread safety! | ||
|
||
@Override | ||
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) { | ||
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data); | ||
defs.put("command", command); | ||
defs.put("args", args); | ||
defs.put("raw_args", raw_args); | ||
defs.put("source", source); | ||
defs.put("player", player); | ||
defs.put("location", location); | ||
defs.put("entity", entity); | ||
return defs; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
Sponge.getEventManager().unregisterListeners(this); | ||
} | ||
|
||
@Listener | ||
public void onCommandSent(SendCommandEvent evt) { | ||
CommandSentScriptEvent event = (CommandSentScriptEvent) clone(); | ||
event.internal = evt; | ||
event.command = new TextTag(evt.getCommand()); | ||
// TODO: Improve splitting (quoted arguments) | ||
ListTag list = new ListTag(); | ||
for (String arg : evt.getArguments().split(" ")) { | ||
list.getInternal().add(new TextTag(arg)); | ||
} | ||
event.args = list; | ||
event.raw_args = new TextTag(evt.getArguments()); | ||
CommandSource source = (CommandSource) evt.getSource(); | ||
if (source instanceof Player) { | ||
event.source = new TextTag("player"); | ||
event.player = new PlayerTag((Player) source); | ||
} | ||
else if (source instanceof CommandBlock) { | ||
event.source = new TextTag("block"); | ||
event.location = new LocationTag(((CommandBlock) source).getLocation()); | ||
} | ||
else if (source instanceof CommandBlockMinecart) { | ||
event.source = new TextTag("minecart"); | ||
event.entity = new EntityTag((CommandBlockMinecart) source); | ||
} | ||
else { | ||
event.source = new TextTag("server"); | ||
} | ||
event.cancelled = evt.isCancelled(); | ||
event.run(); | ||
evt.setCancelled(event.cancelled); | ||
} | ||
|
||
@Override | ||
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) { | ||
if (determination.equals("command")) { | ||
TextTag tt = TextTag.getFor(this::error, value); | ||
command = tt; | ||
internal.setCommand(tt.getInternal()); | ||
} | ||
else if (determination.equals("args")) { | ||
ListTag lt = ListTag.getFor(this::error, value); | ||
args = lt; | ||
String string = ""; | ||
for (AbstractTagObject arg : lt.getInternal()) { | ||
string += " " + ((TextTag) arg).getInternal(); | ||
} | ||
raw_args = new TextTag(string); | ||
internal.setArguments(string); | ||
} | ||
else if (determination.equals("raw_args")) { | ||
TextTag tt = TextTag.getFor(this::error, value); | ||
raw_args = tt; | ||
// TODO: Improve splitting (quoted arguments) | ||
ListTag list = new ListTag(); | ||
for (String arg : tt.getInternal().split(" ")) { | ||
list.getInternal().add(new TextTag(arg)); | ||
} | ||
args = list; | ||
internal.setArguments(tt.getInternal()); | ||
} | ||
else { | ||
super.applyDetermination(errors, determination, value); | ||
} | ||
} | ||
} |
Oops, something went wrong.