Search in sources :

Example 86 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class RegionEvents method blockBreak.

@EventHandler(ignoreCancelled = true)
private void blockBreak(BlockBreakEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        final Location loc2 = event.getBlock().getLocation();
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
            if (!ply.isInMinigame()) {
                return;
            }
            for (Node node : RegionModule.getMinigameModule(ply.getMinigame()).getNodes()) {
                if (node.getLocation().getWorld() == loc2.getWorld()) {
                    Location loc1 = node.getLocation();
                    if (loc1.getBlockX() == loc2.getBlockX() && loc1.getBlockY() == loc2.getBlockY() && loc1.getBlockZ() == loc2.getBlockZ()) {
                        node.execute(Triggers.getTrigger("BLOCK_BREAK"), ply);
                    }
                }
            }
            for (Region region : RegionModule.getMinigameModule(ply.getMinigame()).getRegions()) {
                if (region.locationInRegion(loc2)) {
                    region.execute(Triggers.getTrigger("BLOCK_BREAK"), ply);
                }
            }
        });
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 87 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class BasicRecorder method blockPlace.

@EventHandler(priority = EventPriority.HIGH)
private void blockPlace(BlockPlaceEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && !event.isCancelled()) {
        if (!ply.getMinigame().hasStarted() || ply.isLatejoining()) {
            event.setCancelled(true);
            return;
        }
        Minigame mgm = ply.getMinigame();
        RecorderData d = mgm.getBlockRecorder();
        if (((d.getWhitelistMode() && d.getWBBlocks().contains(event.getBlock().getType())) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(event.getBlock().getType()))) && mgm.canBlockPlace()) {
            d.addBlock(event.getBlockReplacedState(), ply);
        } else {
            event.setCancelled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 88 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class BasicRecorder method paintingPlace.

@EventHandler(ignoreCancelled = true)
private void paintingPlace(HangingPlaceEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply.isInMinigame()) {
        Minigame mgm = ply.getMinigame();
        RecorderData d = mgm.getBlockRecorder();
        if (((d.getWhitelistMode() && d.getWBBlocks().contains(Material.PAINTING)) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(Material.PAINTING))) || ((d.getWhitelistMode() && d.getWBBlocks().contains(Material.ITEM_FRAME)) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(Material.ITEM_FRAME)))) {
            d.addEntity(event.getEntity(), ply, true);
        } else {
            event.setCancelled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 89 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class EditCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        if (plugin.getMinigameManager().hasMinigame(args[0])) {
            Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]);
            if (mgm == null) {
                plugin.getLogger().warning("The Minigame requested has a configuration" + " problem and is returning nulls");
                return false;
            }
            MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
            // noinspection ConstantConditions sanity check
            if (player == null) {
                plugin.getLogger().warning("Player is null");
                Thread.dumpStack();
                return false;
            }
            mgm.displayMenu(player);
        } else {
            sender.sendMessage(ChatColor.RED + "There is no Minigame by the name " + args[0]);
        }
        return true;
    }
    return false;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 90 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class EndCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args == null && sender instanceof Player) {
        MinigamePlayer ply = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
        if (ply.isInMinigame()) {
            forceEnd(sender, ply);
        } else {
            sender.sendMessage(ChatColor.RED + "Error: You are not in a minigame!");
        }
        return true;
    } else if (args != null) {
        Player player = null;
        if (sender instanceof Player) {
            player = (Player) sender;
        }
        if (player == null || player.hasPermission("minigame.end.other")) {
            Player playertoEnd = Bukkit.getPlayerExact(args[0]);
            MinigamePlayer ply = null;
            Team team = null;
            Minigame mgm = null;
            if (args.length == 2 && plugin.getMinigameManager().hasMinigame(args[1])) {
                TeamColor color = TeamColor.matchColor(args[0]);
                mgm = plugin.getMinigameManager().getMinigame(args[1]);
                if (mgm == null) {
                    sender.sendMessage(ChatColor.RED + "No minigme found by the name " + args[1]);
                    return true;
                }
                if (TeamsModule.getMinigameModule(mgm).hasTeam(color)) {
                    team = TeamsModule.getMinigameModule(mgm).getTeam(color);
                } else {
                    sender.sendMessage(ChatColor.RED + "No team found by the name " + args[0] + " in " + mgm.getName(false));
                    return true;
                }
            } else if (args.length == 2 && !plugin.getMinigameManager().hasMinigame(args[1])) {
                sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[1]);
                return true;
            } else if (playertoEnd != null) {
                ply = plugin.getPlayerManager().getMinigamePlayer(playertoEnd);
            } else {
                sender.sendMessage(ChatColor.RED + "No player found by the name " + args[0]);
                return true;
            }
            if (ply != null && ply.isInMinigame()) {
                forceEnd(sender, ply);
            } else if (args.length >= 2 && team != null && mgm != null) {
                if (mgm.hasPlayers()) {
                    List<MinigamePlayer> w = new ArrayList<>(team.getPlayers());
                    int lcount = 0;
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        if (t != team) {
                            lcount += t.getPlayers().size();
                        }
                    }
                    List<MinigamePlayer> l = new ArrayList<>(lcount);
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        if (t != team) {
                            l.addAll(t.getPlayers());
                        }
                    }
                    plugin.getPlayerManager().endMinigame(mgm, w, l);
                    sender.sendMessage(ChatColor.GRAY + "You forced " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + " to win the Minigame.");
                } else {
                    sender.sendMessage(ChatColor.RED + "This Minigame has no players!");
                }
            } else {
                sender.sendMessage(ChatColor.RED + "This player is not playing a Minigame.");
            }
        } else if (player != null) {
            sender.sendMessage(ChatColor.RED + "Error: You don't have permission to force end another players Minigame!");
            sender.sendMessage(ChatColor.RED + "minigame.end.other");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Aggregations

MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)134 EventHandler (org.bukkit.event.EventHandler)46 Minigame (au.com.mineauz.minigames.minigame.Minigame)40 ArrayList (java.util.ArrayList)25 Team (au.com.mineauz.minigames.minigame.Team)24 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)15 Player (org.bukkit.entity.Player)15 Location (org.bukkit.Location)11 ItemStack (org.bukkit.inventory.ItemStack)8 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)7 Menu (au.com.mineauz.minigames.menu.Menu)5 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)5 List (java.util.List)5 PotionEffect (org.bukkit.potion.PotionEffect)5 ResourcePack (au.com.mineauz.minigames.objects.ResourcePack)4 Material (org.bukkit.Material)4 Sign (org.bukkit.block.Sign)4 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)3 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)2