Search in sources :

Example 46 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class Slow method slowTarget.

public void slowTarget(LivingEntity target) {
    PotionEffect effect = new PotionEffect(PotionEffectType.SLOW, getDuration() * 20, 1, false);
    target.addPotionEffect(effect);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect)

Example 47 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class Wither method witherTarget.

public void witherTarget(LivingEntity target) {
    PotionEffect effect = new PotionEffect(PotionEffectType.WITHER, getDuration() * 20, 1, false);
    target.addPotionEffect(effect);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect)

Example 48 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Towny by ElgarL.

the class TownyEntityListener method onPotionSplashEvent.

/**
	 * Prevent potion damage on players in non PVP areas
	 * 
	 * @param event
	 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPotionSplashEvent(PotionSplashEvent event) {
    List<LivingEntity> affectedEntities = (List<LivingEntity>) event.getAffectedEntities();
    ThrownPotion potion = event.getPotion();
    Entity attacker;
    List<PotionEffect> effects = (List<PotionEffect>) potion.getEffects();
    boolean detrimental = false;
    /*
		 * List of potion effects blocked from PvP.
		 */
    List<String> prots = TownySettings.getPotionTypes();
    for (PotionEffect effect : effects) {
        if (prots.contains(effect.getType().getName())) {
            detrimental = true;
        }
    }
    Object source = potion.getShooter();
    if (!(source instanceof Entity)) {
        // TODO: prevent damage from dispensers
        return;
    } else {
        attacker = (Entity) source;
    }
    // Not Wartime
    if (!TownyUniverse.isWarTime())
        for (LivingEntity defender : affectedEntities) {
            /*
				 * Don't block potion use on ourselves
				 * yet allow the use of beneficial potions on all.
				 */
            if (attacker != defender)
                if (CombatUtil.preventDamageCall(plugin, attacker, defender) && detrimental) {
                    event.setIntensity(defender, -1.0);
                }
        }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) ThrownPotion(org.bukkit.entity.ThrownPotion) List(java.util.List) EventHandler(org.bukkit.event.EventHandler)

Example 49 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Denizen-For-Bukkit by DenizenScript.

the class dPlayer method getAttribute.

@Override
public String getAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    if (offlinePlayer == null) {
        return null;
    }
    // Defined in dEntity
    if (attribute.startsWith("is_player")) {
        return Element.TRUE.getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("debug.log")) {
        dB.log(debug());
        return Element.TRUE.getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("debug.no_color")) {
        return new Element(ChatColor.stripColor(debug())).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("debug")) {
        return new Element(debug()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("prefix")) {
        return new Element(prefix).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("chat_history_list")) {
        return // TODO: UUID?
        new dList(PlayerTags.playerChatHistory.get(getName())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("chat_history")) {
        int x = 1;
        if (attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1))) {
            x = attribute.getIntContext(1);
        }
        // No playerchathistory? Return null.
        if (!PlayerTags.playerChatHistory.containsKey(getName())) {
            // TODO: UUID?
            return null;
        }
        // TODO: UUID?
        List<String> messages = PlayerTags.playerChatHistory.get(getName());
        if (messages.size() < x || x < 1) {
            return null;
        }
        return new Element(messages.get(x - 1)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("flag") && attribute.hasContext(1)) {
        String flag_name = attribute.getContext(1);
        if (attribute.getAttribute(2).equalsIgnoreCase("is_expired") || attribute.startsWith("isexpired")) {
            return new Element(!FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(2));
        }
        if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.playerHasFlag(this, flag_name)) {
            return new Element(0).getAttribute(attribute.fulfill(2));
        }
        if (FlagManager.playerHasFlag(this, flag_name)) {
            FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(this, flag_name);
            return new dList(flag.toString(), true, flag.values()).getAttribute(attribute.fulfill(1));
        }
        return new Element(identify()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("has_flag") && attribute.hasContext(1)) {
        String flag_name = attribute.getContext(1);
        return new Element(FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("list_flags")) {
        dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listPlayerFlags(this));
        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);
                    }
                }
            }
        }
        return searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1)) : searchFlags.getAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("current_step")) {
        String outcome = "null";
        if (attribute.hasContext(1)) {
            try {
                outcome = DenizenAPI.getCurrentInstance().getSaves().getString("Players." + getName() + ".Scripts." + dScript.valueOf(attribute.getContext(1)).getName() + ".Current Step");
            } catch (Exception e) {
                outcome = "null";
            }
        }
        return new Element(outcome).getAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("money")) {
        if (Depends.economy != null) {
            // -->
            if (attribute.startsWith("money.currency_singular")) {
                return new Element(Depends.economy.currencyNameSingular()).getAttribute(attribute.fulfill(2));
            }
            // -->
            if (attribute.startsWith("money.currency")) {
                return new Element(Depends.economy.currencyNamePlural()).getAttribute(attribute.fulfill(2));
            }
            return new Element(Depends.economy.getBalance(getOfflinePlayer())).getAttribute(attribute.fulfill(1));
        } else {
            if (!attribute.hasAlternative()) {
                dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            return null;
        }
    }
    if (attribute.startsWith("target")) {
        int range = 50;
        int attribs = 1;
        // -->
        if (attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2) && aH.matchesInteger(attribute.getContext(2))) {
            attribs = 2;
            range = attribute.getIntContext(2);
        }
        List<Entity> entities = getPlayerEntity().getNearbyEntities(range, range, range);
        ArrayList<LivingEntity> possibleTargets = new ArrayList<LivingEntity>();
        for (Entity entity : entities) {
            if (entity instanceof LivingEntity) {
                // if we have a context for entity types, check the entity
                if (attribute.hasContext(1)) {
                    String context = attribute.getContext(1);
                    if (CoreUtilities.toLowerCase(context).startsWith("li@")) {
                        context = context.substring(3);
                    }
                    for (String ent : context.split("\\|")) {
                        boolean valid = false;
                        if (ent.equalsIgnoreCase("npc") && dEntity.isCitizensNPC(entity)) {
                            valid = true;
                        } else if (dEntity.matches(ent)) {
                            // only accept generic entities that are not NPCs
                            if (dEntity.valueOf(ent).isGeneric()) {
                                if (dEntity.isCitizensNPC(entity)) {
                                    valid = true;
                                }
                            } else {
                                valid = true;
                            }
                        }
                        if (valid) {
                            possibleTargets.add((LivingEntity) entity);
                        }
                    }
                } else {
                    // no entity type specified
                    possibleTargets.add((LivingEntity) entity);
                    entity.getType();
                }
            }
        }
        // Find the valid target
        BlockIterator bi;
        try {
            bi = new BlockIterator(getPlayerEntity(), range);
        } catch (IllegalStateException e) {
            return null;
        }
        Block b;
        Location l;
        int bx, by, bz;
        double ex, ey, ez;
        // Loop through player's line of sight
        while (bi.hasNext()) {
            b = bi.next();
            bx = b.getX();
            by = b.getY();
            bz = b.getZ();
            if (b.getType() != Material.AIR) {
                // Line of sight is broken
                break;
            } else {
                // Check for entities near this block in the line of sight
                for (LivingEntity possibleTarget : possibleTargets) {
                    l = possibleTarget.getLocation();
                    ex = l.getX();
                    ey = l.getY();
                    ez = l.getZ();
                    if ((bx - .50 <= ex && ex <= bx + 1.50) && (bz - .50 <= ez && ez <= bz + 1.50) && (by - 1 <= ey && ey <= by + 2.5)) {
                        // Entity is close enough, so return it
                        return new dEntity(possibleTarget).getDenizenObject().getAttribute(attribute.fulfill(attribs));
                    }
                }
            }
        }
        return null;
    }
    // workaround for <e@entity.list_effects>
    if (attribute.startsWith("list_effects")) {
        dList effects = new dList();
        for (PotionEffect effect : getPlayerEntity().getActivePotionEffects()) {
            effects.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + effect.getDuration() + "t");
        }
        return effects.getAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("list")) {
        dB.echoError("DO NOT USE PLAYER.LIST AS A TAG, please use <server.list_online_players> and related tags!");
        List<String> players = new ArrayList<String>();
        if (attribute.startsWith("list.online")) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                players.add(player.getName());
            }
            return new dList(players).getAttribute(attribute.fulfill(2));
        } else if (attribute.startsWith("list.offline")) {
            for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
                if (!player.isOnline()) {
                    players.add("p@" + player.getUniqueId().toString());
                }
            }
            return new dList(players).getAttribute(attribute.fulfill(2));
        } else {
            for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
                players.add("p@" + player.getUniqueId().toString());
            }
            return new dList(players).getAttribute(attribute.fulfill(1));
        }
    }
    if (attribute.startsWith("name") && !isOnline()) // This can be parsed later with more detail if the player is online, so only check for offline.
    {
        return new Element(getName()).getAttribute(attribute.fulfill(1));
    } else if (attribute.startsWith("uuid") && !isOnline()) // This can be parsed later with more detail if the player is online, so only check for offline.
    {
        return new Element(offlinePlayer.getUniqueId().toString()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("type")) {
        return new Element("Player").getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("save_name")) {
        return new Element(getSaveName()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("bed_spawn")) {
        if (getOfflinePlayer().getBedSpawnLocation() == null) {
            return null;
        }
        return new dLocation(getOfflinePlayer().getBedSpawnLocation()).getAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("location") && !isOnline()) {
        return getLocation().getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("first_played")) {
        attribute = attribute.fulfill(1);
        if (attribute.startsWith("milliseconds") || attribute.startsWith("in_milliseconds")) {
            return new Element(getOfflinePlayer().getFirstPlayed()).getAttribute(attribute.fulfill(1));
        }
        return new Duration(getOfflinePlayer().getFirstPlayed() / 50).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("has_played_before")) {
        return new Element(true).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("health.is_scaled")) {
        return new Element(getPlayerEntity().isHealthScaled()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("health.scale")) {
        return new Element(getPlayerEntity().getHealthScale()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("exhaustion")) {
        return new Element(getPlayerEntity().getExhaustion()).getAttribute(attribute.fulfill(1));
    }
    // Handle dEntity oxygen tags here to allow getting them when the player is offline
    if (attribute.startsWith("oxygen.max")) {
        return new Duration((long) getMaximumAir()).getAttribute(attribute.fulfill(2));
    }
    if (attribute.startsWith("oxygen")) {
        return new Duration((long) getRemainingAir()).getAttribute(attribute.fulfill(1));
    }
    // Same with health tags
    if (attribute.startsWith("health.formatted")) {
        return EntityHealth.getHealthFormatted(new dEntity(getPlayerEntity()), attribute);
    }
    if (attribute.startsWith("health.percentage")) {
        double maxHealth = getPlayerEntity().getMaxHealth();
        if (attribute.hasContext(2)) {
            maxHealth = attribute.getIntContext(2);
        }
        return new Element((getPlayerEntity().getHealth() / maxHealth) * 100).getAttribute(attribute.fulfill(2));
    }
    if (attribute.startsWith("health.max")) {
        return new Element(getMaxHealth()).getAttribute(attribute.fulfill(2));
    }
    if (attribute.matches("health")) {
        return new Element(getHealth()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_banned")) {
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(getName());
        if (ban == null) {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        } else if (ban.getExpiration() == null) {
            return Element.TRUE.getAttribute(attribute.fulfill(1));
        }
        return new Element(ban.getExpiration().after(new Date())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_online")) {
        return new Element(isOnline()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_op")) {
        return new Element(getOfflinePlayer().isOp()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_whitelisted")) {
        return new Element(getOfflinePlayer().isWhitelisted()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("last_played")) {
        attribute = attribute.fulfill(1);
        if (attribute.startsWith("milliseconds") || attribute.startsWith("in_milliseconds")) {
            if (isOnline()) {
                return new Element(System.currentTimeMillis()).getAttribute(attribute.fulfill(1));
            }
            return new Element(getOfflinePlayer().getLastPlayed()).getAttribute(attribute.fulfill(1));
        }
        if (isOnline()) {
            return new Duration(System.currentTimeMillis() / 50).getAttribute(attribute);
        }
        return new Duration(getOfflinePlayer().getLastPlayed() / 50).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("groups")) {
        if (Depends.permissions == null) {
            if (!attribute.hasAlternative()) {
                dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            }
            return null;
        }
        dList list = new dList();
        // TODO: optionally specify world
        for (String group : Depends.permissions.getGroups()) {
            if (Depends.permissions.playerInGroup(null, offlinePlayer, group)) {
                list.add(group);
            }
        }
        return list.getAttribute(attribute.fulfill(1));
    }
    if (attribute.startsWith("ban_info")) {
        attribute.fulfill(1);
        BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(getName());
        if (ban == null) {
            return null;
        } else if (ban.getExpiration() != null && ban.getExpiration().before(new Date())) {
            return null;
        }
        // -->
        if (attribute.startsWith("expiration") && ban.getExpiration() != null) {
            return new Duration(ban.getExpiration().getTime() / 50).getAttribute(attribute.fulfill(1));
        } else // -->
        if (attribute.startsWith("reason")) {
            return new Element(ban.getReason()).getAttribute(attribute.fulfill(1));
        } else // -->
        if (attribute.startsWith("created")) {
            return new Duration(ban.getCreated().getTime() / 50).getAttribute(attribute.fulfill(1));
        }
        return null;
    }
    // -->
    if (attribute.startsWith("in_group")) {
        if (Depends.permissions == null) {
            if (!attribute.hasAlternative()) {
                dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            }
            return null;
        }
        String group = attribute.getContext(1);
        // Non-world specific permission
        if (attribute.getAttribute(2).startsWith("global")) {
            return // TODO: Vault UUID support?
            new Element(Depends.permissions.playerInGroup((World) null, getName(), group)).getAttribute(attribute.fulfill(2));
        } else // Permission in certain world
        if (attribute.getAttribute(2).startsWith("world")) {
            return // TODO: Vault UUID support?
            new Element(Depends.permissions.playerInGroup(attribute.getContext(2), getName(), group)).getAttribute(attribute.fulfill(2));
        } else // Permission in current world
        if (isOnline()) {
            return new Element(Depends.permissions.playerInGroup(getPlayerEntity(), group)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("permission") || attribute.startsWith("has_permission")) {
        String permission = attribute.getContext(1);
        // Non-world specific permission
        if (attribute.getAttribute(2).startsWith("global")) {
            if (Depends.permissions == null) {
                if (!attribute.hasAlternative()) {
                    dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                }
                return null;
            }
            return // TODO: Vault UUID support?
            new Element(Depends.permissions.has((World) null, getName(), permission)).getAttribute(attribute.fulfill(2));
        } else // Permission in certain world
        if (attribute.getAttribute(2).startsWith("world")) {
            if (Depends.permissions == null) {
                if (!attribute.hasAlternative()) {
                    dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                }
                return null;
            }
            return // TODO: Vault UUID support?
            new Element(Depends.permissions.has(attribute.getContext(2), getName(), permission)).getAttribute(attribute.fulfill(2));
        } else // Permission in current world
        if (isOnline()) {
            return new Element(getPlayerEntity().hasPermission(permission)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("inventory")) {
        return getInventory().getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("enderchest")) {
        return getEnderChest().getAttribute(attribute.fulfill(1));
    }
    // Player is required to be online after this point...
    if (!isOnline()) {
        return new Element(identify()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("open_inventory")) {
        return new dInventory(getPlayerEntity().getOpenInventory().getTopInventory()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("item_on_cursor")) {
        return new dItem(getPlayerEntity().getItemOnCursor()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("item_in_hand.slot")) {
        return new Element(getPlayerEntity().getInventory().getHeldItemSlot() + 1).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("sidebar.lines")) {
        Sidebar sidebar = SidebarCommand.getSidebar(this);
        if (sidebar == null) {
            return null;
        }
        return new dList(sidebar.getLines()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("sidebar.title")) {
        Sidebar sidebar = SidebarCommand.getSidebar(this);
        if (sidebar == null) {
            return null;
        }
        return new Element(sidebar.getTitle()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("sidebar.scores")) {
        Sidebar sidebar = SidebarCommand.getSidebar(this);
        if (sidebar == null) {
            return null;
        }
        dList scores = new dList();
        for (int score : sidebar.getScores()) {
            scores.add(String.valueOf(score));
        }
        return scores.getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("sidebar.start")) {
        Sidebar sidebar = SidebarCommand.getSidebar(this);
        if (sidebar == null) {
            return null;
        }
        return new Element(sidebar.getStart()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("sidebar.increment")) {
        Sidebar sidebar = SidebarCommand.getSidebar(this);
        if (sidebar == null) {
            return null;
        }
        return new Element(sidebar.getIncrement()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("skin_blob")) {
        return new Element(NMSHandler.getInstance().getProfileEditor().getPlayerSkinBlob(getPlayerEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("selected_npc")) {
        if (getPlayerEntity().hasMetadata("selected")) {
            return getSelectedNPC().getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("entity") && !attribute.startsWith("entity_")) {
        return new dEntity(getPlayerEntity()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("ip") || attribute.startsWith("host_name")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("address_only")) {
            return new Element(getPlayerEntity().getAddress().toString()).getAttribute(attribute.fulfill(1));
        }
        String host = getPlayerEntity().getAddress().getHostName();
        // -->
        if (attribute.startsWith("address")) {
            return new Element(getPlayerEntity().getAddress().toString()).getAttribute(attribute.fulfill(1));
        }
        return new Element(host).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("name.display")) {
        return new Element(getPlayerEntity().getDisplayName()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("name.list")) {
        return new Element(getPlayerEntity().getPlayerListName()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("nameplate")) {
        return new Element(NMSHandler.getInstance().getProfileEditor().getPlayerName(getPlayerEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("name")) {
        return new Element(getName()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_finished")) {
        dScript script = dScript.valueOf(attribute.getContext(1));
        if (script == null) {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }
        return new Element(FinishCommand.getScriptCompletes(getName(), script.getName()) > 0).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_failed")) {
        dScript script = dScript.valueOf(attribute.getContext(1));
        if (script == null) {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }
        return new Element(FailCommand.getScriptFails(getName(), script.getName()) > 0).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("compass_target")) {
        Location target = getPlayerEntity().getCompassTarget();
        if (target != null) {
            return new dLocation(target).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("chunk_loaded") && attribute.hasContext(1)) {
        dChunk chunk = dChunk.valueOf(attribute.getContext(1));
        if (chunk == null) {
            return null;
        }
        return new Element(hasChunkLoaded(chunk.chunk)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("can_fly") || attribute.startsWith("allowed_flight")) {
        return new Element(getPlayerEntity().getAllowFlight()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("fly_speed")) {
        return new Element(getPlayerEntity().getFlySpeed()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("food_level.formatted")) {
        double maxHunger = getPlayerEntity().getMaxHealth();
        if (attribute.hasContext(2)) {
            maxHunger = attribute.getIntContext(2);
        }
        int foodLevel = getFoodLevel();
        if (foodLevel / maxHunger < .10) {
            return new Element("starving").getAttribute(attribute.fulfill(2));
        } else if (foodLevel / maxHunger < .40) {
            return new Element("famished").getAttribute(attribute.fulfill(2));
        } else if (foodLevel / maxHunger < .75) {
            return new Element("parched").getAttribute(attribute.fulfill(2));
        } else if (foodLevel / maxHunger < 1) {
            return new Element("hungry").getAttribute(attribute.fulfill(2));
        } else {
            return new Element("healthy").getAttribute(attribute.fulfill(2));
        }
    }
    // -->
    if (attribute.startsWith("saturation")) {
        return new Element(getPlayerEntity().getSaturation()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("food_level")) {
        return new Element(getFoodLevel()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("gamemode")) {
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("id")) {
            return new Element(getPlayerEntity().getGameMode().getValue()).getAttribute(attribute.fulfill(1));
        }
        return new Element(getPlayerEntity().getGameMode().name()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("is_blocking")) {
        return new Element(getPlayerEntity().isBlocking()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("ping")) {
        return new Element(NMSHandler.getInstance().getPlayerHelper().getPing(getPlayerEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_flying")) {
        return new Element(getPlayerEntity().isFlying()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_sleeping")) {
        return new Element(getPlayerEntity().isSleeping()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_sneaking")) {
        return new Element(getPlayerEntity().isSneaking()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_sprinting")) {
        return new Element(getPlayerEntity().isSprinting()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_achievement")) {
        Achievement ach = Achievement.valueOf(attribute.getContext(1).toUpperCase());
        return new Element(getPlayerEntity().hasAchievement(ach)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("statistic")) {
        Statistic statistic = Statistic.valueOf(attribute.getContext(1).toUpperCase());
        if (statistic == null) {
            return null;
        }
        // -->
        if (attribute.getAttribute(2).startsWith("qualifier")) {
            dObject obj = ObjectFetcher.pickObjectFor(attribute.getContext(2));
            try {
                if (obj instanceof dMaterial) {
                    return new Element(getPlayerEntity().getStatistic(statistic, ((dMaterial) obj).getMaterial())).getAttribute(attribute.fulfill(2));
                } else if (obj instanceof dEntity) {
                    return new Element(getPlayerEntity().getStatistic(statistic, ((dEntity) obj).getBukkitEntityType())).getAttribute(attribute.fulfill(2));
                } else {
                    return null;
                }
            } catch (Exception e) {
                dB.echoError("Invalid statistic: " + statistic + " for this player!");
                return null;
            }
        }
        try {
            return new Element(getPlayerEntity().getStatistic(statistic)).getAttribute(attribute.fulfill(1));
        } catch (Exception e) {
            dB.echoError("Invalid statistic: " + statistic + " for this player!");
            return null;
        }
    }
    // -->
    if (attribute.startsWith("time_asleep")) {
        return new Duration(getPlayerEntity().getSleepTicks() / 20).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("time")) {
        return new Element(getPlayerEntity().getPlayerTime()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("walk_speed")) {
        return new Element(getPlayerEntity().getWalkSpeed()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("weather")) {
        if (getPlayerEntity().getPlayerWeather() != null) {
            return new Element(getPlayerEntity().getPlayerWeather().name()).getAttribute(attribute.fulfill(1));
        } else {
            return null;
        }
    }
    // -->
    if (attribute.startsWith("xp.level")) {
        return new Element(getPlayerEntity().getLevel()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("xp.to_next_level")) {
        return new Element(getPlayerEntity().getExpToLevel()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("xp.total")) {
        return new Element(getPlayerEntity().getTotalExperience()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("xp")) {
        return new Element(getPlayerEntity().getExp() * 100).getAttribute(attribute.fulfill(1));
    }
    if (Depends.chat != null) {
        // -->
        if (attribute.startsWith("chat_prefix")) {
            String prefix = Depends.chat.getPlayerPrefix(getWorld().getName(), getOfflinePlayer());
            if (prefix == null) {
                return null;
            }
            return new Element(prefix).getAttribute(attribute.fulfill(1));
        } else // -->
        if (attribute.startsWith("chat_suffix")) {
            String suffix = Depends.chat.getPlayerSuffix(getWorld().getName(), getOfflinePlayer());
            if (suffix == null) {
                return null;
            }
            return new Element(suffix).getAttribute(attribute.fulfill(1));
        }
    }
    // Iterate through this object's properties' attributes
    for (Property property : PropertyParser.getProperties(this)) {
        String returned = property.getAttribute(attribute);
        if (returned != null) {
            return returned;
        }
    }
    return new dEntity(getPlayerEntity()).getAttribute(attribute);
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) BlockIterator(org.bukkit.util.BlockIterator) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) FlagManager(net.aufdemrand.denizen.flags.FlagManager) LivingEntity(org.bukkit.entity.LivingEntity) ImprovedOfflinePlayer(net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer) Property(net.aufdemrand.denizencore.objects.properties.Property) Pattern(java.util.regex.Pattern) Player(org.bukkit.entity.Player) ImprovedOfflinePlayer(net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer) Date(java.util.Date) Block(org.bukkit.block.Block) Sidebar(net.aufdemrand.denizen.nms.abstracts.Sidebar)

Example 50 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Denizen-For-Bukkit by DenizenScript.

the class EntityPotionEffects method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("potion_effects")) {
        dList effects = dList.valueOf(mechanism.getValue().asString());
        for (String effect : effects) {
            List<String> split = CoreUtilities.split(effect, ',');
            if (split.size() != 3) {
                continue;
            }
            PotionEffectType effectType = PotionEffectType.getByName(split.get(0));
            if (Integer.valueOf(split.get(1)) == null || Integer.valueOf(split.get(2)) == null || effectType == null) {
                continue;
            }
            entity.getLivingEntity().addPotionEffect(new PotionEffect(effectType, Integer.valueOf(split.get(2)), Integer.valueOf(split.get(1))));
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)87 Player (org.bukkit.entity.Player)28 Location (org.bukkit.Location)16 LivingEntity (org.bukkit.entity.LivingEntity)13 ArrayList (java.util.ArrayList)12 PotionEffectType (org.bukkit.potion.PotionEffectType)12 EventHandler (org.bukkit.event.EventHandler)11 ItemStack (org.bukkit.inventory.ItemStack)10 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)9 Entity (org.bukkit.entity.Entity)9 Projectile (org.bukkit.entity.Projectile)6 Minigame (au.com.mineauz.minigames.minigame.Minigame)3 List (java.util.List)3 Vector (org.bukkit.util.Vector)3 LoadoutAddon (au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)2 MinorPowerPowerStance (com.magmaguy.elitemobs.powerstances.MinorPowerPowerStance)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2