use of com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException in project Denizen-For-Bukkit by DenizenScript.
the class DisguiseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NetworkInterceptHelper.enable();
EntityTag entity = scriptEntry.getObjectTag("entity");
EntityTag as = scriptEntry.argForPrefix("as", EntityTag.class, true);
boolean cancel = scriptEntry.argAsBoolean("cancel");
boolean global = scriptEntry.argAsBoolean("global");
boolean self = scriptEntry.argAsBoolean("self");
List<PlayerTag> players = scriptEntry.argForPrefixList("players", PlayerTag.class, true);
if (as == null && !cancel) {
throw new InvalidArgumentsRuntimeException("Must specify a valid type to disguise as!");
}
if (players == null && !global) {
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player != null && player.isOnline()) {
players = Collections.singletonList(player);
} else {
throw new InvalidArgumentsRuntimeException("Must have a valid player attached, or 'global' set!");
}
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), entity, db("cancel", cancel), as, db("global", global), db("self", self), db("players", players));
}
HashMap<UUID, TrackedDisguise> playerMap = disguises.get(entity.getUUID());
if (playerMap != null) {
if (global) {
for (Map.Entry<UUID, TrackedDisguise> entry : playerMap.entrySet()) {
entry.getValue().isActive = false;
if (entry.getKey() == null) {
if (entry.getValue().toOthers != null) {
FakeEntity.idsToEntities.remove(entry.getValue().toOthers.overrideUUID);
}
for (Player player : entity.getWorld().getPlayers()) {
if (!EntityTag.isNPC(player)) {
entry.getValue().removeFor(new PlayerTag(player));
}
}
} else {
PlayerTag player = new PlayerTag(entry.getKey());
entry.getValue().removeFor(player);
}
}
disguises.remove(entity.getUUID());
} else {
for (PlayerTag player : players) {
TrackedDisguise disguise = playerMap.remove(player.getUUID());
if (disguise != null) {
disguise.isActive = false;
disguise.removeFor(player);
if (disguise.toOthers != null) {
FakeEntity.idsToEntities.remove(disguise.toOthers.overrideUUID);
}
if (playerMap.isEmpty()) {
disguises.remove(entity.getUUID());
}
}
}
}
}
if (!cancel) {
TrackedDisguise disguise = new TrackedDisguise(entity, as);
disguise.as.entity = NMSHandler.getPlayerHelper().sendEntitySpawn(new ArrayList<>(), as.getEntityType(), entity.getLocation(), as.mechanisms == null ? null : new ArrayList<>(as.mechanisms), -1, null, false).entity.getBukkitEntity();
if (global) {
playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
playerMap.put(null, disguise);
disguise.isActive = true;
ArrayList<PlayerTag> playerSet = players == null ? new ArrayList<>() : new ArrayList<>(players);
for (Player player : entity.getWorld().getPlayers()) {
if (!EntityTag.isNPC(player) && !playerSet.contains(new PlayerTag(player)) && (self || !player.getUniqueId().equals(entity.getUUID()))) {
playerSet.add(new PlayerTag(player));
}
}
disguise.sendTo(playerSet);
} else {
for (PlayerTag player : players) {
playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
playerMap.put(player.getUUID(), disguise);
disguise.isActive = true;
}
disguise.sendTo(players);
}
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException in project Denizen-For-Bukkit by DenizenScript.
the class EngageCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
if (!Utilities.entryHasNPC(scriptEntry)) {
throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!");
}
DurationTag duration = scriptEntry.getObjectTag("duration");
boolean linkedPlayer = scriptEntry.argAsBoolean("player");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, duration, db("player", linkedPlayer));
}
if (duration.getSecondsAsInt() > 0) {
setEngaged(npc.getCitizen(), linkedPlayer ? Utilities.getEntryPlayer(scriptEntry) : null, duration.getSecondsAsInt());
} else {
setEngaged(npc.getCitizen(), linkedPlayer ? Utilities.getEntryPlayer(scriptEntry) : null, true);
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException in project Denizen-For-Bukkit by DenizenScript.
the class AssignmentCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
Action action = (Action) scriptEntry.getObject("action");
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("action", action), script, db("npc", npcs));
}
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
for (NPCTag npc : npcs) {
switch(action) {
case SET:
{
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
AssignmentTrait assignment = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
assignment.clearAssignments(player);
assignment.addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
}
case ADD:
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
case REMOVE:
if (script == null) {
Deprecations.assignmentRemove.warn(scriptEntry);
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
} else {
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
trait.removeAssignmentScript(script.getName(), player);
trait.checkAutoRemove();
}
}
break;
case CLEAR:
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
break;
}
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException 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()));
}
Aggregations