Search in sources :

Example 96 with Location

use of org.bukkit.Location 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 97 with Location

use of org.bukkit.Location in project Minigames by AddstarMC.

the class FloorDegenerator method degenerateRandom.

private void degenerateRandom(Location lowest, Location highest, int chance) {
    Location curblock = lowest.clone();
    int x = curblock.getBlockX();
    int z = curblock.getBlockZ();
    int y = curblock.getBlockY();
    Random random = new Random();
    do {
        curblock.setZ(z);
        curblock.setX(x);
        curblock.setY(y);
        for (int i = lowest.getBlockX(); i <= highest.getBlockX() + 1; i++) {
            for (int k = lowest.getBlockZ(); k <= highest.getBlockZ() + 1; k++) {
                if (curblock.getBlock().getType() != Material.AIR && random.nextInt(100) < chance) {
                    mgm.getBlockRecorder().addBlock(curblock.getBlock(), null);
                    curblock.getBlock().setType(Material.AIR);
                }
                curblock.setZ(k);
            }
            curblock.setX(i);
            curblock.setZ(z);
        }
        y++;
    } while (y <= highest.getBlockY());
}
Also used : Random(java.util.Random) Location(org.bukkit.Location)

Example 98 with Location

use of org.bukkit.Location in project Minigames by AddstarMC.

the class FloorDegenerator method degenerateCircle.

private void degenerateCircle(Location lowest, Location highest) {
    int middledist = (int) Math.abs(Math.floor((highest.getBlockX() - lowest.getBlockX()) / 2));
    int radius = middledist - radiusModifier;
    Location centerBlock = lowest.clone();
    centerBlock.setX(centerBlock.getX() + middledist);
    centerBlock.setZ(centerBlock.getZ() + middledist);
    Location curBlock = centerBlock.clone();
    int size = (int) Math.pow(radius, 3) + 8;
    for (int i = 0; i < size; i++) {
        double cirPoint = 2 * Math.PI * i / size;
        double cx = centerBlock.getX() - 0.5 + Math.round(radius * Math.cos(cirPoint));
        double cz = centerBlock.getZ() - 0.5 + Math.round(radius * Math.sin(cirPoint));
        curBlock.setX(cx);
        curBlock.setZ(cz);
        for (int k = lowest.getBlockY(); k <= highest.getBlockY(); k++) {
            curBlock.setY(k);
            mgm.getBlockRecorder().addBlock(curBlock.getBlock(), null);
            curBlock.getBlock().setType(Material.AIR);
        }
    }
    radiusModifier++;
    if (middledist == radiusModifier) {
        stopDegenerator();
    }
}
Also used : Location(org.bukkit.Location)

Example 99 with Location

use of org.bukkit.Location 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 100 with Location

use of org.bukkit.Location 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

Location (org.bukkit.Location)351 Player (org.bukkit.entity.Player)90 World (org.bukkit.World)56 EventHandler (org.bukkit.event.EventHandler)43 Test (org.junit.Test)43 Vector (org.bukkit.util.Vector)38 ArrayList (java.util.ArrayList)29 Block (org.bukkit.block.Block)18 Entity (org.bukkit.entity.Entity)17 User (com.earth2me.essentials.User)16 ItemStack (org.bukkit.inventory.ItemStack)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 List (java.util.List)12 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)11 BlockState (org.bukkit.block.BlockState)11 UUID (java.util.UUID)10 LivingEntity (org.bukkit.entity.LivingEntity)10 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)9