Search in sources :

Example 51 with DurationTag

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));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 52 with DurationTag

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);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) FakeEntity(com.denizenscript.denizen.utilities.entity.FakeEntity) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 53 with DurationTag

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.");
}
Also used : Anchors(net.citizensnpcs.trait.Anchors) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) Command(net.citizensnpcs.api.command.Command) Requirements(net.citizensnpcs.api.command.Requirements)

Example 54 with DurationTag

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;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_16.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)54 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)39 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)16 ListTag (com.denizenscript.denizencore.objects.core.ListTag)16 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)13 List (java.util.List)11 Player (org.bukkit.entity.Player)7 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)6 ColorTag (com.denizenscript.denizen.objects.ColorTag)5 PotionEffect (org.bukkit.potion.PotionEffect)5 PotionEffectType (org.bukkit.potion.PotionEffectType)5 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 NPCTag (com.denizenscript.denizen.objects.NPCTag)4 WorldTag (com.denizenscript.denizen.objects.WorldTag)4 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)4 LivingEntity (org.bukkit.entity.LivingEntity)4 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3