Search in sources :

Example 6 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method switchBlock.

// Break off this portion of the code from execute() so it can be used in both execute and the delayed runnable
public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, SwitchState switchState, Player player) {
    World world = interactLocation.getWorld();
    boolean currentState = (interactLocation.getBlock().getData() & 0x8) > 0;
    String state = switchState.toString();
    // Try for a linked player
    if (player == null && Bukkit.getOnlinePlayers().size() > 0) {
        // If there's none, link any player
        if (Bukkit.getOnlinePlayers().size() > 0) {
            player = (Player) Bukkit.getOnlinePlayers().toArray()[0];
        } else if (Depends.citizens != null) {
            // If there are no players, link any Human NPC
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                if (npc.isSpawned() && npc.getEntity() instanceof Player) {
                    player = (Player) npc.getEntity();
                    break;
                }
            }
        // TODO: backup if no human NPC available? (Fake EntityPlayer instance?)
        }
    }
    if ((state.equals("ON") && !currentState) || (state.equals("OFF") && currentState) || state.equals("TOGGLE")) {
        try {
            if (interactLocation.getBlock().getType() == Material.IRON_DOOR_BLOCK) {
                Location block;
                if (interactLocation.clone().add(0, -1, 0).getBlock().getType() == Material.IRON_DOOR_BLOCK) {
                    block = interactLocation.clone().add(0, -1, 0);
                } else {
                    block = interactLocation;
                }
                block.getBlock().setData((byte) (block.getBlock().getData() ^ 4));
            } else {
                NMSHandler.getInstance().getEntityHelper().forceInteraction(player, interactLocation);
            }
            dB.echoDebug(scriptEntry, "Switched " + interactLocation.getBlock().getType().toString() + "! Current state now: " + ((interactLocation.getBlock().getData() & 0x8) > 0 ? "ON" : "OFF"));
        } catch (NullPointerException e) {
            dB.echoError("Cannot switch " + interactLocation.getBlock().getType().toString() + "!");
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) World(org.bukkit.World) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 7 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class RenameCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    Element name = (Element) scriptEntry.getObject("name");
    dB.report(scriptEntry, getName(), name.debug());
    NPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen();
    Location prev = npc.isSpawned() ? npc.getEntity().getLocation() : null;
    npc.despawn(DespawnReason.PENDING_RESPAWN);
    npc.setName(name.asString().length() > 128 ? name.asString().substring(0, 128) : name.asString());
    if (prev != null) {
        npc.spawn(prev);
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Element(net.aufdemrand.denizencore.objects.Element) Location(org.bukkit.Location)

Example 8 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class TraitCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element toggle = scriptEntry.getElement("state");
    Element traitName = scriptEntry.getElement("trait");
    NPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen();
    dB.report(scriptEntry, getName(), traitName.debug() + toggle.debug() + ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().debug());
    Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString());
    if (trait == null) {
        dB.echoError(scriptEntry.getResidingQueue(), "Trait not found: " + traitName.asString());
        return;
    }
    switch(Toggle.valueOf(toggle.asString())) {
        case TRUE:
        case ON:
            if (npc.hasTrait(trait)) {
                dB.echoError(scriptEntry.getResidingQueue(), "NPC already has trait '" + traitName.asString() + "'");
            } else {
                npc.addTrait(trait);
            }
            break;
        case FALSE:
        case OFF:
            if (!npc.hasTrait(trait)) {
                dB.echoError(scriptEntry.getResidingQueue(), "NPC does not have trait '" + traitName.asString() + "'");
            } else {
                npc.removeTrait(trait);
            }
            break;
        case TOGGLE:
            if (npc.hasTrait(trait)) {
                npc.removeTrait(trait);
            } else {
                npc.addTrait(trait);
            }
            break;
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Element(net.aufdemrand.denizencore.objects.Element)

Example 9 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class InvisibleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Element state = scriptEntry.getElement("state");
    dEntity target = (dEntity) scriptEntry.getObject("target");
    // Report to dB
    dB.report(scriptEntry, getName(), state.debug() + target.debug());
    if (target.isCitizensNPC()) {
        NPC npc = target.getDenizenNPC().getCitizen();
        if (!npc.hasTrait(InvisibleTrait.class)) {
            npc.addTrait(InvisibleTrait.class);
        }
        InvisibleTrait trait = npc.getTrait(InvisibleTrait.class);
        switch(Action.valueOf(state.asString().toUpperCase())) {
            case FALSE:
                trait.setInvisible(false);
                break;
            case TRUE:
                trait.setInvisible(true);
                break;
            case TOGGLE:
                trait.toggle();
                break;
        }
    } else {
        switch(Action.valueOf(state.asString().toUpperCase())) {
            case FALSE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    ((ArmorStand) target.getBukkitEntity()).setVisible(true);
                } else {
                    target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                }
                break;
            case TRUE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    ((ArmorStand) target.getBukkitEntity()).setVisible(false);
                } else {
                    new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
                }
                break;
            case TOGGLE:
                if (target.getBukkitEntity() instanceof ArmorStand) {
                    if (((ArmorStand) target.getBukkitEntity()).isVisible()) {
                        ((ArmorStand) target.getBukkitEntity()).setVisible(true);
                    } else {
                        ((ArmorStand) target.getBukkitEntity()).setVisible(false);
                    }
                } else {
                    if (target.getLivingEntity().hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                        target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                    } else {
                        new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
                    }
                }
                break;
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) ArmorStand(org.bukkit.entity.ArmorStand) PotionEffect(org.bukkit.potion.PotionEffect) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) InvisibleTrait(net.aufdemrand.denizen.npc.traits.InvisibleTrait)

Example 10 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class ServerTags method serverTag.

@TagManager.TagEvents
public void serverTag(ReplaceableTagEvent event) {
    if (!event.matches("server", "svr", "global") || event.replaced()) {
        return;
    }
    Attribute attribute = event.getAttributes().fulfill(1);
    // -->
    if (attribute.startsWith("object_is_valid")) {
        dObject o = ObjectFetcher.pickObjectFor(attribute.getContext(1), new BukkitTagContext(null, null, false, null, false, null));
        event.setReplaced(new Element(!(o == null || o instanceof Element)).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_whitelist")) {
        event.setReplaced(new Element(Bukkit.hasWhitelist()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_flag")) {
        String flag_name;
        if (attribute.hasContext(1)) {
            flag_name = attribute.getContext(1);
        } else {
            event.setReplaced("null");
            return;
        }
        event.setReplaced(new Element(FlagManager.serverHasFlag(flag_name)).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("flag")) {
        String flag_name;
        if (attribute.hasContext(1)) {
            flag_name = attribute.getContext(1);
        } else {
            event.setReplaced("null");
            return;
        }
        attribute.fulfill(1);
        // NOTE: Meta is in dList.java
        if (attribute.startsWith("is_expired") || attribute.startsWith("isexpired")) {
            event.setReplaced(new Element(!FlagManager.serverHasFlag(flag_name)).getAttribute(attribute.fulfill(1)));
            return;
        }
        // NOTE: Meta is in dList.java
        if (attribute.startsWith("size") && !FlagManager.serverHasFlag(flag_name)) {
            event.setReplaced(new Element(0).getAttribute(attribute.fulfill(1)));
            return;
        }
        if (FlagManager.serverHasFlag(flag_name)) {
            FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager().getGlobalFlag(flag_name);
            event.setReplaced(new dList(flag.toString(), true, flag.values()).getAttribute(attribute));
        }
        return;
    }
    // -->
    if (attribute.startsWith("list_materials")) {
        dList allMats = new dList();
        for (Material mat : Material.values()) {
            allMats.add(mat.name());
        }
        event.setReplaced(allMats.getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("list_flags")) {
        dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listGlobalFlags());
        dList searchFlags = null;
        if (!allFlags.isEmpty() && attribute.hasContext(1)) {
            searchFlags = new dList();
            String search = attribute.getContext(1);
            if (search.startsWith("regex:")) {
                try {
                    Pattern pattern = Pattern.compile(search.substring(6), Pattern.CASE_INSENSITIVE);
                    for (String flag : allFlags) {
                        if (pattern.matcher(flag).matches()) {
                            searchFlags.add(flag);
                        }
                    }
                } catch (Exception e) {
                    dB.echoError(e);
                }
            } else {
                search = CoreUtilities.toLowerCase(search);
                for (String flag : allFlags) {
                    if (CoreUtilities.toLowerCase(flag).contains(search)) {
                        searchFlags.add(flag);
                    }
                }
            }
        }
        event.setReplaced(searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1)) : searchFlags.getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("list_notables")) {
        dList allNotables = new dList();
        if (attribute.hasContext(1)) {
            String type = CoreUtilities.toLowerCase(attribute.getContext(1));
            types: for (Map.Entry<String, Class> typeClass : NotableManager.getReverseClassIdMap().entrySet()) {
                if (type.equals(CoreUtilities.toLowerCase(typeClass.getKey()))) {
                    for (Object notable : NotableManager.getAllType(typeClass.getValue())) {
                        allNotables.add(((dObject) notable).identify());
                    }
                    break types;
                }
            }
        } else {
            for (Notable notable : NotableManager.notableObjects.values()) {
                allNotables.add(((dObject) notable).identify());
            }
        }
        event.setReplaced(allNotables.getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("start_time")) {
        event.setReplaced(new Duration(Denizen.startTime / 50).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_allocated")) {
        event.setReplaced(new Element(Runtime.getRuntime().totalMemory()).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_max")) {
        event.setReplaced(new Element(Runtime.getRuntime().maxMemory()).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_free")) {
        event.setReplaced(new Element(Runtime.getRuntime().freeMemory()).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("available_processors")) {
        event.setReplaced(new Element(Runtime.getRuntime().availableProcessors()).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("current_time_millis")) {
        event.setReplaced(new Element(System.currentTimeMillis()).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("has_event") && attribute.hasContext(1)) {
        event.setReplaced(new Element(OldEventManager.eventExists(attribute.getContext(1)) || OldEventManager.eventExists(OldEventManager.StripIdentifiers(attribute.getContext(1)))).getAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("get_event_handlers") && attribute.hasContext(1)) {
        String eventName = attribute.getContext(1).toUpperCase();
        List<WorldScriptContainer> EventsOne = OldEventManager.events.get("ON " + eventName);
        List<WorldScriptContainer> EventsTwo = OldEventManager.events.get("ON " + OldEventManager.StripIdentifiers(eventName));
        if (EventsOne == null && EventsTwo == null) {
            dB.echoError("No world scripts will handle the event '" + eventName + "'");
        } else {
            dList list = new dList();
            if (EventsOne != null) {
                for (WorldScriptContainer script : EventsOne) {
                    list.add("s@" + script.getName());
                }
            }
            if (EventsTwo != null) {
                for (WorldScriptContainer script : EventsTwo) {
                    if (!list.contains("s@" + script.getName())) {
                        list.add("s@" + script.getName());
                    }
                }
            }
            event.setReplaced(list.getAttribute(attribute.fulfill(1)));
        }
    }
    // -->
    if (attribute.startsWith("selected_npc")) {
        NPC npc = ((Citizens) Bukkit.getPluginManager().getPlugin("Citizens")).getNPCSelector().getSelected(Bukkit.getConsoleSender());
        if (npc == null) {
            return;
        } else {
            event.setReplaced(new dNPC(npc).getAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("get_npcs_named") && Depends.citizens != null && attribute.hasContext(1)) {
        dList npcs = new dList();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            if (npc.getName().equalsIgnoreCase(attribute.getContext(1))) {
                npcs.add(dNPC.mirrorCitizensNPC(npc).identify());
            }
        }
        event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_file") && attribute.hasContext(1)) {
        File f = new File(DenizenAPI.getCurrentInstance().getDataFolder(), attribute.getContext(1));
        try {
            if (!Settings.allowStrangeYAMLSaves() && !f.getCanonicalPath().startsWith(DenizenAPI.getCurrentInstance().getDataFolder().getCanonicalPath())) {
                dB.echoError("Invalid path specified. Invalid paths have been denied by the server administrator.");
                return;
            }
        } catch (Exception e) {
            dB.echoError(e);
            return;
        }
        event.setReplaced(new Element(f.exists()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_files") && attribute.hasContext(1)) {
        File folder = new File(DenizenAPI.getCurrentInstance().getDataFolder(), attribute.getContext(1));
        if (!folder.exists() || !folder.isDirectory()) {
            return;
        }
        try {
            if (!Settings.allowStrangeYAMLSaves() && !folder.getCanonicalPath().startsWith(DenizenAPI.getCurrentInstance().getDataFolder().getCanonicalPath())) {
                dB.echoError("Invalid path specified. Invalid paths have been denied by the server administrator.");
                return;
            }
        } catch (Exception e) {
            dB.echoError(e);
            return;
        }
        File[] files = folder.listFiles();
        if (files == null) {
            return;
        }
        dList list = new dList();
        for (File file : files) {
            list.add(file.getName());
        }
        event.setReplaced(list.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_permissions")) {
        event.setReplaced(new Element(Depends.permissions != null && Depends.permissions.isEnabled()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_economy")) {
        event.setReplaced(new Element(Depends.economy != null && Depends.economy.isEnabled()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("denizen_version")) {
        event.setReplaced(new Element(DenizenAPI.getCurrentInstance().getDescription().getVersion()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("bukkit_version")) {
        event.setReplaced(new Element(Bukkit.getBukkitVersion()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("version")) {
        event.setReplaced(new Element(Bukkit.getServer().getVersion()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("java_version")) {
        event.setReplaced(new Element(System.getProperty("java.version")).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("max_players")) {
        event.setReplaced(new Element(Bukkit.getServer().getMaxPlayers()).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_sql_connections")) {
        dList list = new dList();
        for (Map.Entry<String, Connection> entry : SQLCommand.connections.entrySet()) {
            try {
                if (!entry.getValue().isClosed()) {
                    list.add(entry.getKey());
                } else {
                    SQLCommand.connections.remove(entry.getKey());
                }
            } catch (SQLException e) {
                dB.echoError(attribute.getScriptEntry().getResidingQueue(), e);
            }
        }
        event.setReplaced(list.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_permission_groups")) {
        if (Depends.permissions == null) {
            dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            return;
        }
        event.setReplaced(new dList(Arrays.asList(Depends.permissions.getGroups())).getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_plugin_names")) {
        dList plugins = new dList();
        for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
            plugins.add(plugin.getName());
        }
        event.setReplaced(plugins.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_scripts")) {
        dList scripts = new dList();
        for (String str : ScriptRegistry._getScriptNames()) {
            scripts.add("s@" + str);
        }
        event.setReplaced(scripts.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("match_player") && attribute.hasContext(1)) {
        Player matchPlayer = null;
        String matchInput = CoreUtilities.toLowerCase(attribute.getContext(1));
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (CoreUtilities.toLowerCase(player.getName()).equals(matchInput)) {
                matchPlayer = player;
                break;
            } else if (CoreUtilities.toLowerCase(player.getName()).contains(matchInput) && matchPlayer == null) {
                matchPlayer = player;
            }
        }
        if (matchPlayer != null) {
            event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("match_offline_player") && attribute.hasContext(1)) {
        UUID matchPlayer = null;
        String matchInput = CoreUtilities.toLowerCase(attribute.getContext(1));
        for (Map.Entry<String, UUID> entry : dPlayer.getAllPlayers().entrySet()) {
            if (CoreUtilities.toLowerCase(entry.getKey()).equals(matchInput)) {
                matchPlayer = entry.getValue();
                break;
            } else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && matchPlayer == null) {
                matchPlayer = entry.getValue();
            }
        }
        if (matchPlayer != null) {
            event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("get_npcs_assigned") && Depends.citizens != null && attribute.hasContext(1)) {
        dScript script = dScript.valueOf(attribute.getContext(1));
        if (script == null || !(script.getContainer() instanceof AssignmentScriptContainer)) {
            dB.echoError("Invalid script specified.");
        } else {
            dList npcs = new dList();
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                if (npc.hasTrait(AssignmentTrait.class) && npc.getTrait(AssignmentTrait.class).hasAssignment() && npc.getTrait(AssignmentTrait.class).getAssignment().getName().equalsIgnoreCase(script.getName())) {
                    npcs.add(dNPC.mirrorCitizensNPC(npc).identify());
                }
            }
            event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
            return;
        }
    }
    // -->
    if (attribute.startsWith("get_online_players_flagged") && attribute.hasContext(1)) {
        String flag = attribute.getContext(1);
        dList players = new dList();
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(new dPlayer(player), flag).size() > 0) {
                players.add(new dPlayer(player).identify());
            }
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("get_players_flagged") && attribute.hasContext(1)) {
        String flag = attribute.getContext(1);
        dList players = new dList();
        for (Map.Entry<String, UUID> entry : dPlayer.getAllPlayers().entrySet()) {
            if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(new dPlayer(entry.getValue()), flag).size() > 0) {
                players.add(new dPlayer(entry.getValue()).identify());
            }
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("get_spawned_npcs_flagged") && Depends.citizens != null && attribute.hasContext(1)) {
        String flag = attribute.getContext(1);
        dList npcs = new dList();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            dNPC dNpc = dNPC.mirrorCitizensNPC(npc);
            if (dNpc.isSpawned() && FlagManager.npcHasFlag(dNpc, flag)) {
                npcs.add(dNpc.identify());
            }
        }
        event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("get_npcs_flagged") && Depends.citizens != null && attribute.hasContext(1)) {
        String flag = attribute.getContext(1);
        dList npcs = new dList();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            dNPC dNpc = dNPC.mirrorCitizensNPC(npc);
            if (FlagManager.npcHasFlag(dNpc, flag)) {
                npcs.add(dNpc.identify());
            }
        }
        event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_npcs") && Depends.citizens != null) {
        dList npcs = new dList();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            npcs.add(dNPC.mirrorCitizensNPC(npc).identify());
        }
        event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_worlds")) {
        dList worlds = new dList();
        for (World world : Bukkit.getWorlds()) {
            worlds.add(dWorld.mirrorBukkitWorld(world).identify());
        }
        event.setReplaced(worlds.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_plugins")) {
        dList plugins = new dList();
        for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
            plugins.add(new dPlugin(plugin).identify());
        }
        event.setReplaced(plugins.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_players")) {
        dList players = new dList();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            players.add(dPlayer.mirrorBukkitPlayer(player).identify());
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_online_players")) {
        dList players = new dList();
        for (Player player : Bukkit.getOnlinePlayers()) {
            players.add(dPlayer.mirrorBukkitPlayer(player).identify());
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_offline_players")) {
        dList players = new dList();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            if (!player.isOnline()) {
                players.add(dPlayer.mirrorBukkitPlayer(player).identify());
            }
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_banned_players")) {
        dList banned = new dList();
        for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
            banned.add(dPlayer.mirrorBukkitPlayer(player).identify());
        }
        event.setReplaced(banned.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_ops")) {
        dList players = new dList();
        for (OfflinePlayer player : Bukkit.getOperators()) {
            players.add(dPlayer.mirrorBukkitPlayer(player).identify());
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_online_ops")) {
        dList players = new dList();
        for (OfflinePlayer player : Bukkit.getOperators()) {
            if (player.isOnline()) {
                players.add(dPlayer.mirrorBukkitPlayer(player).identify());
            }
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_offline_ops")) {
        dList players = new dList();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            if (player.isOp() && !player.isOnline()) {
                players.add(dPlayer.mirrorBukkitPlayer(player).identify());
            }
        }
        event.setReplaced(players.getAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("motd")) {
        event.setReplaced(new Element(Bukkit.getServer().getMotd()).getAttribute(attribute.fulfill(1)));
        return;
    } else // -->
    if (attribute.startsWith("entity_is_spawned") && attribute.hasContext(1)) {
        dEntity ent = dEntity.valueOf(attribute.getContext(1));
        event.setReplaced(new Element((ent != null && ent.isUnique() && ent.isSpawned()) ? "true" : "false").getAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("player_is_valid") && attribute.hasContext(1)) {
        event.setReplaced(new Element(dPlayer.playerNameIsValid(attribute.getContext(1))).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("npc_is_valid") && attribute.hasContext(1)) {
        dNPC npc = dNPC.valueOf(attribute.getContext(1));
        event.setReplaced(new Element((npc != null && npc.isValid())).getAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("current_bossbars")) {
        dList dl = new dList();
        for (String str : BossBarCommand.bossBarMap.keySet()) {
            dl.add(str);
        }
        event.setReplaced(dl.getAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("recent_tps")) {
        dList list = new dList();
        for (double tps : NMSHandler.getInstance().getRecentTps()) {
            list.add(new Element(tps).identify());
        }
        event.setReplaced(list.getAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("port")) {
        event.setReplaced(new Element(NMSHandler.getInstance().getPort()).getAttribute(attribute.fulfill(1)));
    }
// TODO: Add everything else from Bukkit.getServer().*
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) Attribute(net.aufdemrand.denizencore.tags.Attribute) SQLException(java.sql.SQLException) WorldScriptContainer(net.aufdemrand.denizencore.scripts.containers.core.WorldScriptContainer) AssignmentScriptContainer(net.aufdemrand.denizen.scripts.containers.core.AssignmentScriptContainer) FlagManager(net.aufdemrand.denizen.flags.FlagManager) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) UUID(java.util.UUID) Pattern(java.util.regex.Pattern) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Connection(java.sql.Connection) net.aufdemrand.denizen.objects.dPlugin(net.aufdemrand.denizen.objects.dPlugin) Notable(net.aufdemrand.denizencore.objects.notable.Notable) SQLException(java.sql.SQLException) AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) File(java.io.File) Map(java.util.Map) Plugin(org.bukkit.plugin.Plugin) net.aufdemrand.denizen.objects.dPlugin(net.aufdemrand.denizen.objects.dPlugin)

Aggregations

NPC (net.citizensnpcs.api.npc.NPC)18 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)5 Element (net.aufdemrand.denizencore.objects.Element)5 Player (org.bukkit.entity.Player)4 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)3 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)3 Location (org.bukkit.Location)3 Zombie (org.bukkit.entity.Zombie)3 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 FlagManager (net.aufdemrand.denizen.flags.FlagManager)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 Attribute (net.aufdemrand.denizencore.tags.Attribute)2 Age (net.citizensnpcs.trait.Age)2 File (java.io.File)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 UUID (java.util.UUID)1