use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class ShowFakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (arg.matches("cancel")) {
scriptEntry.addObject("cancel", new ElementTag(true));
} else if (!scriptEntry.hasObject("materials") && arg.matchesArgumentList(MaterialTag.class)) {
scriptEntry.addObject("materials", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify at least one valid location!");
}
if (!scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must have a valid, online player attached!");
}
if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
throw new InvalidArgumentsException("Must specify valid material(s)!");
}
scriptEntry.defaultObject("duration", new DurationTag(10));
scriptEntry.defaultObject("cancel", new ElementTag(false));
}
use of com.denizenscript.denizencore.objects.core.DurationTag 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.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCCommandHandler method startFishing.
@Command(aliases = { "npc" }, usage = "fish (--location x,y,z,world) (--anchor anchor_name) (-c) (--reel_time <duration>) (--cast_time <duration>)", desc = "Makes the NPC fish, casting at the given location.", flags = "c", modifiers = { "fish" }, min = 1, max = 3, permission = "denizen.npc.fish")
@Requirements(selected = true, ownership = true)
public void startFishing(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
FishingTrait trait = npc.getOrAddTrait(FishingTrait.class);
if (trait.isFishing()) {
Messaging.sendError(sender, npc.getName() + " is already fishing! Use '/npc stopfishing' to stop.");
return;
}
if (args.hasValueFlag("percent")) {
trait.setCatchPercent(args.getFlagInteger("percent"));
}
if (args.hasValueFlag("reel_time")) {
DurationTag duration = DurationTag.valueOf(args.getFlag("reel_time"), CoreUtilities.basicContext);
if (duration == null) {
Messaging.sendError(sender, "Invalid reel duration.");
return;
}
trait.reelTickRate = duration.getTicksAsInt();
Messaging.send(sender, "Set reel rate to " + duration.formatted(true));
}
if (args.hasValueFlag("cast_time")) {
DurationTag duration = DurationTag.valueOf(args.getFlag("cast_time"), CoreUtilities.basicContext);
if (duration == null) {
Messaging.sendError(sender, "Invalid cast duration.");
return;
}
trait.reelTickRate = duration.getTicksAsInt();
Messaging.send(sender, "Set cast rate to " + duration.formatted(true));
}
if (args.hasFlag('c')) {
trait.startFishing(args.getSenderTargetBlockLocation());
} else if (args.hasValueFlag("location")) {
String[] argsArray = args.getFlag("location").split(",");
if (argsArray.length != 4) {
Messaging.sendError(sender, "Usage: /npc fish --location x,y,z,world");
return;
}
trait.startFishing(LocationTag.valueOf(argsArray[0] + "," + argsArray[1] + "," + argsArray[2] + "," + argsArray[3], CoreUtilities.basicContext));
} else if (args.hasValueFlag("anchor")) {
if (npc.hasTrait(Anchors.class)) {
Anchors anchors = npc.getOrAddTrait(Anchors.class);
if (anchors.getAnchor(args.getFlag("anchor")) != null) {
trait.startFishing(anchors.getAnchor(args.getFlag("anchor")).getLocation());
}
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
} else {
trait.startFishing();
}
Messaging.send(sender, npc.getName() + " is now fishing.");
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showSignEditor.
@Override
public boolean showSignEditor(Player player, Location location) {
if (location == null) {
LocationTag fakeSign = new LocationTag(player.getLocation());
fakeSign.setY(0);
FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
BlockPosition pos = new BlockPosition(fakeSign.getX(), 0, fakeSign.getZ());
((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().playerConnection.networkManager).packetListener.fakeSignExpected = pos;
sendPacket(player, new PacketPlayOutOpenSignEditor(pos));
return true;
}
TileEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getTileEntity(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
if (tileEntity instanceof TileEntitySign) {
TileEntitySign sign = (TileEntitySign) tileEntity;
// Prevent client crashing by sending current state of the sign
sendPacket(player, sign.getUpdatePacket());
sign.isEditable = true;
sign.a((EntityHuman) ((CraftPlayer) player).getHandle());
sendPacket(player, new PacketPlayOutOpenSignEditor(sign.getPosition()));
return true;
} else {
return false;
}
}
Aggregations