Search in sources :

Example 51 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class Events method onTeleportAway.

@EventHandler
public void onTeleportAway(PlayerTeleportEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && (event.getCause() == TeleportCause.COMMAND || event.getCause() == TeleportCause.PLUGIN || (!ply.getMinigame().isAllowedEnderpearls() && event.getCause() == TeleportCause.ENDER_PEARL))) {
        if (!ply.getAllowTeleport()) {
            Location from = event.getFrom();
            Location to = event.getTo();
            if (from.getWorld() != to.getWorld() || from.distance(to) > 2) {
                event.setCancelled(true);
                event.getPlayer().sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noTeleport"));
            }
        }
    }
}
Also used : Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 52 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class Events method playerShoot.

@EventHandler(ignoreCancelled = true)
private void playerShoot(ProjectileLaunchEvent event) {
    if (event.getEntityType() == EntityType.SNOWBALL) {
        Snowball snowball = (Snowball) event.getEntity();
        if (snowball.getShooter() != null && snowball.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) snowball.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ItemStack mainhand = ply.getPlayer().getInventory().getItemInMainHand();
                if (mainhand.getType() == Material.SNOW_BALL) {
                    mainhand.setAmount(16);
                    ply.getPlayer().updateInventory();
                } else {
                    ply.getPlayer().getInventory().addItem(new ItemStack(Material.SNOW_BALL, 1));
                }
            }
        }
    } else if (event.getEntityType() == EntityType.EGG) {
        Egg egg = (Egg) event.getEntity();
        if (egg.getShooter() != null && egg.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) egg.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ply.getPlayer().getInventory().addItem(new ItemStack(Material.EGG));
            }
        }
    }
}
Also used : Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) Egg(org.bukkit.entity.Egg) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 53 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class TreasureHuntMechanic method timerExpire.

@EventHandler
private void timerExpire(TimerExpireEvent event) {
    if (event.getMinigame().getType() != MinigameType.GLOBAL && !event.getMinigame().getMechanicName().equals(getMechanic()))
        return;
    Minigame mgm = event.getMinigame();
    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
    if (thm.hasTreasureLocation()) {
        mgm.setMinigameTimer(new MinigameTimer(mgm, thm.getTreasureWaitTime()));
        Location old = thm.getTreasureLocation();
        removeTreasure(mgm);
        if (!thm.isTreasureFound()) {
            MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plyDespawn", mgm.getName(true)) + "\n" + ChatColor.GRAY + MinigameUtils.formStr("minigame.treasurehunt.plyDespawnCoords", old.getBlockX(), old.getBlockY(), old.getBlockZ()), mgm, "minigame.treasure.announce");
        }
        thm.setTreasureFound(false);
    } else {
        spawnTreasure(mgm);
    }
}
Also used : TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) MinigameTimer(au.com.mineauz.minigames.MinigameTimer) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 54 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class TreasureHuntMechanic method interactEvent.

@EventHandler
private void interactEvent(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block cblock = event.getClickedBlock();
        if (cblock.getState() instanceof Chest && !event.isCancelled()) {
            for (Minigame minigame : mdata.getAllMinigames().values()) {
                if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equalsIgnoreCase(getMechanic()) && minigame.getMinigameTimer() != null) {
                    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
                    if (!thm.isTreasureFound() && thm.hasTreasureLocation()) {
                        int x1 = thm.getTreasureLocation().getBlockX();
                        int x2 = cblock.getLocation().getBlockX();
                        int y1 = thm.getTreasureLocation().getBlockY();
                        int y2 = cblock.getLocation().getBlockY();
                        int z1 = thm.getTreasureLocation().getBlockZ();
                        int z2 = cblock.getLocation().getBlockZ();
                        if (x2 == x1 && y2 == y1 && z2 == z1) {
                            MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plyFound", event.getPlayer().getDisplayName(), minigame.getName(true)), minigame, "minigame.treasure.announce");
                            event.setCancelled(true);
                            Chest chest = (Chest) cblock.getState();
                            event.getPlayer().openInventory(chest.getInventory());
                            thm.setTreasureFound(true);
                            minigame.getMinigameTimer().setTimeLeft(300);
                        }
                    }
                }
            }
        }
    }
}
Also used : Chest(org.bukkit.block.Chest) TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Block(org.bukkit.block.Block) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 55 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class TreasureHuntMechanic method timerTick.

@EventHandler
private void timerTick(MinigameTimerTickEvent event) {
    if (event.getMinigame().getType() != MinigameType.GLOBAL && !event.getMinigame().getMechanicName().equals(getMechanic()))
        return;
    Minigame mgm = event.getMinigame();
    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
    if (!thm.hasTreasureLocation() || thm.isTreasureFound())
        return;
    int time = event.getTimeLeft();
    int hintTime1 = event.getMinigame().getTimer() - 1;
    int hintTime2 = (int) (event.getMinigame().getTimer() * 0.75);
    int hintTime3 = (int) (event.getMinigame().getTimer() * 0.50);
    int hintTime4 = (int) (event.getMinigame().getTimer() * 0.25);
    Location block = thm.getTreasureLocation();
    if (time == hintTime1) {
        double dfcx = 0.0;
        double dfcz = 0.0;
        String xdir = null;
        String zdir = null;
        if (mgm.getStartLocations().get(0).getX() > block.getX()) {
            dfcx = mgm.getStartLocations().get(0).getX() - block.getX();
            xdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.west");
        } else {
            dfcx = block.getX() - mgm.getStartLocations().get(0).getX();
            xdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.east");
        }
        if (mgm.getStartLocations().get(0).getZ() > block.getZ()) {
            dfcz = mgm.getStartLocations().get(0).getZ() - block.getZ();
            zdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.north");
        } else {
            dfcz = block.getZ() - mgm.getStartLocations().get(0).getZ();
            zdir = MinigameUtils.getLang("minigame.treasurehunt.hint1.south");
        }
        String dir = null;
        if (dfcz > dfcx) {
            if (dfcx > dfcz / 2) {
                dir = zdir + xdir.toLowerCase();
            } else {
                dir = zdir;
            }
        } else {
            if (dfcz > dfcx / 2) {
                dir = zdir + xdir.toLowerCase();
            } else {
                dir = xdir;
            }
        }
        String hint = MinigameUtils.formStr("minigame.treasurehunt.hint1.hint", mgm.getName(true), dir, thm.getLocation());
        MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
        thm.addHint(ChatColor.GRAY + hint);
    } else if (time == hintTime2) {
        block.setY(block.getY() - 1);
        String hint = MinigameUtils.formStr("minigame.treasurehunt.hint2", mgm.getName(true), block.getBlock().getType().toString().toLowerCase().replace("_", " "));
        MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
        thm.addHint(ChatColor.GRAY + hint);
        block.setY(block.getY() + 1);
    } else if (time == hintTime3) {
        int height = block.getBlockY();
        String dir;
        int dist;
        if (height > 62) {
            dist = height - 62;
            dir = MinigameUtils.getLang("minigame.treasurehunt.hint3.above");
        } else {
            dist = 62 - height;
            dir = MinigameUtils.getLang("minigame.treasurehunt.hint3.below");
        }
        String hint = MinigameUtils.formStr("minigame.treasurehunt.hint3.hint", mgm.getName(true), dist, dir);
        MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
        thm.addHint(ChatColor.GRAY + hint);
    } else if (time == hintTime4) {
        String hint = MinigameUtils.formStr("minigame.treasurehunt.hint4", mgm.getName(true), block.getBlock().getBiome().toString().toLowerCase().replace("_", " "));
        MinigameUtils.broadcast(hint, mgm, "minigame.treasure.announce");
        thm.addHint(ChatColor.GRAY + hint);
    }
}
Also used : TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (org.bukkit.event.EventHandler)532 Player (org.bukkit.entity.Player)185 Entity (org.bukkit.entity.Entity)70 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)67 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)62 Block (org.bukkit.block.Block)62 ItemStack (org.bukkit.inventory.ItemStack)55 Location (org.bukkit.Location)54 Island (com.wasteofplastic.acidisland.Island)42 Element (net.aufdemrand.denizencore.objects.Element)38 LivingEntity (org.bukkit.entity.LivingEntity)37 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)31 Minigame (au.com.mineauz.minigames.minigame.Minigame)29 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)29 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)28 Projectile (org.bukkit.entity.Projectile)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)23 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)22 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)18 ArrayList (java.util.ArrayList)18