use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onDeath.
/**
* Handle player deaths.
*/
@EventHandler
public void onDeath(PlayerDeathEvent event) {
// Check if player was killed in an Arena
Player player = event.getEntity();
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
if (playerArena == null) {
player.setBedSpawnLocation(ConfigUtils.getSpawnLocation(), true);
return;
}
// Find killer and increment kills
if (player.getKiller() != null) {
MissileWarsPlayer killer = playerArena.getPlayerInArena(player.getKiller().getUniqueId());
killer.incrementKills();
ConfigUtils.sendConfigSound("player-kill", killer.getMCPlayer());
}
Component deathMessage = event.deathMessage();
event.setDeathMessage("");
// Count death if player is on a team
if (!playerArena.getTeam(player.getUniqueId()).equals("no team")) {
MissileWarsPlayer missileWarsPlayer = playerArena.getPlayerInArena(player.getUniqueId());
missileWarsPlayer.incrementDeaths();
for (Player p : player.getWorld().getPlayers()) {
p.sendMessage(deathMessage);
}
}
player.setBedSpawnLocation(playerArena.getPlayerSpawn(player), true);
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class ArenaGameruleListener method onEntityDamage.
/**
* Handle friendly fire.
*/
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
// Ensure we are handling a player in an arena
if (event.getEntityType() != EntityType.PLAYER) {
return;
}
Player player = (Player) event.getEntity();
ArenaManager arenaManager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena arena = arenaManager.getArena(player.getUniqueId());
if ((arena == null) || !arena.isRunning()) {
return;
}
// Check if player is damaged by a player
Player damager = null;
if (event.getDamager().getType() == EntityType.PLAYER) {
damager = (Player) event.getDamager();
} else if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
if (projectile.getShooter() instanceof Player) {
damager = (Player) projectile.getShooter();
}
}
if (damager == null) {
return;
}
// Stop event if damager and damaged are on same team
if (arena.getTeam(player.getUniqueId()).equalsIgnoreCase(arena.getTeam(damager.getUniqueId())) && !arena.getTeam(player.getUniqueId()).equalsIgnoreCase("no team")) {
event.setCancelled(true);
}
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class ArenaInventoryListener method selectArena.
/**
* Handle arena selection.
*/
@EventHandler
public void selectArena(InventoryClickEvent event) {
// Check if player is selecting an Arena
if (!(event.getWhoClicked() instanceof Player)) {
return;
}
Player player = (Player) event.getWhoClicked();
if (!selectingArena.contains(player)) {
return;
}
// Check for arena selection
event.setCancelled(true);
if (event.getClickedInventory() == null || !event.getClickedInventory().equals(event.getView().getTopInventory())) {
return;
}
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena selectedArena = manager.getArena(event.getSlot());
if (selectedArena == null) {
return;
}
// Attempt to send player to arena
if (selectedArena.joinPlayer(player)) {
player.closeInventory();
} else {
ConfigUtils.sendConfigMessage("messages.arena-full", player, selectedArena, null);
}
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class MissileWarsPlugin method onEnable.
@Override
public void onEnable() {
// Load instance
plugin = this;
// Register serializable data
ConfigurationSerialization.registerClass(Arena.class);
// Save data files
log("Loading and saving config files...");
saveDefaultConfig();
saveIfNotPresent("messages.yml");
saveIfNotPresent("sounds.yml");
saveIfNotPresent("items.yml");
saveIfNotPresent("maps.yml");
saveIfNotPresent("ranks.yml");
saveIfNotPresent("default.json");
log("Loaded all config files.");
// Load commands and events
log("Loading commands and events...");
getCommand("MissileWars").setExecutor(new MissileWarsCommand());
getCommand("Spectate").setExecutor(new SpectateCommand());
getCommand("VoteMap").setExecutor(new VoteMapCommand());
Bukkit.getPluginManager().registerEvents(new ArenaGameruleListener(), this);
Bukkit.getPluginManager().registerEvents(new ArenaInventoryListener(), this);
Bukkit.getPluginManager().registerEvents(new JoinLeaveListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomItemListener(), this);
Bukkit.getPluginManager().registerEvents(new WorldCreationListener(), this);
log("Commands and events loaded.");
// Load decks
log("Creating and loading deck items...");
deckManager = new DeckManager();
log("All deck items locked and loaded.");
// Load player deck cache
log("Starting player deck cache...");
jsonManager = new JSONManager(this);
log("Player deck cache loaded!");
// Load arenas
log("Loading up arenas...");
arenaManager = new ArenaManager(this);
arenaManager.loadArenas();
log("All arenas ready to go.");
// Load placeholders
log("Hooking into PlaceholderAPI...");
new MissileWarsPlaceholder().register();
log("All placeholders registered.");
// Load economy
log("Hooking into Vault...");
setupVault();
log("Economy setup complete.");
// Load MySQL
log("Setting up the MySQL database...");
setupDatabase();
log("MySQL setup complete.");
log("Missile Wars is ready to play :)");
}
use of com.leomelonseeds.missilewars.arenas.ArenaManager in project MissileWars by Leomelonseeds.
the class CustomItemListener method getPlayerArena.
/**
* Get the Arena the current player is in.
*
* @param player the player
* @return the Arena the player is in
*/
private Arena getPlayerArena(Player player) {
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena arena = manager.getArena(player.getUniqueId());
return arena;
}
Aggregations