Search in sources :

Example 1 with IslandJoinEvent

use of com.wasteofplastic.acidisland.events.IslandJoinEvent in project acidisland by tastybento.

the class IslandCmd method addPlayertoTeam.

/**
 * Adds a player to a team. The player and the teamleader MAY be the same
 *
 * @param playerUUID - the player's UUID
 * @param teamLeader
 * @return true if the player is successfully added
 */
public boolean addPlayertoTeam(final UUID playerUUID, final UUID teamLeader) {
    // location
    if (!plugin.getPlayers().setJoinTeam(playerUUID, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader))) {
        return false;
    }
    // if it exists, and if not set to the island location
    if (!playerUUID.equals(teamLeader)) {
        // Clear any old home locations
        plugin.getPlayers().clearHomeLocations(playerUUID);
        // Set homes and spawn point home locations if they exist
        for (Entry<Integer, Location> homes : plugin.getPlayers().getHomeLocations(teamLeader).entrySet()) {
            if (homes.getKey() < 2) {
                plugin.getPlayers().setHomeLocation(playerUUID, homes.getValue(), homes.getKey());
            }
        }
        if (plugin.getPlayers().getHomeLocation(teamLeader, 1) == null) {
            plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getIslandLocation(teamLeader));
        // plugin.getLogger().info("DEBUG: Setting player's home to the team island location");
        }
        // If the leader's member list does not contain player then add it
        if (!plugin.getPlayers().getMembers(teamLeader).contains(playerUUID)) {
            plugin.getPlayers().addTeamMember(teamLeader, playerUUID);
        }
        // add it
        if (!plugin.getPlayers().getMembers(teamLeader).contains(teamLeader)) {
            plugin.getPlayers().addTeamMember(teamLeader, teamLeader);
        }
        // Fire event
        final Island island = plugin.getGrid().getIsland(teamLeader);
        final IslandJoinEvent event = new IslandJoinEvent(playerUUID, island);
        plugin.getServer().getPluginManager().callEvent(event);
    }
    return true;
}
Also used : IslandJoinEvent(com.wasteofplastic.acidisland.events.IslandJoinEvent) Island(com.wasteofplastic.acidisland.Island) Location(org.bukkit.Location)

Aggregations

Island (com.wasteofplastic.acidisland.Island)1 IslandJoinEvent (com.wasteofplastic.acidisland.events.IslandJoinEvent)1 Location (org.bukkit.Location)1