Search in sources :

Example 1 with ArenaManager

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);
}
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) Component(net.kyori.adventure.text.Component) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ArenaManager

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);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ArenaManager

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);
    }
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Player(org.bukkit.entity.Player) MissileWarsPlayer(com.leomelonseeds.missilewars.teams.MissileWarsPlayer) Arena(com.leomelonseeds.missilewars.arenas.Arena) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ArenaManager

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 :)");
}
Also used : ArenaGameruleListener(com.leomelonseeds.missilewars.listener.ArenaGameruleListener) ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) JSONManager(com.leomelonseeds.missilewars.utilities.JSONManager) MissileWarsPlaceholder(com.leomelonseeds.missilewars.utilities.MissileWarsPlaceholder) JoinLeaveListener(com.leomelonseeds.missilewars.listener.JoinLeaveListener) VoteMapCommand(com.leomelonseeds.missilewars.commands.VoteMapCommand) ArenaInventoryListener(com.leomelonseeds.missilewars.listener.ArenaInventoryListener) DeckManager(com.leomelonseeds.missilewars.decks.DeckManager) CustomItemListener(com.leomelonseeds.missilewars.listener.CustomItemListener) WorldCreationListener(com.leomelonseeds.missilewars.listener.WorldCreationListener) MissileWarsCommand(com.leomelonseeds.missilewars.commands.MissileWarsCommand) SpectateCommand(com.leomelonseeds.missilewars.commands.SpectateCommand)

Example 5 with ArenaManager

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;
}
Also used : ArenaManager(com.leomelonseeds.missilewars.arenas.ArenaManager) Arena(com.leomelonseeds.missilewars.arenas.Arena)

Aggregations

ArenaManager (com.leomelonseeds.missilewars.arenas.ArenaManager)16 Arena (com.leomelonseeds.missilewars.arenas.Arena)15 Player (org.bukkit.entity.Player)13 EventHandler (org.bukkit.event.EventHandler)10 MissileWarsPlayer (com.leomelonseeds.missilewars.teams.MissileWarsPlayer)9 JSONObject (org.json.JSONObject)2 MissileWarsPlugin (com.leomelonseeds.missilewars.MissileWarsPlugin)1 MissileWarsCommand (com.leomelonseeds.missilewars.commands.MissileWarsCommand)1 SpectateCommand (com.leomelonseeds.missilewars.commands.SpectateCommand)1 VoteMapCommand (com.leomelonseeds.missilewars.commands.VoteMapCommand)1 DeckManager (com.leomelonseeds.missilewars.decks.DeckManager)1 ArenaGameruleListener (com.leomelonseeds.missilewars.listener.ArenaGameruleListener)1 ArenaInventoryListener (com.leomelonseeds.missilewars.listener.ArenaInventoryListener)1 CustomItemListener (com.leomelonseeds.missilewars.listener.CustomItemListener)1 JoinLeaveListener (com.leomelonseeds.missilewars.listener.JoinLeaveListener)1 WorldCreationListener (com.leomelonseeds.missilewars.listener.WorldCreationListener)1 MissileWarsTeam (com.leomelonseeds.missilewars.teams.MissileWarsTeam)1 JSONManager (com.leomelonseeds.missilewars.utilities.JSONManager)1 MissileWarsPlaceholder (com.leomelonseeds.missilewars.utilities.MissileWarsPlaceholder)1 DecimalFormat (java.text.DecimalFormat)1