Search in sources :

Example 21 with MinigamePlayer

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

the class RegionEvents method playerQuit.

@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
    if (RegionModule.getMinigameModule(event.getMinigame()) == null) {
        Minigames.debugMessage(event.getMinigame() + " called region event with no RegionModule loaded... was this intended?");
        return;
    }
    MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    Minigame mg = ply.getMinigame();
    for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
        if (r.hasPlayer(ply))
            r.removePlayer(ply);
    }
    for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
        node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
            node.setEnabled(true);
        }
    }
    for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
        if (region.playerInRegion(ply))
            region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (RegionExecutor exec : region.getExecutors()) {
                exec.clearTriggers();
            }
            region.removeTickTask();
            region.setEnabled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor) EventHandler(org.bukkit.event.EventHandler)

Example 22 with MinigamePlayer

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

the class EventsTest method onPlayerDisconnect.

public void onPlayerDisconnect() {
    PlayerMock mock = server.addPlayer();
    mock.setLocation(server.getWorld("GAMES").getSpawnLocation());
    PlayerJoinEvent event = new PlayerJoinEvent(mock, "Joined the Server");
    server.getPluginManager().callEvent(event);
    MinigamePlayer player = plugin.getPlayerManager().getMinigamePlayer(mock);
    JoinCommand command = new JoinCommand();
    String[] args = { game.getName(false) };
    command.onCommand(mock, game, "", args);
    assertTrue(player.isInMinigame());
    PlayerQuitEvent event2 = new PlayerQuitEvent(mock, "has left the game");
    server.getPluginManager().callEvent(event2);
    assertFalse(player.isInMinigame());
    assertFalse(plugin.getPlayerManager().hasMinigamePlayer(player.getUUID()));
}
Also used : PlayerMock(be.seeseemelk.mockbukkit.entity.PlayerMock) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) JoinCommand(au.com.mineauz.minigames.commands.JoinCommand)

Example 23 with MinigamePlayer

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

the class ScoreSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    if (player.isInMinigame() && player.getPlayer().isOnGround()) {
        Minigame mg = player.getMinigame();
        int score = Integer.parseInt(sign.getLine(2));
        if (!mg.isTeamGame()) {
            if (player.hasClaimedScore(sign.getLocation())) {
                player.sendMessage(MinigameUtils.getLang("sign.score.alreadyUsed"), MinigameMessageType.ERROR);
                return true;
            }
            player.addScore(score);
            mg.setScore(player, player.getScore());
            player.sendInfoMessage(MinigameUtils.formStr("sign.score.addScore", score, player.getScore()));
            if (mg.getMaxScore() != 0 && mg.getMaxScorePerPlayer() <= player.getScore()) {
                Minigames.getPlugin().getPlayerManager().endMinigame(player);
            }
            player.addClaimedScore(sign.getLocation());
        } else {
            TeamColor steam = TeamColor.matchColor(ChatColor.stripColor(sign.getLine(3)));
            Team pteam = player.getTeam();
            if (steam == null || !TeamsModule.getMinigameModule(mg).hasTeam(steam) || pteam.getColor() == steam) {
                if (Minigames.getPlugin().getMinigameManager().hasClaimedScore(mg, sign.getLocation(), 0)) {
                    player.sendMessage(MinigameUtils.getLang("sign.score.alreadyUsedTeam"), MinigameMessageType.ERROR);
                    return true;
                }
                player.addScore(score);
                mg.setScore(player, player.getScore());
                pteam.addScore(score);
                player.sendInfoMessage(MinigameUtils.formStr("sign.score.addScoreTeam", score, pteam.getChatColor().toString() + pteam.getScore()));
                Minigames.getPlugin().getMinigameManager().addClaimedScore(mg, sign.getLocation(), 0);
                if (mg.getMaxScore() != 0 && mg.getMaxScorePerPlayer() <= pteam.getScore()) {
                    List<MinigamePlayer> winners = new ArrayList<>(pteam.getPlayers());
                    List<MinigamePlayer> losers = new ArrayList<>(mg.getPlayers().size() - pteam.getPlayers().size());
                    for (Team t : TeamsModule.getMinigameModule(mg).getTeams()) {
                        if (t != pteam)
                            losers.addAll(t.getPlayers());
                    }
                    Minigames.getPlugin().getPlayerManager().endMinigame(mg, winners, losers);
                }
            }
        }
    } else if (player.isInMinigame() && !player.getPlayer().isOnGround()) {
        player.sendMessage(MinigameUtils.getLang("sign.onGround"), MinigameMessageType.ERROR);
    }
    return true;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 24 with MinigamePlayer

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

the class MinigameTool method openMenu.

public void openMenu(MinigamePlayer player) {
    Menu men = new Menu(2, "Set Tool Mode", player);
    final MenuItemCustom miselect = new MenuItemCustom("Select", MinigameUtils.stringToList("Selects and area;or points visually"), Material.DIAMOND_BLOCK);
    final MenuItemCustom mideselect = new MenuItemCustom("Deselect", MinigameUtils.stringToList("Deselects an;area or points"), Material.GLASS);
    final MinigamePlayer fply = player;
    miselect.setClick(object -> {
        if (mode != null) {
            mode.select(fply, minigame, TeamsModule.getMinigameModule(minigame).getTeam(team));
        }
        return miselect.getItem();
    });
    mideselect.setClick(object -> {
        if (mode != null) {
            mode.deselect(fply, minigame, TeamsModule.getMinigameModule(minigame).getTeam(team));
        }
        return mideselect.getItem();
    });
    men.addItem(mideselect, men.getSize() - 1);
    men.addItem(miselect, men.getSize() - 2);
    List<String> teams = new ArrayList<>(TeamColor.values().length + 1);
    for (TeamColor col : TeamColor.values()) teams.add(MinigameUtils.capitalize(col.toString().replace("_", " ")));
    teams.add("None");
    men.addItem(new MenuItemToolTeam("Team", Material.PAPER, new Callback<String>() {

        @Override
        public String getValue() {
            if (getTeam() != null)
                return MinigameUtils.capitalize(getTeam().toString().replace("_", " "));
            return "None";
        }

        @Override
        public void setValue(String value) {
            setTeam(TeamColor.matchColor(value.replace(" ", "_")));
        }
    }, teams), men.getSize() - 3);
    for (ToolMode m : ToolModes.getToolModes()) {
        men.addItem(new MenuItemToolMode(m.getDisplayName(), MinigameUtils.stringToList(m.getDescription()), m.getIcon(), m));
    }
    men.displayMenu(player);
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor)

Example 25 with MinigamePlayer

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

the class MinigamesTest method onQuitMinigame.

@Test
public void onQuitMinigame() {
    plugin.getPlayerManager().addMinigamePlayer(player);
    MinigamePlayer mplayer = plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId());
    plugin.getPlayerManager().joinMinigame(mplayer, game, false, 0D);
    player.assertLocation(lobby, 0);
    Assert.assertTrue(plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId()).isInMinigame());
    plugin.getPlayerManager().quitMinigame(plugin.getPlayerManager().getMinigamePlayer(player), false);
    player.assertLocation(quit, 0);
    assertFalse(plugin.getPlayerManager().getMinigamePlayer(player.getUniqueId()).isInMinigame());
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Test(org.junit.Test)

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