Search in sources :

Example 11 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Minigames by AddstarMC.

the class PlayerData method joinMinigame.

public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
    MinigameType type = minigame.getType();
    JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    boolean canStart = minigame.getMechanic().checkCanStart(minigame, player);
    if (!event.isCancelled()) {
        if ((minigame.isEnabled() || player.getPlayer().hasPermission("minigame.join.disabled")) && (minigame.getState() == MinigameState.IDLE || minigame.getState() == MinigameState.OCCUPIED || minigame.getState() == MinigameState.WAITING || (minigame.getState() == MinigameState.STARTED && minigame.canLateJoin())) && /*!minigame.isRegenerating() && 
					(!minigame.isNotWaitingForPlayers() || (minigame.canLateJoin() && minigame.getMpTimer().getPlayerWaitTimeLeft() == 0)) &&*/
        (minigame.getStartLocations().size() > 0 || (minigame.isTeamGame() && TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) && minigame.getEndPosition() != null && minigame.getQuitPosition() != null && (minigame.getType() == MinigameType.SINGLEPLAYER || minigame.getLobbyPosition() != null) && ((type == MinigameType.SINGLEPLAYER && !minigame.isSpMaxPlayers()) || minigame.getPlayers().size() < minigame.getMaxPlayers()) && minigame.getMechanic().validTypes().contains(minigame.getType()) && canStart) {
            //Do betting stuff
            if (isBetting) {
                if (minigame.getMpBets() == null && (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR || betAmount != 0)) {
                    minigame.setMpBets(new MultiplayerBets());
                }
                MultiplayerBets pbet = minigame.getMpBets();
                ItemStack item = player.getPlayer().getInventory().getItemInMainHand().clone();
                if (pbet != null && ((betAmount != 0 && pbet.canBet(player, betAmount) && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) >= betAmount) || (pbet.canBet(player, item) && item.getType() != Material.AIR && pbet.betValue(item.getType()) > 0))) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.plyMsg"), null);
                    if (betAmount == 0) {
                        pbet.addBet(player, item);
                    } else {
                        pbet.addBet(player, betAmount);
                        plugin.getEconomy().withdrawPlayer(player.getPlayer().getPlayer(), betAmount);
                    }
                    player.getPlayer().getInventory().removeItem(new ItemStack(item.getType(), 1));
                } else if (item.getType() == Material.AIR && betAmount == 0) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.plyNoBet"), "error");
                    return;
                } else if (betAmount != 0 && !pbet.canBet(player, betAmount)) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.incorrectAmount"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.incorrectAmountInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
                    return;
                } else if (betAmount != 0 && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) < betAmount) {
                    player.sendMessage(MinigameUtils.getLang("player.bet.notEnoughMoney"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.notEnoughMoneyInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
                    return;
                } else {
                    player.sendMessage(MinigameUtils.getLang("player.bet.incorrectItem"), "error");
                    player.sendMessage(MinigameUtils.formStr("player.bet.incorrectItemInfo", 1, minigame.getMpBets().highestBetName()), "error");
                    return;
                }
            }
            //Try teleport the player to their designated area.
            boolean tpd = false;
            if (type == MinigameType.SINGLEPLAYER) {
                List<Location> locs = new ArrayList<Location>(minigame.getStartLocations());
                Collections.shuffle(locs);
                tpd = player.teleport(locs.get(0));
                if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() && player.getPlayer().hasPermission("minigame.set.start")) {
                    player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Join location is across worlds! This may cause some server performance issues!", "error");
                }
            } else {
                tpd = player.teleport(minigame.getLobbyPosition());
                if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != minigame.getLobbyPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.lobby")) {
                    player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Lobby location is across worlds! This may cause some server performance issues!", "error");
                }
            }
            if (!tpd) {
                player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
                return;
            }
            //Give them the game type name
            if (minigame.getGametypeName() == null)
                player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), "win");
            else
                player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), "win");
            //Give them the objective
            if (minigame.getObjective() != null) {
                player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
                player.sendMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
                player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
            }
            //Prepare regeneration region for rollback.
            if (minigame.getBlockRecorder().hasRegenArea() && !minigame.getBlockRecorder().hasCreatedRegenBlocks()) {
                RecorderData d = minigame.getBlockRecorder();
                d.setCreatedRegenBlocks(true);
                Location cur = new Location(minigame.getRegenArea1().getWorld(), 0, 0, 0);
                for (double y = d.getRegenMinY(); y <= d.getRegenMaxY(); y++) {
                    cur.setY(y);
                    for (double x = d.getRegenMinX(); x <= d.getRegenMaxX(); x++) {
                        cur.setX(x);
                        for (double z = d.getRegenMinZ(); z <= d.getRegenMaxZ(); z++) {
                            cur.setZ(z);
                            d.addBlock(cur.getBlock(), null);
                        }
                    }
                }
            }
            //Standardize player
            player.storePlayerData();
            player.setMinigame(minigame);
            minigame.addPlayer(player);
            WeatherTimeModule.getMinigameModule(minigame).applyCustomTime(player);
            WeatherTimeModule.getMinigameModule(minigame).applyCustomWeather(player);
            player.setCheckpoint(player.getPlayer().getLocation());
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setWalkSpeed(0.2f);
            player.setStartTime(Calendar.getInstance().getTimeInMillis());
            player.setGamemode(minigame.getDefaultGamemode());
            if (minigame.getType() == MinigameType.SINGLEPLAYER) {
                if (!minigame.isAllowedFlight()) {
                    player.setCanFly(false);
                } else {
                    player.setCanFly(true);
                    if (minigame.isFlightEnabled())
                        player.getPlayer().setFlying(true);
                }
            } else {
                player.getPlayer().setAllowFlight(false);
            }
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            //Hide Spectators
            for (MinigamePlayer pl : minigame.getSpectators()) {
                player.getPlayer().hidePlayer(pl.getPlayer());
            }
            if (minigame.getPlayers().size() == 1) {
                //Register regen recorder events
                if (minigame.getBlockRecorder().hasRegenArea())
                    Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
                WeatherTimeModule.getMinigameModule(minigame).startTimeLoop();
            }
            //Call Type specific join
            mdata.minigameType(type).joinMinigame(player, minigame);
            //Call Mechanic specific join
            minigame.getMechanic().joinMinigame(minigame, player);
            //Send other players the join message.
            mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
            player.updateInventory();
            if (minigame.canDisplayScoreboard()) {
                player.getPlayer().setScoreboard(minigame.getScoreboardManager());
                minigame.setScore(player, 1);
                minigame.setScore(player, 0);
            }
        } else if (!minigame.isEnabled()) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.notEnabled"), "error");
        } else if (minigame.getState() == MinigameState.REGENERATING) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.regenerating"), "error");
        } else if (minigame.getState() == MinigameState.STARTED && !minigame.canLateJoin()) {
            player.sendMessage(MinigameUtils.getLang("minigame.started"), "error");
        } else if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin() && minigame.getPlayers().size() != minigame.getMaxPlayers()) {
            player.sendMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()), null);
        } else if (minigame.getStartLocations().size() == 0 || (minigame.isTeamGame() && !TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noStart"), "error");
        } else if (minigame.getEndPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), "error");
        } else if (minigame.getQuitPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), "error");
        } else if (minigame.getLobbyPosition() == null) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noLobby"), "error");
        } else if (minigame.getPlayers().size() >= minigame.getMaxPlayers()) {
            player.sendMessage(MinigameUtils.getLang("minigame.full"), "error");
        } else if (!minigame.getMechanic().validTypes().contains(minigame.getType())) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.invalidMechanic"), "error");
        } else if (!canStart) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.mechanicStartFail"), "error");
        }
    }
}
Also used : RecorderData(au.com.mineauz.minigames.blockRecorder.RecorderData) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) JoinMinigameEvent(au.com.mineauz.minigames.events.JoinMinigameEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 12 with PotionEffect

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

the class CastCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    PotionEffectType effect = (PotionEffectType) scriptEntry.getObject("effect");
    int amplifier = scriptEntry.getElement("amplifier").asInt();
    Duration duration = (Duration) scriptEntry.getObject("duration");
    boolean remove = scriptEntry.getElement("remove").asBoolean();
    Element showParticles = scriptEntry.getElement("show_particles");
    Element ambient = scriptEntry.getElement("ambient");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("Target(s)", entities.toString()) + aH.debugObj("Effect", effect.getName()) + aH.debugObj("Amplifier", amplifier) + duration.debug() + ambient.debug() + showParticles.debug());
    boolean amb = ambient.asBoolean();
    boolean showP = showParticles.asBoolean();
    // Apply the PotionEffect to the targets!
    for (dEntity entity : entities) {
        if (entity.getLivingEntity().hasPotionEffect(effect)) {
            entity.getLivingEntity().removePotionEffect(effect);
        }
        if (remove) {
            continue;
        }
        PotionEffect potion = new PotionEffect(effect, duration.getTicksAsInt(), amplifier, amb, showP);
        if (!potion.apply(entity.getLivingEntity())) {
            dB.echoError(scriptEntry.getResidingQueue(), "Bukkit was unable to apply '" + potion.getType().getName() + "' to '" + entity.toString() + "'.");
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) PotionEffectType(org.bukkit.potion.PotionEffectType) Element(net.aufdemrand.denizencore.objects.Element) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration)

Example 13 with PotionEffect

use of org.bukkit.potion.PotionEffect 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 14 with PotionEffect

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

the class dEntity method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (isGeneric()) {
        mechanisms.add(mechanism);
        return;
    }
    Element value = mechanism.getValue();
    // -->
    if (mechanism.matches("item_in_hand")) {
        NMSHandler.getInstance().getEntityHelper().setItemInHand(getLivingEntity(), value.asType(dItem.class).getItemStack());
    }
    // -->
    if (mechanism.matches("item_in_offhand")) {
        NMSHandler.getInstance().getEntityHelper().setItemInOffHand(getLivingEntity(), value.asType(dItem.class).getItemStack());
    }
    // -->
    if (mechanism.matches("shooter")) {
        setShooter(value.asType(dEntity.class));
    }
    // -->
    if (mechanism.matches("can_pickup_items") && mechanism.requireBoolean()) {
        getLivingEntity().setCanPickupItems(value.asBoolean());
    }
    // -->
    if (mechanism.matches("fall_distance") && mechanism.requireFloat()) {
        entity.setFallDistance(value.asFloat());
    }
    // -->
    if (mechanism.matches("fire_time") && mechanism.requireObject(Duration.class)) {
        entity.setFireTicks(value.asType(Duration.class).getTicksAsInt());
    }
    // -->
    if (mechanism.matches("leash_holder") && mechanism.requireObject(dEntity.class)) {
        getLivingEntity().setLeashHolder(value.asType(dEntity.class).getBukkitEntity());
    }
    // -->
    if (mechanism.matches("can_breed") && mechanism.requireBoolean()) {
        ((Ageable) getLivingEntity()).setBreed(true);
    }
    // -->
    if (mechanism.matches("breed") && mechanism.requireBoolean()) {
        NMSHandler.getInstance().getEntityHelper().setBreeding((Animals) getLivingEntity(), value.asBoolean());
    }
    // -->
    if (mechanism.matches("passenger") && mechanism.requireObject(dEntity.class)) {
        entity.setPassenger(value.asType(dEntity.class).getBukkitEntity());
    }
    // -->
    if (mechanism.matches("time_lived") && mechanism.requireObject(Duration.class)) {
        entity.setTicksLived(value.asType(Duration.class).getTicksAsInt());
    }
    // -->
    if (mechanism.matches("remaining_air") && mechanism.requireInteger()) {
        getLivingEntity().setRemainingAir(value.asInt());
    }
    // -->
    if (mechanism.matches("remove_effects")) {
        for (PotionEffect potionEffect : this.getLivingEntity().getActivePotionEffects()) {
            getLivingEntity().removePotionEffect(potionEffect.getType());
        }
    }
    // -->
    if (mechanism.matches("remove_when_far_away") && mechanism.requireBoolean()) {
        getLivingEntity().setRemoveWhenFarAway(value.asBoolean());
    }
    // -->
    if (mechanism.matches("velocity") && mechanism.requireObject(dLocation.class)) {
        setVelocity(value.asType(dLocation.class).toVector());
    }
    // -->
    if (mechanism.matches("move") && mechanism.requireObject(dLocation.class)) {
        NMSHandler.getInstance().getEntityHelper().move(getBukkitEntity(), value.asType(dLocation.class).toVector());
    }
    // -->
    if (mechanism.matches("interact_with") && mechanism.requireObject(dLocation.class)) {
        dLocation interactLocation = value.asType(dLocation.class);
        NMSHandler.getInstance().getEntityHelper().forceInteraction(getPlayer(), interactLocation);
    }
    // -->
    if (mechanism.matches("play_death")) {
        getLivingEntity().playEffect(EntityEffect.DEATH);
    }
    // -->
    if ((mechanism.matches("pickup_delay") || mechanism.matches("pickupdelay")) && getBukkitEntity() instanceof Item && mechanism.requireObject(Duration.class)) {
        ((Item) getBukkitEntity()).setPickupDelay(value.asType(Duration.class).getTicksAsInt());
    }
    // -->
    if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && mechanism.matches("gliding") && mechanism.requireBoolean()) {
        getLivingEntity().setGliding(value.asBoolean());
    }
    // -->
    if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && mechanism.matches("glowing") && mechanism.requireBoolean()) {
        getLivingEntity().setGlowing(value.asBoolean());
        if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(getLivingEntity())) {
            CitizensAPI.getNPCRegistry().getNPC(getLivingEntity()).data().setPersistent(NPC.GLOWING_METADATA, value.asBoolean());
        }
    }
    // -->
    if (mechanism.matches("dragon_phase")) {
        EnderDragon ed = (EnderDragon) getLivingEntity();
        ed.setPhase(EnderDragon.Phase.valueOf(value.asString().toUpperCase()));
    }
    // -->
    if (mechanism.matches("experience") && getBukkitEntity() instanceof ExperienceOrb && mechanism.requireInteger()) {
        ((ExperienceOrb) getBukkitEntity()).setExperience(value.asInt());
    }
    // Iterate through this object's properties' mechanisms
    for (Property property : PropertyParser.getProperties(this)) {
        property.adjust(mechanism);
        if (mechanism.fulfilled()) {
            break;
        }
    }
    if (!mechanism.fulfilled()) {
        mechanism.reportInvalid();
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) Property(net.aufdemrand.denizencore.objects.properties.Property)

Example 15 with PotionEffect

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

the class EntityPotionEffects method getPropertyString.

/////////
// Property Methods
///////
public String getPropertyString() {
    Collection<PotionEffect> effects = entity.getLivingEntity().getActivePotionEffects();
    if (effects.isEmpty()) {
        return null;
    }
    dList returnable = new dList();
    for (PotionEffect effect : effects) {
        returnable.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + effect.getDuration());
    }
    return returnable.identify().substring(3);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)224 Player (org.bukkit.entity.Player)61 PotionEffectType (org.bukkit.potion.PotionEffectType)39 Location (org.bukkit.Location)37 LivingEntity (org.bukkit.entity.LivingEntity)37 EventHandler (org.bukkit.event.EventHandler)36 ItemStack (org.bukkit.inventory.ItemStack)34 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)23 PotionMeta (org.bukkit.inventory.meta.PotionMeta)18 Vector (org.bukkit.util.Vector)16 Random (java.util.Random)14 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)9 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)9 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 Projectile (org.bukkit.entity.Projectile)7 PotionData (org.bukkit.potion.PotionData)7