Search in sources :

Example 11 with MissileWarsPlayer

use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.

the class Arena method removePlayer.

/**
 * Remove a player with a given UUID from the arena.
 *
 * @param uuid the UUID of the player
 */
public void removePlayer(UUID uuid) {
    // Remove player from all teams and queues
    MissileWarsPlayer toRemove = new MissileWarsPlayer(uuid);
    players.remove(toRemove);
    if (playerVotes != null && playerVotes.containsKey(uuid)) {
        String toChange = playerVotes.get(uuid);
        mapVotes.put(toChange, mapVotes.get(toChange) - (Bukkit.getPlayer(uuid).hasPermission("umw.extravote") ? 2 : 1));
        playerVotes.remove(uuid);
    }
    for (MissileWarsPlayer mwPlayer : players) {
        ConfigUtils.sendConfigMessage("messages.leave-arena-others", mwPlayer.getMCPlayer(), null, toRemove.getMCPlayer());
    }
    // Cancel tasks if starting and below min players
    int minPlayers = MissileWarsPlugin.getPlugin().getConfig().getInt("minimum-players");
    if (!running && startTime != null && players.size() < minPlayers) {
        for (BukkitTask task : tasks) {
            task.cancel();
        }
        startTime = null;
    }
    spectators.remove(toRemove);
    blueQueue.remove(toRemove);
    redQueue.remove(toRemove);
    if (redTeam != null) {
        redTeam.removePlayer(toRemove);
        blueTeam.removePlayer(toRemove);
    }
    // Run proper clearing commands on the player
    Arena arena = this;
    new BukkitRunnable() {

        @Override
        public void run() {
            Player mcPlayer = toRemove.getMCPlayer();
            if (mcPlayer != null) {
                mcPlayer.teleport(ConfigUtils.getSpawnLocation());
                mcPlayer.setGameMode(GameMode.ADVENTURE);
                mcPlayer.setHealth(20);
                InventoryUtils.loadInventory(mcPlayer);
                ConfigUtils.sendConfigMessage("messages.leave-arena", mcPlayer, arena, null);
                RankUtils.setPlayerExpBar(mcPlayer);
                // Notify discord
                TextChannel discordChannel = DiscordSRV.getPlugin().getMainTextChannel();
                discordChannel.sendMessage(":arrow_forward: " + mcPlayer.getName() + " rejoined lobby from arena " + arena.getName()).queue();
                for (Player player : Bukkit.getWorld("world").getPlayers()) {
                    ConfigUtils.sendConfigMessage("messages.leave-arena-lobby", player, null, mcPlayer);
                }
            }
        }
    }.runTaskLater(MissileWarsPlugin.getPlugin(), 1L);
    checkEmpty();
}
Also used : Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) TextChannel(github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 12 with MissileWarsPlayer

use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.

the class Arena method getPositionInQueue.

/**
 * Get the position in queue of a certain player with a given UUID.
 *
 * @param uuid the uuid to check for
 * @return the position in queue of a certain player with a given UUID or -1 if they are not in a queue
 */
public int getPositionInQueue(UUID uuid) {
    // Check red queue
    int pos = 1;
    for (MissileWarsPlayer player : redQueue) {
        if (player.getMCPlayerId().equals(uuid)) {
            return pos;
        }
        pos++;
    }
    // Check blue queue
    pos = 1;
    for (MissileWarsPlayer player : blueQueue) {
        if (player.getMCPlayerId().equals(uuid)) {
            return pos;
        }
        pos++;
    }
    return -1;
}
Also used : MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer)

Example 13 with MissileWarsPlayer

use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.

the class SpectateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    // Ensure sender is a Player
    if (!(sender instanceof Player)) {
        sendErrorMsg(sender, "You must be a player");
        return true;
    }
    Player player = (Player) sender;
    // Try to find Arena
    ArenaManager arenaManager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = arenaManager.getArena(player.getUniqueId());
    if (arena == null) {
        sendErrorMsg(player, "You are not in an arena!");
        return true;
    }
    // Check if player is currently spectating
    MissileWarsPlayer missileWarsPlayer = arena.getPlayerInArena(player.getUniqueId());
    if (arena.isSpectating(missileWarsPlayer)) {
        arena.removeSpectator(missileWarsPlayer);
        return true;
    }
    // Allow player to spectate
    arena.addSpectator(player.getUniqueId());
    return true;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Example 14 with MissileWarsPlayer

use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.

the class ArenaInventoryListener method onItemPickup.

/**
 * Manage item pickups.
 */
@EventHandler
public void onItemPickup(EntityPickupItemEvent event) {
    // Check if player is in Arena
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getEntity();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null) {
        return;
    }
    MissileWarsPlayer mwPlayer = arena.getPlayerInArena(player.getUniqueId());
    // Cancel event if player cannot pick up item based on their given deck
    if (mwPlayer.getDeck() != null && !mwPlayer.getDeck().hasInventorySpace(mwPlayer.getMCPlayer())) {
        event.setCancelled(true);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 15 with MissileWarsPlayer

use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.

the class ArenaInventoryListener method onItemDrop.

/**
 * Manage item dropping.
 */
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
    // Check if player is in Arena
    Player player = event.getPlayer();
    ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
    Arena arena = manager.getArena(player.getUniqueId());
    if (arena == null) {
        return;
    }
    // Stop drops entirely if player not on team
    if ((arena.getTeam(player.getUniqueId()).equals("no team"))) {
        event.setCancelled(true);
        return;
    }
    // Stop drops of gear items
    MissileWarsPlayer mwPlayer = arena.getPlayerInArena(player.getUniqueId());
    if (mwPlayer.getDeck().getGear().contains(event.getItemDrop().getItemStack())) {
        event.setCancelled(true);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MissileWarsPlayer (com.leomelonseeds.missilewars.teams.MissileWarsPlayer)15 Player (org.bukkit.entity.Player)9 Arena (com.leomelonseeds.missilewars.arenas.Arena)4 ArenaManager (com.leomelonseeds.missilewars.arenas.ArenaManager)4 TextChannel (github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel)3 EventHandler (org.bukkit.event.EventHandler)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 MissileWarsPlugin (com.leomelonseeds.missilewars.MissileWarsPlugin)2 LinkedList (java.util.LinkedList)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 BukkitTask (org.bukkit.scheduler.BukkitTask)2 MissileWarsTeam (com.leomelonseeds.missilewars.teams.MissileWarsTeam)1 SQLManager (com.leomelonseeds.missilewars.utilities.SQLManager)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Random (java.util.Random)1 UUID (java.util.UUID)1