Examples of dPlayer


Examples of net.aufdemrand.denizen.objects.dPlayer

        // Now, check if the 'click trigger' specifically is enabled. 'name' is inherited from the
        // super AbstractTrigger and contains the name of the trigger that was use in registration.
        if (!npc.getTriggerTrait().isEnabled(name)) return;

        // We'll get the player too, since it makes reading the next few methods a bit easier:
        dPlayer player = dPlayer.mirrorBukkitPlayer(event.getClicker());

        // Check availability based on the NPC's ENGAGED status and the trigger's COOLDOWN that is
        // provided (and adjustable) by the TriggerTrait. Just use .trigger(...)!
        // If unavailable (engaged or not cool), .trigger calls 'On Unavailable' action and returns false.
        // If available (not engaged, and cool), .trigger sets cool down and returns true.
        TriggerTrait.TriggerContext trigger = npc.getTriggerTrait().trigger(this, player);

        if (!trigger.wasTriggered()) return;

        if (trigger.hasDetermination()
                && trigger.getDetermination().equalsIgnoreCase("cancelled")) {
            event.setCancelled(true);
            return;
        }

        // Note: In some cases, the automatic actions that .trigger offers may not be
        // desired. In this case, it's recommended to at least use .triggerCooldownOnly which
        // only handles cooling down the trigger with the triggertrait if the 'available' criteria
        // is met. This handles the built-in cooldown that TriggerTrait implements.

        // Okay, now we need to know which interact script will be selected for the Player/NPC
        // based on requirements/npc's assignment script. To get that information, use:
        // InteractScriptHelper.getInteractScript(dNPC, Player, Trigger Class)
        // .getInteractScript will check the Assignment for possible scripts, and automatically
        // check requirements for each of them.
        InteractScriptContainer script = npc.getInteractScript(player, getClass());

        // In an Interact Script, Triggers can have multiple scripts to choose from depending on
        // some kind of 'criteria'. For the 'Click Trigger', that criteria is the item the Player
        // has in hand. Let's get the possible criteria to see which 'Click Trigger script', if any,
        // should trigger. For example:
        //
        // Script Name:
        //   type: interact
        //   steps:
        //     current step:
        //       click trigger:
        String id = null;
        if (script != null) {
            Map<String, String> idMap = script.getIdMapFor(this.getClass(), player);
            if (!idMap.isEmpty())
                // Iterate through the different id entries in the step's click trigger
                for (Map.Entry<String, String> entry : idMap.entrySet()) {
                    // Tag the entry value to account for replaceables
                    String entry_value = TagManager.tag(player, npc, entry.getValue());
                    // Check if the item specified in the specified id's 'trigger:' key
                    // matches the item that the player is holding.
                    dItem item = dItem.valueOf(entry_value);
                    if (item == null) {
                        dB.echoError("Invalid click trigger in script '" + script.getName() + "' (null trigger item)!");
                    }
                    if (item != null && item.comparesTo(player.getPlayerEntity().getItemInHand()) >= 0
                            && script.checkSpecificTriggerScriptRequirementsFor(this.getClass(),
                            player, npc, entry.getKey()))
                        id = entry.getKey();
                }
        }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

                // Fill player/off-line player
                if (arg.matchesPrefix("player") && !if_ignore) {
                    dB.echoDebug(scriptEntry, "...replacing the linked player with " + arg.getValue());
                    String value = TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(), arg.getValue(), false, scriptEntry);
                    dPlayer player = dPlayer.valueOf(value);
                    if (player == null || !player.isValid()) {
                        dB.echoError(scriptEntry.getResidingQueue(), value + " is an invalid player!");
                        return false;
                    }
                    scriptEntry.setPlayer(player);
                }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        dPlayer player = (dPlayer) scriptEntry.getObject("targetplayer");
        dNPC npc = (dNPC) scriptEntry.getObject("targetnpc");
        Element amount = scriptEntry.getElement("amount");

        dB.report(scriptEntry, getName(),
                (player == null?"": player.debug())
                +(npc == null?"":npc.debug())
                +amount.debug());

        if (npc != null) {
            if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
                dB.echoError(scriptEntry.getResidingQueue(), "This NPC does not have the HungerTrait enabled! Use /trait hunger");
                return;
            }
            npc.getCitizen().getTrait(HungerTrait.class).feed(amount.asInt());
        }
        else if (player != null) {
            if (95999 - player.getPlayerEntity().getFoodLevel() < amount.asInt()) // Setting hunger too high = error
                amount = new Element(95999 - player.getPlayerEntity().getFoodLevel());
            player.getPlayerEntity().setFoodLevel(player.getPlayerEntity().getFoodLevel() + amount.asInt());
        }
        else {
            dB.echoError(scriptEntry.getResidingQueue(), "No target?"); // Mostly just here to quiet code analyzers.
        }
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

                        //
                        if (!isCloseEnough(BukkitPlayer, npc)
                                && hasExitedProximityOf(BukkitPlayer, npc)) continue;

                        // Get the player
                        dPlayer player = dPlayer.mirrorBukkitPlayer(BukkitPlayer);

                        //
                        // Check to make sure the NPC has an assignment. If no assignment, a script doesn't need to be parsed,
                        // but it does still need to trigger for cooldown and action purposes.
                        //
                        InteractScriptContainer script = npc.getInteractScriptQuietly(player, ProximityTrigger.class);

                        //
                        // Set default ranges with information from the TriggerTrait. This allows per-npc overrides and will
                        // automatically check the config for defaults.
                        //
                        double entryRadius = npc.getTriggerTrait().getRadius(name);
                        double exitRadius = npc.getTriggerTrait().getRadius(name);
                        double moveRadius = npc.getTriggerTrait().getRadius(name);


                        //
                        // If a script was found, it might have custom ranges.
                        //
                        if (script != null) {
                            try {
                                if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "ENTRY RADIUS"))
                                    entryRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "ENTRY RADIUS"));
                            } catch (NumberFormatException nfe) {
                                dB.echoDebug(script, "Entry Radius was not an integer.  Assuming " + entryRadius + " as the radius.");
                            }
                            try {
                                if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "EXIT RADIUS"))
                                    exitRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "EXIT RADIUS"));
                            } catch (NumberFormatException nfe) {
                                dB.echoDebug(script, "Exit Radius was not an integer.  Assuming " + exitRadius + " as the radius.");
                            }
                            try {
                                if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "MOVE RADIUS"))
                                    moveRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "MOVE RADIUS"));
                            } catch (NumberFormatException nfe) {
                                dB.echoDebug(script, "Move Radius was not an integer.  Assuming " + moveRadius + " as the radius.");
                            }
                        }

                        Location npcLocation = npc.getLocation();

                        //
                        // If the Player switches worlds while in range of an NPC, trigger still needs to
                        // fire since technically they have exited proximity. Let's check that before
                        // trying to calculate a distance between the Player and NPC, which will throw
                        // an exception if worlds do not match.
                        //
                        boolean playerChangedWorlds = false;
                        if (npcLocation.getWorld() != player.getWorld())
                            playerChangedWorlds = true;

                        //
                        // If the user is outside the range, and was previously within the
                        // range, then execute the "Exit" script.
                        //
                        // If the user entered the range and were not previously within the
                        // range, then execute the "Entry" script.
                        //
                        // If the user was previously within the range and moved, then execute
                        // the "Move" script.
                        //
                        boolean exitedProximity = hasExitedProximityOf(BukkitPlayer, npc);
                        double distance = 0;
                        if (!playerChangedWorlds) distance = npcLocation.distance(player.getLocation());

                        if (!exitedProximity
                                && (playerChangedWorlds || distance >= exitRadius)) {
                            if (!npc.getTriggerTrait().triggerCooldownOnly(trigger, player))
                                continue;
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

        Element mode = scriptEntry.getElement("mode");
        Element amount = scriptEntry.getElement("amount");

        dB.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());

        dPlayer player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer();

        switch (Type.valueOf(type.asString().toUpperCase())) {
            case MAXIMUM:
                switch(Mode.valueOf(type.asString().toUpperCase())) {
                    case SET:
                        player.setMaximumAir(amount.asInt());
                        break;
                    case ADD:
                        player.setMaximumAir(player.getMaximumAir() + amount.asInt());
                        break;
                    case REMOVE:
                        player.setMaximumAir(player.getMaximumAir() - amount.asInt());
                        break;
                }
                return;
            case REMAINING:
                switch(Mode.valueOf(type.asString().toUpperCase())) {
                    case SET:
                        player.setRemainingAir(amount.asInt());
                        break;

                    case ADD:
                        player.setRemainingAir(player.getRemainingAir() + amount.asInt());
                        break;

                    case REMOVE:
                        player.setRemainingAir(player.getRemainingAir() - amount.asInt());
                        break;
                }
                return;
        }
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

    @EventHandler
    public void playerJoin(PlayerJoinEvent event) {

        Denizen denizen = DenizenAPI.getCurrentInstance();
        dPlayer player = new dPlayer(event.getPlayer());

        // Any saves quest listeners in progress?
        if (!denizen.getSaves().contains("Listeners." + player.getSaveName())) return;
        Set<String> inProgress = denizen.getSaves().getConfigurationSection("Listeners." + player.getSaveName()).getKeys(false);
        // If empty, no quest listeners to load.
        if (inProgress.isEmpty()) return;

        // TODO: Players.SAVENAME.Listeners?
        String path = "Listeners." + player.getSaveName() + ".";

        // If not empty, let's do the loading process for each.
        for (String listenerId : inProgress) {
            // People tend to worry when they see long-ass stacktraces.. let's catch them.
            try {
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

            // Iterate through viewers, store them in the viewerMap,
            // and make them see this scoreboard if they are online
            for (String viewer : viewerList) {
                if (dPlayer.matches(viewer)) {
                    dPlayer player = dPlayer.valueOf(viewer);
                    viewerMap.put(player.getName(), id);

                    if (player.isOnline())
                        player.getPlayerEntity().setScoreboard(board);
                }
            }

            ConfigurationSection objSection = rootSection
                    .getConfigurationSection(id + ".Objectives");
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

        return oldRenderers;
    }

    @Override
    public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
        dPlayer pl = dPlayer.mirrorBukkitPlayer(player);
        for (MapText text : textList)
            mapCanvas.drawText(text.x, text.y, MinecraftFont.Font, TagManager.tag(pl, pl.getSelectedNPC(), text.text));
        for (MapImage image : imageList) {
            Image i = new ImageIcon(image.file).getImage();
            // Use custom function to draw image to allow transparency
            this.drawImage(image.x, image.y, image.resize ? MapPalette.resizeImage(i) : i, mapCanvas);
        }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dPlayer

                // dB.echoDebug(ChatColor.YELLOW + "//REPLACED//" + ChatColor.WHITE + " '%s' with flag value '" + event.getReplaced() + "'.", flagName);
            }

        } else if (event.getType().toUpperCase().startsWith("P")) {
            // Separate name since subType context may specify a different (or offline) player
            dPlayer player = event.getPlayer();

            // No name? No flag replacement!
            if (player == null) return;

            if (denizen.flagManager().getPlayerFlag(player, flagName).get(index).isEmpty()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.