use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class FakeSpawnCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
EntityTag entity = scriptEntry.getObjectTag("entity");
LocationTag location = scriptEntry.getObjectTag("location");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag cancel = scriptEntry.getElement("cancel");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), entity, cancel, location, duration, db("players", players));
}
if (cancel != null && cancel.asBoolean()) {
if (entity.isFake) {
FakeEntity fakeEnt = FakeEntity.idsToEntities.get(entity.getUUID());
if (fakeEnt != null) {
fakeEnt.cancelEntity();
} else {
Debug.echoDebug(scriptEntry, "Entity '" + entity + "' cannot be cancelled: not listed in fake-entity map.");
}
}
} else {
FakeEntity created = FakeEntity.showFakeEntityTo(players, entity, location, duration);
scriptEntry.addObject("faked_entity", created.entity);
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class KickCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag reason = scriptEntry.getElement("reason");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("targets", targets), reason);
}
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
player.getPlayerEntity().kickPlayer(reason.toString());
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class ClickableCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
ElementTag path = scriptEntry.getElement("path");
ElementTag cancel = scriptEntry.argForPrefixAsElement("cancel", null);
List<PlayerTag> forPlayers = scriptEntry.argForPrefixList("for", PlayerTag.class, true);
ElementTag usages = scriptEntry.argForPrefixAsElement("usages", null);
ListTag definitions = scriptEntry.argForPrefix("def", ListTag.class, true);
DurationTag until = scriptEntry.argForPrefix("until", DurationTag.class, true);
MapTag defMap = scriptEntry.getObjectTag("def_map");
if (script == null && cancel == null) {
throw new InvalidArgumentsRuntimeException("Missing script argument!");
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), script, cancel, path, usages, definitions, defMap, until, db("for", forPlayers));
}
if (cancel != null) {
UUID id;
try {
id = UUID.fromString(cancel.asString());
} catch (IllegalArgumentException ex) {
Debug.echoError("Invalid cancel ID: " + ex.getMessage());
return;
}
Clickable clicky = clickables.remove(id);
if (clicky == null) {
Debug.echoDebug(scriptEntry, "Cancelled ID didn't exist, nothing to cancel.");
} else {
Debug.echoDebug(scriptEntry, "Cancelled.");
}
return;
}
UUID id = UUID.randomUUID();
Clickable newClickable = new Clickable();
newClickable.script = script;
newClickable.path = path == null ? null : path.asString();
newClickable.definitions = definitions;
newClickable.remainingUsages = usages == null ? -1 : usages.asInt();
newClickable.until = until == null ? 0 : (System.currentTimeMillis() + until.getMillis());
newClickable.context = scriptEntry.context;
newClickable.npc = Utilities.getEntryNPC(scriptEntry);
newClickable.defMap = defMap;
if (forPlayers != null) {
newClickable.forPlayers = new HashSet<>(forPlayers.size());
for (PlayerTag player : forPlayers) {
newClickable.forPlayers.add(player.getUUID());
}
}
clickables.put(id, newClickable);
scriptEntry.addObject("command", new ElementTag("/denizenclickable " + id));
scriptEntry.addObject("id", new ElementTag(id.toString()));
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method tabComplete.
@Override
public List<String> tabComplete(CommandSender commandSender, String alias, String[] arguments) {
if (!script.hasTabCompleteProcedure()) {
return super.tabComplete(commandSender, alias, arguments);
}
Map<String, ObjectTag> context = new HashMap<>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
context.put("args", new ListTag(args, true));
context.put("raw_args", new ElementTag(raw_args, true));
context.put("alias", new ElementTag(alias, true));
PlayerTag player = null;
NPCTag npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (EntityTag.isCitizensNPC(pl)) {
npc = NPCTag.fromEntity(pl);
} else {
player = PlayerTag.mirrorBukkitPlayer(pl);
}
context.put("server", new ElementTag(false));
} else {
context.put("server", new ElementTag(true));
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null) {
npc = new NPCTag(citizen);
}
}
return script.runTabCompleteProcedure(player, npc, context, arguments);
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method execute.
@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
if (!testPermission(commandSender)) {
return true;
}
Map<String, ObjectTag> context = new HashMap<>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
context.put("args", new ListTag(args, true));
context.put("raw_args", new ElementTag(raw_args, true));
context.put("alias", new ElementTag(commandLabel, true));
PlayerTag player = null;
NPCTag npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (EntityTag.isCitizensNPC(pl)) {
npc = NPCTag.fromEntity(pl);
} else {
player = PlayerTag.mirrorBukkitPlayer(pl);
}
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("player"));
} else {
if (commandSender instanceof BlockCommandSender) {
context.put("command_block_location", new LocationTag(((BlockCommandSender) commandSender).getBlock().getLocation()));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_block"));
} else if (commandSender instanceof CommandMinecart) {
context.put("command_minecart", new EntityTag((CommandMinecart) commandSender));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_minecart"));
} else {
context.put("server", new ElementTag(true));
context.put("source_type", new ElementTag("server"));
}
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null) {
npc = new NPCTag(citizen);
}
}
script.runCommandScript(player, npc, context);
return true;
}
Aggregations