Search in sources :

Example 51 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)

Example 52 with Location

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

the class MultiplayerType method playerRespawn.

/*----------------*/
/*-----EVENTS-----*/
/*----------------*/
@EventHandler(priority = EventPriority.HIGHEST)
public void playerRespawn(PlayerRespawnEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply.isInMinigame() && ply.getMinigame().getType() == MinigameType.MULTIPLAYER) {
        Minigame mg = ply.getMinigame();
        Location respawnPos;
        if (ply.getMinigame().isTeamGame()) {
            Team team = ply.getTeam();
            if (mg.hasStarted() && !ply.isLatejoining()) {
                if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
                    respawnPos = ply.getCheckpoint();
                } else {
                    List<Location> starts = new ArrayList<Location>();
                    if (TeamsModule.getMinigameModule(mg).hasTeamStartLocations()) {
                        starts.addAll(team.getStartLocations());
                        ply.getLoadout().equiptLoadout(ply);
                    } else {
                        starts.addAll(mg.getStartLocations());
                    }
                    Collections.shuffle(starts);
                    respawnPos = starts.get(0);
                }
                ply.getLoadout().equiptLoadout(ply);
            } else {
                respawnPos = mg.getLobbyPosition();
            }
        } else {
            if (mg.hasStarted() && !ply.isLatejoining()) {
                if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
                    respawnPos = ply.getCheckpoint();
                } else {
                    List<Location> starts = new ArrayList<Location>();
                    starts.addAll(mg.getStartLocations());
                    Collections.shuffle(starts);
                    respawnPos = starts.get(0);
                }
                ply.getLoadout().equiptLoadout(ply);
            } else {
                respawnPos = mg.getLobbyPosition();
            }
        }
        event.setRespawnLocation(respawnPos);
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                ply.getPlayer().setNoDamageTicks(60);
            }
        });
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 53 with Location

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

the class TreasureHuntMechanic method removeTreasure.

public static void removeTreasure(Minigame minigame) {
    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
    thm.clearHints();
    if (thm.hasTreasureLocation()) {
        Location old = thm.getTreasureLocation();
        boolean loaded = false;
        Chunk c = null;
        if (!old.getWorld().isChunkInUse(old.getChunk().getX(), old.getChunk().getZ())) {
            old.getChunk().load();
            loaded = true;
            c = old.getChunk();
        }
        if (old.getBlock().getState() instanceof Chest) {
            Chest chest = (Chest) old.getBlock().getState();
            chest.getInventory().clear();
        }
        old.getBlock().setType(Material.AIR);
        if (loaded && !c.getWorld().isChunkInUse(c.getX(), c.getZ())) {
            c.unload();
        }
        thm.setTreasureLocation(null);
    }
}
Also used : TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Chest(org.bukkit.block.Chest) Chunk(org.bukkit.Chunk) Location(org.bukkit.Location)

Example 54 with Location

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

the class SetBlockAction method executeRegionAction.

@SuppressWarnings("deprecation")
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
    Location temp = region.getFirstPoint();
    for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
        temp.setY(y);
        for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
            temp.setX(x);
            for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
                temp.setZ(z);
                BlockState bs = temp.getBlock().getState();
                bs.setType(Material.getMaterial(type.getFlag()));
                if (usedur.getFlag()) {
                    bs.getData().setData(dur.getFlag().byteValue());
                }
                bs.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Location(org.bukkit.Location)

Example 55 with Location

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

the class SetRegionCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        MinigamePlayer ply = Minigames.plugin.pdata.getMinigamePlayer((Player) sender);
        RegionModule rmod = RegionModule.getMinigameModule(minigame);
        if (args.length == 2) {
            if (args[0].equalsIgnoreCase("select")) {
                Location ploc = ply.getLocation();
                ploc.setY(ploc.getY() - 1);
                if (args[1].equals("1")) {
                    Location p2 = ply.getSelectionPoints()[1];
                    ply.clearSelection();
                    ply.setSelection(ploc, p2);
                    ply.sendMessage(ChatColor.GRAY + "Point 1 selected");
                } else {
                    Location p2 = ply.getSelectionPoints()[0];
                    ply.clearSelection();
                    ply.setSelection(p2, ploc);
                    ply.sendMessage(ChatColor.GRAY + "Point 2 selected");
                }
                return true;
            } else if (args[0].equalsIgnoreCase("create")) {
                if (ply.hasSelection()) {
                    String name = args[1];
                    rmod.addRegion(name, new Region(name, ply.getSelectionPoints()[0], ply.getSelectionPoints()[1]));
                    ply.clearSelection();
                    ply.sendMessage(ChatColor.GRAY + "Created new region for " + minigame.getName(false) + " named " + name);
                } else {
                    ply.sendMessage(ChatColor.RED + "You have not made a selection!");
                }
                return true;
            } else if (args[0].equalsIgnoreCase("delete")) {
                if (rmod.hasRegion(args[1])) {
                    rmod.removeRegion(args[1]);
                    ply.sendMessage(ChatColor.GRAY + "Removed the region named " + args[1] + " from " + minigame.getName(false));
                } else {
                    ply.sendMessage(ChatColor.GRAY + "No region by the name " + args[1] + " was found in " + minigame.getName(false));
                }
                return true;
            }
        } else if (args.length == 1) {
            if (args[0].equalsIgnoreCase("modify")) {
                rmod.displayMenu(ply, null);
                return true;
            }
        }
    }
    return false;
}
Also used : RegionModule(au.com.mineauz.minigamesregions.RegionModule) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Region(au.com.mineauz.minigamesregions.Region) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)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 Island (com.wasteofplastic.acidisland.Island)12