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();
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations